Merge lp:~therp-nl/web-addons/trunk-web-hide-buttons into lp:~webaddons-core-editors/web-addons/6.1

Proposed by Ronald Portier (Therp)
Status: Merged
Merged at revision: 13
Proposed branch: lp:~therp-nl/web-addons/trunk-web-hide-buttons
Merge into: lp:~webaddons-core-editors/web-addons/6.1
Diff against target: 122 lines (+103/-0)
3 files modified
web_hide_buttons/AUTHORS (+3/-0)
web_hide_buttons/__openerp__.py (+43/-0)
web_hide_buttons/static/src/js/web_hide_buttons.js (+57/-0)
To merge this branch: bzr merge lp:~therp-nl/web-addons/trunk-web-hide-buttons
Reviewer Review Type Date Requested Status
Niels Huylebroeck (community) Approve
Holger Brunn (Therp) Approve
Guewen Baconnier @ Camptocamp Approve
Review via email: mp+143402@code.launchpad.net

Description of the change

This merge adds a module to optionally hide the create and delete buttons from the web.

Wether one of the buttons is hidden or not depends on configuration of the context in the view action. So you can have most views with the buttons intact, and some views with the buttons readonly.

This is now limited to the Create and Delete buttons, but might in the future be extended to the duplicate and other buttons or UI elements al well.

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Actually, the 'duplicate' button is hidden if 'nocreate' is defined in the context but it cannot be hidden separately.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve
Revision history for this message
Niels Huylebroeck (red15) wrote :

Would be great if you could split the duplicate / create filters.

Something like

if (context.nocreate) {
    // Hide the create button
}
if (context.nocreate | context.noduplicate) {
    // Hide the duplicate button
}

Revision history for this message
Niels Huylebroeck (red15) wrote :

Just found something in default base addon:

http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/head:/openerp/addons/base/module/module_view.xml#L73

You can see they specify edit="0" and create="0"

Seems the handling of the arguments is done in the form view template on :
http://bazaar.launchpad.net/~openerp/openerp-web/7.0/view/head:/addons/web/static/src/xml/base.xml#L806

Perhaps we should not create duplicate functionality and more keywords...
I would still like to be able to avoid deletion via a view definition but it would be preferable to do it via a similar qweb / template inspired way i think.

review: Disapprove
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

> Just found something in default base addon:
>
> http://bazaar.launchpad.net/~openerp/openobject-
> server/7.0/view/head:/openerp/addons/base/module/module_view.xml#L73
>
> You can see they specify edit="0" and create="0"

note that the MP is targetted for 6.1. Are these available on that version?

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

no, this attributes were introduced in 7.0

review: Approve
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Niels, I hope that your question has been answered by now. I'll give you a couple of days to react, otherwise I'll merge this proposal based on the two approves.

Revision history for this message
Niels Huylebroeck (red15) wrote :

Sorry for forgetting about this merge. Just ran into this while searching for the exact way to do it in v7.0.

Indeed it's not available for 6.1 but I wanted to suggest mainly to use the same words to avoid more migration work when moving from v6.1 to v7.0 but alas ... :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'web_hide_buttons'
2=== added file 'web_hide_buttons/AUTHORS'
3--- web_hide_buttons/AUTHORS 1970-01-01 00:00:00 +0000
4+++ web_hide_buttons/AUTHORS 2013-01-15 20:53:22 +0000
5@@ -0,0 +1,3 @@
6+Ronald Portier <ronald@therp.nl>
7+Stefan Rijnhart <stefan@therp.nl>
8+
9
10=== added file 'web_hide_buttons/__init__.py'
11=== added file 'web_hide_buttons/__openerp__.py'
12--- web_hide_buttons/__openerp__.py 1970-01-01 00:00:00 +0000
13+++ web_hide_buttons/__openerp__.py 2013-01-15 20:53:22 +0000
14@@ -0,0 +1,43 @@
15+# -*- encoding: utf-8 -*-
16+##############################################################################
17+#
18+# Copyright (C) 2013 Therp B.V. (<http://www.therp.nl>)
19+#
20+# This program is free software: you can redistribute it and/or modify
21+# it under the terms of the GNU Affero General Public License as published
22+# by the Free Software Foundation, either version 3 of the License, or
23+# (at your option) any later version.
24+#
25+# This program is distributed in the hope that it will be useful,
26+# but WITHOUT ANY WARRANTY; without even the implied warranty of
27+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+# GNU Affero General Public License for more details.
29+#
30+# You should have received a copy of the GNU Affero General Public License
31+# along with this program. If not, see <http://www.gnu.org/licenses/>.
32+#
33+##############################################################################
34+{
35+ 'name': 'web hide buttons',
36+ 'application': False,
37+ 'version': '6.1.r003',
38+ 'category': 'Web',
39+ 'description': '''
40+This module makes it possible to hide Create and Delete buttons from the
41+user, if requested through the context of the action defining the window.
42+To hide both buttons add the following element to the xml for the
43+ir.actions.act_window:
44+<field name="context">{'nodelete': '1', 'nocreate': '1'}</field>
45+''',
46+ 'author': 'Therp B.V.',
47+ 'website': 'http://www.therp.nl',
48+ 'license': 'AGPLv3',
49+ 'depends': [
50+ 'web',
51+ ],
52+ 'init_xml': [],
53+ 'update_xml': [],
54+ 'demo_xml': [],
55+ 'installable': True,
56+ 'js': ['static/src/js/web_hide_buttons.js'],
57+ }
58
59=== added directory 'web_hide_buttons/static'
60=== added directory 'web_hide_buttons/static/src'
61=== added directory 'web_hide_buttons/static/src/js'
62=== added file 'web_hide_buttons/static/src/js/web_hide_buttons.js'
63--- web_hide_buttons/static/src/js/web_hide_buttons.js 1970-01-01 00:00:00 +0000
64+++ web_hide_buttons/static/src/js/web_hide_buttons.js 2013-01-15 20:53:22 +0000
65@@ -0,0 +1,57 @@
66+/* -----------------------------------------------------------\
67+ * web functions for web_hide_buttons
68+ * --------------------------------------------------------- */
69+
70+/* comments to control jslint */
71+/*jslint nomen: true, white: true, */
72+/*global window, openerp, $, _ */
73+
74+openerp.web_hide_buttons = function (openerp) {
75+ 'use strict';
76+
77+ /** Change ListView to not show Create and Delete buttons when that
78+ has been requested through the context passed from the action.
79+ */
80+ openerp.web.ListView.include({
81+
82+ on_loaded : function (record) {
83+ var result, context;
84+ result = this._super.apply(this, arguments);
85+ if (this.groups.datagroup.context) {
86+ context = this.groups.datagroup.context;
87+ if (context.nocreate) {
88+ this.$element.find('.oe-list-add')
89+ .attr('disabled', true).hide();
90+ }
91+ if (context.nodelete) {
92+ this.$element.find('.oe-list-delete')
93+ .attr('disabled', true).hide();
94+ }
95+ }
96+ return result;
97+ }
98+ });
99+
100+ openerp.web.FormView.include({
101+
102+ on_loaded : function (record) {
103+ var result, context;
104+ result = this._super.apply(this, arguments);
105+ context = this.dataset.get_context();
106+ if (context) {
107+ if (context.nocreate) {
108+ this.$element.find('.oe_form_button_create')
109+ .attr('disabled', true).hide();
110+ this.$element.find('.oe_form_button_duplicate')
111+ .attr('disabled', true).hide();
112+ }
113+ if (context.nodelete) {
114+ this.$element.find('.oe_form_button_delete')
115+ .attr('disabled', true).hide();
116+ }
117+ }
118+ return result;
119+ }
120+ });
121+
122+};

Subscribers

People subscribed via source and target branches