[MERGE] trunk-access-ui-jam (hide buttons or disable actions to create/edit/delete that are not permitted to user)
bzr revid: rco@openerp.com-20120905093859-oh1udej3kgyghudy
This commit is contained in:
commit
b339be1450
|
@ -2711,6 +2711,12 @@
|
||||||
content: "ö";
|
content: "ö";
|
||||||
color: #404040;
|
color: #404040;
|
||||||
}
|
}
|
||||||
|
.openerp .oe_list_cannot_edit .oe_list_header_handle, .openerp .oe_list_cannot_edit .oe_list_field_handle {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.openerp .oe_list_cannot_delete .oe_list_record_delete {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
.openerp .tree_header {
|
.openerp .tree_header {
|
||||||
background-color: #f0f0f0;
|
background-color: #f0f0f0;
|
||||||
border-bottom: 1px solid #cacaca;
|
border-bottom: 1px solid #cacaca;
|
||||||
|
|
|
@ -2072,6 +2072,13 @@ $sheet-max-width: 860px
|
||||||
.oe_list_handle
|
.oe_list_handle
|
||||||
@include text-to-icon("ö")
|
@include text-to-icon("ö")
|
||||||
|
|
||||||
|
.oe_list_cannot_edit
|
||||||
|
.oe_list_header_handle, .oe_list_field_handle
|
||||||
|
display: none !important
|
||||||
|
.oe_list_cannot_delete
|
||||||
|
.oe_list_record_delete
|
||||||
|
display: none !important
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// Tree view {{{
|
// Tree view {{{
|
||||||
.tree_header
|
.tree_header
|
||||||
|
|
|
@ -141,14 +141,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
if (!this.sidebar && this.options.$sidebar) {
|
if (!this.sidebar && this.options.$sidebar) {
|
||||||
this.sidebar = new instance.web.Sidebar(this);
|
this.sidebar = new instance.web.Sidebar(this);
|
||||||
this.sidebar.appendTo(this.$sidebar);
|
this.sidebar.appendTo(this.$sidebar);
|
||||||
if(this.fields_view.toolbar) {
|
if (this.fields_view.toolbar) {
|
||||||
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
||||||
}
|
}
|
||||||
this.sidebar.add_items('other', [
|
this.sidebar.add_items('other', _.compact([
|
||||||
{ label: _t('Delete'), callback: self.on_button_delete },
|
self.is_action_enabled('delete') && { label: _t('Delete'), callback: self.on_button_delete },
|
||||||
{ label: _t('Duplicate'), callback: self.on_button_duplicate },
|
self.is_action_enabled('create') && { label: _t('Duplicate'), callback: self.on_button_duplicate },
|
||||||
{ label: _t('Set Default'), callback: function (item) { self.open_defaults_dialog(); } }
|
{ label: _t('Set Default'), callback: function (item) { self.open_defaults_dialog(); } }
|
||||||
]);
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.has_been_loaded.resolve();
|
this.has_been_loaded.resolve();
|
||||||
|
@ -3473,7 +3473,7 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
||||||
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
||||||
},
|
},
|
||||||
form_view_options: {'not_interactible_on_create':true},
|
form_view_options: {'not_interactible_on_create':true},
|
||||||
readonly: self.o2m.get("effective_readonly")
|
readonly: !this.is_action_enabled('edit') || self.o2m.get("effective_readonly")
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
do_button_action: function (name, id, callback) {
|
do_button_action: function (name, id, callback) {
|
||||||
|
@ -3561,7 +3561,11 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
||||||
});
|
});
|
||||||
instance.web.form.One2ManyList = instance.web.ListView.List.extend({
|
instance.web.form.One2ManyList = instance.web.ListView.List.extend({
|
||||||
pad_table_to: function (count) {
|
pad_table_to: function (count) {
|
||||||
this._super(count > 0 ? count - 1 : 0);
|
if (!this.view.is_action_enabled('create')) {
|
||||||
|
this._super(count);
|
||||||
|
} else {
|
||||||
|
this._super(count > 0 ? count - 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
// magical invocation of wtf does that do
|
// magical invocation of wtf does that do
|
||||||
if (this.view.o2m.get('effective_readonly')) {
|
if (this.view.o2m.get('effective_readonly')) {
|
||||||
|
@ -3574,6 +3578,11 @@ instance.web.form.One2ManyList = instance.web.ListView.List.extend({
|
||||||
}).length;
|
}).length;
|
||||||
if (this.options.selectable) { columns++; }
|
if (this.options.selectable) { columns++; }
|
||||||
if (this.options.deletable) { columns++; }
|
if (this.options.deletable) { columns++; }
|
||||||
|
|
||||||
|
if (!this.view.is_action_enabled('create')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var $cell = $('<td>', {
|
var $cell = $('<td>', {
|
||||||
colspan: columns,
|
colspan: columns,
|
||||||
'class': 'oe_form_field_one2many_list_row_add'
|
'class': 'oe_form_field_one2many_list_row_add'
|
||||||
|
|
|
@ -250,6 +250,12 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
|
||||||
|
|
||||||
this.$el.html(QWeb.render(this._template, this));
|
this.$el.html(QWeb.render(this._template, this));
|
||||||
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
||||||
|
|
||||||
|
// add css classes that reflect the (absence of) access rights
|
||||||
|
this.$el.toggleClass('oe_list_cannot_create', !this.is_action_enabled('create'))
|
||||||
|
.toggleClass('oe_list_cannot_edit', !this.is_action_enabled('edit'))
|
||||||
|
.toggleClass('oe_list_cannot_delete', !this.is_action_enabled('delete'));
|
||||||
|
|
||||||
// Head hook
|
// Head hook
|
||||||
// Selecting records
|
// Selecting records
|
||||||
this.$el.find('.oe_list_record_selector').click(function(){
|
this.$el.find('.oe_list_record_selector').click(function(){
|
||||||
|
@ -351,11 +357,11 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
|
||||||
if (!this.sidebar && this.options.$sidebar) {
|
if (!this.sidebar && this.options.$sidebar) {
|
||||||
this.sidebar = new instance.web.Sidebar(this);
|
this.sidebar = new instance.web.Sidebar(this);
|
||||||
this.sidebar.appendTo(this.options.$sidebar);
|
this.sidebar.appendTo(this.options.$sidebar);
|
||||||
this.sidebar.add_items('other', [
|
this.sidebar.add_items('other', _.compact([
|
||||||
{ label: _t("Import"), callback: this.on_sidebar_import },
|
self.is_action_enabled('create') && { label: _t("Import"), callback: this.on_sidebar_import },
|
||||||
{ label: _t("Export"), callback: this.on_sidebar_export },
|
{ label: _t("Export"), callback: this.on_sidebar_export },
|
||||||
{ label: _t('Delete'), callback: this.do_delete_selected }
|
self.is_action_enabled('delete') && { label: _t('Delete'), callback: this.do_delete_selected }
|
||||||
]);
|
]));
|
||||||
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
||||||
this.sidebar.$el.hide();
|
this.sidebar.$el.hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -759,7 +759,7 @@ openerp.web.list_editable = function (instance) {
|
||||||
|
|
||||||
instance.web.ListView.List.include(/** @lends instance.web.ListView.List# */{
|
instance.web.ListView.List.include(/** @lends instance.web.ListView.List# */{
|
||||||
row_clicked: function (event) {
|
row_clicked: function (event) {
|
||||||
if (!this.view.editable()) {
|
if (!this.view.editable() || ! this.view.is_action_enabled('edit')) {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
}
|
||||||
var record_id = $(event.currentTarget).data('id');
|
var record_id = $(event.currentTarget).data('id');
|
||||||
|
|
|
@ -1235,6 +1235,15 @@ instance.web.View = instance.web.Widget.extend({
|
||||||
*/
|
*/
|
||||||
reload: function () {
|
reload: function () {
|
||||||
return $.when();
|
return $.when();
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Return whether the user can perform the action ('create', 'edit', 'delete') in this view.
|
||||||
|
* An action is disabled by setting the corresponding attribute in the view's main element,
|
||||||
|
* like: <form string="" create="false" edit="false" delete="false">
|
||||||
|
*/
|
||||||
|
is_action_enabled: function(action) {
|
||||||
|
var attrs = this.fields_view.arch.attrs;
|
||||||
|
return (action in attrs) ? JSON.parse(attrs[action]) : true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -636,7 +636,7 @@
|
||||||
<t t-if="column.tag !== 'button'"><t t-esc="column.string"/></t>
|
<t t-if="column.tag !== 'button'"><t t-esc="column.string"/></t>
|
||||||
</th>
|
</th>
|
||||||
</t>
|
</t>
|
||||||
<th t-if="options.deletable" width="13px"/>
|
<th t-if="options.deletable" class="oe_list_record_delete" width="13px"/>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
|
@ -650,7 +650,7 @@
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
<div t-name="ListView.buttons" class="oe_list_buttons">
|
<div t-name="ListView.buttons" class="oe_list_buttons">
|
||||||
<t t-if="!widget.no_leaf and widget.options.action_buttons !== false and widget.options.addable">
|
<t t-if="!widget.no_leaf and widget.options.action_buttons !== false and widget.options.addable and widget.is_action_enabled('create')">
|
||||||
<button type="button" class="oe_button oe_list_add oe_highlight">
|
<button type="button" class="oe_button oe_list_add oe_highlight">
|
||||||
<t t-esc="widget.options.addable"/>
|
<t t-esc="widget.options.addable"/>
|
||||||
</button>
|
</button>
|
||||||
|
@ -726,10 +726,12 @@
|
||||||
<div t-name="FormView.buttons" class="oe_form_buttons">
|
<div t-name="FormView.buttons" class="oe_form_buttons">
|
||||||
<t t-if="widget.options.action_buttons !== false">
|
<t t-if="widget.options.action_buttons !== false">
|
||||||
<span class="oe_form_buttons_view">
|
<span class="oe_form_buttons_view">
|
||||||
<div style="display: inline-block;"> <!-- required for the bounce effect on button -->
|
<!-- required for the bounce effect on button -->
|
||||||
<button type="button" class="oe_button oe_form_button_edit" accesskey="E">Edit</button>
|
<div t-if="widget.is_action_enabled('edit')" style="display: inline-block;">
|
||||||
|
<button type="button" class="oe_button oe_form_button_edit" accesskey="E">Edit</button>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="oe_button oe_form_button_create" accesskey="C">Create</button>
|
<button t-if="widget.is_action_enabled('create')"
|
||||||
|
type="button" class="oe_button oe_form_button_create" accesskey="C">Create</button>
|
||||||
</span>
|
</span>
|
||||||
<span class="oe_form_buttons_edit">
|
<span class="oe_form_buttons_edit">
|
||||||
<button type="button" class="oe_button oe_form_button_save oe_highlight" accesskey="S">Save</button>
|
<button type="button" class="oe_button oe_form_button_save oe_highlight" accesskey="S">Save</button>
|
||||||
|
|
|
@ -47,7 +47,7 @@ instance.web.DiagramView = instance.web.View.extend({
|
||||||
return label.tag == "label";
|
return label.tag == "label";
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$el.html(QWeb.render("DiagramView", this));
|
this.$el.html(QWeb.render("DiagramView", {'widget': this}));
|
||||||
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
||||||
|
|
||||||
_.each(self.labels,function(label){
|
_.each(self.labels,function(label){
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<t t-name="DiagramView">
|
<t t-name="DiagramView">
|
||||||
<div class="oe_diagram_header" t-att-id="element_id + '_header'">
|
<div class="oe_diagram_header" t-att-id="widget.element_id + '_header'">
|
||||||
<h3 class="oe_diagram_title"/>
|
<h3 class="oe_diagram_title"/>
|
||||||
<div class="oe_diagram_buttons">
|
<div t-if="widget.is_action_enabled('create')" class="oe_diagram_buttons">
|
||||||
<button type="button" id="new_node" class="oe_button oe_diagram_button_new">New Node</button>
|
<button type="button" id="new_node" class="oe_button oe_diagram_button_new">New Node</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_diagram_pager">
|
<div class="oe_diagram_pager">
|
||||||
|
|
|
@ -183,12 +183,13 @@ instance.web_gantt.GanttView = instance.web.View.extend({
|
||||||
self.on_task_display(task_info.internal_task);
|
self.on_task_display(task_info.internal_task);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (this.is_action_enabled('create')) {
|
||||||
// insertion of create button
|
// insertion of create button
|
||||||
var td = $($("table td", self.$el)[0]);
|
var td = $($("table td", self.$el)[0]);
|
||||||
var rendered = QWeb.render("GanttView-create-button");
|
var rendered = QWeb.render("GanttView-create-button");
|
||||||
$(rendered).prependTo(td);
|
$(rendered).prependTo(td);
|
||||||
$(".oe_gantt_button_create", this.$el).click(this.on_task_create);
|
$(".oe_gantt_button_create", this.$el).click(this.on_task_create);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
on_task_changed: function(task_obj) {
|
on_task_changed: function(task_obj) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
@ -74,18 +74,16 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
|
||||||
return $.when();
|
return $.when();
|
||||||
},
|
},
|
||||||
_is_quick_create_enabled: function() {
|
_is_quick_create_enabled: function() {
|
||||||
if (! this.options.quick_creatable)
|
if (!this.options.quick_creatable || !this.is_action_enabled('create'))
|
||||||
return false;
|
return false;
|
||||||
if (this.fields_view.arch.attrs.quick_create !== undefined)
|
if (this.fields_view.arch.attrs.quick_create !== undefined)
|
||||||
return JSON.parse(this.fields_view.arch.attrs.quick_create);
|
return JSON.parse(this.fields_view.arch.attrs.quick_create);
|
||||||
return !! this.group_by;
|
return !! this.group_by;
|
||||||
},
|
},
|
||||||
_is_create_enabled: function() {
|
is_action_enabled: function(action) {
|
||||||
if (! this.options.creatable)
|
if (action === 'create' && !this.options.creatable)
|
||||||
return false;
|
return false;
|
||||||
if (this.fields_view.arch.attrs.create !== undefined)
|
return this._super(action);
|
||||||
return JSON.parse(this.fields_view.arch.attrs.create);
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
add_qweb_template: function() {
|
add_qweb_template: function() {
|
||||||
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
|
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
|
||||||
|
@ -738,16 +736,19 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
|
||||||
trigger: 'hover'
|
trigger: 'hover'
|
||||||
});
|
});
|
||||||
|
|
||||||
// If no draghandle is found, make the whole card as draghandle
|
// If no draghandle is found, make the whole card as draghandle (provided one can edit)
|
||||||
if (!this.$el.find('.oe_kanban_draghandle').length) {
|
if (!this.$el.find('.oe_kanban_draghandle').length) {
|
||||||
this.$el.children(':first').addClass('oe_kanban_draghandle');
|
this.$el.children(':first')
|
||||||
|
.toggleClass('oe_kanban_draghandle', this.view.is_action_enabled('edit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$el.find('.oe_kanban_action').click(function() {
|
this.$el.find('.oe_kanban_action').click(function() {
|
||||||
var $action = $(this),
|
var $action = $(this),
|
||||||
type = $action.data('type') || 'button',
|
type = $action.data('type') || 'button',
|
||||||
method = 'do_action_' + (type === 'action' ? 'object' : type);
|
method = 'do_action_' + (type === 'action' ? 'object' : type);
|
||||||
if (_.str.startsWith(type, 'switch_')) {
|
if ((type === 'edit' || type === 'delete') && ! self.view.is_action_enabled(type)) {
|
||||||
|
self.view.open_record(self.id);
|
||||||
|
} else if (_.str.startsWith(type, 'switch_')) {
|
||||||
self.view.do_switch_view(type.substr(7));
|
self.view.do_switch_view(type.substr(7));
|
||||||
} else if (typeof self[method] === 'function') {
|
} else if (typeof self[method] === 'function') {
|
||||||
self[method]($action);
|
self[method]($action);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</t>
|
</t>
|
||||||
<div t-name="KanbanView.buttons" class="oe_kanban_buttons">
|
<div t-name="KanbanView.buttons" class="oe_kanban_buttons">
|
||||||
<t t-if="widget.options.action_buttons !== false">
|
<t t-if="widget.options.action_buttons !== false">
|
||||||
<t t-if="widget._is_create_enabled()">
|
<t t-if="widget.is_action_enabled('create')">
|
||||||
<button type="button" class="oe_kanban_button_new oe_highlight">
|
<button type="button" class="oe_kanban_button_new oe_highlight">
|
||||||
<t t-esc="widget.options.create_text || _t('Create')"/>
|
<t t-esc="widget.options.create_text || _t('Create')"/>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue