Files
web/web_hide_buttons/static/src/js/web_hide_buttons.js
Ronald Portier 0bd224bf4e [IMP] Add possibility to hide Create and Delete buttons on web, if
requested through context for action.
2013-01-15 21:28:10 +01:00

58 lines
1.9 KiB
JavaScript

/* -----------------------------------------------------------\
* web functions for web_hide_buttons
* --------------------------------------------------------- */
/* comments to control jslint */
/*jslint nomen: true, white: true, */
/*global window, openerp, $, _ */
openerp.web_hide_buttons = function (openerp) {
'use strict';
/** Change ListView to not show Create and Delete buttons when that
has been requested through the context passed from the action.
*/
openerp.web.ListView.include({
on_loaded : function (record) {
var result, context;
result = this._super.apply(this, arguments);
if (this.groups.datagroup.context) {
context = this.groups.datagroup.context;
if (context.nocreate) {
this.$element.find('.oe-list-add')
.attr('disabled', true).hide();
}
if (context.nodelete) {
this.$element.find('.oe-list-delete')
.attr('disabled', true).hide();
}
}
return result;
}
});
openerp.web.FormView.include({
on_loaded : function (record) {
var result, context;
result = this._super.apply(this, arguments);
context = this.dataset.get_context();
if (context) {
if (context.nocreate) {
this.$element.find('.oe_form_button_create')
.attr('disabled', true).hide();
this.$element.find('.oe_form_button_duplicate')
.attr('disabled', true).hide();
}
if (context.nodelete) {
this.$element.find('.oe_form_button_delete')
.attr('disabled', true).hide();
}
}
return result;
}
});
};