[IMP] cleanup shortcuts toggle code
bzr revid: xmo@openerp.com-20110816123510-gcx0dk8b2sgox5oi
This commit is contained in:
parent
840f25e143
commit
1d5f8506c8
|
@ -1181,21 +1181,17 @@ background: linear-gradient(top, #ffffff 0%,#ebe9e9 100%); /* W3C */
|
|||
box-shadow: none;
|
||||
}
|
||||
/* Shortcuts*/
|
||||
#shortcut_add_remove {
|
||||
.oe-shortcut-toggle {
|
||||
height: 20px;
|
||||
padding: 0;
|
||||
width: 24px;
|
||||
cursor: pointer;
|
||||
display: inline; /*IE7 */
|
||||
display: inline-block;
|
||||
background: url(/base/static/src/img/add-shortcut.png) no-repeat bottom;
|
||||
}
|
||||
.shortcut-add {
|
||||
background: url(/base/static/src/img/add-shortcut.png) no-repeat;
|
||||
background-position: bottom;
|
||||
}
|
||||
.shortcut-remove{
|
||||
background: url(/base/static/src/img/remove-shortcut.png) no-repeat;
|
||||
background-position: bottom;
|
||||
.oe-shortcut-remove{
|
||||
background: url(/base/static/src/img/remove-shortcut.png) no-repeat bottom;
|
||||
}
|
||||
/* ================ */
|
||||
.oe-shortcuts {
|
||||
|
|
|
@ -160,7 +160,6 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
|
|||
view_promise;
|
||||
this.active_view = view_type;
|
||||
var view = this.views[view_type];
|
||||
this.shortcut_check(view.view_id,view_type);
|
||||
if (!view.controller) {
|
||||
// Lazy loading of views
|
||||
var controllerclass = this.registry.get_object(view_type);
|
||||
|
@ -272,44 +271,7 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
|
|||
*/
|
||||
contexts: function () {
|
||||
return [];
|
||||
},
|
||||
shortcut_check : function(view_id,view_type){
|
||||
main_view = this.session.action_manager.viewmanager.views_src[0];
|
||||
if (view_type == "tree" || main_view.view_id == view_id && main_view.view_type == view_type &&
|
||||
this.element_id == "oe_app"){
|
||||
$('#shortcut_add_remove').show();
|
||||
var img = "shortcut-add";
|
||||
for(var list_shortcut=0; list_shortcut<this.session.sc_list.length; list_shortcut++){
|
||||
if (this.session.sc_list[list_shortcut]['res_id'] == this.session.active_id)
|
||||
{img = "shortcut-remove"}
|
||||
}
|
||||
$('#shortcut_add_remove').addClass(img);
|
||||
}
|
||||
else{
|
||||
$('#shortcut_add_remove').hide();
|
||||
}
|
||||
this.shortcut_add_remove();
|
||||
},
|
||||
shortcut_add_remove: function(){
|
||||
var self = this;
|
||||
var shortcut_selector =$('#shortcut_add_remove');
|
||||
var dataset_shortcut = new openerp.base.DataSet(this, 'ir.ui.view_sc');
|
||||
shortcut_selector.click(function(ev,id){
|
||||
if(shortcut_selector.hasClass("shortcut-remove")){
|
||||
var unlink_id = $("li[id="+self.session.active_id+"]").attr('shortcut-id');
|
||||
dataset_shortcut.unlink([parseInt(unlink_id)]);
|
||||
shortcut_selector.removeClass("shortcut-remove");
|
||||
shortcut_selector.addClass("shortcut-add"); }
|
||||
else {
|
||||
var data = {'user_id': self.uid, 'res_id': self.session.active_id, 'resource': 'ir.ui.menu', 'name': self.action.name};
|
||||
dataset_shortcut.create(data);
|
||||
shortcut_selector.removeClass("shortcut-add");
|
||||
shortcut_selector.addClass("shortcut-remove"); }
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
openerp.base.NullViewManager = openerp.base.generate_null_object_class(openerp.base.ViewManager, {
|
||||
|
@ -392,6 +354,48 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
|||
return [];
|
||||
}
|
||||
return [this.action.context];
|
||||
},
|
||||
on_mode_switch: function (view_type) {
|
||||
this._super(view_type);
|
||||
this.shortcut_check(this.views[view_type]);
|
||||
},
|
||||
shortcut_check : function(view) {
|
||||
var self = this;
|
||||
// display shortcuts if on the first view for the action
|
||||
var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
|
||||
if (!(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.sc_list).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');
|
||||
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[id=" + self.session.active_id + "]").data('shortcut-id');
|
||||
dataset_shortcut.unlink([parseInt(unlink_id)]);
|
||||
$shortcut_toggle.removeClass("oe-shortcut-remove");
|
||||
} else {
|
||||
dataset_shortcut.create({
|
||||
'user_id': self.uid,
|
||||
'res_id': self.session.active_id,
|
||||
'resource': 'ir.ui.menu',
|
||||
'name': self.action.name
|
||||
});
|
||||
$shortcut_toggle.addClass("oe-shortcut-remove");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -417,10 +417,8 @@
|
|||
<table class="view-manager-main-table">
|
||||
<tr>
|
||||
<td class="view-manager-main-content">
|
||||
<!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
|
||||
<t t-if="view.view_type != form" t-foreach="views" t-as="view">
|
||||
<a id = "shortcut_add_remove" title="Add / Remove Shortcut..." href="javascript: void(0)"> </a>
|
||||
</t>
|
||||
<a class="oe-shortcut-toggle" title="Add / Remove Shortcut..."
|
||||
href="javascript: void(0)"> </a>
|
||||
<div class="oe_vm_switch">
|
||||
<t t-if="views.length != 1" t-foreach="views" t-as="view">
|
||||
<button type="button" t-att-data-view-type="view.view_type">
|
||||
|
|
Loading…
Reference in New Issue