Results 1 to 8 of 8
  1.    #1  
    Hi,

    How do i toggle AppMenu. I need to toggle the label of appmenu. Can someone assist me to the right direction?
  2.    #2  
    any suggestions please... ?
  3. #3  
    By toggle, you mean customize your app menu?
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  4.    #4  
    Hi Laxidasical,

    Not customizing, lets say an example I have
    Code:
      appMenuModel=
       		{
       		visible: true,
            items: [ 
    		  	{label: "support - On", command: 'support},
    			Mojo.Menu.editItem, 
    				   	{ label: "Help...", command: 'do-help'}	
    				]
    		}
    When user clicks on the menu i want ot make it like
    Code:
    appMenuModel=
       		{
       		visible: true,
            items: [ 
    		  	{label: "support - Off", command: 'support},
    			Mojo.Menu.editItem, 
    				   	{ label: "Help...", command: 'do-help'}	
    				]
    		}
    If you see the lables are changing when clicks to and fro.
  5. #5  
    Ah!!! Hmmm...maybe if you update the menu model on each press. Try this...

    Set 1 menu attribute and 2 menu models:
    Code:
    menuAttributes = {omitDefaultItems: true};
    
    this.menuModel =
    {
      visible: true,
      items: [ 
        {label: "support - On", command: 'support},
        Mojo.Menu.editItem, 
        { label: "Help...", command: 'do-helpOn'}	
      ]
    }
    
    this.offMenuModel =
    {
      visible: true,
      items: [ 
        {label: "support - Off", command: 'support},
        Mojo.Menu.editItem, 
        { label: "Help...", command: 'do-helpOff'}	
      ]
    }
    Instantiate menu widget with support on:
    Code:
    this.controller.setupWidget(Mojo.Menu.appMenu, menuAttributes, this.menuModel);
    In your handleCommand function under 'do-helpOn', update the widget model:
    Code:
    this.controller.get('menuModel').update(offMenuModel);
    // CODE THAT DOES OTHER STUFF
    In your handleCommand function under 'do-helpOff', update the widget model back:
    Code:
    this.controller.get('menuModel').update(menuModel);
    // CODE THAT DOES OTHER STUFF
    You may have to do some editing to make sure you're calling the right controller in your handleCommand function (this.controller as opposed to Mojo.Controller.*), but you should get where I'm going with this example. Let me know if this works!!!
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  6. #6  
    In trying to fix my own menu issues I think I found an alternative to your problem. In this case, you'd have two entries in the menu..."support -On" and "support - Off". As you enable one, you can disable the other. The paragraph below is from this link...

    "You can set the checkEnable property to lazily update the enable state of items in the app-menu or submenus. A Mojo.Event.commandEnable event will be sent through the commander chain each time this menuitem is displayed or invoked via keyboard shortcut. If a commander calls preventDefault() on the event, then the menu item's model will be modified to disable the menu item. Otherwise it will be enabled. This is useful when a menu item, particularly in the App Menu, is tied to a feature that may or may not be available at a given time. It's used by the framework with the Edit menu to disable the cut/copy/paste options whenever there isn't a text field in focus."

    I think the first possible solution above is more elegant for the user if you can get it to work, but if not this is a good alternative.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  7. #7  
    This is a fairly late response and I'm pretty new to WebOS development but I just ran into the same situation of wanting to toggle what a menu items label was and what command was used. This might not be the best way to go about it but here is the basic setup I started with:

    Code:
    StageAssistant.prototype.setup = function() {
    	
        //Setup Application Menu
        mediaMenuAttr = {omitDefaultItems: true};
        mediaMenuModel = {
           visible: true,
           items: [
             {label: "Disable Item", command: 'do-Disable-Item'},
             Mojo.Menu.helpItem
           ]
        };
      
      //Application Menu Shortcuts
      myItem = mediaMenuModel.items[0]; //zero since it's first item in array
      
      //setup scenes
      this.controller.pushScene({name: "main", disableSceneScroller: true});
      this.controller.setWindowOrientation("free");
    };
    
    // handle menu commands
    StageAssistant.prototype.handleCommand = function(event) {
      var currentScene = this.controller.activeScene();
      if(event.type == Mojo.Event.command) {
        switch(event.command) {
          case 'do-Disable-Item' : 
          	myItem.label = 'Enable Item';
          	myItem.command = 'do-Enable-Item';
          	break;
          case 'do-Enable-Item' :
          	myItem.label = 'Disable Item';
          	myItem.command = 'do-Disable-Item';
          	break;
        }
      }
    };
    -Michael Russell
  8. #8  
    This is a fairly late response and I'm pretty new to WebOS development but I just ran into the same situation of wanting to toggle what a menu items label was and what command was used. This might not be the best way to go about it but here is the basic setup I started with:

    Code:
    StageAssistant.prototype.setup = function() {
    	
        //Setup Application Menu
        mediaMenuAttr = {omitDefaultItems: true};
        mediaMenuModel = {
           visible: true,
           items: [
             {label: "Disable Item", command: 'do-Disable-Item'},
             Mojo.Menu.helpItem
           ]
        };
      
      //Application Menu Shortcuts
      myItem = mediaMenuModel.items[0]; //zero since it's first item in array
      
      //setup scenes
      this.controller.pushScene({name: "main", disableSceneScroller: true});
      this.controller.setWindowOrientation("free");
    };
    
    // handle menu commands
    StageAssistant.prototype.handleCommand = function(event) {
      var currentScene = this.controller.activeScene();
      if(event.type == Mojo.Event.command) {
        switch(event.command) {
          case 'do-Disable-Item' : 
          	myItem.label = 'Enable Item';
          	myItem.command = 'do-Enable-Item';
          	break;
          case 'do-Enable-Item' :
          	myItem.label = 'Disable Item';
          	myItem.command = 'do-Disable-Item';
          	break;
        }
      }
    };
    -Michael Russell

Posting Permissions