[ADD] marking of currently selected filters in the drawer
authorXavier Morel <xmo@openerp.com>
Fri, 18 May 2012 15:23:42 +0000 (17:23 +0200)
committerXavier Morel <xmo@openerp.com>
Fri, 18 May 2012 15:23:42 +0000 (17:23 +0200)
Visually hints to users currently manipulating the drawer that a given
filter is currently selected.

bzr revid: xmo@openerp.com-20120518152342-xmqhwlml0bsgodhq

addons/web/static/src/css/base.css
addons/web/static/src/css/base.sass
addons/web/static/src/js/search.js

index 5dcc1f3..37b4de1 100644 (file)
 }
 .openerp .oe_searchview .oe_searchview_drawer .oe_searchview_filters li {
   list-style: none;
-  padding: 3px 6px;
+  padding: 3px 6px 3px 18px;
   height: 14px;
   line-height: 14px;
   color: inherit;
   cursor: pointer;
 }
+.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_filters li.oe_selected {
+  background: url(/web/static/src/img/icons/gtk-apply.png) left center no-repeat;
+}
 .openerp .oe_searchview .oe_searchview_drawer .oe_searchview_filters li:hover {
   background-color: #f0f0fa;
 }
index ecade4f..67e2399 100644 (file)
@@ -1094,15 +1094,19 @@ $colour4: #8a89ba
 
                 li
                     list-style: none
-                    padding: 3px 6px
+                    padding: 3px 6px 3px 18px
                     height: 14px
                     line-height: 14px
                     color: inherit
                     cursor: pointer
 
+                    &.oe_selected
+                        background: url(/web/static/src/img/icons/gtk-apply.png) left center no-repeat
+                    // after oe_selected so background color is not overridden
                     &:hover
                         background-color: $hover-background
 
+
             .oe_searchview_custom
                 form
                     display: none
index 2532dea..91423b5 100644 (file)
@@ -644,8 +644,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
         // load defaults
         var defaults_fetched = $.when.apply(null, _(this.inputs).invoke(
             'facet_for_defaults', this.defaults)).then(function () {
-                self.query.reset(_(arguments).compact(), {silent: true});
-                self.renderFacets();
+                self.query.reset(_(arguments).compact(), {preventSearch: true});
             });
 
         return $.when(drawer_started, defaults_fetched)
@@ -800,7 +799,10 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
      *
      * @param e jQuery event object coming from the "Search" button
      */
-    do_search: function () {
+    do_search: function (_query, options) {
+        if (options && options.preventSearch) {
+            return;
+        }
         var search = this.build_search_data();
         if (!_.isEmpty(search.errors)) {
             this.on_invalid(search.errors);
@@ -1009,11 +1011,34 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
         }
         this._super(view);
         this.filters = filters;
+        this.view.query.on('add remove change reset', this.proxy('search_change'));
     },
     start: function () {
         this.$element.on('click', 'li', this.proxy('toggle_filter'));
         return $.when(null);
     },
+    /**
+     * Handles change of the search query: any of the group's filter which is
+     * in the search query should be visually checked in the drawer
+     */
+    search_change: function () {
+        var self = this;
+        var $filters = this.$element.find('> li').removeClass('oe_selected');
+        var facet = this.view.query.find(_.bind(this.match_facet, this));
+        if (!facet) { return; }
+        facet.values.each(function (v) {
+            var i = _(self.filters).indexOf(v.get('value'));
+            if (i === -1) { return; }
+            $filters.eq(i).addClass('oe_selected');
+        });
+    },
+    /**
+     * Matches the group to a facet, in order to find if the group is
+     * represented in the current search query
+     */
+    match_facet: function (facet) {
+        return facet.get('field') === this;
+    },
     make_facet: function (values) {
         return {
             category: _t("Filter"),
@@ -1130,7 +1155,7 @@ instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
         this._super(filters, view);
         // Not flanders: facet unicity is handled through the
         // (category, field) pair of facet attributes. This is all well and
-        // good for regular filter groups where a group matche a facet, but for
+        // good for regular filter groups where a group matches a facet, but for
         // groupby we want a single facet. So cheat: add an attribute on the
         // view which proxies to the first GroupbyGroup, so it can be used
         // for every GroupbyGroup and still provides the various methods needed
@@ -1144,6 +1169,9 @@ instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
             }
         }
     },
+    match_facet: function (facet) {
+        return facet.get('field') === this.getParent()._s_groupby;
+    },
     make_facet: function (values) {
         return {
             category: _t("GroupBy"),