Thibault Delavallée (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-stage-state-tde into lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-stage-state-tde/+merge/107342
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-stage-state-tde/+merge/107342
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-stage-state-tde.
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js	2012-05-22 16:13:14 +0000
+++ addons/web/static/src/js/view_form.js	2012-05-25 07:53:18 +0000
@@ -3874,63 +3874,112 @@
         this._super();
         this.selected_value = null;
 
-        this.render_list();
+        //this.render_list();
     },
     set_value: function(value_) {
         this._super(value_);
-        this.selected_value = value_;
-
+        /** find selected value: ex:
+         * - many2one: [2, "New"] -> 2
+         * - selection: new -> new */
+        if (this.field.type == "many2one") {
+            this.selected_value = value_[0];
+        }
+        else {
+            this.selected_value = value_;
+        }
         this.render_list();
     },
+    /** Get the status list and render them
+     *  to_show: [[identifier, value_to_displaty]] where
+     *   - identifier = db value for a selection, id for a many2one
+     *   - display_val = value that will be displayed
+     *   - ex: [[0, "New"]] (selection) or [["new", "new"]] (many2one)
+     */
     render_list: function() {
         var self = this;
+        // get selection values
+        var selection_done = this.get_selection();
+        // search in the external relation for all possible values, then render them
+        var rendering_done = $.when(selection_done).pipe(function () {
+            self.filter_selection();
+        }).pipe(self.proxy('render_elements'));
+        return rendering_done;
+    },
+    get_selection: function() {
+        var self = this;
+        if (this.field.type == "many2one") {
+            this.selection = [];
+            // get a DataSet on the current model (ex: crm.lead)
+            var model = new instance.web.DataSet(this, this.field_manager.dataset.model);
+            // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage)
+            console.log('this');
+            console.log(this);
+            var context = self.build_context();
+            console.log('context');
+            console.log(context);
+            var domain = self.build_domain();
+            console.log('domain');
+            console.log(domain);
+            //var new_domain = new instance.web.CompoundDomain(['|'], domain, [['case_default', '=', 'True']]);
+            //console.log(new_domain);
+            var model_ext = new instance.web.DataSetSearch(this, this.field.relation, context);
+            // fetch selection
+            //var read_defer = model_ext.read_slice(['name'], {'domain': domain, 'context': context}).pipe( function (records) {
+            var read_defer = model_ext.read_slice(['name'], {'domain': []}).pipe( function (records) {
+                self.to_show = [];
+                _(records).each(function (record) {
+                    self.selection.push([record.id, record.name]);
+                });
+                console.log('to_show');
+                console.log(self.to_show);
+            });
+        }
+        else {
+            this.selection = this.field.selection;
+            var read_defer = true;
+        }
+        return read_defer;
+    },
+    /** Filters this.selection, according to values coming from the statusbar_visible
+     *  attribute of the field. For example: statusbar_visible="draft,open"
+     *  There is however two main possibilities :
+     *  - the value is the identifier, for a selection (new for [new, "New"])
+     *    -> in this case, the options values refer to list[x][0]
+     *  - the value is the name or displayed value, for a many2one
+     *    (Draft for [0, "Draft"])
+     *    -> in this case, the options values refer to list[x][0]
+     */
+    filter_selection: function() {
+        var self = this;
+        if (this.field.type == "many2one") {
+            var index = 1;
+        }
+        else {
+            var index = 0;
+        }
         var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","),
             function(x) { return _.str.trim(x); });
         shown = _.select(shown, function(x) { return x.length > 0; });
-
+        
         if (shown.length == 0) {
-            this.to_show = this.field.selection;
+            this.to_show = this.selection;
         } else {
-            this.to_show = _.select(this.field.selection, function(x) {
-                return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value;
+            this.to_show = _.select(this.selection, function(x) {
+                return _.indexOf(shown, x[index]) !== -1 || x[0] === self.selected_value;
             });
         }
-
+    },
+    render_elements: function () {
         var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_});
         this.$element.html(content);
 
         var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}");
         var color = colors[this.selected_value];
         if (color) {
-            var elem = this.$element.find("li.oe-arrow-list-selected span");
-            elem.css("border-color", color);
-            if (this.check_white(color))
-                elem.css("color", "white");
-            elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before");
-            elem.css("border-left-color", "rgba(0,0,0,0)");
-            elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after");
-            elem.css("border-color", "rgba(0,0,0,0)");
-            elem.css("border-left-color", color);
+            var elem = this.$element.find("li.oe_form_steps_active span");
+            elem.css("color", color);
         }
     },
-    check_white: function(color) {
-        var div = $("<div></div>");
-        div.css("display", "none");
-        div.css("color", color);
-        div.appendTo($("body"));
-        var ncolor = div.css("color");
-        div.remove();
-        var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor);
-        if (!res) {
-            return false;
-        }
-        var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])];
-        var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11;
-        if (lum < 128) {
-            return true;
-        }
-        return false;
-    }
 });
 
 /**
@@ -3961,7 +4010,7 @@
     'progressbar': 'instance.web.form.FieldProgressBar',
     'image': 'instance.web.form.FieldBinaryImage',
     'binary': 'instance.web.form.FieldBinaryFile',
-    'statusbar': 'instance.web.form.FieldStatus'
+    'statusbar': 'instance.web.form.FieldStatus',
 });
 
 /**

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2012-05-22 16:13:14 +0000
+++ addons/web/static/src/xml/base.xml	2012-05-25 07:53:18 +0000
@@ -1075,21 +1075,11 @@
     </div>
 </t>
 <t t-name="FieldStatus.content">
-    <ul class="oe-arrow-list">
-        <t t-set="size" t-value="widget.to_show.length"/>
-        <t t-foreach="_.range(size)" t-as="i">
-            <li t-att-class="widget.to_show[i][0] === widget.selected_value ? 'oe-arrow-list-selected' : ''">
-                <span class="oe-arrow-list-before" t-if="i &gt; 0"></span><span><t t-esc="widget.to_show[i][1]"/></span><span class="oe-arrow-list-after" t-if="i &lt; size - 1"></span>
-            </li>
-        </t>
-    </ul>
-</t>
-<t t-name="FieldStatus.content">
     <ul class="oe_form_steps">
         <t t-set="size" t-value="widget.to_show.length"/>
         <t t-foreach="_.range(size)" t-as="i">
             <li t-att-class="widget.to_show[i][0] === widget.selected_value ? 'oe_form_steps_active' : ''">
-                <t t-esc="widget.to_show[i][1]"/>
+                <span><t t-esc="widget.to_show[i][1]"/></span>
                 <img t-att-src='_s + "/web/static/src/img/form_steps.png"' class="oe_form_steps_arrow" t-if="i &lt; size - 1"/>
             </li>
         </t>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to