Xavier (Open ERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-custom-filters-checking-xmo 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-custom-filters-checking-xmo/+merge/112023

"Selects" and "deselects" custom filters in the drawer (adds/removes check 
mark) when adding them to the search query or removing them therefrom.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-custom-filters-checking-xmo/+merge/112023
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-custom-filters-checking-xmo.
=== modified file 'addons/web/static/src/js/search.js'
--- addons/web/static/src/js/search.js	2012-06-25 13:52:15 +0000
+++ addons/web/static/src/js/search.js	2012-06-26 08:13:22 +0000
@@ -1540,6 +1540,14 @@
         var self = this;
         this.model = new instance.web.Model('ir.filters');
         this.filters = {};
+        this.view.query
+            .on('remove', function (facet) {
+                if (!facet.get('is_custom_filter')) {
+                    return;
+                }
+                self.clear_selection();
+            })
+            .on('reset', this.proxy('clear_selection'));
         this.$element.on('submit', 'form', this.proxy('save_current'));
         this.$element.on('click', 'h4', function () {
             self.$element.toggleClass('oe_opened');
@@ -1549,6 +1557,9 @@
             model: this.view.model
         }).pipe(this.proxy('set_filters'));
     },
+    clear_selection: function () {
+        this.$element.find('li.oe_selected').removeClass('oe_selected');
+    },
     append_filter: function (filter) {
         var self = this;
         var key = _.str.sprintf('(%s)%s', filter.user_id, filter.name);
@@ -1583,8 +1594,10 @@
                     get_groupby: function () { return [filter.context]; },
                     get_domain: function () { return filter.domain; }
                 },
+                is_custom_filter: true,
                 values: [{label: filter.name, value: null}]
             }]);
+            $filter.addClass('oe_selected');
         });
     },
     set_filters: function (filters) {

=== modified file 'addons/web/static/test/search.js'
--- addons/web/static/test/search.js	2012-05-22 13:23:21 +0000
+++ addons/web/static/test/search.js	2012-06-26 08:13:22 +0000
@@ -1094,6 +1094,72 @@
             });
     });
 
+    module('saved_filters', {
+        setup: function () {
+            instance = window.openerp.init([]);
+            window.openerp.web.corelib(instance);
+            window.openerp.web.coresetup(instance);
+            window.openerp.web.chrome(instance);
+            window.openerp.web.data(instance);
+            window.openerp.web.formats(instance);
+            window.openerp.web.search(instance);
+
+            instance.web.qweb.add_template(doc);
+
+            mockifyRPC(instance.connection);
+        }
+    });
+    asyncTest('checkboxing', 6, function () {
+        var view = makeSearchView();
+        instance.connection.responses['/web/searchview/get_filters'] = function () {
+            return {result: [{
+                name: "filter name",
+                user_id: 42
+            }]};
+        };
+        var $fix = $('#qunit-fixture');
+
+        view.appendTo($fix)
+            .always(start)
+            .fail(function (error) { ok(false, error.message); })
+            .done(function () {
+                var $row = $fix.find('.oe_searchview_custom li:first').click();
+
+                ok($row.hasClass('oe_selected'), "should check/select the filter's row");
+                ok($row.hasClass("oe_searchview_custom_private"),
+                    "should have private filter note/class");
+                equal(view.query.length, 1, "should have only one facet");
+                var values = view.query.at(0).values;
+                equal(values.length, 1,
+                    "should have only one value in the facet");
+                equal(values.at(0).get('label'), 'filter name',
+                    "displayed label should be the name of the filter");
+                equal(values.at(0).get('value'), null,
+                    "should have no value set");
+            })
+    });
+    asyncTest('removal', 1, function () {
+        var view = makeSearchView();
+        instance.connection.responses['/web/searchview/get_filters'] = function () {
+            return {result: [{
+                name: "filter name",
+                user_id: 42
+            }]};
+        };
+        var $fix = $('#qunit-fixture');
+
+        view.appendTo($fix)
+            .always(start)
+            .fail(function (error) { ok(false, error.message); })
+            .done(function () {
+                var $row = $fix.find('.oe_searchview_custom li:first').click();
+
+                view.query.remove(view.query.at(0));
+                ok(!$row.hasClass('oe_selected'),
+                    "should not be checked anymore");
+            })
+    });
+
     module('advanced', {
         setup: function () {
             instance = window.openerp.init([]);

_______________________________________________
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