[IMP] stop using custom /web/searchview endpoints in search view
authorXavier Morel <xmo@openerp.com>
Mon, 26 Nov 2012 09:38:18 +0000 (10:38 +0100)
committerXavier Morel <xmo@openerp.com>
Mon, 26 Nov 2012 09:38:18 +0000 (10:38 +0100)
bzr revid: xmo@openerp.com-20121126093818-omxaj3qljolgq8qj

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

index e0a95df..b7514e8 100644 (file)
@@ -341,17 +341,19 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
         if (this.headless) {
             this.ready.resolve();
         } else {
-            var load_view = this.rpc("/web/searchview/load", {
+            var load_view = this.rpc("/web/view/load", {
                 model: this.model,
                 view_id: this.view_id,
-                context: this.dataset.get_context() });
-
-            $.when(load_view)
-                .then(function(r) {
-                    self.search_view_loaded(r)
-                }, function () {
-                    self.ready.reject.apply(null, arguments);
-                });
+                view_type: 'search',
+                context: instance.web.pyeval.eval(
+                    'context', this.dataset.get_context())
+            });
+
+            $.when(load_view).then(function (r) {
+                return self.search_view_loaded(r)
+            }).fail(function () {
+                self.ready.reject.apply(null, arguments);
+            });
         }
 
         instance.web.bus.on('click', this, function(ev) {
@@ -615,16 +617,16 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
 
     search_view_loaded: function(data) {
         var self = this;
-        this.fields_view = data.fields_view;
-        if (data.fields_view.type !== 'search' ||
-            data.fields_view.arch.tag !== 'search') {
+        this.fields_view = data;
+        if (data.type !== 'search' ||
+            data.arch.tag !== 'search') {
                 throw new Error(_.str.sprintf(
                     "Got non-search view after asking for a search view: type %s, arch root %s",
-                    data.fields_view.type, data.fields_view.arch.tag));
+                    data.type, data.arch.tag));
         }
         this.make_widgets(
-            data.fields_view['arch'].children,
-            data.fields_view.fields);
+            data['arch'].children,
+            data.fields);
 
         this.add_common_inputs();
 
@@ -632,6 +634,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
         var drawer_started = $.when.apply(
             null, _(this.select_for_drawer()).invoke(
                 'appendTo', this.$('.oe_searchview_drawer')));
+
         
         // load defaults
         var defaults_fetched = $.when.apply(null, _(this.inputs).invoke(
@@ -1506,16 +1509,10 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({
         this.$el.on('click', 'h4', function () {
             self.$el.toggleClass('oe_opened');
         });
-        // FIXME: local eval of domain and context to get rid of special endpoint
-        return this.rpc('/web/searchview/get_filters', {
-            model: this.view.model
-        })
+        return this.model.call('get_filters', [this.view.model])
             .then(this.proxy('set_filters'))
-            .then(function () {
-                self.is_ready.resolve(null);
-            }, function () {
-                self.is_ready.reject();
-            });
+            .done(function () { self.is_ready.resolve(); })
+            .fail(function () { self.is_ready.reject.apply(self.is_ready, arguments); });
     },
     /**
      * Special implementation delaying defaults until CustomFilters is loaded
@@ -1708,7 +1705,7 @@ instance.web.search.Advanced = instance.web.search.Input.extend({
             });
         return $.when(
             this._super(),
-            this.rpc("/web/searchview/fields_get", {model: this.view.model}).done(function(data) {
+            new instance.web.Model(this.view.model).call('fields_get').done(function(data) {
                 self.fields = _.extend({
                     id: { string: 'ID', type: 'id' }
                 }, data.fields);
index 20534ef..870ce24 100644 (file)
@@ -152,9 +152,9 @@ var makeSearchView = function (instance, dummy_widget_attributes, defaults) {
     instance.dummy = {};
     instance.dummy.DummyWidget = instance.web.search.Field.extend(
         dummy_widget_attributes || {});
-    if (!('/web/searchview/load' in instance.session.responses)) {
-        instance.session.responses['/web/searchview/load'] = function () {
-            return {fields_view: {
+    if (!('/web/view/load' in instance.session.responses)) {
+        instance.session.responses['/web/view/load'] = function () {
+            return {
                 type: 'search',
                 fields: {
                     dummy: {type: 'char', string: "Dummy"}
@@ -171,13 +171,13 @@ var makeSearchView = function (instance, dummy_widget_attributes, defaults) {
                         children: []
                     }]
                 }
-            }};
+            };
         };
     }
-    instance.session.responses['/web/searchview/get_filters'] = function () {
+    instance.session.responses['ir.filters:get_filters'] = function () {
         return [];
     };
-    instance.session.responses['/web/searchview/fields_get'] = function () {
+    instance.session.responses['dummy.model:fields_get'] = function () {
         return {fields: {
             dummy: {type: 'char', string: 'Dummy'}
         }};
@@ -890,9 +890,9 @@ openerp.testing.section('filters', {
     rpc: 'mock',
     templates: true,
     setup: function (instance, $s, mock) {
-        mock('/web/searchview/load', function () {
+        mock('/web/view/load', function () {
             // view with a single group of filters
-            return {fields_view: {
+            return {
                 type: 'search',
                 fields: {},
                 arch: {
@@ -915,7 +915,7 @@ openerp.testing.section('filters', {
                         children: []
                     }]
                 }
-            }};
+            };
         });
     }
 }, function (test) {
@@ -992,7 +992,7 @@ openerp.testing.section('saved_filters', {
 }, function (test) {
     test('checkboxing', {asserts: 6}, function (instance, $fix, mock) {
         var view = makeSearchView(instance);
-        mock('/web/searchview/get_filters', function () {
+        mock('ir.filters:get_filters', function () {
             return [{ name: "filter name", user_id: 42 }];
         });
 
@@ -1015,7 +1015,7 @@ openerp.testing.section('saved_filters', {
     });
     test('removal', {asserts: 1}, function (instance, $fix, mock) {
         var view = makeSearchView(instance);
-        mock('/web/searchview/get_filters', function () {
+        mock('ir.filters:get_filters', function () {
             return [{ name: "filter name", user_id: 42 }];
         });