[IMP] use shortcuts list shoved directly into session as the communication channel between stuff adding and removing shortcuts in the viewmanager and the shortcuts list display in the header
no standard cross-elements communication method yet, so... if there's one one day, it should replace this hodge-podge system. Also need better error handling bzr revid: xmo@openerp.com-20110816140425-q2a71idlxnhuortb
This commit is contained in:
@@ -25,8 +25,8 @@ openerp.base.Session = openerp.base.Widget.extend( /** @lends openerp.base.Sessi
|
||||
this.module_list = [];
|
||||
this.module_loaded = {"base": true};
|
||||
this.context = {};
|
||||
this.sc_list ={};
|
||||
this.active_id = "";
|
||||
this.shortcuts = [];
|
||||
this.active_id = null;
|
||||
},
|
||||
start: function() {
|
||||
this.session_restore();
|
||||
@@ -863,9 +863,37 @@ openerp.base.Header = openerp.base.Widget.extend({
|
||||
return this.shortcut_load();
|
||||
},
|
||||
shortcut_load :function(){
|
||||
var self = this;
|
||||
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) {
|
||||
self.session.sc_list = 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')
|
||||
|
||||
@@ -369,7 +369,7 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
||||
return;
|
||||
}
|
||||
$shortcut_toggle.removeClass('oe-shortcut-remove').show();
|
||||
if (_(this.session.sc_list).detect(function (shortcut) {
|
||||
if (_(this.session.shortcuts).detect(function (shortcut) {
|
||||
return shortcut.res_id === self.session.active_id; })) {
|
||||
$shortcut_toggle.addClass("oe-shortcut-remove");
|
||||
}
|
||||
@@ -378,15 +378,13 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
||||
shortcut_add_remove: function() {
|
||||
var self = this;
|
||||
var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
|
||||
var dataset_shortcut = new openerp.base.DataSet(this, 'ir.ui.view_sc');
|
||||
$shortcut_toggle.click(function() {
|
||||
if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
|
||||
var unlink_id = $(".oe-shortcuts li[data-id=" + self.session.active_id + "]").data('shortcut-id');
|
||||
dataset_shortcut.unlink([parseInt(unlink_id)]);
|
||||
$(self.session.shortcuts.binding).trigger('remove-current');
|
||||
$shortcut_toggle.removeClass("oe-shortcut-remove");
|
||||
} else {
|
||||
dataset_shortcut.create({
|
||||
'user_id': self.uid,
|
||||
$(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
|
||||
|
||||
Reference in New Issue
Block a user