2012-05-03 11:42:51 +00:00
|
|
|
/*############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2011-2012 OpenERP SA (<http://openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
############################################################################*/
|
|
|
|
|
|
|
|
openerp.web_shortcuts = function (instance) {
|
|
|
|
|
|
|
|
var QWeb = instance.web.qweb,
|
|
|
|
_t = instance.web._t;
|
|
|
|
|
|
|
|
instance.web_shortcuts.Shortcuts = instance.web.Widget.extend({
|
|
|
|
template: 'Systray.Shortcuts',
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super();
|
|
|
|
this.on('load', this, this.load);
|
|
|
|
this.on('add', this, this.add);
|
|
|
|
this.on('display', this, this.display);
|
|
|
|
this.on('remove', this, this.remove);
|
|
|
|
this.on('click', this, this.click);
|
|
|
|
this.dataset = new instance.web.DataSet(this, 'ir.ui.view_sc');
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
|
|
|
this.trigger('load');
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.on('click', '.oe_systray_shortcuts_items a', function() {
|
2012-05-03 11:42:51 +00:00
|
|
|
self.trigger('click', $(this));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
load: function() {
|
|
|
|
var self = this;
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.find('.oe_systray_shortcuts_items').empty();
|
2012-10-31 10:31:48 +00:00
|
|
|
return this.rpc('/web/shortcuts/list', {}).done(function(shortcuts) {
|
2012-05-03 11:42:51 +00:00
|
|
|
_.each(shortcuts, function(sc) {
|
|
|
|
self.trigger('display', sc);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
add: function (sc) {
|
|
|
|
var self = this;
|
2012-11-15 14:44:55 +00:00
|
|
|
this.dataset.create(sc).then(function(out){
|
2012-11-15 16:05:50 +00:00
|
|
|
self.trigger('load');
|
2012-05-03 11:42:51 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
display: function(sc) {
|
|
|
|
var self = this;
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.find('.oe_systray_shortcuts_items').append();
|
2012-05-03 11:42:51 +00:00
|
|
|
var $sc = $(QWeb.render('Systray.Shortcuts.Item', {'shortcut': sc}));
|
2012-08-24 18:27:43 +00:00
|
|
|
$sc.appendTo(self.$el.find('.oe_systray_shortcuts_items'));
|
2012-05-03 11:42:51 +00:00
|
|
|
},
|
|
|
|
remove: function (menu_id) {
|
|
|
|
var menu_id = this.session.active_id;
|
2012-08-24 18:27:43 +00:00
|
|
|
var $shortcut = this.$el.find('.oe_systray_shortcuts_items li a[data-id=' + menu_id + ']');
|
2012-05-03 11:42:51 +00:00
|
|
|
var shortcut_id = $shortcut.data('shortcut-id');
|
|
|
|
$shortcut.remove();
|
|
|
|
this.dataset.unlink([shortcut_id]);
|
|
|
|
},
|
|
|
|
click: function($link) {
|
|
|
|
var self = this,
|
|
|
|
id = $link.data('id');
|
|
|
|
self.session.active_id = id;
|
2012-07-24 12:52:57 +00:00
|
|
|
// TODO: Use do_action({menu_id: id, type: 'ir.actions.menu'})
|
2012-10-31 10:31:48 +00:00
|
|
|
self.rpc('/web/menu/action', {'menu_id': id}).done(function(ir_menu_data) {
|
2012-05-03 11:42:51 +00:00
|
|
|
if (ir_menu_data.action.length){
|
2012-10-29 10:59:31 +00:00
|
|
|
instance.webclient.on_menu_action({action_id: ir_menu_data.action[0][2].id});
|
2012-05-03 11:42:51 +00:00
|
|
|
}
|
|
|
|
});
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.find('.oe_systray_shortcuts').trigger('mouseout');
|
2012-05-03 11:42:51 +00:00
|
|
|
},
|
|
|
|
has: function(menu_id) {
|
2012-08-24 18:27:43 +00:00
|
|
|
return !!this.$el.find('a[data-id=' + menu_id + ']').length;
|
2012-05-03 11:42:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.web.UserMenu.include({
|
|
|
|
do_update: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
2012-10-31 10:31:48 +00:00
|
|
|
this.update_promise.done(function() {
|
2012-05-03 11:42:51 +00:00
|
|
|
if (self.shortcuts) {
|
|
|
|
self.shortcuts.trigger('load');
|
|
|
|
} else {
|
|
|
|
self.shortcuts = new instance.web_shortcuts.Shortcuts(self);
|
2012-08-24 18:27:43 +00:00
|
|
|
self.shortcuts.appendTo(instance.webclient.$el.find('.oe_systray'));
|
2012-05-03 11:42:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.web.ViewManagerAction.include({
|
2012-11-15 16:05:50 +00:00
|
|
|
switch_mode: function (view_type, no_store) {
|
2012-05-03 11:42:51 +00:00
|
|
|
var self = this;
|
2012-10-31 10:31:48 +00:00
|
|
|
this._super.apply(this, arguments).done(function() {
|
2012-11-15 16:05:50 +00:00
|
|
|
self.shortcut_check(self.views[view_type]);
|
2012-05-03 11:42:51 +00:00
|
|
|
});
|
|
|
|
},
|
2012-11-15 16:05:50 +00:00
|
|
|
shortcut_check : function(view) {
|
2012-05-03 11:42:51 +00:00
|
|
|
var self = this;
|
|
|
|
var shortcuts_menu = instance.webclient.user_menu.shortcuts;
|
|
|
|
var grandparent = this.getParent() && this.getParent().getParent();
|
|
|
|
// display shortcuts if on the first view for the action
|
2012-08-24 18:27:43 +00:00
|
|
|
var $shortcut_toggle = this.$el.find('.oe_shortcuts_toggle');
|
2012-11-15 16:05:50 +00:00
|
|
|
if (!this.action.name ||
|
2012-05-03 11:42:51 +00:00
|
|
|
!(view.view_type === this.views_src[0].view_type
|
|
|
|
&& view.view_id === this.views_src[0].view_id)) {
|
|
|
|
$shortcut_toggle.hide();
|
|
|
|
return;
|
2012-11-15 16:05:50 +00:00
|
|
|
}
|
2012-06-27 14:13:52 +00:00
|
|
|
$shortcut_toggle.toggleClass('oe_shortcuts_remove', shortcuts_menu.has(self.session.active_id));
|
2012-05-03 11:42:51 +00:00
|
|
|
$shortcut_toggle.unbind("click").click(function() {
|
2012-06-27 14:13:52 +00:00
|
|
|
if ($shortcut_toggle.hasClass("oe_shortcuts_remove")) {
|
2012-05-03 11:42:51 +00:00
|
|
|
shortcuts_menu.trigger('remove', self.session.active_id);
|
|
|
|
} else {
|
|
|
|
shortcuts_menu.trigger('add', {
|
|
|
|
'user_id': self.session.uid,
|
|
|
|
'res_id': self.session.active_id,
|
|
|
|
'resource': 'ir.ui.menu',
|
|
|
|
'name': self.action.name
|
|
|
|
});
|
|
|
|
}
|
2012-06-27 14:13:52 +00:00
|
|
|
$shortcut_toggle.toggleClass("oe_shortcuts_remove");
|
2012-05-03 11:42:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|