topc to docs added: How to create a custom menu

task's create_menu method corrected
master 5.4.123
Andrew Yushev 4 months ago
parent 7e74eb052a
commit ac3ae8717c
  1. 8
      docs/how_to/how_to_create_a_custom_menu.txt
  2. 1
      docs/how_to/index.txt
  3. 43
      docs/refs/client/task/m_create_menu.txt
  4. 2
      jam/__init__.py
  5. 11
      jam/js/jam.js
  6. 5
      jam/js/jam.min.js

@ -0,0 +1,8 @@
===========================
How to create a custom menu
===========================
To create a custom menu you must specify a custom_menu option for the task's
:doc:`create_menu </refs/client/task/m_create_menu>`
method in the task's client module.

@ -15,6 +15,7 @@ Here is a useful code that you can use in your applications:
how_to_add_a_button_to_a_form
how_to_execute_script_from_client
how_to_change_style_and_attributes_of_elements
how_to_create_a_custom_menu
to_append_a_record_without_view_form
how_to_prohibit_changing_record
how_to_link_two_tables

@ -42,6 +42,8 @@ The following parameters could be passed to the method:
* ``options`` - an object that can have the following attributes:
* ``custom_menu`` - use this option to create a custom menu, see below for details
* ``view_first`` - if it is true the view form of the first item in the menu will
be displayed after menu is created, the default value is ``false``
@ -52,8 +54,28 @@ The following parameters could be passed to the method:
* ``splash_screen`` - an html that will be displayed in the forms_container when
all tabs are closed
Custom menu option
------------------
To create your own custom menu you must set a custom_menu option.
This option is a list of menu objects, each object can be:
* Jam.py item or item group
* array: the first element of the array is the name of the menu item, and
the second is the list of menu objects
* object with one attribute: the key of the attribute is the name of menu item
and the value - a list of menu objects
* object with one attribute: the key of the attribute is the name of menu item
and the value - function to be executed when the menu item is clicked
To add a separator, an empty string ('') can be added to the list of menu objects
Example
=======
@ -64,5 +86,22 @@ Example
view_first: true
});
An example with custom menu:
.. code-block:: js
let menu = [
['First', [task.invoices, task.customers]],
{'Second': [task.catalogs, '', task.reports]},
{Third: [task.tracks, {Params: function() {alert('params clicked')}}]},
{Fourth: [task.task.analytics, {'Artists list': [task.artists]}]},
task.reports,
{Params: function() {alert('params clicked')}},
];
task.create_menu($("#menu"), $("#content"), {
custom_menu: menu,
splash_screen: '<h1 class="text-center">Jam.py Demo Application</h1>',
view_first: true
});

@ -1,4 +1,4 @@
__version__ = (5, 4, 122)
__version__ = (5, 4, 123)
def version():
return '%s.%s.%s' % __version__

@ -2473,10 +2473,10 @@
}
},
create_menu_item: function(menu_item, parent, options) {
create_menu_item: function(menu_item, parent, options, caption) {
if (menu_item.items.length) {
if (menu_item.items.length === 1 && !options.create_group_for_single_item) {
this.create_menu_item(menu_item.items[0], parent, options);
this.create_menu_item(menu_item.items[0], parent, options, menu_item.caption);
}
else {
let li,
@ -2498,9 +2498,12 @@
}
}
else {
if (menu_item.caption) {
if (caption || menu_item.caption) {
if (!caption) {
caption = menu_item.caption
}
parent.append($('<li>')
.append($('<a class="item-menu" href="#">' + menu_item.caption + '</a>')
.append($('<a class="item-menu" href="#">' + caption + '</a>')
.data('action', menu_item.action)));
}
else {

5
jam/js/jam.min.js vendored

@ -267,13 +267,14 @@ try{priv_dic=this.user_privileges[item.ID];}catch(e){priv_dic=null;}
if(priv_dic){return priv_dic[priv_name];}else{return false;}}},create_cookie:function(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}else{expires="";}
document.cookie=escape(name)+"="+escape(value)+expires+"; path=/";},read_cookie:function(name){var nameEQ=escape(name)+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)===' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)===0)return unescape(c.substring(nameEQ.length,c.length));}
return null;},erase_cookie:function(name){this.create_cookie(name,"",-1);},set_forms_container:function(container,options){if(container&&container.length){this.forms_container=container;if(options&&options.splash_screen){this.splash_screen=options.splash_screen;}
if(this.forms_in_tabs){this.init_tabs(container,'tabs-top',this.splash_screen,true);}}},create_menu_item:function(menu_item,parent,options){if(menu_item.items.length){if(menu_item.items.length===1&&!options.create_group_for_single_item){this.create_menu_item(menu_item.items[0],parent,options);}
if(this.forms_in_tabs){this.init_tabs(container,'tabs-top',this.splash_screen,true);}}},create_menu_item:function(menu_item,parent,options,caption){if(menu_item.items.length){if(menu_item.items.length===1&&!options.create_group_for_single_item){this.create_menu_item(menu_item.items[0],parent,options,menu_item.caption);}
else{let li,ul;if(parent.hasClass('dropdown-menu')){li=$('<li class="dropdown-submenu"><a tabindex="-1" href="#">'+
menu_item.caption+'</a></li>');}
else{li=$('<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">'+
menu_item.caption+' <b class="caret"></b></a></li>');}
parent.append(li);ul=$('<ul class="dropdown-menu">');li.append(ul);for(let i=0;i<menu_item.items.length;i++){this.create_menu_item(menu_item.items[i],ul,options)}}}
else{if(menu_item.caption){parent.append($('<li>').append($('<a class="item-menu" href="#">'+menu_item.caption+'</a>').data('action',menu_item.action)));}
else{if(caption||menu_item.caption){if(!caption){caption=menu_item.caption}
parent.append($('<li>').append($('<a class="item-menu" href="#">'+caption+'</a>').data('action',menu_item.action)));}
else{parent.append($('<li class="divider"></li>'));}}},add_menu_item:function(custom_item,parent){let menu_item={},item=custom_item,sub_items=[];if(custom_item instanceof Array){item=custom_item[0];if(custom_item.length>1){sub_items=custom_item[1]}}
else if(custom_item instanceof Object&&!(item instanceof AbsrtactItem)){for(item in custom_item){if(custom_item[item]instanceof Array){sub_items=custom_item[item];}
else if(custom_item[item]instanceof AbsrtactItem){sub_items[0]=custom_item[item];}

Loading…
Cancel
Save