From cf1cd07dd282eb129b7545c18cb05b26bbdfbc0c Mon Sep 17 00:00:00 2001 From: tarteo Date: Thu, 23 Feb 2017 15:39:09 +0100 Subject: [PATCH] [FIX] Add to shortcuts button --- web_shortcut/static/src/css/web_shortcut.css | 6 +-- web_shortcut/static/src/js/web_shortcut.js | 48 ++++++++++++++------ web_shortcut/static/src/xml/web_shortcut.xml | 16 ++----- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/web_shortcut/static/src/css/web_shortcut.css b/web_shortcut/static/src/css/web_shortcut.css index ae5a3cef..fbf93d2c 100644 --- a/web_shortcut/static/src/css/web_shortcut.css +++ b/web_shortcut/static/src/css/web_shortcut.css @@ -2,9 +2,9 @@ .oe_systray_shortcuts .oe_star_off { color: #eee; } -.oe_shortcuts_toggle { +.oe_shortcut_toggle { height: 20px; - margin-top: 3px; + margin-top: 9px; padding: 0; width: 24px; cursor: pointer; @@ -12,7 +12,7 @@ background: url(/web/static/src/img/add-shortcut.png) no-repeat center center; float: left; } -.oe_shortcuts_remove{ +.oe_shortcut_remove{ background: url(/web/static/src/img/remove-shortcut.png) no-repeat center center; } .oe_shortcuts { diff --git a/web_shortcut/static/src/js/web_shortcut.js b/web_shortcut/static/src/js/web_shortcut.js index 4c32aa3f..bf3a2105 100644 --- a/web_shortcut/static/src/js/web_shortcut.js +++ b/web_shortcut/static/src/js/web_shortcut.js @@ -23,6 +23,7 @@ odoo.define('web.shortcut', function(require) { menu = require('web.UserMenu'), client = require('web.WebClient'), view_manager = require('web.ViewManager'), + qweb = require('web.core').qweb, model = require('web.DataModel'); @@ -63,7 +64,7 @@ odoo.define('web.shortcut', function(require) { display: function(sc) { var self = this; this.$el.find('.oe_systray_shortcut_menu').append(); - var $sc = $(QWeb.render('Systray.ShortcutMenu.Item', {'shortcut': sc})); + var $sc = $(qweb.render('Systray.ShortcutMenu.Item', {'shortcut': sc})); $sc.appendTo(self.$el.find('.oe_systray_shortcut_menu')); }, remove: function (menu_id) { @@ -77,7 +78,7 @@ odoo.define('web.shortcut', function(require) { var self = this, action_id = $link.data('id'); - new model('ir.ui.menu').query(['action']).filter([['id', '=', id]]).context(null).all().then(function(menu) { + new model('ir.ui.menu').query(['action']).filter([['id', '=', action_id]]).context(null).all().then(function(menu) { var action_str = menu[0].action; var action_str_parts = action_str.split(','); action_id = parseInt(action_str_parts[1]); @@ -91,16 +92,17 @@ odoo.define('web.shortcut', function(require) { menu.include({ + start: function() { + var res = this._super.apply(this, arguments); + this.shortcuts = new ShortcutMenu(self); + this.shortcuts.prependTo(this.$el.parent()); + return res; + }, do_update: function() { var self = this; this._super.apply(this, arguments); this.update_promise.done(function() { - if (self.shortcuts) { - self.shortcuts.trigger('load'); - } else { - self.shortcuts = new ShortcutMenu(self); - self.shortcuts.prependTo(self.$el.parent()); - } + self.shortcuts.trigger('load'); }); }, }); @@ -109,27 +111,39 @@ odoo.define('web.shortcut', function(require) { client.include({ show_application: function() { var self = this; - this._super.apply(this, arguments); - this.user_menu.on('click', this, function(action_id) { - self.do_action(action_id); + var res = this._super.apply(this, arguments); + this.user_menu.shortcuts.on('click', this, function(action_id) { + self.do_action(action_id, { + clear_breadcrumbs: true, + replace_breadcrumb: true + }); }); + return res; } }); view_manager.include({ + start: function() { + var res = this._super.apply(this, arguments); + console.log(this); + return res; + }, switch_mode: function (view_type, no_store) { var self = this; - this._super.apply(this, arguments).done(function() { + return this._super.apply(this, arguments).done(function() { self.shortcut_check(self.views[view_type]); }); }, shortcut_check: function(view) { + console.log('shortcut_check'); var self = this; - console.log(this); - var shortcuts_menu = this.action_manager.webclient.user_menu.shortcuts; // display shortcuts if on the first view for the action - var $shortcut_toggle = this.$el.find('.oe_shortcut_toggle'); + if (!this.action_manager) { + console.log(this); + return; + } + var $shortcut_toggle = this.action_manager.$el.find('.oe_shortcut_toggle'); if (!this.action.name || !(view.view_type === this.view_stack[0].view_type && view.view_id === this.view_stack[0].view_id)) { @@ -137,7 +151,10 @@ odoo.define('web.shortcut', function(require) { return; } // Anonymous users don't have user_menu + var shortcuts_menu = this.action_manager.webclient.user_menu.shortcuts; + console.log(self.session); if (shortcuts_menu) { + console.log(self.session.active_id); $shortcut_toggle.toggleClass('oe_shortcut_remove', shortcuts_menu.has(self.session.active_id)); $shortcut_toggle.unbind("click").click(function() { if ($shortcut_toggle.hasClass("oe_shortcut_remove")) { @@ -152,6 +169,7 @@ odoo.define('web.shortcut', function(require) { $shortcut_toggle.toggleClass("oe_shortcut_remove"); }); } + console.log('done_shortcut_check'); } }); diff --git a/web_shortcut/static/src/xml/web_shortcut.xml b/web_shortcut/static/src/xml/web_shortcut.xml index 82012653..ba32ade6 100644 --- a/web_shortcut/static/src/xml/web_shortcut.xml +++ b/web_shortcut/static/src/xml/web_shortcut.xml @@ -18,20 +18,14 @@ - - - + + console.log(ctx); + + -