[IMP] remove redundancy in creating a facet from a default value in m2o fields
authorXavier Morel <xmo@openerp.com>
Thu, 26 Apr 2012 14:10:33 +0000 (16:10 +0200)
committerXavier Morel <xmo@openerp.com>
Thu, 26 Apr 2012 14:10:33 +0000 (16:10 +0200)
bzr revid: xmo@openerp.com-20120426141033-5blb5ifdfnzeea03

addons/web/static/src/js/search.js

index a75dd6f..5ef6db4 100644 (file)
@@ -1271,21 +1271,17 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
         });
     },
     facet_for: function (value) {
-        var self = this;
+        var self = this, fromPair = function (a) { return {
+            category: self.attrs.string,
+            field: self,
+            values: [{label: a[1], value: a[0]}]
+        } };
         if (value instanceof Array) {
-            return $.when({
-                category: this.attrs.string,
-                value: value[1],
-                values: [{label: value[1], value: value[0]}]
-            });
+            return $.when(fromPair(value));
         }
         return this.model.call('name_get', [value], {}).pipe(function (names) {
             if (_(names).isEmpty()) { return null; }
-            return {
-                category: self.attrs.string,
-                field: self,
-                values: [{label: names[0][1], value: names[0][0]}]
-            };
+            return fromPair(names[0]);
         })
     },
     make_domain: function (name, operator, facet) {