Is there a way to create form context submenu for a form context menu

Ratish1
Tera Contributor

Using Ui context menu, It is possible to create a submenu in a menu but over list view . I am trying to create a form context menu I did it using Ui action but is it possible to create submenu under that. I am not able to find any helpful link for doing so.

4 REPLIES 4

mfamphlett
Mega Expert

Did you ever find a way of doing this?


mfamphlett
Mega Expert

Incase you still wanted a solution, or for anyone else who comes across this, here's what I ended up doing.



At first i was hoping it would be possible to modify the code which generates the form header context menu and add some logic for creating submenus from a new field on the ui action table. Unfortunately although some of the context menu is generated from various ui macros it seems the code which generates the ui actions part of the menu is not available for customisation.



I ended up coming up with the following client side code which modifies the menu after it's created. It's not an ideal solution since it involves a bit of DOM manipulation but it does the job. This can be run in an onload client script for the specific table you want to add sub menus on. The array at the beginning defines the structure for the new submenus.



(function() {


  // new submenus: items array denotes the sysids, names and/or onclick functions of the ui actions


  // to move into them (if ui action is set to client=true the name of the onclick function must be


  // used otherwise if it has a name (e.g. 'sysverb_insert') that must be used otherwise use the sysid


  // submenus/items will appear in the order listed


  var subMenus = [


      {


          name: 'Submenu 1',


          items: [


              '<ui action name>',


              '<ui action sysid>',


              '<ui action onclick>'


          ]


      },


      {


          name: 'Submenu 2',


          items: [


              '<ui action name>',


              '<ui action sysid>',


              '<ui action onclick>'


          ]


      }


  ];


  // get context menu


  var gcm = new GwtContextMenu('context_1');


  var jcm = $j(gcm.menu);


  // create and position new sub-menus


  for (var i = 0; i < subMenus.length; i++) {


      var sm = subMenus[i];


      var gcsm = new GwtContextMenu('new_context_submenu_' + i);


      // insert new menu just before the first line break (bottom of the ui actions context menu section)


      jcm.find('div.context_item_hr:first')


          .before(gcm.addMenu(sm.name, gcsm));


      // move items into the menu


      for (var j = 0; j < sm.items.length; j++) {


          jcm.find('div.context_item[href*="' + sm.items[j] + '"]')


              .appendTo(gcsm.menu);


      }


  }


})();


Even if its DOM manipulation, great solution!


Hello,

 

I'm trying to implement your solution, what if the UI action is set to client=true and has an action name as well? I tried both of them and the submenu does not appear.

 

Thanks!