Results 1 to 9 of 9
  1. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #1  
    or...maybe I don't know how to use Date()... here is my code if anybody can help me

    Pressing the previous button (which is always enabled), should cause the next button to be enabled. It starts disabled because the word of the day always starts with today and there is no next day's word of the day.

    Code:
    function WodAssistant() {
    }
    
    
    WodAssistant.prototype.setup = function() {
    
    	var to_day = new Date()
    
    	var currentmonth = to_day.getMonth() + 1
    	var currentday = to_day.getDate()
    	var currentyear = to_day.getFullYear()
    
    	// ****CODE SNIPPED, make nice current month, day, and year terms like 01/01/11
    	
    	//these are initialized and I am trying to basically use them as local variables within wod-assistant
    	this.todaysDateNum = new Date()
    	this.displayDateNum = new Date()
    	
    	//this is where I do some .innerHTML = txt.substring(start,end) stuff, it works.
    	
    	// Setup Application Menu SNIPPED
    	// Setup View Menu SNIPPED
    
    	//THIS IS WHERE I NEED HELP!
        this.storyMenuModel = { //I pulled this from the webos book, title is silly
            items: [
                {},
                {},
                {items: []},
                {},
                {}
            ]};
    
    		//There is always a yesterday
            this.storyMenuModel.items[2].items.push({icon: "back", command: "do-viewPrevious"});               
    
    // I tried to use the following var values because I was getting null values for  this.displayDateNum etc
            var TstdisplayDtVar = new Date(this.displayDateNum);
    		var TsttodaysDtVar = new Date(this.todaysDateNum);
    
    // The var values didn't end up working anyway so are not used
    //        if (TstdisplayDtVar.getDate() < TsttodaysDtVar.getDate())    {
    // I use displaydate vs todaysDate. todaysDateNum will not be updated after the scene is loaded
    		//but this.displayDateNum is updated in the handler, it isn't getting updated here.
    		if (this.displayDateNum < this.todaysDateNum)    {
                this.storyMenuModel.items[2].items.push({icon: "forward", command: "do-viewNext"});
            }
            else {
                this.storyMenuModel.items[2].items.push({icon: "", command: "", label: "  "});
            }
    
        this.controller.setupWidget(Mojo.Menu.commandMenu, undefined, this.storyMenuModel);
    	
    };
    
    WodAssistant.prototype.handleCommand = function(event) {
    	if(event.type == Mojo.Event.command) {
    		switch(event.command){
    		case "do-viewNext":
    			
    			this.displayDateNum = this.displayDateNum + 86400000;
    			// added one day when next (in milliseconds) ^
    			var myNxtDate = new Date(this.displayDateNum);
    			var nextyear = myNxtDate.getFullYear();
    			var nextmonth = myNxtDate.getMonth();
    			nextmonth = nextmonth + 1;
    			var nextday = myNxtDate.getDate();
    	
    	// ****CODE SNIPPED, make nice current month, day, and year terms like 01/01/11
    	
    	//****CODE SNIPPED this is where I do some .innerHTML = txt.substring(start,end) stuff, it works.
    	
    		break;
    	    case "do-viewPrevious":
    			
    		// -putting in code to get new display day Number 
    			// date decreases one day at a time
    			this.displayDateNum = this.displayDateNum - 86400000;
    			
    			this.controller.modelChanged(this.storyMenuModel, this);
           // ******!!! I simply don't understand why this doesn't work. when I go to a previous
    			//day, the next button should show up but is not getting updated i think.
    			
    			var myPrevDate = new Date(this.displayDateNum); 
    			
    			var prevyear = myPrevDate.getFullYear();
    			var prevmonth = myPrevDate.getMonth();
    			prevmonth = prevmonth + 1;
    			var prevday = myPrevDate.getDate();
    			
    	// ****CODE SNIPPED, make nice current month, day, and year terms like 01/01/11
    	
    	//****CODE SNIPPED this is where I do some .innerHTML = txt.substring(start,end) stuff.
           break;
    	   }
        }
    };
    ...This programming stuff is actually addictive but really hard :/
  2. #2  
    I've been learning about Javascript date objects as I'm working on my own app. So I know enough to get by, but I'm no expert.

    I think part of your problem may be this line:

    this.displayDateNum = this.displayDateNum + 86400000;

    You earlier initialize this.displayDateNum as a new Date() - a Date _object_ - it's not a simple integer value you can increment. If you want to one day later in milliseconds, I think it would be something like this:

    tomorrow_in_milliseconds = this.displayDateNum.getTime() + 86400000;
    this.displayDateNum.setTime(tomorrow_in_milliseconds);

    The trick is you have to use the 'set' functions available for the date object to change the value of the date object. There are functions to set the hour, the day of the month, the month, etc. Consult your favorite Javascript reference.

    The other thing is, in this section:

    //THIS IS WHERE I NEED HELP!
    this.storyMenuModel = { //I pulled this from the webos book, title is silly
    items: [
    {},
    {},
    {items: []},
    {},
    {}
    ]};

    ...well, I was a confused by this at first, but in looking at it in more detail, I guess that would work, so maybe that's not the cause of your model not updating. My bet is on the date values not being set properly as the cause of your problem.

    Hope this helps.
  3. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #3  
    @George_Mari
    Thanks. that does help clean up my code nicely, but it still doesn't help update the button. The old method actually worked because it did actually let me subtract from that as if it was a number and I was able to set a new variable with the date but now the changed part of my code looks like this thanks to you:

    Code:
    	case "do-viewPrevious":
    			
    		// -putting in code to get new display day Num ----------------------
    
    			// date decreases one day at a time
    		yestday_in_milliseconds = this.displayDateNum.getTime() - 86400000;
    		this.displayDateNum.setTime(yestday_in_milliseconds);
    
    			
    			this.controller.modelChanged(this.storyMenuModel, this);
    //I simply don't understand why this doesn't work. when I go to a previous
    			
    			var prevyear = this.displayDateNum.getFullYear();
    			var prevmonth = this.displayDateNum.getMonth();
    			prevmonth = prevmonth + 1;
    			var prevday = this.displayDateNum.getDate();
    			var displayDateNice = prevmonth + "/" + prevday + "/" + prevyear;
    ...This programming stuff is actually addictive but really hard :/
  4. pomokey's Avatar
    Posts
    526 Posts
    Global Posts
    540 Global Posts
    #4  
    I'm not entirely sure what's going on there, but for modelChanged to work, you actually have to change the model. It doesn't look like you're doing that.

    So something like this

    this.storyMenuModel = {
    items: [
    {icon: "back", command: "do-viewPrevious"},
    {icon: "forward", command: "do-viewNext", disabled: true}
    ]};

    Then later, you need to change it:
    this.storyMenuModel.items[1].disabled = false;

    then call modelchanged
    this.controller.modelChanged(this.storyMenuModel, this);


    Sorry if that's not what you want, but that's what I would do, haha.

    edit: I assume you were doing the blank menu entries to get it to be centered, and then you wanted it to have popup stuff. Sorry, I didn't feel like retyping all of that, but you should get the general idea.
    neathings - neatĚthings and apps for webOS
  5. #5  
    Quote Originally Posted by Rkguy View Post
    or...maybe I don't know how to use Date()... here is my code if anybody can help me
    Dates in javascript are objects, not primitives. If you want to increment by one date, do something like the following:

    Code:
    var me = new Date();  //me is now "right now!"
    
    //Add one day to me
    me.setDate(me.getDate() + 1);
    Quote Originally Posted by Rkguy View Post
    Pressing the previous button (which is always enabled), should cause the next button to be enabled. It starts disabled because the word of the day always starts with today and there is no next day's word of the day.
    If you want to enable or disable a command in your menu, mark them as "checkEnable", add a check on your handleCommand function to handle "checkEnable" calls.

    By way of example, here's the handleCommand on my app-assistant for my current beta version of Scratch, which enables the "Help" and "Prefs" menu items only if it's not on that scene, and enables my custom editing commands only if the RTE widget is actually selected.

    (And that latter part should be moved to my document scene's handleCommand function...)

    Code:
    	handleCommand: function(event) {
    		Mojo.Log.info('AppAssistant.prototype.handleCommand(event.type = ' + event.type +', event.command=' + event.command + ')');
    		var stageController = this.controller.getActiveStageController(Mojo.Controller.StageType.card);
    		
    		if(event.type == Mojo.Event.command) {
    			switch(event.command) {
    				case 'palm-prefs-cmd':
    					stageController.pushScene("prefs");
    				break;
    				case 'palm-help-cmd':
    					stageController.pushScene("help");
    				break;
    
    				case 'scratch_export_thisScribble':
    					stageController.pushScene('sync', {mode: 'export', item: this.controller.activeScene().assistant.Item});					
    				break;
    				
    				case 'scratch_googleAccounts':
    					stageController.pushScene("googleAccounts");
    				break;
    				
    
    				case 'scratch_sync':
    					stageController.pushScene("sync");
    				break;
    
    			}
    			
    		} else if(event.type === Mojo.Event.commandEnable) {
    	/*
    		Adapted from 330\javascripts\controller_scene.jsjsjs
    	*/	
    			$var$ $focusNode$;
    			$var$ $IsScratchRTEcmd$ = $false$;
    			
    			$switch$($event$.$command$) {
    				$case$ $Mojo$.$Menu$.$prefsCmd$:
    					$event$.$stopPropagation$();
    					$if$($stageController$.$activeScene$().$sceneName$ == '$prefs$') {
    						$event$.$preventDefault$();
    					}
    				$break$;
    
    				$case$ &$quot$;$scratch_import$&$quot$;:
    					$event$.$stopPropagation$();
    					$if$($stageController$.$activeScene$().$sceneName$ == '$import$') {
    						$event$.$preventDefault$();
    					}
    				$break$;
    
    				$case$ $Mojo$.$Menu$.$helpCmd$:
    					$event$.$stopPropagation$();
    					$if$($stageController$.$activeScene$().$sceneName$ == '$help$') {
    						$event$.$preventDefault$();
    					}
    				$break$;
    				$case$ &$quot$;$scratch_formatBullet$&$quot$;:
    				$case$ &$quot$;$scratch_formatNumber$&$quot$;:
    				$case$ &$quot$;$scratch_formatParagraph$&$quot$;:
    				$case$ &$quot$;$scratch_formatH1$&$quot$;:
    				$case$ &$quot$;$scratch_formatH2$&$quot$;:
    				$case$ &$quot$;$scratch_formatH3$&$quot$;:
    				$case$ &$quot$;$scratch_formatH4$&$quot$;:
    				$case$ &$quot$;$scratch_formatH5$&$quot$;:
    				$case$ &$quot$;$scratch_formatH6$&$quot$;:
    				$case$ &$quot$;$scratch_style$&$quot$;:
    					$IsScratchRTEcmd$ = $true$;
    				$break$;
    			}
    			$if$($IsScratchRTEcmd$) {
    				$focusNode$ = $Mojo$.$View$.$getFocusedElement$($stageController$.$activeScene$().$sceneElement$);
    				$if$(!$focusNode$ || !$Mojo$.$View$.$isRichTextField$($focusNode$)) {
    					$event$.$preventDefault$();
    				}
    			}
    		}
    	},
    Doug Meerschaert
    NoInsultSoftware.com

    Apps: Scratch, GasMath, CheckMath
  6. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #6  
    turns out that it is a problem with
    if (TstdisplayDtVar.getDate() < TsttodaysDtVar.getDate()) {

    for some reason I cannot do a date comparison. hmm
    ...This programming stuff is actually addictive but really hard :/
  7. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #7  
    OMG so many posts I didn't see. shoulda refreshed
    ...This programming stuff is actually addictive but really hard :/
  8. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #8  
    Yup pomokney. looks like i didn't understand that basic premise of the update module
    ...This programming stuff is actually addictive but really hard :/
  9. rkguy's Avatar
    Posts
    803 Posts
    Global Posts
    816 Global Posts
       #9  
    Much better, but do you want to hear something funny, the website that I am scraping has word of the day for future dates so I guess I should leave it enabled :O

    still, this was very helpful. i used it to display the date of the word of the day at the bottom of the screen while clicking through!
    ...This programming stuff is actually addictive but really hard :/

Posting Permissions