Merge lp:~domsense/web-addons/adding_web_field_style into lp:~webaddons-core-editors/web-addons/6.1

Proposed by Lorenzo Battistini
Status: Rejected
Rejected by: Stefan Rijnhart (Opener)
Proposed branch: lp:~domsense/web-addons/adding_web_field_style
Merge into: lp:~webaddons-core-editors/web-addons/6.1
Diff against target: 264 lines (+230/-0)
6 files modified
web_field_style/AUTHORS.txt (+4/-0)
web_field_style/__init__.py (+20/-0)
web_field_style/__openerp__.py (+58/-0)
web_field_style/server-view.rng.patch (+14/-0)
web_field_style/static/js/web_field_style.js (+42/-0)
web_field_style/static/xml/web_field_style.xml (+92/-0)
To merge this branch: bzr merge lp:~domsense/web-addons/adding_web_field_style
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Disapprove
Alexandre Fayolle - camptocamp Needs Fixing
Guewen Baconnier @ Camptocamp Abstain
Review via email: mp+144023@code.launchpad.net

Description of the change

Allows to specify different colors or
    CSS class per field in view definition.

    Three new attributes will be available on the field element of a view:
        `bgcolor` for setting the background color
        `fgcolor` for setting the foreground color (basically the text)
        `ccsclass` for setting a custom CSS class to be applied on the field

    `bg/fgcolor` are very useful for people that only want to change some field color without
    having to deal with CSS.

    NOTE: you must apply a simple patch to this server's file

        `server/openerp/addons/base/rng/view.rng`

    Just use the patch provided by this module (see server-view.rng.patch in the root of the package).

To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Is it not possible to patch the file when this module is installed and to unpatch when the module is uninstalled? This would greatly simplify installation for end users.

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

Also: the README.txt file does not seem to match the copyright information in the file headers.

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

Noticed a typo in the description: ccsclass (should've been cssclass i presume)

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

I'm not in favor to include addons in the community addons which needs to manually patch the server or the addons.

By the way, there is a way, a bit tricky I have to admit, to use the 'options' attribute on the fields.

Basically, the options defined in a field are available in this.node.attrs.options and are stored as JSON. That's far to be as convenient as new attributes for bgcolor, fgcolor and cssclass, but this method does not require to patch the server.

Example (customize the name of the 'create' button on one2many fields):

    openerp.web_custom = function (openerp) {
        var QWeb = openerp.web.qweb;

        var _t = openerp.web._t;

        openerp.web.form.FieldOne2Many.include({

            load_views: function() {
                var self = this;
                var result = this._super();
                var custom_options_str = this.node.attrs.options || '{}';
                var custom_options = JSON.parse(custom_options_str);
                _.each(this.views, function(view) {
                    // apply the custom options defined in the xml field like
                    // <field name="descr_ids" options='{"addable": "+"}'>
                    _.extend(view.options, custom_options);

                    // re-apply the read-only deactivation because they
                    // have the priority in all cases
                    if(view.view_type === "list") {
                        if (self.is_readonly()) {
                            view.options.addable = null;
                            view.options.deletable = null;
                            view.options.isClarkGable = false;
                        }
                    } else if (view.view_type === "form") {
                        if (self.is_readonly()) {
                            view.view_type = 'page';
                        }
                    }
                });
                return result;
            }

        });
    };

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

I'm -1 on this MP, because of the patch requirement

review: Needs Fixing
Revision history for this message
Davide Corio (enlightx-deactivatedaccount) wrote :

personally i won't spend time on this addon since on v7, webclient is changed a lot from this point of view and allows things like style="background-color:green;", then this module won't be that useful in the future

Revision history for this message
Davide Corio (enlightx-deactivatedaccount) wrote :

the first "won't" was actually a "would not" :-)

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

are we going to do something with this one or should we finally reject it because of the patch requirement which would be my choice?

review: Disapprove
Revision history for this message
Lorenzo Battistini (elbati) wrote :

On 06/03/2013 03:19 PM, Holger Brunn (Therp) wrote:
> are we going to do something with this one or should we finally reject it because of the patch requirement which would be my choice?

It can be rejected.

Unmerged revisions

3. By Lorenzo Battistini

[ADD] web_field_style

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'web_field_style'
2=== added file 'web_field_style/AUTHORS.txt'
3--- web_field_style/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ web_field_style/AUTHORS.txt 2013-01-20 15:31:20 +0000
5@@ -0,0 +1,4 @@
6+Authors
7+=======
8+
9+Simone Orsi <simone.orsi@domsense.com> [simahawk]
10
11=== added file 'web_field_style/__init__.py'
12--- web_field_style/__init__.py 1970-01-01 00:00:00 +0000
13+++ web_field_style/__init__.py 2013-01-20 15:31:20 +0000
14@@ -0,0 +1,20 @@
15+# -*- coding: utf-8 -*-
16+##############################################################################
17+#
18+# Copyright (C) 2012-2013 Agile Business Group sagl
19+# (<http://www.agilebg.com>)
20+#
21+# This program is free software: you can redistribute it and/or modify
22+# it under the terms of the GNU Affero General Public License as published
23+# by the Free Software Foundation, either version 3 of the License, or
24+# (at your option) any later version.
25+#
26+# This program is distributed in the hope that it will be useful,
27+# but WITHOUT ANY WARRANTY; without even the implied warranty of
28+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+# GNU Affero General Public License for more details.
30+#
31+# You should have received a copy of the GNU Affero General Public License
32+# along with this program. If not, see <http://www.gnu.org/licenses/>.
33+#
34+##############################################################################
35
36=== added file 'web_field_style/__openerp__.py'
37--- web_field_style/__openerp__.py 1970-01-01 00:00:00 +0000
38+++ web_field_style/__openerp__.py 2013-01-20 15:31:20 +0000
39@@ -0,0 +1,58 @@
40+# -*- coding: utf-8 -*-
41+##############################################################################
42+#
43+# Copyright (C) 2012-2013 Agile Business Group sagl
44+# (<http://www.agilebg.com>)
45+#
46+# This program is free software: you can redistribute it and/or modify
47+# it under the terms of the GNU Affero General Public License as published
48+# by the Free Software Foundation, either version 3 of the License, or
49+# (at your option) any later version.
50+#
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU Affero General Public License for more details.
55+#
56+# You should have received a copy of the GNU Affero General Public License
57+# along with this program. If not, see <http://www.gnu.org/licenses/>.
58+#
59+##############################################################################
60+
61+{
62+ 'name': 'Field Style',
63+ 'version': '1.0',
64+ 'category': 'web',
65+ 'description': """Allows to specify different colors or
66+ CSS class per field in view definition.
67+
68+ Three new attributes will be available on the field element of a view:
69+ `bgcolor` for setting the background color
70+ `fgcolor` for setting the foreground color (basically the text)
71+ `ccsclass` for setting a custom CSS class to be applied on the field
72+
73+ `bg/fgcolor` are very useful for people that only want to change some field color without
74+ having to deal with CSS.
75+
76+ NOTE: you must apply a simple patch to this server's file
77+
78+ `server/openerp/addons/base/rng/view.rng`
79+
80+ Just use the patch provided by this module (see server-view.rng.patch in the root of the package).
81+
82+ """,
83+ 'author': 'Agile Business Group & Domsense',
84+ 'website': 'http://www.agilebg.com',
85+ 'license': 'AGPL-3',
86+ 'depends': ['web'],
87+ 'data': [],
88+ 'active': False,
89+ 'installable': True,
90+ 'js': [
91+ 'static/js/web_field_style.js',
92+ ],
93+ 'qweb': [
94+ 'static/xml/web_field_style.xml',
95+ ],
96+}
97+
98
99=== added file 'web_field_style/server-view.rng.patch'
100--- web_field_style/server-view.rng.patch 1970-01-01 00:00:00 +0000
101+++ web_field_style/server-view.rng.patch 2013-01-20 15:31:20 +0000
102@@ -0,0 +1,14 @@
103+=== modified file 'openerp/addons/base/rng/view.rng'
104+--- openerp/addons/base/rng/view.rng 2012-02-13 10:17:58 +0000
105++++ openerp/addons/base/rng/view.rng 2012-08-13 10:13:00 +0000
106+@@ -500,6 +500,9 @@
107+ <rng:attribute name="name" />
108+ <rng:ref name="overload"/>
109+ <rng:ref name="access_rights"/>
110++ <rng:optional><rng:attribute name="bgcolor"/></rng:optional>
111++ <rng:optional><rng:attribute name="fgcolor"/></rng:optional>
112++ <rng:optional><rng:attribute name="cssclass"/></rng:optional>
113+ <rng:optional><rng:attribute name="domain_filter"/></rng:optional>
114+ <rng:optional><rng:attribute name="attrs"/></rng:optional>
115+ <rng:optional><rng:attribute name="string"/></rng:optional>
116+
117
118=== added directory 'web_field_style/static'
119=== added directory 'web_field_style/static/js'
120=== added file 'web_field_style/static/js/web_field_style.js'
121--- web_field_style/static/js/web_field_style.js 1970-01-01 00:00:00 +0000
122+++ web_field_style/static/js/web_field_style.js 2013-01-20 15:31:20 +0000
123@@ -0,0 +1,42 @@
124+// @@@ web_field_style custom JS @@@
125+
126+openerp.web_field_style = function(openerp) {
127+
128+ openerp.web.form.Field.include({
129+
130+ default_style: 'width:100%;',
131+
132+ init: function(view, node) {
133+ this._super(view, node);
134+ this.setup_styles(view, node);
135+ },
136+
137+ setup_styles : function(view, node){
138+ // style
139+ // this is done for allowing ppl to set up different colors per field
140+ // without having to deal with css
141+ var style = this.default_style;
142+ if(node.attrs.bgcolor){
143+ style += 'background-color:' + node.attrs.bgcolor + ' !important;';
144+ }
145+ if(node.attrs.fgcolor){
146+ style += 'color:' + node.attrs.fgcolor + ' !important;';
147+ }
148+ this.input_style = style;
149+ // css class
150+ var cssclass = 'field_' + this.type;
151+ cssclass += _(['integer', 'float', 'float_time']).contains(this.type) ? ' oe-number' : '';
152+ if(node.attrs.cssclass){
153+ cssclass += ' ' + node.attrs.cssclass;
154+ }
155+ this.input_cssclass = cssclass;
156+ }
157+ });
158+
159+
160+ // openerp.web.form.FieldChar = openerp.web.form.FieldChar.extend({
161+ // default_style: 'width:100%;',
162+
163+ // });
164+
165+}
166
167=== added directory 'web_field_style/static/xml'
168=== added file 'web_field_style/static/xml/web_field_style.xml'
169--- web_field_style/static/xml/web_field_style.xml 1970-01-01 00:00:00 +0000
170+++ web_field_style/static/xml/web_field_style.xml 2013-01-20 15:31:20 +0000
171@@ -0,0 +1,92 @@
172+<?xml version="1.0" encoding="UTF-8"?>
173+
174+<templates>
175+
176+<t t-name="FieldChar" t-extend="FieldChar">
177+ <t t-jquery="input" t-operation="replace">
178+ <input
179+ t-att-type="widget.password ? 'password' : 'text'"
180+ size="1"
181+ t-att-name="widget.name"
182+ t-att-id="widget.element_id"
183+ t-att-maxlength="widget.field.size"
184+ t-att-class="widget.input_cssclass"
185+ t-att-style="widget.input_style"
186+ />
187+ </t>
188+</t>
189+
190+<t t-name="FieldText" t-extend="FieldText">
191+ <t t-jquery="textarea" t-operation="replace">
192+ <textarea
193+ rows="6"
194+ t-att-name="widget.name"
195+ t-att-id="widget.element_id"
196+ t-att-maxlength="widget.field.size"
197+ t-att-class="widget.input_cssclass"
198+ t-att-style="widget.input_style"
199+ />
200+ </t>
201+</t>
202+
203+<t t-name="web.datetimepicker">
204+ <div class="oe_datepicker_root">
205+ <input
206+ type="text"
207+ size="1"
208+ class="oe_datepicker_container"
209+ disabled="disabled"
210+ style="display: none;"
211+ />
212+ <input
213+ type="text"
214+ size="1"
215+ t-att-style="widget.input_style"
216+ t-att-name="widget.name"
217+ t-attf-class="oe_datepicker_master field_#{widget.type_of_date} #{widget.input_cssclass}"
218+ />
219+ <img
220+ class="oe_input_icon oe_datepicker_trigger"
221+ t-att-src='_s + "/web/static/src/img/ui/field_calendar.png"'
222+ title="Select date"
223+ width="16"
224+ height="16"
225+ border="0"
226+ />
227+ </div>
228+</t>
229+
230+<t t-name="FieldSelection">
231+ <select
232+ t-att-name="widget.name"
233+ t-att-id="widget.element_id"
234+ t-att-class="widget.input_cssclass"
235+ t-att-style="widget.input_style">
236+ <t t-foreach="widget.values" t-as="option">
237+ <option><t t-esc="option[1]"/></option>
238+ </t>
239+ </select>
240+</t>
241+
242+<t t-name="FieldReference">
243+ <table border="0" width="100%" cellpadding="0" cellspacing="0"
244+ t-attf-class="oe_frame oe_forms #{widget.input_cssclass}">
245+ <tr>
246+ <td t-attf-class="oe_form_frame_cell oe_form_selection #{widget.selection.element_class}">
247+ <t t-raw="widget.selection.render()"/>
248+ </td>
249+ <td t-attf-class="oe_form_frame_cell oe_form_many2one #{widget.m2o.element_class}" nowrap="true" style="display: none">
250+ <t t-raw="widget.m2o.render()"/>
251+ </td>
252+ </tr>
253+ </table>
254+</t>
255+<t t-name="FieldBoolean">
256+ <input type="checkbox"
257+ t-att-name="widget.name"
258+ t-att-class="widget.input_cssclass"
259+ t-att-style="widget.input_style"
260+ />
261+</t>
262+
263+</templates>
264\ No newline at end of file

Subscribers

People subscribed via source and target branches