From 978eae621d54b8c8bf1bc0afdf2d754d40bc2c42 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 10 May 2012 20:52:14 +0200 Subject: [PATCH] [CHG] split custom filters handling out of regular filters bzr revid: xmo@openerp.com-20120510185214-qyh7wybl0un036dt --- addons/web/static/src/css/base.css | 11 +++- addons/web/static/src/css/base.sass | 10 ++- addons/web/static/src/js/search.js | 94 +++++++++++++++++------------ addons/web/static/src/xml/base.xml | 2 +- 4 files changed, 73 insertions(+), 44 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 466e51e7a90..6d2287aa1c0 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1175,6 +1175,14 @@ border: 1px solid #cccccc; text-align: left; } +.openerp .oe_searchview .oe_searchview_drawer > div { + border-top: 1px solid #cccccc; + margin: 3px 0; +} +.openerp .oe_searchview .oe_searchview_drawer > div:first-child { + border-top: none; + margin: 0; +} .openerp .oe_searchview .oe_searchview_drawer button, .openerp .oe_searchview .oe_searchview_drawer .button { border: none; background: white; @@ -1228,8 +1236,7 @@ color: #404040; } .openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4 { - border-top: 1px solid #cccccc; - margin: 5px 0 3px; + margin: 0; cursor: pointer; } .openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4:before { diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 55d56056619..cf35624d4b1 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -932,6 +932,13 @@ $colour4: #8a89ba border: 1px solid #ccc text-align: left + > div + border-top: 1px solid #ccc + margin: 3px 0 + > div:first-child + border-top: none + margin: 0 + button, .button border: none background: white @@ -980,8 +987,7 @@ $colour4: #8a89ba .oe_searchview_advanced h4 - border-top: 1px solid #ccc - margin: 5px 0 3px + margin: 0 cursor: pointer h4:before diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 2e4abda7b2a..3a190a538db 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -624,9 +624,11 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea data.fields_view.fields); // add Filters to this.inputs, need view.controls filled - var filters = new instance.web.search.Filters(this); + (new instance.web.search.Filters(this)); + // add custom filters to this.inputs + (new instance.web.search.CustomFilters(this)); // add Advanced to this.inputs - var advanced = new instance.web.search.Advanced(this); + (new instance.web.search.Advanced(this)); // build drawer var drawer_started = $.when.apply( @@ -1479,28 +1481,52 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({ instance.web.search.CustomFilters = instance.web.search.Input.extend({ template: 'SearchView.CustomFilters', + _in_drawer: true, start: function () { + this.model = new instance.web.Model('ir.filters'); + this.filters = {}; this.$element.on('submit', 'form', this.proxy('save_current')); // FIXME: local eval of domain and context to get rid of special endpoint return this.rpc('/web/searchview/get_filters', { model: this.view.model }).pipe(this.proxy('set_filters')); }, - set_filters: function (filters) { + append_filter: function (filter) { var self = this; - var content = this.$element.find('.oe_searchview_custom_list'); - return $.when.apply(null, _(filters).chain() - .map(function (filter) { - // FIXME: handling of ``disabled`` being set - var f = new instance.web.search.Filter({attrs: { - string: filter.name, - context: filter.context, - domain: filter.domain - }}, self.view); - return new instance.web.search.FilterGroup([f], self.view); - }) - .invoke('appendTo', content) - .value()); + var key = _.str.sprintf('(%s)%s', filter.user_id, filter.name); + + var $filter; + if (key in this.filters) { + $filter = this.filters[key]; + } else { + var id = filter.id; + $filter = this.filters[key] = $('
  • ') + .appendTo(this.$element.find('.oe_searchview_custom_list')) + .text(filter.name); + $('