[REM] Removed use of attrs and replaced it with modifiers
authorFabien Meghazi <fme@openerp.com>
Thu, 7 Jul 2011 10:37:40 +0000 (12:37 +0200)
committerFabien Meghazi <fme@openerp.com>
Thu, 7 Jul 2011 10:37:40 +0000 (12:37 +0200)
Warning ! You need server Revision: 3497 revid:vmt@openerp.com-20110705122222-bhim9uft3l3sqee8

bzr revid: fme@openerp.com-20110707103740-4m6vrj18wfi2hacy

addons/base/controllers/main.py
addons/base/static/src/js/form.js
addons/base/static/src/js/list-editable.js
addons/base/static/src/js/list.js
addons/base/static/src/xml/base.xml

index aa870df..1179eb3 100644 (file)
@@ -594,36 +594,6 @@ class View(openerpweb.Controller):
             return {'result': True}
         return {'result': False}
 
-    def normalize_attrs(self, elem, context):
-        """ Normalize @attrs, @invisible, @required, @readonly and @states, so
-        the client only has to deal with @attrs.
-
-        See `the discoveries pad <http://pad.openerp.com/discoveries>`_ for
-        the rationale.
-
-        :param elem: the current view node (Python object)
-        :type elem: xml.etree.ElementTree.Element
-        :param dict context: evaluation context
-        """
-        # If @attrs is normalized in json by server, the eval should be replaced by simplejson.loads
-        attrs = openerpweb.ast.literal_eval(elem.get('attrs', '{}'))
-        if 'states' in elem.attrib:
-            attrs.setdefault('invisible', [])\
-                .append(('state', 'not in', elem.attrib.pop('states').split(',')))
-        if attrs:
-            elem.set('attrs', simplejson.dumps(attrs))
-        for a in ['invisible', 'readonly', 'required']:
-            if a in elem.attrib:
-                # In the XML we trust
-                avalue = bool(eval(elem.get(a, 'False'),
-                                   {'context': context or {}}))
-                if not avalue:
-                    del elem.attrib[a]
-                else:
-                    elem.attrib[a] = '1'
-                    if a == 'invisible' and 'attrs' in elem.attrib:
-                        del elem.attrib['attrs']
-
     def transform_view(self, view_string, session, context=None):
         # transform nodes on the fly via iterparse, instead of
         # doing it statically on the parsing result
@@ -633,7 +603,6 @@ class View(openerpweb.Controller):
             if event == "start":
                 if root is None:
                     root = elem
-                self.normalize_attrs(elem, context)
                 self.parse_domains_and_contexts(elem, session)
         return root
 
index ad9bd74..7071c40 100644 (file)
@@ -132,7 +132,7 @@ openerp.base.FormView =  openerp.base.View.extend( /** @lends openerp.base.FormV
     on_form_changed: function() {
         for (var w in this.widgets) {
             w = this.widgets[w];
-            w.process_attrs();
+            w.process_modifiers();
             w.update_dom();
         }
     },
@@ -503,7 +503,7 @@ openerp.base.form.compute_domain = function(expr, fields) {
                 stack.push(!_(val).contains(field));
                 break;
             default:
-                this.log("Unsupported operator in attrs :", op);
+                this.log("Unsupported operator in modifiers :", op);
         }
     }
     return _.all(stack);
@@ -514,7 +514,7 @@ openerp.base.form.Widget = openerp.base.Controller.extend({
     init: function(view, node) {
         this.view = view;
         this.node = node;
-        this.attrs = JSON.parse(this.node.attrs.attrs || '{}');
+        this.modifiers = JSON.parse(this.node.attrs.modifiers || '{}');
         this.type = this.type || node.tag;
         this.element_name = this.element_name || this.type;
         this.element_id = [this.view.element_id, this.element_name, this.view.widgets_counter++].join("_");
@@ -527,15 +527,15 @@ openerp.base.form.Widget = openerp.base.Controller.extend({
 
         this.string = this.string || node.attrs.string;
         this.help = this.help || node.attrs.help;
-        this.invisible = (node.attrs.invisible == '1');
+        this.invisible = this.modifiers['invisible'] === true;
     },
     start: function() {
         this.$element = $('#' + this.element_id);
     },
-    process_attrs: function() {
+    process_modifiers: function() {
         var compute_domain = openerp.base.form.compute_domain;
-        for (var a in this.attrs) {
-            this[a] = compute_domain(this.attrs[a], this.view.fields);
+        for (var a in this.modifiers) {
+            this[a] = compute_domain(this.modifiers[a], this.view.fields);
         }
     },
     update_dom: function() {
@@ -736,10 +736,9 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
         this.field = view.fields_view.fields[node.attrs.name] || {};
         this.string = node.attrs.string || this.field.string;
         this.help = node.attrs.help || this.field.help;
-        this.invisible = (this.invisible || this.field.invisible == '1');
-        this.nolabel = (this.field.nolabel || node.attrs.nolabel) == '1';
-        this.readonly = (this.field.readonly || node.attrs.readonly) == '1';
-        this.required = (this.field.required || node.attrs.required) == '1';
+        this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1';
+        this.readonly = this.modifiers['readonly'] === true;
+        this.required = this.modifiers['required'] === true;
         this.invalid = false;
         this.touched = false;
     },
index 8b4b16f..a460dfc 100644 (file)
@@ -268,10 +268,12 @@ openerp.base.list.editable = function (openerp) {
         openerp.base.list.form[key] = (form_widgets.get_object(key)).extend({
             update_dom: function () {
                 this.$element.children().css('visibility', '');
-                if (this.invisible && this.node.attrs.invisible !== '1') {
+                if (this.invisible) {
                     this.$element.children().css('visibility', 'hidden');
                 } else {
+                    this.invisible = !!this.modifiers.tree_invisible;
                     this._super();
+                    this.invisible = false;
                 }
             }
         });
index aa3fe3f..587d2d6 100644 (file)
@@ -252,18 +252,18 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
             var name = field.attrs.name;
             var column = _.extend({id: name, tag: field.tag},
                     field.attrs, fields[name]);
-            // attrs computer
-            if (column.attrs) {
-                var attrs = JSON.parse(column.attrs);
-                column.attrs_for = function (fields) {
+            // modifiers computer
+            if (column.modifiers) {
+                var modifiers = JSON.parse(column.modifiers);
+                column.modifiers_for = function (fields) {
                     var result = {};
-                    for (var attr in attrs) {
-                        result[attr] = domain_computer(attrs[attr], fields);
+                    for (var modifier in modifiers) {
+                        result[modifier] = domain_computer(modifiers[modifier], fields);
                     }
                     return result;
                 };
             } else {
-                column.attrs_for = noop;
+                column.modifiers_for = noop;
             }
             return column;
         };
@@ -275,10 +275,10 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
         if (grouped) {
             this.columns.unshift({
                 id: '_group', tag: '', string: "Group", meta: true,
-                attrs_for: function () { return {}; }
+                modifiers_for: function () { return {}; }
             }, {
                 id: '_count', tag: '', string: '#', meta: true,
-                attrs_for: function () { return {}; }
+                modifiers_for: function () { return {}; }
             });
         }
 
index d37e1dd..c949a89 100644 (file)
         <td t-if="!column.meta and column.invisible !== '1'" t-att-title="column.help"
             t-att-class="'oe-field-cell' + (align ? ' oe-number' : '')"
             t-att-data-field="column.id">
-            <t t-set="attrs" t-value="column.attrs_for(row.data)"/>
+            <t t-set="attrs" t-value="column.modifiers_for(row.data)"/>
             <t t-if="!attrs.invisible">
                 <t t-set="is_button" t-value="column.tag === 'button'"/>
                 <!-- TODO: get correct widget from form -->