Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    AutoChild - Unable to use menu as autochild

    Smartclient 7.0rc4
    Mozilla 3.6.8

    I am trying to create contextMenu using autochild

    Code:
    isc.VLayout.create({
     ID: "MainPanel",
     myMenuDefaults: {
         _constructor: isc.Menu,
         .......			    				
    
     },
     myListGridDefaults: {
           ...
           contextMenu: "autoChild:myMenu",
           ....
     },
     initWidget: function() {
    			this.Super("initWidget", arguments);	         	 
    			this.addAutoChild("myMenu");
                            this.addAutoChild("myListGrid");
     }
    });
    As you can see there is a Main Panel which has a listgrid and a menu
    we set menu as contextmenu(by using autochild) for the listgrid


    But I see the following happening

    1. Menu shows up in the main panel itself. On top or bottom in panel as ordered in initWidget of main panel
    2. The menu never shows up in the listgrid rightclick.
    3. I even tried removing and adding "this.addAutoChild("myMenu"); from initWidget" but it didn't help.

    Help!

    #2
    Menus are not children, they appear as pop-ups above the component. If you want to use the AutoChild system to create one, use createAutoChild(), not addAutoChild().

    Comment


      #3
      I tried this code:

      Code:
      isc.VLayout.create({
       ID: "MainPanel",
       myMenuDefaults: {
           _constructor: isc.Menu,
          {item:"clickMeItem", click:
      	function (){
                           //issue: this.creator is coming as undefined
                      }
          },
           .......			    				
      
       },
       myListGridDefaults: {
             ...
             contextMenu: "autoChild:myMenu",
             ....
       },
       initWidget: function() {
      	this.Super("initWidget", arguments);	         	 
      	this.addAutoChild("myListGrid");
              this.myListGrid.contextMenu = this.createAutoChild("myMenu");
              
       }
      });
      I am able to see the menu now on the fly which is good.
      There is another problem now. We cannot access the creator from the menu items click method.

      I even tried moving menu inside myListgrid definition but that did not help!


      Help!

      Comment


        #4
        We tried to isolate the problem with a working code in menu samples

        Code:
        isc.MenuButton.create({
            ID: "menuButton",
            title: "File",
            width: 100,
            menuDefaults:{
              _constructor :isc.Menu,
              autoDraw: false,
              showShadow: true,
              shadowDepth: 10,
              data: [
                {title: "New", keyTitle: "Ctrl+N", icon: "icons/16/document_plain_new.png",click:"alert(this.creator)"},
                {title: "Open", keyTitle: "Ctrl+O", icon: "icons/16/folder_out.png"},
                {isSeparator: true},
                {title: "Save", keyTitle: "Ctrl+S", icon: "icons/16/disk_blue.png"},
                {title: "Save As", icon: "icons/16/save_as.png"},
                {isSeparator: true},
                {title: "Recent Documents", icon: "icons/16/folder_document.png", submenu: [
                    {title: "data.xml", checked: true},
                    {title: "Component Guide.doc"},
                    {title: "SmartClient.doc", checked: true},
                    {title: "AJAX.doc"}
                ]},
                {isSeparator: true},
                {title: "Export as...", icon: "icons/16/export1.png", submenu: [
                    {title: "XML"},
                    {title: "CSV"},
                    {title: "Plain text"}
                ]},
                {isSeparator: true},
                {title: "Print", enabled: false, keyTitle: "Ctrl+P", icon: "icons/16/printer3.png"}
              ]
        },
        
        initWidget: function() {
            this.Super("initWidget", arguments);     
            this.menu = this.createAutoChild("menu");
            
        }
        });
        Click on Menu button to open the menu which is an autochild.
        Click on New Menu item should alert a creator object
        We must get the creator from "New" menu item


        This is not happening.
        I need the ref of the parent element so that I can call any method within parent.

        Help!

        Comment


          #5
          The "creator" is available on Canvas AutoChildren. Your click handler is in a MenuItem which is not a Canvas. Use menu.creator from that scope.

          Comment


            #6
            Superb!!!!!

            It works just fine.
            Also I am able to take references of parent..
            Adding a code snippet to help someone who needs it in future.....

            In the following example refer to this "menu.creator.ID"

            Code:
            isc.VLayout.create({
            ID: "mainPanel",
               menuOneDefaults:{
                  _constructor :isc.Menu,
                  autoDraw: false,
                  showShadow: true,
                  shadowDepth: 10,
                  data: [
                    {title: "New", keyTitle: "Ctrl+N", icon: "icons/16/document_plain_new.png",click:"alert(menu.creator.ID);"},
                    {title: "Open", keyTitle: "Ctrl+O", icon: "icons/16/folder_out.png"},
                    {isSeparator: true},
                    {title: "Save", keyTitle: "Ctrl+S", icon: "icons/16/disk_blue.png"},
                    {title: "Save As", icon: "icons/16/save_as.png"},
                    {isSeparator: true},
                    {title: "Recent Documents", icon: "icons/16/folder_document.png", submenu: [
                        {title: "data.xml", checked: true},
                        {title: "Component Guide.doc"},
                        {title: "SmartClient.doc", checked: true},
                        {title: "AJAX.doc"}
                    ]},
                    {isSeparator: true},
                    {title: "Export as...", icon: "icons/16/export1.png", submenu: [
                        {title: "XML"},
                        {title: "CSV"},
                        {title: "Plain text"}
                    ]},
                    {isSeparator: true},
                    {title: "Print", enabled: false, keyTitle: "Ctrl+P", icon: "icons/16/printer3.png"}
                  ]
            },
            menuButtonDefaults: {
                _constructor: isc.MenuButton,
                title: "File",
                width: 100
            },
            initWidget: function() {
                this.Super("initWidget", arguments);   
                this.addAutoChild("menuButton");
                this.menuButton.menu = this.createAutoChild("menuOne");    
            }
            
            });

            Thanks alot!!

            Comment

            Working...
            X