[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:
Raphael Collet 2012-09-05 11:38:59 +02:00
commit b339be1450
12 changed files with 77 additions and 36 deletions

View File

@ -2711,6 +2711,12 @@
content: "ö";
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 {
background-color: #f0f0f0;
border-bottom: 1px solid #cacaca;

View File

@ -2072,6 +2072,13 @@ $sheet-max-width: 860px
.oe_list_handle
@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_header

View File

@ -141,14 +141,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
if (!this.sidebar && this.options.$sidebar) {
this.sidebar = new instance.web.Sidebar(this);
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_items('other', [
{ label: _t('Delete'), callback: self.on_button_delete },
{ label: _t('Duplicate'), callback: self.on_button_duplicate },
this.sidebar.add_items('other', _.compact([
self.is_action_enabled('delete') && { label: _t('Delete'), callback: self.on_button_delete },
self.is_action_enabled('create') && { label: _t('Duplicate'), callback: self.on_button_duplicate },
{ label: _t('Set Default'), callback: function (item) { self.open_defaults_dialog(); } }
]);
]));
}
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);
},
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) {
@ -3561,7 +3561,11 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
});
instance.web.form.One2ManyList = instance.web.ListView.List.extend({
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
if (this.view.o2m.get('effective_readonly')) {
@ -3574,6 +3578,11 @@ instance.web.form.One2ManyList = instance.web.ListView.List.extend({
}).length;
if (this.options.selectable) { columns++; }
if (this.options.deletable) { columns++; }
if (!this.view.is_action_enabled('create')) {
return;
}
var $cell = $('<td>', {
colspan: columns,
'class': 'oe_form_field_one2many_list_row_add'

View File

@ -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.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
// Selecting records
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) {
this.sidebar = new instance.web.Sidebar(this);
this.sidebar.appendTo(this.options.$sidebar);
this.sidebar.add_items('other', [
{ label: _t("Import"), callback: this.on_sidebar_import },
this.sidebar.add_items('other', _.compact([
self.is_action_enabled('create') && { label: _t("Import"), callback: this.on_sidebar_import },
{ 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.$el.hide();
}

View File

@ -759,7 +759,7 @@ openerp.web.list_editable = function (instance) {
instance.web.ListView.List.include(/** @lends instance.web.ListView.List# */{
row_clicked: function (event) {
if (!this.view.editable()) {
if (!this.view.editable() || ! this.view.is_action_enabled('edit')) {
return this._super.apply(this, arguments);
}
var record_id = $(event.currentTarget).data('id');

View File

@ -1235,6 +1235,15 @@ instance.web.View = instance.web.Widget.extend({
*/
reload: function () {
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;
}
});

View File

@ -636,7 +636,7 @@
<t t-if="column.tag !== 'button'"><t t-esc="column.string"/></t>
</th>
</t>
<th t-if="options.deletable" width="13px"/>
<th t-if="options.deletable" class="oe_list_record_delete" width="13px"/>
</tr>
</thead>
<tfoot>
@ -650,7 +650,7 @@
</tfoot>
</table>
<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">
<t t-esc="widget.options.addable"/>
</button>
@ -726,10 +726,12 @@
<div t-name="FormView.buttons" class="oe_form_buttons">
<t t-if="widget.options.action_buttons !== false">
<span class="oe_form_buttons_view">
<div style="display: inline-block;"> <!-- required for the bounce effect on button -->
<button type="button" class="oe_button oe_form_button_edit" accesskey="E">Edit</button>
<!-- required for the bounce effect on 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>
<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 class="oe_form_buttons_edit">
<button type="button" class="oe_button oe_form_button_save oe_highlight" accesskey="S">Save</button>

View File

@ -47,7 +47,7 @@ instance.web.DiagramView = instance.web.View.extend({
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']);
_.each(self.labels,function(label){

View File

@ -1,8 +1,8 @@
<template>
<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"/>
<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>
</div>
<div class="oe_diagram_pager">

View File

@ -183,12 +183,13 @@ instance.web_gantt.GanttView = instance.web.View.extend({
self.on_task_display(task_info.internal_task);
}
});
// insertion of create button
var td = $($("table td", self.$el)[0]);
var rendered = QWeb.render("GanttView-create-button");
$(rendered).prependTo(td);
$(".oe_gantt_button_create", this.$el).click(this.on_task_create);
if (this.is_action_enabled('create')) {
// insertion of create button
var td = $($("table td", self.$el)[0]);
var rendered = QWeb.render("GanttView-create-button");
$(rendered).prependTo(td);
$(".oe_gantt_button_create", this.$el).click(this.on_task_create);
}
},
on_task_changed: function(task_obj) {
var self = this;

View File

@ -74,18 +74,16 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
return $.when();
},
_is_quick_create_enabled: function() {
if (! this.options.quick_creatable)
if (!this.options.quick_creatable || !this.is_action_enabled('create'))
return false;
if (this.fields_view.arch.attrs.quick_create !== undefined)
return JSON.parse(this.fields_view.arch.attrs.quick_create);
return !! this.group_by;
},
_is_create_enabled: function() {
if (! this.options.creatable)
is_action_enabled: function(action) {
if (action === 'create' && !this.options.creatable)
return false;
if (this.fields_view.arch.attrs.create !== undefined)
return JSON.parse(this.fields_view.arch.attrs.create);
return true;
return this._super(action);
},
add_qweb_template: function() {
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'
});
// 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) {
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() {
var $action = $(this),
type = $action.data('type') || 'button',
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));
} else if (typeof self[method] === 'function') {
self[method]($action);

View File

@ -14,7 +14,7 @@
</t>
<div t-name="KanbanView.buttons" class="oe_kanban_buttons">
<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">
<t t-esc="widget.options.create_text || _t('Create')"/>
</button>