11/* Copyright 2004-today Odoo SA (<http://www.odoo.com>)
22 * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
33
4- odoo . define ( 'web.shortcut' , function ( require ) {
4+ odoo . define ( 'web.shortcut' , function ( require ) {
55 var Widget = require ( 'web.Widget' ) ,
6- UserMenu = require ( 'web.UserMenu' ) ,
76 WebClient = require ( 'web.WebClient' ) ,
87 ViewManager = require ( 'web.ViewManager' ) ,
98 ActionManager = require ( 'web.ActionManager' ) ,
109 core = require ( 'web.core' ) ,
1110 qweb = core . qweb ,
1211 DataModel = require ( 'web.DataModel' ) ,
13- session = require ( 'web.session' ) ;
14-
12+ session = require ( 'web.session' ) ,
13+ SystrayMenu = require ( 'web.SystrayMenu' ) ;
1514
1615 var ShortcutMenu = Widget . extend ( {
1716 template : 'Systray.ShortcutMenu' ,
18- init : function ( ) {
17+ init : function ( ) {
1918 this . _super ( ) ;
2019 this . on ( 'load' , this , this . load ) ;
2120 this . on ( 'add' , this , this . add ) ;
2221 this . on ( 'display' , this , this . display ) ;
2322 this . on ( 'remove' , this , this . remove ) ;
2423 this . model = new DataModel ( 'web.shortcut' ) ;
2524 } ,
26- start : function ( ) {
25+ start : function ( ) {
2726 var self = this ;
2827 this . _super ( ) ;
2928 this . trigger ( 'load' ) ;
30- this . $el . on ( 'click' , '.oe_systray_shortcut_menu a' , function ( ) {
29+ this . $el . on ( 'click' , '.oe_systray_shortcut_menu a' , function ( ) {
3130 self . click ( $ ( this ) ) ;
3231 } ) ;
3332 } ,
34- load : function ( ) {
33+ load : function ( ) {
3534 var self = this ;
36- this . $el . find ( '.oe_systray_shortcut_menu' ) . empty ( ) ;
37- return this . model . call ( 'get_user_shortcuts' , [
38- ] ) . done ( function ( shortcuts ) {
39- _ . each ( shortcuts , function ( sc ) {
35+ return this . model . call ( 'get_user_shortcuts' , [ ] ) . done ( function ( shortcuts ) {
36+ self . $el . find ( '.oe_systray_shortcut_menu' ) . empty ( ) ;
37+ _ . each ( shortcuts , function ( sc ) {
4038 self . trigger ( 'display' , sc ) ;
4139 } ) ;
4240 } ) ;
4341 } ,
4442 add : function ( sc ) {
4543 var self = this ;
46- this . model . call ( 'create' , [ sc ] ) . then ( function ( out ) {
44+ this . model . call ( 'create' , [ sc ] ) . then ( function ( out ) {
4745 self . trigger ( 'load' ) ;
4846 } ) ;
4947 } ,
50- display : function ( sc ) {
48+ display : function ( sc ) {
5149 var self = this ;
5250 this . $el . find ( '.oe_systray_shortcut_menu' ) . append ( ) ;
5351 var $sc = $ ( qweb . render ( 'Systray.ShortcutMenu.Item' , { shortcut : sc } ) ) ;
5452 $sc . appendTo ( self . $el . find ( '.oe_systray_shortcut_menu' ) ) ;
5553 } ,
5654 remove : function ( menu_id ) {
57- var menu_id = this . session . active_id ;
5855 var $shortcut = this . $el . find ( '.oe_systray_shortcut_menu li a[data-id=' + menu_id + ']' ) ;
5956 var shortcut_id = $shortcut . data ( 'shortcut-id' ) ;
6057 $shortcut . remove ( ) ;
6158 this . model . call ( 'unlink' , [ shortcut_id ] ) ;
6259 } ,
63- click : function ( $link ) {
60+ click : function ( $link ) {
6461 var self = this ,
6562 action_id = $link . data ( 'id' ) ;
66-
67- new DataModel ( 'ir.ui.menu' ) . query ( [ 'action' ] ) . filter ( [ [ 'id' , '=' , action_id ] ] ) . context ( null ) . all ( ) . then ( function ( menu ) {
63+ new DataModel ( 'ir.ui.menu' ) . query ( [ 'action' ] ) . filter ( [ [ 'id' , '=' , action_id ] ] ) . context ( null ) . all ( ) . then ( function ( menu ) {
6864 var action_str = menu [ 0 ] . action ;
6965 var action_str_parts = action_str . split ( ',' ) ;
7066 action_id = parseInt ( action_str_parts [ 1 ] ) ;
7167 self . trigger ( 'click' , action_id ) ;
7268 } ) ;
7369 } ,
74- has : function ( menu_id ) {
70+ has : function ( menu_id ) {
7571 return ! ! this . $el . find ( 'a[data-id=' + menu_id + ']' ) . length ;
7672 }
7773 } ) ;
7874
7975
80- UserMenu . include ( {
81- start : function ( ) {
82- this . shortcuts = new ShortcutMenu ( self ) ;
83- this . shortcuts . prependTo ( this . $el . parent ( ) ) ;
84- return this . _super . apply ( this , arguments ) ;
85- } ,
86- do_update : function ( ) {
87- var self = this ;
88- var res = this . _super . apply ( this , arguments ) ;
89- this . shortcuts . trigger ( 'load' ) ;
90- return res ;
91- } ,
92- } ) ;
76+ SystrayMenu . Items . push ( ShortcutMenu ) ;
9377
9478
9579 WebClient . include ( {
96- show_application : function ( ) {
80+ current_action_updated : function ( action ) {
81+ this . shortcut_menu = _ . find ( this . systray_menu . widgets , function ( item ) {
82+ return item instanceof ShortcutMenu ;
83+ } ) ;
84+ } ,
85+ show_application : function ( ) {
9786 var self = this ;
98- var res = this . _super . apply ( this , arguments ) ;
99- this . user_menu . shortcuts . on ( 'click' , this , function ( action_id ) {
100- self . do_action ( action_id , {
101- clear_breadcrumbs : true ,
102- replace_breadcrumb : true
87+ return this . _super . apply ( this , arguments ) . then ( function ( ) {
88+ self . shortcut_menu = _ . find ( self . systray_menu . widgets , function ( item ) {
89+ return item instanceof ShortcutMenu ;
90+ } ) ;
91+ self . shortcut_menu . on ( 'click' , self , function ( action_id ) {
92+ self . do_action ( action_id , {
93+ clear_breadcrumbs : true ,
94+ replace_breadcrumb : true
95+ } ) ;
10396 } ) ;
10497 } ) ;
105- return res ;
10698 }
10799 } ) ;
108100
109101
110102 ViewManager . include ( {
111103 switch_mode : function ( view_type , no_store ) {
112104 var self = this ;
113- return this . _super . apply ( this , arguments ) . done ( function ( ) {
105+ return this . _super . apply ( this , arguments ) . done ( function ( ) {
114106 self . shortcut_check ( self . views [ view_type ] ) ;
115107 } ) ;
116108 } ,
117- shortcut_check : function ( view ) {
109+ shortcut_check : function ( view ) {
118110 var self = this ;
119111
120112 // Child view managers
@@ -124,26 +116,37 @@ odoo.define('web.shortcut', function(require) {
124116
125117 // display shortcuts if on the first view for the action
126118 var $shortcut_toggle = this . action_manager . main_control_panel . $el . find ( '.oe_shortcut_toggle' ) ;
127- if ( ! this . action . name ||
128- ! ( view . view_type === this . view_stack [ 0 ] . view_type &&
119+ if ( ! this . action . name || ! ( view . view_type === this . view_stack [ 0 ] . view_type &&
129120 view . view_id === this . view_stack [ 0 ] . view_id )
130- ) {
121+ ) {
131122 $shortcut_toggle . addClass ( 'hidden' ) ;
132123 return ;
133124 }
134125 $shortcut_toggle . removeClass ( 'hidden' ) ;
135126
136127 // Anonymous users don't have user_menu
137- var shortcuts_menu = this . action_manager . webclient . user_menu . shortcuts ;
128+ var shortcuts_menu = this . action_manager . webclient . shortcut_menu ;
138129 if ( shortcuts_menu ) {
139130 $shortcut_toggle . toggleClass ( 'oe_shortcut_remove' , shortcuts_menu . has ( self . session . active_id ) ) ;
140- $shortcut_toggle . unbind ( "click" ) . click ( function ( ) {
131+ $shortcut_toggle . unbind ( "click" ) . click ( function ( ) {
132+ var menu_id = session . active_id ;
133+ // In the case we come from a parent menu, no action is linked to the menu
134+ // We must take the first child menu
135+ if ( self . action_manager . webclient . menu_data ) {
136+ for ( var i = 0 ; i < self . action_manager . webclient . menu_data . children . length ; i ++ ) {
137+ if ( self . action_manager . webclient . menu_data . children [ i ] . id === session . active_id ) {
138+ menu_id = self . action_manager . webclient . menu_data . children [ i ] . children [ 0 ] . id ;
139+ break ;
140+ }
141+ }
142+ }
141143 if ( $shortcut_toggle . hasClass ( "oe_shortcut_remove" ) ) {
142- shortcuts_menu . trigger ( 'remove' , self . session . active_id ) ;
143- } else {
144+ shortcuts_menu . trigger ( 'remove' , menu_id ) ;
145+ }
146+ else {
144147 shortcuts_menu . trigger ( 'add' , {
145148 'user_id' : session . uid ,
146- 'menu_id' : session . active_id ,
149+ 'menu_id' : menu_id ,
147150 'name' : session . name
148151 } ) ;
149152 }
@@ -155,7 +158,7 @@ odoo.define('web.shortcut', function(require) {
155158
156159
157160 ActionManager . include ( {
158- do_action : function ( ) {
161+ do_action : function ( ) {
159162 this . main_control_panel . $el . find ( '.oe_shortcut_toggle' ) . addClass ( 'hidden' ) ;
160163 return this . _super . apply ( this , arguments ) ;
161164 }
0 commit comments