summaryrefslogtreecommitdiff
path: root/addons/base/static/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/base/static/src/js')
-rw-r--r--addons/base/static/src/js/chrome.js62
-rw-r--r--addons/base/static/src/js/core.js2
-rw-r--r--addons/base/static/src/js/views.js44
3 files changed, 102 insertions, 6 deletions
diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js
index 49d2099c948..927a000f002 100644
--- a/addons/base/static/src/js/chrome.js
+++ b/addons/base/static/src/js/chrome.js
@@ -573,13 +573,66 @@ openerp.base.Header = openerp.base.Widget.extend({
this._super(parent, element_id);
},
start: function() {
- this.do_update();
+ return this.do_update();
},
- do_update: function() {
+ do_update: function () {
this.$element.html(QWeb.render("Header", this));
this.$element.find(".logout").click(this.on_logout);
+ return this.shortcut_load();
},
- on_logout: function() {}
+ shortcut_load :function(){
+ var self = this,
+ sc = self.session.shortcuts,
+ shortcuts_ds = new openerp.base.DataSet(this, 'ir.ui.view_sc');
+ // TODO: better way to communicate between sections.
+ // sc.bindings, because jquery does not bind/trigger on arrays...
+ if (!sc.binding) {
+ sc.binding = {};
+ $(sc.binding).bind({
+ 'add': function (e, attrs) {
+ var $shortcut = $('<li>', {
+ 'data-id': attrs.res_id
+ }).text(attrs.name)
+ .appendTo(self.$element.find('.oe-shortcuts ul'));
+ shortcuts_ds.create(attrs, function (out) {
+ $shortcut.data('shortcut-id', out.result);
+ });
+ },
+ 'remove-current': function () {
+ var menu_id = self.session.active_id;
+ var $shortcut = self.$element
+ .find('.oe-shortcuts li[data-id=' + menu_id + ']');
+ var shortcut_id = $shortcut.data('shortcut-id');
+ $shortcut.remove();
+ shortcuts_ds.unlink([shortcut_id]);
+ }
+ });
+ }
+ return this.rpc('/base/session/sc_list', {}, function(shortcuts) {
+ sc.splice(0, sc.length);
+ sc.push.apply(sc, shortcuts);
+
+ self.$element.find('.oe-shortcuts')
+ .html(QWeb.render('Shortcuts', {'shortcuts': shortcuts}))
+ .undelegate('li', 'click')
+ .delegate('li', 'click', function(e) {
+ e.stopPropagation();
+ var id = $(this).data('id');
+ self.session.active_id = id;
+ self.rpc('/base/menu/action', {'menu_id':id}, function(ir_menu_data) {
+ if (ir_menu_data.action.length){
+ self.on_action(ir_menu_data.action[0][2]);
+ }
+ });
+ });
+ });
+ },
+ on_action: function(action) {
+ },
+
+ on_logout: function() {
+ this.$element.find('.oe-shortcuts ul').empty();
+ }
});
openerp.base.Menu = openerp.base.Widget.extend({
@@ -641,6 +694,7 @@ openerp.base.Menu = openerp.base.Widget.extend({
$secondary.show();
if (id) {
+ this.session.active_id = id;
this.rpc('/base/menu/action', {'menu_id': id},
this.on_menu_action_loaded);
}
@@ -699,7 +753,7 @@ openerp.base.WebClient = openerp.base.Widget.extend({
this.menu = new openerp.base.Menu(this, "oe_menu", "oe_secondary_menu");
this.menu.on_action.add(this.on_menu_action);
-
+ this.header.on_action.add(this.on_menu_action);
},
start: function() {
this.session.start();
diff --git a/addons/base/static/src/js/core.js b/addons/base/static/src/js/core.js
index 9c5bf358d7b..96c6cb1372a 100644
--- a/addons/base/static/src/js/core.js
+++ b/addons/base/static/src/js/core.js
@@ -635,6 +635,8 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
this.module_list = [];
this.module_loaded = {"base": true};
this.context = {};
+ this.shortcuts = [];
+ this.active_id = null;
},
start: function() {
this.session_restore();
diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js
index 7e6bfa0a5cb..f21c6387d32 100644
--- a/addons/base/static/src/js/views.js
+++ b/addons/base/static/src/js/views.js
@@ -92,7 +92,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
ir_actions_client: function (action) {
this.client_widget = openerp.base.client_actions.get_object(action.tag);
new this.client_widget(this, this.element_id, action.params).start();
- },
+ }
});
openerp.base.ViewManager = openerp.base.Widget.extend({
@@ -285,13 +285,53 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
var searchview_loaded = this.setup_search_view(
searchview_id || false, search_defaults);
-
+
// schedule auto_search
if (searchview_loaded != null && this.action['auto_search']) {
$.when(searchview_loaded, inital_view_loaded)
.then(this.searchview.do_search);
}
}
+ },
+ on_mode_switch: function (view_type) {
+ this._super(view_type);
+ this.shortcut_check(this.views[view_type]);
+ },
+ shortcut_check : function(view) {
+ var self = this;
+ var grandparent = this.widget_parent && this.widget_parent.widget_parent;
+ // display shortcuts if on the first view for the action
+ var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
+ if (!(grandparent instanceof openerp.base.WebClient) ||
+ !(view.view_type === this.views_src[0].view_type
+ && view.view_id === this.views_src[0].view_id)) {
+ $shortcut_toggle.hide();
+ return;
+ }
+ $shortcut_toggle.removeClass('oe-shortcut-remove').show();
+ if (_(this.session.shortcuts).detect(function (shortcut) {
+ return shortcut.res_id === self.session.active_id; })) {
+ $shortcut_toggle.addClass("oe-shortcut-remove");
+ }
+ this.shortcut_add_remove();
+ },
+ shortcut_add_remove: function() {
+ var self = this;
+ var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
+ $shortcut_toggle.click(function() {
+ if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
+ $(self.session.shortcuts.binding).trigger('remove-current');
+ $shortcut_toggle.removeClass("oe-shortcut-remove");
+ } else {
+ $(self.session.shortcuts.binding).trigger('add', {
+ 'user_id': self.session.uid,
+ 'res_id': self.session.active_id,
+ 'resource': 'ir.ui.menu',
+ 'name': self.action.name
+ });
+ $shortcut_toggle.addClass("oe-shortcut-remove");
+ }
+ });
}
});