[FIX] fixes searchbar navigation (web client)
[odoo/odoo.git] / addons / web / static / src / js / search.js
1 openerp.web.search = function(instance) {
2 var QWeb = instance.web.qweb,
3       _t =  instance.web._t,
4      _lt = instance.web._lt;
5 _.mixin({
6     sum: function (obj) { return _.reduce(obj, function (a, b) { return a + b; }, 0); }
7 });
8
9 /** @namespace */
10 var my = instance.web.search = {};
11
12 var B = Backbone;
13 my.FacetValue = B.Model.extend({
14
15 });
16 my.FacetValues = B.Collection.extend({
17     model: my.FacetValue
18 });
19 my.Facet = B.Model.extend({
20     initialize: function (attrs) {
21         var values = attrs.values;
22         delete attrs.values;
23
24         B.Model.prototype.initialize.apply(this, arguments);
25
26         this.values = new my.FacetValues(values || []);
27         this.values.on('add remove change reset', function () {
28             this.trigger('change', this);
29         }, this);
30     },
31     get: function (key) {
32         if (key !== 'values') {
33             return B.Model.prototype.get.call(this, key);
34         }
35         return this.values.toJSON();
36     },
37     set: function (key, value) {
38         if (key !== 'values') {
39             return B.Model.prototype.set.call(this, key, value);
40         }
41         this.values.reset(value);
42     },
43     toJSON: function () {
44         var out = {};
45         var attrs = this.attributes;
46         for(var att in attrs) {
47             if (!attrs.hasOwnProperty(att) || att === 'field') {
48                 continue;
49             }
50             out[att] = attrs[att];
51         }
52         out.values = this.values.toJSON();
53         return out;
54     }
55 });
56 my.SearchQuery = B.Collection.extend({
57     model: my.Facet,
58     initialize: function () {
59         B.Collection.prototype.initialize.apply(
60             this, arguments);
61         this.on('change', function (facet) {
62             if(!facet.values.isEmpty()) { return; }
63
64             this.remove(facet, {silent: true});
65         }, this);
66     },
67     add: function (values, options) {
68         options || (options = {});
69         if (!(values instanceof Array)) {
70             values = [values];
71         }
72
73         _(values).each(function (value) {
74             var model = this._prepareModel(value, options);
75             var previous = this.detect(function (facet) {
76                 return facet.get('category') === model.get('category')
77                     && facet.get('field') === model.get('field');
78             });
79             if (previous) {
80                 previous.values.add(model.get('values'));
81                 return;
82             }
83             B.Collection.prototype.add.call(this, model, options);
84         }, this);
85         return this;
86     },
87     toggle: function (value, options) {
88         options || (options = {});
89
90         var facet = this.detect(function (facet) {
91             return facet.get('category') === value.category
92                 && facet.get('field') === value.field;
93         });
94         if (!facet) {
95             return this.add(value, options);
96         }
97
98         var changed = false;
99         _(value.values).each(function (val) {
100             var already_value = facet.values.detect(function (v) {
101                 return v.get('value') === val.value
102                     && v.get('label') === val.label;
103             });
104             // toggle value
105             if (already_value) {
106                 facet.values.remove(already_value, {silent: true});
107             } else {
108                 facet.values.add(val, {silent: true});
109             }
110             changed = true;
111         });
112         // "Commit" changes to values array as a single call, so observers of
113         // change event don't get misled by intermediate incomplete toggling
114         // states
115         facet.trigger('change', facet);
116         return this;
117     }
118 });
119
120 function assert(condition, message) {
121     if(!condition) {
122         throw new Error(message);
123     }
124 }
125 my.InputView = instance.web.Widget.extend({
126     template: 'SearchView.InputView',
127     events: {
128         focus: function () { this.trigger('focused', this); },
129         blur: function () { this.$el.text(''); this.trigger('blurred', this); },
130         keydown: 'onKeydown',
131         paste: 'onPaste',
132     },
133     getSelection: function () {
134         this.el.normalize();
135         // get Text node
136         var root = this.el.childNodes[0];
137         if (!root || !root.textContent) {
138             // if input does not have a child node, or the child node is an
139             // empty string, then the selection can only be (0, 0)
140             return {start: 0, end: 0};
141         }
142         var range = window.getSelection().getRangeAt(0);
143         // In Firefox, depending on the way text is selected (drag, double- or
144         // triple-click) the range may start or end on the parent of the
145         // selected text node‽ Check for this condition and fixup the range
146         // note: apparently with C-a this can go even higher?
147         if (range.startContainer === this.el && range.startOffset === 0) {
148             range.setStart(root, 0);
149         }
150         if (range.endContainer === this.el && range.endOffset === 1) {
151             range.setEnd(root, root.length)
152         }
153         assert(range.startContainer === root,
154                "selection should be in the input view");
155         assert(range.endContainer === root,
156                "selection should be in the input view");
157         return {
158             start: range.startOffset,
159             end: range.endOffset
160         }
161     },
162     onKeydown: function (e) {
163         this.el.normalize();
164         var sel;
165         switch (e.which) {
166         // Do not insert newline, but let it bubble so searchview can use it
167         case $.ui.keyCode.ENTER:
168             e.preventDefault();
169             break;
170
171         // FIXME: may forget content if non-empty but caret at index 0, ok?
172         case $.ui.keyCode.BACKSPACE:
173             sel = this.getSelection();
174             if (sel.start === 0 && sel.start === sel.end) {
175                 e.preventDefault();
176                 var preceding = this.getParent().siblingSubview(this, -1);
177                 if (preceding && (preceding instanceof my.FacetView)) {
178                     preceding.model.destroy();
179                 }
180             }
181             break;
182
183         // let left/right events propagate to view if caret is at input border
184         // and not a selection
185         case $.ui.keyCode.LEFT:
186             sel = this.getSelection();
187             if (sel.start !== 0 || sel.start !== sel.end) {
188                 e.stopPropagation();
189             }
190             break;
191         case $.ui.keyCode.RIGHT:
192             sel = this.getSelection();
193             var len = this.$el.text().length;
194             if (sel.start !== len || sel.start !== sel.end) {
195                 e.stopPropagation();
196             }
197             break;
198         }
199     },
200     setCursorAtEnd: function () {
201         this.el.normalize();
202         var sel = window.getSelection();
203         sel.removeAllRanges();
204         var range = document.createRange();
205         // in theory, range.selectNodeContents should work here. In practice,
206         // MSIE9 has issues from time to time, instead of selecting the inner
207         // text node it would select the reference node instead (e.g. in demo
208         // data, company news, copy across the "Company News" link + the title,
209         // from about half the link to half the text, paste in search box then
210         // hit the left arrow key, getSelection would blow up).
211         //
212         // Explicitly selecting only the inner text node (only child node
213         // since we've normalized the parent) avoids the issue
214         range.selectNode(this.el.childNodes[0]);
215         range.collapse(false);
216         sel.addRange(range);
217     },
218     onPaste: function () {
219         this.el.normalize();
220         // In MSIE and Webkit, it is possible to get various representations of
221         // the clipboard data at this point e.g.
222         // window.clipboardData.getData('Text') and
223         // event.clipboardData.getData('text/plain') to ensure we have a plain
224         // text representation of the object (and probably ensure the object is
225         // pastable as well, so nobody puts an image in the search view)
226         // (nb: since it's not possible to alter the content of the clipboard
227         // — at least in Webkit — to ensure only textual content is available,
228         // using this would require 1. getting the text data; 2. manually
229         // inserting the text data into the content; and 3. cancelling the
230         // paste event)
231         //
232         // But Firefox doesn't support the clipboard API (as of FF18)
233         // although it correctly triggers the paste event (Opera does not even
234         // do that) => implement lowest-denominator system where onPaste
235         // triggers a followup "cleanup" pass after the data has been pasted
236         setTimeout(function () {
237             // Read text content (ignore pasted HTML)
238             var data = this.$el.text();
239             // paste raw text back in
240             this.$el.empty().text(data);
241             this.el.normalize();
242             // Set the cursor at the end of the text, so the cursor is not lost
243             // in some kind of error-spawning limbo.
244             this.setCursorAtEnd();
245         }.bind(this), 0);
246     }
247 });
248 my.FacetView = instance.web.Widget.extend({
249     template: 'SearchView.FacetView',
250     events: {
251         'focus': function () { this.trigger('focused', this); },
252         'blur': function () { this.trigger('blurred', this); },
253         'click': function (e) {
254             if ($(e.target).is('.oe_facet_remove')) {
255                 this.model.destroy();
256                 return false;
257             }
258             this.$el.focus();
259             e.stopPropagation();
260         },
261         'keydown': function (e) {
262             var keys = $.ui.keyCode;
263             switch (e.which) {
264             case keys.BACKSPACE:
265             case keys.DELETE:
266                 this.model.destroy();
267                 return false;
268             }
269         }
270     },
271     init: function (parent, model) {
272         this._super(parent);
273         this.model = model;
274         this.model.on('change', this.model_changed, this);
275     },
276     destroy: function () {
277         this.model.off('change', this.model_changed, this);
278         this._super();
279     },
280     start: function () {
281         var self = this;
282         var $e = this.$('> span:last-child');
283         return $.when(this._super()).then(function () {
284             return $.when.apply(null, self.model.values.map(function (value) {
285                 return new my.FacetValueView(self, value).appendTo($e);
286             }));
287         });
288     },
289     model_changed: function () {
290         this.$el.text(this.$el.text() + '*');
291     }
292 });
293 my.FacetValueView = instance.web.Widget.extend({
294     template: 'SearchView.FacetView.Value',
295     init: function (parent, model) {
296         this._super(parent);
297         this.model = model;
298         this.model.on('change', this.model_changed, this);
299     },
300     destroy: function () {
301         this.model.off('change', this.model_changed, this);
302         this._super();
303     },
304     model_changed: function () {
305         this.$el.text(this.$el.text() + '*');
306     }
307 });
308
309 instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.SearchView# */{
310     template: "SearchView",
311     events: {
312         // focus last input if view itself is clicked
313         'click': function (e) {
314             if (e.target === this.$('.oe_searchview_facets')[0]) {
315                 this.$('.oe_searchview_input:last').focus();
316             }
317         },
318         // search button
319         'click button.oe_searchview_search': function (e) {
320             e.stopImmediatePropagation();
321             this.do_search();
322         },
323         'click .oe_searchview_clear': function (e) {
324             e.stopImmediatePropagation();
325             this.query.reset();
326         },
327         'click .oe_searchview_unfold_drawer': function (e) {
328             e.stopImmediatePropagation();
329             this.$el.toggleClass('oe_searchview_open_drawer');
330         },
331         'keydown .oe_searchview_input, .oe_searchview_facet': function (e) {
332             switch(e.which) {
333             case $.ui.keyCode.LEFT:
334                 this.focusPreceding(e.target);
335                 e.preventDefault();
336                 break;
337             case $.ui.keyCode.RIGHT:
338                 this.focusFollowing(e.target);
339                 e.preventDefault();
340                 break;
341             }
342         },
343         'autocompleteopen': function () {
344             this.$el.autocomplete('widget').css('z-index', 9999);
345         },
346     },
347     /**
348      * @constructs instance.web.SearchView
349      * @extends instance.web.Widget
350      *
351      * @param parent
352      * @param dataset
353      * @param view_id
354      * @param defaults
355      * @param {Object} [options]
356      * @param {Boolean} [options.hidden=false] hide the search view
357      * @param {Boolean} [options.disable_custom_filters=false] do not load custom filters from ir.filters
358      */
359     init: function(parent, dataset, view_id, defaults, options) {
360         // Backward compatibility - Can be removed when forward porting
361         if (Object(options) !== options) {
362             options = {
363                 hidden: !!options
364             };
365         }
366         // End of Backward compatibility
367         this.options = _.defaults(options || {}, {
368             hidden: false,
369             disable_custom_filters: false,
370         });
371         this._super(parent);
372         this.dataset = dataset;
373         this.model = dataset.model;
374         this.view_id = view_id;
375
376         this.defaults = defaults || {};
377         this.has_defaults = !_.isEmpty(this.defaults);
378
379         this.inputs = [];
380         this.controls = [];
381
382         this.headless = this.options.hidden && !this.has_defaults;
383
384         this.input_subviews = [];
385
386         this.ready = $.Deferred();
387     },
388     start: function() {
389         var self = this;
390         var p = this._super();
391
392         this.setup_global_completion();
393         this.query = new my.SearchQuery()
394                 .on('add change reset remove', this.proxy('do_search'))
395                 .on('add change reset remove', this.proxy('renderFacets'));
396
397         if (this.options.hidden) {
398             this.$el.hide();
399         }
400         if (this.headless) {
401             this.ready.resolve();
402         } else {
403             var load_view = instance.web.fields_view_get({
404                 model: this.dataset._model,
405                 view_id: this.view_id,
406                 view_type: 'search',
407                 context: this.dataset.get_context(),
408             });
409
410             this.alive($.when(load_view)).then(function (r) {
411                 return self.search_view_loaded(r)
412             }).fail(function () {
413                 self.ready.reject.apply(null, arguments);
414             });
415         }
416
417         instance.web.bus.on('click', this, function(ev) {
418             if ($(ev.target).parents('.oe_searchview').length === 0) {
419                 self.$el.removeClass('oe_searchview_open_drawer');
420             }
421         });
422
423         return $.when(p, this.ready);
424     },
425     show: function () {
426         this.$el.show();
427     },
428     hide: function () {
429         this.$el.hide();
430     },
431
432     subviewForRoot: function (subview_root) {
433         return _(this.input_subviews).detect(function (subview) {
434             return subview.$el[0] === subview_root;
435         });
436     },
437     siblingSubview: function (subview, direction, wrap_around) {
438         var index = _(this.input_subviews).indexOf(subview) + direction;
439         if (wrap_around && index < 0) {
440             index = this.input_subviews.length - 1;
441         } else if (wrap_around && index >= this.input_subviews.length) {
442             index = 0;
443         }
444         return this.input_subviews[index];
445     },
446     focusPreceding: function (subview_root) {
447         return this.siblingSubview(
448             this.subviewForRoot(subview_root), -1, true)
449                 .$el.focus();
450     },
451     focusFollowing: function (subview_root) {
452         return this.siblingSubview(
453             this.subviewForRoot(subview_root), +1, true)
454                 .$el.focus();
455     },
456
457     /**
458      * Sets up thingie where all the mess is put?
459      */
460     select_for_drawer: function () {
461         return _(this.inputs).filter(function (input) {
462             return input.in_drawer();
463         });
464     },
465     /**
466      * Sets up search view's view-wide auto-completion widget
467      */
468     setup_global_completion: function () {
469         var autocomplete = this.$el.autocomplete({
470             source: this.proxy('complete_global_search'),
471             select: this.proxy('select_completion'),
472             focus: function (e) { e.preventDefault(); },
473             html: true,
474             autoFocus: true,
475             minLength: 1,
476             delay: 250,
477         }).data('autocomplete');
478
479         this.$el.on('input', function () {
480             this.$el.autocomplete('close');
481         }.bind(this));
482
483         // MonkeyPatch autocomplete instance
484         _.extend(autocomplete, {
485             _renderItem: function (ul, item) {
486                 // item of completion list
487                 var $item = $( "<li></li>" )
488                     .data( "item.autocomplete", item )
489                     .appendTo( ul );
490
491                 if (item.facet !== undefined) {
492                     // regular completion item
493                     return $item.append(
494                         (item.label)
495                             ? $('<a>').html(item.label)
496                             : $('<a>').text(item.value));
497                 }
498                 return $item.text(item.label)
499                     .css({
500                         borderTop: '1px solid #cccccc',
501                         margin: 0,
502                         padding: 0,
503                         zoom: 1,
504                         'float': 'left',
505                         clear: 'left',
506                         width: '100%'
507                     });
508             },
509             _value: function() {
510                 return self.$('div.oe_searchview_input').text();
511             },
512         });
513     },
514     /**
515      * Provide auto-completion result for req.term (an array to `resp`)
516      *
517      * @param {Object} req request to complete
518      * @param {String} req.term searched term to complete
519      * @param {Function} resp response callback
520      */
521     complete_global_search:  function (req, resp) {
522         $.when.apply(null, _(this.inputs).chain()
523             .filter(function (input) { return input.visible(); })
524             .invoke('complete', req.term)
525             .value()).then(function () {
526                 resp(_(_(arguments).compact()).flatten(true));
527         });
528     },
529
530     /**
531      * Action to perform in case of selection: create a facet (model)
532      * and add it to the search collection
533      *
534      * @param {Object} e selection event, preventDefault to avoid setting value on object
535      * @param {Object} ui selection information
536      * @param {Object} ui.item selected completion item
537      */
538     select_completion: function (e, ui) {
539         e.preventDefault();
540
541         var input_index = _(this.input_subviews).indexOf(
542             this.subviewForRoot(
543                 this.$('div.oe_searchview_input:focus')[0]));
544         this.query.add(ui.item.facet, {at: input_index / 2});
545     },
546     childFocused: function () {
547         this.$el.addClass('oe_focused');
548     },
549     childBlurred: function () {
550         var val = this.$el.val();
551         this.$el.val('');
552         var complete = this.$el.data('autocomplete');
553         if ((val && complete.term === undefined) || complete.previous) {
554             throw new Error("new jquery.ui version altering implementation" +
555                             " details relied on");
556         }
557         delete complete.term;
558         this.$el.removeClass('oe_focused')
559                      .trigger('blur');
560     },
561     /**
562      *
563      * @param {openerp.web.search.SearchQuery | openerp.web.search.Facet} _1
564      * @param {openerp.web.search.Facet} [_2]
565      * @param {Object} [options]
566      */
567     renderFacets: function (_1, _2, options) {
568         // _1: model if event=change, otherwise collection
569         // _2: undefined if event=change, otherwise model
570         var self = this;
571         var started = [];
572         var $e = this.$('div.oe_searchview_facets');
573         _.invoke(this.input_subviews, 'destroy');
574         this.input_subviews = [];
575
576         var i = new my.InputView(this);
577         started.push(i.appendTo($e));
578         this.input_subviews.push(i);
579         this.query.each(function (facet) {
580             var f = new my.FacetView(this, facet);
581             started.push(f.appendTo($e));
582             self.input_subviews.push(f);
583
584             var i = new my.InputView(this);
585             started.push(i.appendTo($e));
586             self.input_subviews.push(i);
587         }, this);
588         _.each(this.input_subviews, function (childView) {
589             childView.on('focused', self, self.proxy('childFocused'));
590             childView.on('blurred', self, self.proxy('childBlurred'));
591         });
592
593         $.when.apply(null, started).then(function () {
594             var input_to_focus;
595             // options.at: facet inserted at given index, focus next input
596             // otherwise just focus last input
597             if (!options || typeof options.at !== 'number') {
598                 input_to_focus = _.last(self.input_subviews);
599             } else {
600                 input_to_focus = self.input_subviews[(options.at + 1) * 2];
601             }
602
603             input_to_focus.$el.focus();
604         });
605     },
606
607     /**
608      * Builds a list of widget rows (each row is an array of widgets)
609      *
610      * @param {Array} items a list of nodes to convert to widgets
611      * @param {Object} fields a mapping of field names to (ORM) field attributes
612      * @param {Object} [group] group to put the new controls in
613      */
614     make_widgets: function (items, fields, group) {
615         if (!group) {
616             group = new instance.web.search.Group(
617                 this, 'q', {attrs: {string: _t("Filters")}});
618         }
619         var self = this;
620         var filters = [];
621         _.each(items, function (item) {
622             if (filters.length && item.tag !== 'filter') {
623                 group.push(new instance.web.search.FilterGroup(filters, group));
624                 filters = [];
625             }
626
627             switch (item.tag) {
628             case 'separator': case 'newline':
629                 break;
630             case 'filter':
631                 filters.push(new instance.web.search.Filter(item, group));
632                 break;
633             case 'group':
634                 self.make_widgets(item.children, fields,
635                     new instance.web.search.Group(group, 'w', item));
636                 break;
637             case 'field':
638                 var field = this.make_field(
639                     item, fields[item['attrs'].name], group);
640                 group.push(field);
641                 // filters
642                 self.make_widgets(item.children, fields, group);
643                 break;
644             }
645         }, this);
646
647         if (filters.length) {
648             group.push(new instance.web.search.FilterGroup(filters, this));
649         }
650     },
651     /**
652      * Creates a field for the provided field descriptor item (which comes
653      * from fields_view_get)
654      *
655      * @param {Object} item fields_view_get node for the field
656      * @param {Object} field fields_get result for the field
657      * @param {Object} [parent]
658      * @returns instance.web.search.Field
659      */
660     make_field: function (item, field, parent) {
661         var obj = instance.web.search.fields.get_any( [item.attrs.widget, field.type]);
662         if(obj) {
663             return new (obj) (item, field, parent || this);
664         } else {
665             console.group('Unknown field type ' + field.type);
666             console.error('View node', item);
667             console.info('View field', field);
668             console.info('In view', this);
669             console.groupEnd();
670             return null;
671         }
672     },
673
674     add_common_inputs: function() {
675         // add Filters to this.inputs, need view.controls filled
676         (new instance.web.search.Filters(this));
677         // add custom filters to this.inputs
678         this.custom_filters = new instance.web.search.CustomFilters(this);
679         // add Advanced to this.inputs
680         (new instance.web.search.Advanced(this));
681     },
682
683     search_view_loaded: function(data) {
684         var self = this;
685         this.fields_view = data;
686         if (data.type !== 'search' ||
687             data.arch.tag !== 'search') {
688                 throw new Error(_.str.sprintf(
689                     "Got non-search view after asking for a search view: type %s, arch root %s",
690                     data.type, data.arch.tag));
691         }
692         this.make_widgets(
693             data['arch'].children,
694             data.fields);
695
696         this.add_common_inputs();
697
698         // build drawer
699         var drawer_started = $.when.apply(
700             null, _(this.select_for_drawer()).invoke(
701                 'appendTo', this.$('.oe_searchview_drawer')));
702
703         
704         // load defaults
705         var defaults_fetched = $.when.apply(null, _(this.inputs).invoke(
706                 'facet_for_defaults', this.defaults))
707             .then(this.proxy('setup_default_query'));
708
709         return $.when(drawer_started, defaults_fetched)
710             .then(function () { 
711                 self.trigger("search_view_loaded", data);
712                 self.ready.resolve();
713             });
714     },
715     setup_default_query: function () {
716         // Hacky implementation of CustomFilters#facet_for_defaults ensure
717         // CustomFilters will be ready (and CustomFilters#filters will be
718         // correctly filled) by the time this method executes.
719         var custom_filters = this.custom_filters.filters;
720         if (!this.options.disable_custom_filters && !_(custom_filters).isEmpty()) {
721             // Check for any is_default custom filter
722             var personal_filter = _(custom_filters).find(function (filter) {
723                 return filter.user_id && filter.is_default;
724             });
725             if (personal_filter) {
726                 this.custom_filters.toggle_filter(personal_filter, true);
727                 return;
728             }
729
730             var global_filter = _(custom_filters).find(function (filter) {
731                 return !filter.user_id && filter.is_default;
732             });
733             if (global_filter) {
734                 this.custom_filters.toggle_filter(global_filter, true);
735                 return;
736             }
737         }
738         // No custom filter, or no is_default custom filter, apply view defaults
739         this.query.reset(_(arguments).compact(), {preventSearch: true});
740     },
741     /**
742      * Extract search data from the view's facets.
743      *
744      * Result is an object with 4 (own) properties:
745      *
746      * errors
747      *     An array of any error generated during data validation and
748      *     extraction, contains the validation error objects
749      * domains
750      *     Array of domains
751      * contexts
752      *     Array of contexts
753      * groupbys
754      *     Array of domains, in groupby order rather than view order
755      *
756      * @return {Object}
757      */
758     build_search_data: function () {
759         var domains = [], contexts = [], groupbys = [], errors = [];
760
761         this.query.each(function (facet) {
762             var field = facet.get('field');
763             try {
764                 var domain = field.get_domain(facet);
765                 if (domain) {
766                     domains.push(domain);
767                 }
768                 var context = field.get_context(facet);
769                 if (context) {
770                     contexts.push(context);
771                 }
772                 var group_by = field.get_groupby(facet);
773                 if (group_by) {
774                     groupbys.push.apply(groupbys, group_by);
775                 }
776             } catch (e) {
777                 if (e instanceof instance.web.search.Invalid) {
778                     errors.push(e);
779                 } else {
780                     throw e;
781                 }
782             }
783         });
784         return {
785             domains: domains,
786             contexts: contexts,
787             groupbys: groupbys,
788             errors: errors
789         };
790     }, 
791     /**
792      * Performs the search view collection of widget data.
793      *
794      * If the collection went well (all fields are valid), then triggers
795      * :js:func:`instance.web.SearchView.on_search`.
796      *
797      * If at least one field failed its validation, triggers
798      * :js:func:`instance.web.SearchView.on_invalid` instead.
799      *
800      * @param [_query]
801      * @param {Object} [options]
802      */
803     do_search: function (_query, options) {
804         if (options && options.preventSearch) {
805             return;
806         }
807         var search = this.build_search_data();
808         if (!_.isEmpty(search.errors)) {
809             this.on_invalid(search.errors);
810             return;
811         }
812         this.trigger('search_data', search.domains, search.contexts, search.groupbys);
813     },
814     /**
815      * Triggered after the SearchView has collected all relevant domains and
816      * contexts.
817      *
818      * It is provided with an Array of domains and an Array of contexts, which
819      * may or may not be evaluated (each item can be either a valid domain or
820      * context, or a string to evaluate in order in the sequence)
821      *
822      * It is also passed an array of contexts used for group_by (they are in
823      * the correct order for group_by evaluation, which contexts may not be)
824      *
825      * @event
826      * @param {Array} domains an array of literal domains or domain references
827      * @param {Array} contexts an array of literal contexts or context refs
828      * @param {Array} groupbys ordered contexts which may or may not have group_by keys
829      */
830     /**
831      * Triggered after a validation error in the SearchView fields.
832      *
833      * Error objects have three keys:
834      * * ``field`` is the name of the invalid field
835      * * ``value`` is the invalid value
836      * * ``message`` is the (in)validation message provided by the field
837      *
838      * @event
839      * @param {Array} errors a never-empty array of error objects
840      */
841     on_invalid: function (errors) {
842         this.do_notify(_t("Invalid Search"), _t("triggered from search view"));
843         this.trigger('invalid_search', errors);
844     }
845 });
846
847 /**
848  * Registry of search fields, called by :js:class:`instance.web.SearchView` to
849  * find and instantiate its field widgets.
850  */
851 instance.web.search.fields = new instance.web.Registry({
852     'char': 'instance.web.search.CharField',
853     'text': 'instance.web.search.CharField',
854     'html': 'instance.web.search.CharField',
855     'boolean': 'instance.web.search.BooleanField',
856     'integer': 'instance.web.search.IntegerField',
857     'id': 'instance.web.search.IntegerField',
858     'float': 'instance.web.search.FloatField',
859     'selection': 'instance.web.search.SelectionField',
860     'datetime': 'instance.web.search.DateTimeField',
861     'date': 'instance.web.search.DateField',
862     'many2one': 'instance.web.search.ManyToOneField',
863     'many2many': 'instance.web.search.CharField',
864     'one2many': 'instance.web.search.CharField'
865 });
866 instance.web.search.Invalid = instance.web.Class.extend( /** @lends instance.web.search.Invalid# */{
867     /**
868      * Exception thrown by search widgets when they hold invalid values,
869      * which they can not return when asked.
870      *
871      * @constructs instance.web.search.Invalid
872      * @extends instance.web.Class
873      *
874      * @param field the name of the field holding an invalid value
875      * @param value the invalid value
876      * @param message validation failure message
877      */
878     init: function (field, value, message) {
879         this.field = field;
880         this.value = value;
881         this.message = message;
882     },
883     toString: function () {
884         return _.str.sprintf(
885             _t("Incorrect value for field %(fieldname)s: [%(value)s] is %(message)s"),
886             {fieldname: this.field, value: this.value, message: this.message}
887         );
888     }
889 });
890 instance.web.search.Widget = instance.web.Widget.extend( /** @lends instance.web.search.Widget# */{
891     template: null,
892     /**
893      * Root class of all search widgets
894      *
895      * @constructs instance.web.search.Widget
896      * @extends instance.web.Widget
897      *
898      * @param parent parent of this widget
899      */
900     init: function (parent) {
901         this._super(parent);
902         var ancestor = parent;
903         do {
904             this.view = ancestor;
905         } while (!(ancestor instanceof instance.web.SearchView)
906                && (ancestor = (ancestor.getParent && ancestor.getParent())));
907     }
908 });
909
910 instance.web.search.add_expand_listener = function($root) {
911     $root.find('a.searchview_group_string').click(function (e) {
912         $root.toggleClass('folded expanded');
913         e.stopPropagation();
914         e.preventDefault();
915     });
916 };
917 instance.web.search.Group = instance.web.search.Widget.extend({
918     init: function (parent, icon, node) {
919         this._super(parent);
920         var attrs = node.attrs;
921         this.modifiers = attrs.modifiers =
922             attrs.modifiers ? JSON.parse(attrs.modifiers) : {};
923         this.attrs = attrs;
924         this.icon = icon;
925         this.name = attrs.string;
926         this.children = [];
927
928         this.view.controls.push(this);
929     },
930     push: function (input) {
931         this.children.push(input);
932     },
933     visible: function () {
934         return !this.modifiers.invisible;
935     },
936 });
937
938 instance.web.search.Input = instance.web.search.Widget.extend( /** @lends instance.web.search.Input# */{
939     _in_drawer: false,
940     /**
941      * @constructs instance.web.search.Input
942      * @extends instance.web.search.Widget
943      *
944      * @param parent
945      */
946     init: function (parent) {
947         this._super(parent);
948         this.load_attrs({});
949         this.view.inputs.push(this);
950     },
951     /**
952      * Fetch auto-completion values for the widget.
953      *
954      * The completion values should be an array of objects with keys category,
955      * label, value prefixed with an object with keys type=section and label
956      *
957      * @param {String} value value to complete
958      * @returns {jQuery.Deferred<null|Array>}
959      */
960     complete: function (value) {
961         return $.when(null)
962     },
963     /**
964      * Returns a Facet instance for the provided defaults if they apply to
965      * this widget, or null if they don't.
966      *
967      * This default implementation will try calling
968      * :js:func:`instance.web.search.Input#facet_for` if the widget's name
969      * matches the input key
970      *
971      * @param {Object} defaults
972      * @returns {jQuery.Deferred<null|Object>}
973      */
974     facet_for_defaults: function (defaults) {
975         if (!this.attrs ||
976             !(this.attrs.name in defaults && defaults[this.attrs.name])) {
977             return $.when(null);
978         }
979         return this.facet_for(defaults[this.attrs.name]);
980     },
981     in_drawer: function () {
982         return !!this._in_drawer;
983     },
984     get_context: function () {
985         throw new Error(
986             "get_context not implemented for widget " + this.attrs.type);
987     },
988     get_groupby: function () {
989         throw new Error(
990             "get_groupby not implemented for widget " + this.attrs.type);
991     },
992     get_domain: function () {
993         throw new Error(
994             "get_domain not implemented for widget " + this.attrs.type);
995     },
996     load_attrs: function (attrs) {
997         attrs.modifiers = attrs.modifiers ? JSON.parse(attrs.modifiers) : {};
998         this.attrs = attrs;
999     },
1000     /**
1001      * Returns whether the input is "visible". The default behavior is to
1002      * query the ``modifiers.invisible`` flag on the input's description or
1003      * view node.
1004      *
1005      * @returns {Boolean}
1006      */
1007     visible: function () {
1008         if (this.attrs.modifiers.invisible) {
1009             return false;
1010         }
1011         var parent = this;
1012         while ((parent = parent.getParent()) &&
1013                (   (parent instanceof instance.web.search.Group)
1014                 || (parent instanceof instance.web.search.Input))) {
1015             if (!parent.visible()) {
1016                 return false;
1017             }
1018         }
1019         return true;
1020     },
1021 });
1022 instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{
1023     template: 'SearchView.filters',
1024     icon: 'q',
1025     completion_label: _lt("Filter on: %s"),
1026     /**
1027      * Inclusive group of filters, creates a continuous "button" with clickable
1028      * sections (the normal display for filters is to be a self-contained button)
1029      *
1030      * @constructs instance.web.search.FilterGroup
1031      * @extends instance.web.search.Input
1032      *
1033      * @param {Array<instance.web.search.Filter>} filters elements of the group
1034      * @param {instance.web.SearchView} parent parent in which the filters are contained
1035      */
1036     init: function (filters, parent) {
1037         // If all filters are group_by and we're not initializing a GroupbyGroup,
1038         // create a GroupbyGroup instead of the current FilterGroup
1039         if (!(this instanceof instance.web.search.GroupbyGroup) &&
1040               _(filters).all(function (f) {
1041                   if (!f.attrs.context) { return false; }
1042                   var c = instance.web.pyeval.eval('context', f.attrs.context);
1043                   return !_.isEmpty(c.group_by);})) {
1044             return new instance.web.search.GroupbyGroup(filters, parent);
1045         }
1046         this._super(parent);
1047         this.filters = filters;
1048         this.view.query.on('add remove change reset', this.proxy('search_change'));
1049     },
1050     start: function () {
1051         this.$el.on('click', 'li', this.proxy('toggle_filter'));
1052         return $.when(null);
1053     },
1054     /**
1055      * Handles change of the search query: any of the group's filter which is
1056      * in the search query should be visually checked in the drawer
1057      */
1058     search_change: function () {
1059         var self = this;
1060         var $filters = this.$('> li').removeClass('oe_selected');
1061         var facet = this.view.query.find(_.bind(this.match_facet, this));
1062         if (!facet) { return; }
1063         facet.values.each(function (v) {
1064             var i = _(self.filters).indexOf(v.get('value'));
1065             if (i === -1) { return; }
1066             $filters.filter(function () {
1067                 return Number($(this).data('index')) === i;
1068             }).addClass('oe_selected');
1069         });
1070     },
1071     /**
1072      * Matches the group to a facet, in order to find if the group is
1073      * represented in the current search query
1074      */
1075     match_facet: function (facet) {
1076         return facet.get('field') === this;
1077     },
1078     make_facet: function (values) {
1079         return {
1080             category: _t("Filter"),
1081             icon: this.icon,
1082             values: values,
1083             field: this
1084         }
1085     },
1086     make_value: function (filter) {
1087         return {
1088             label: filter.attrs.string || filter.attrs.help || filter.attrs.name,
1089             value: filter
1090         };
1091     },
1092     facet_for_defaults: function (defaults) {
1093         var self = this;
1094         var fs = _(this.filters).chain()
1095             .filter(function (f) {
1096                 return f.attrs && f.attrs.name && !!defaults[f.attrs.name];
1097             }).map(function (f) {
1098                 return self.make_value(f);
1099             }).value();
1100         if (_.isEmpty(fs)) { return $.when(null); }
1101         return $.when(this.make_facet(fs));
1102     },
1103     /**
1104      * Fetches contexts for all enabled filters in the group
1105      *
1106      * @param {openerp.web.search.Facet} facet
1107      * @return {*} combined contexts of the enabled filters in this group
1108      */
1109     get_context: function (facet) {
1110         var contexts = facet.values.chain()
1111             .map(function (f) { return f.get('value').attrs.context; })
1112             .without('{}')
1113             .reject(_.isEmpty)
1114             .value();
1115
1116         if (!contexts.length) { return; }
1117         if (contexts.length === 1) { return contexts[0]; }
1118         return _.extend(new instance.web.CompoundContext, {
1119             __contexts: contexts
1120         });
1121     },
1122     /**
1123      * Fetches group_by sequence for all enabled filters in the group
1124      *
1125      * @param {VS.model.SearchFacet} facet
1126      * @return {Array} enabled filters in this group
1127      */
1128     get_groupby: function (facet) {
1129         return  facet.values.chain()
1130             .map(function (f) { return f.get('value').attrs.context; })
1131             .without('{}')
1132             .reject(_.isEmpty)
1133             .value();
1134     },
1135     /**
1136      * Handles domains-fetching for all the filters within it: groups them.
1137      *
1138      * @param {VS.model.SearchFacet} facet
1139      * @return {*} combined domains of the enabled filters in this group
1140      */
1141     get_domain: function (facet) {
1142         var domains = facet.values.chain()
1143             .map(function (f) { return f.get('value').attrs.domain; })
1144             .without('[]')
1145             .reject(_.isEmpty)
1146             .value();
1147
1148         if (!domains.length) { return; }
1149         if (domains.length === 1) { return domains[0]; }
1150         for (var i=domains.length; --i;) {
1151             domains.unshift(['|']);
1152         }
1153         return _.extend(new instance.web.CompoundDomain(), {
1154             __domains: domains
1155         });
1156     },
1157     toggle_filter: function (e) {
1158         this.toggle(this.filters[Number($(e.target).data('index'))]);
1159     },
1160     toggle: function (filter) {
1161         this.view.query.toggle(this.make_facet([this.make_value(filter)]));
1162     },
1163     complete: function (item) {
1164         var self = this;
1165         item = item.toLowerCase();
1166         var facet_values = _(this.filters).chain()
1167             .filter(function (filter) { return filter.visible(); })
1168             .filter(function (filter) {
1169                 var at = {
1170                     string: filter.attrs.string || '',
1171                     help: filter.attrs.help || '',
1172                     name: filter.attrs.name || ''
1173                 };
1174                 var include = _.str.include;
1175                 return include(at.string.toLowerCase(), item)
1176                     || include(at.help.toLowerCase(), item)
1177                     || include(at.name.toLowerCase(), item);
1178             })
1179             .map(this.make_value)
1180             .value();
1181         if (_(facet_values).isEmpty()) { return $.when(null); }
1182         return $.when(_.map(facet_values, function (facet_value) {
1183             return {
1184                 label: _.str.sprintf(self.completion_label.toString(),
1185                                      _.escape(facet_value.label)),
1186                 facet: self.make_facet([facet_value])
1187             }
1188         }));
1189     }
1190 });
1191 instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
1192     icon: 'w',
1193     completion_label: _lt("Group by: %s"),
1194     init: function (filters, parent) {
1195         this._super(filters, parent);
1196         // Not flanders: facet unicity is handled through the
1197         // (category, field) pair of facet attributes. This is all well and
1198         // good for regular filter groups where a group matches a facet, but for
1199         // groupby we want a single facet. So cheat: add an attribute on the
1200         // view which proxies to the first GroupbyGroup, so it can be used
1201         // for every GroupbyGroup and still provides the various methods needed
1202         // by the search view. Use weirdo name to avoid risks of conflicts
1203         if (!this.view._s_groupby) {
1204             this.view._s_groupby = {
1205                 help: "See GroupbyGroup#init",
1206                 get_context: this.proxy('get_context'),
1207                 get_domain: this.proxy('get_domain'),
1208                 get_groupby: this.proxy('get_groupby')
1209             }
1210         }
1211     },
1212     match_facet: function (facet) {
1213         return facet.get('field') === this.view._s_groupby;
1214     },
1215     make_facet: function (values) {
1216         return {
1217             category: _t("GroupBy"),
1218             icon: this.icon,
1219             values: values,
1220             field: this.view._s_groupby
1221         };
1222     }
1223 });
1224 instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
1225     template: 'SearchView.filter',
1226     /**
1227      * Implementation of the OpenERP filters (button with a context and/or
1228      * a domain sent as-is to the search view)
1229      *
1230      * Filters are only attributes holder, the actual work (compositing
1231      * domains and contexts, converting between facets and filters) is
1232      * performed by the filter group.
1233      *
1234      * @constructs instance.web.search.Filter
1235      * @extends instance.web.search.Input
1236      *
1237      * @param node
1238      * @param parent
1239      */
1240     init: function (node, parent) {
1241         this._super(parent);
1242         this.load_attrs(node.attrs);
1243     },
1244     facet_for: function () { return $.when(null); },
1245     get_context: function () { },
1246     get_domain: function () { },
1247 });
1248 instance.web.search.Field = instance.web.search.Input.extend( /** @lends instance.web.search.Field# */ {
1249     template: 'SearchView.field',
1250     default_operator: '=',
1251     /**
1252      * @constructs instance.web.search.Field
1253      * @extends instance.web.search.Input
1254      *
1255      * @param view_section
1256      * @param field
1257      * @param parent
1258      */
1259     init: function (view_section, field, parent) {
1260         this._super(parent);
1261         this.load_attrs(_.extend({}, field, view_section.attrs));
1262     },
1263     facet_for: function (value) {
1264         return $.when({
1265             field: this,
1266             category: this.attrs.string || this.attrs.name,
1267             values: [{label: String(value), value: value}]
1268         });
1269     },
1270     value_from: function (facetValue) {
1271         return facetValue.get('value');
1272     },
1273     get_context: function (facet) {
1274         var self = this;
1275         // A field needs a context to send when active
1276         var context = this.attrs.context;
1277         if (_.isEmpty(context) || !facet.values.length) {
1278             return;
1279         }
1280         var contexts = facet.values.map(function (facetValue) {
1281             return new instance.web.CompoundContext(context)
1282                 .set_eval_context({self: self.value_from(facetValue)});
1283         });
1284
1285         if (contexts.length === 1) { return contexts[0]; }
1286
1287         return _.extend(new instance.web.CompoundContext, {
1288             __contexts: contexts
1289         });
1290     },
1291     get_groupby: function () { },
1292     /**
1293      * Function creating the returned domain for the field, override this
1294      * methods in children if you only need to customize the field's domain
1295      * without more complex alterations or tests (and without the need to
1296      * change override the handling of filter_domain)
1297      *
1298      * @param {String} name the field's name
1299      * @param {String} operator the field's operator (either attribute-specified or default operator for the field
1300      * @param {Number|String} facet parsed value for the field
1301      * @returns {Array<Array>} domain to include in the resulting search
1302      */
1303     make_domain: function (name, operator, facet) {
1304         return [[name, operator, this.value_from(facet)]];
1305     },
1306     get_domain: function (facet) {
1307         if (!facet.values.length) { return; }
1308
1309         var value_to_domain;
1310         var self = this;
1311         var domain = this.attrs['filter_domain'];
1312         if (domain) {
1313             value_to_domain = function (facetValue) {
1314                 return new instance.web.CompoundDomain(domain)
1315                     .set_eval_context({self: self.value_from(facetValue)});
1316             };
1317         } else {
1318             value_to_domain = function (facetValue) {
1319                 return self.make_domain(
1320                     self.attrs.name,
1321                     self.attrs.operator || self.default_operator,
1322                     facetValue);
1323             };
1324         }
1325         var domains = facet.values.map(value_to_domain);
1326
1327         if (domains.length === 1) { return domains[0]; }
1328         for (var i = domains.length; --i;) {
1329             domains.unshift(['|']);
1330         }
1331
1332         return _.extend(new instance.web.CompoundDomain, {
1333             __domains: domains
1334         });
1335     }
1336 });
1337 /**
1338  * Implementation of the ``char`` OpenERP field type:
1339  *
1340  * * Default operator is ``ilike`` rather than ``=``
1341  *
1342  * * The Javascript and the HTML values are identical (strings)
1343  *
1344  * @class
1345  * @extends instance.web.search.Field
1346  */
1347 instance.web.search.CharField = instance.web.search.Field.extend( /** @lends instance.web.search.CharField# */ {
1348     default_operator: 'ilike',
1349     complete: function (value) {
1350         if (_.isEmpty(value)) { return $.when(null); }
1351         var label = _.str.sprintf(_.str.escapeHTML(
1352             _t("Search %(field)s for: %(value)s")), {
1353                 field: '<em>' + _.escape(this.attrs.string) + '</em>',
1354                 value: '<strong>' + _.escape(value) + '</strong>'});
1355         return $.when([{
1356             label: label,
1357             facet: {
1358                 category: this.attrs.string,
1359                 field: this,
1360                 values: [{label: value, value: value}]
1361             }
1362         }]);
1363     }
1364 });
1365 instance.web.search.NumberField = instance.web.search.Field.extend(/** @lends instance.web.search.NumberField# */{
1366     complete: function (value) {
1367         var val = this.parse(value);
1368         if (isNaN(val)) { return $.when(); }
1369         var label = _.str.sprintf(
1370             _t("Search %(field)s for: %(value)s"), {
1371                 field: '<em>' + _.escape(this.attrs.string) + '</em>',
1372                 value: '<strong>' + _.escape(value) + '</strong>'});
1373         return $.when([{
1374             label: label,
1375             facet: {
1376                 category: this.attrs.string,
1377                 field: this,
1378                 values: [{label: value, value: val}]
1379             }
1380         }]);
1381     },
1382 });
1383 /**
1384  * @class
1385  * @extends instance.web.search.NumberField
1386  */
1387 instance.web.search.IntegerField = instance.web.search.NumberField.extend(/** @lends instance.web.search.IntegerField# */{
1388     error_message: _t("not a valid integer"),
1389     parse: function (value) {
1390         try {
1391             return instance.web.parse_value(value, {'widget': 'integer'});
1392         } catch (e) {
1393             return NaN;
1394         }
1395     }
1396 });
1397 /**
1398  * @class
1399  * @extends instance.web.search.NumberField
1400  */
1401 instance.web.search.FloatField = instance.web.search.NumberField.extend(/** @lends instance.web.search.FloatField# */{
1402     error_message: _t("not a valid number"),
1403     parse: function (value) {
1404         try {
1405             return instance.web.parse_value(value, {'widget': 'float'});
1406         } catch (e) {
1407             return NaN;
1408         }
1409     }
1410 });
1411
1412 /**
1413  * Utility function for m2o & selection fields taking a selection/name_get pair
1414  * (value, name) and converting it to a Facet descriptor
1415  *
1416  * @param {instance.web.search.Field} field holder field
1417  * @param {Array} pair pair value to convert
1418  */
1419 function facet_from(field, pair) {
1420     return {
1421         field: field,
1422         category: field['attrs'].string,
1423         values: [{label: pair[1], value: pair[0]}]
1424     };
1425 }
1426
1427 /**
1428  * @class
1429  * @extends instance.web.search.Field
1430  */
1431 instance.web.search.SelectionField = instance.web.search.Field.extend(/** @lends instance.web.search.SelectionField# */{
1432     // This implementation is a basic <select> field, but it may have to be
1433     // altered to be more in line with the GTK client, which uses a combo box
1434     // (~ jquery.autocomplete):
1435     // * If an option was selected in the list, behave as currently
1436     // * If something which is not in the list was entered (via the text input),
1437     //   the default domain should become (`ilike` string_value) but **any
1438     //   ``context`` or ``filter_domain`` becomes falsy, idem if ``@operator``
1439     //   is specified. So at least get_domain needs to be quite a bit
1440     //   overridden (if there's no @value and there is no filter_domain and
1441     //   there is no @operator, return [[name, 'ilike', str_val]]
1442     template: 'SearchView.field.selection',
1443     init: function () {
1444         this._super.apply(this, arguments);
1445         // prepend empty option if there is no empty option in the selection list
1446         this.prepend_empty = !_(this.attrs.selection).detect(function (item) {
1447             return !item[1];
1448         });
1449     },
1450     complete: function (needle) {
1451         var self = this;
1452         var results = _(this.attrs.selection).chain()
1453             .filter(function (sel) {
1454                 var value = sel[0], label = sel[1];
1455                 if (!value) { return false; }
1456                 return label.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
1457             })
1458             .map(function (sel) {
1459                 return {
1460                     label: _.escape(sel[1]),
1461                     facet: facet_from(self, sel)
1462                 };
1463             }).value();
1464         if (_.isEmpty(results)) { return $.when(null); }
1465         return $.when.call(null, [{
1466             label: _.escape(this.attrs.string)
1467         }].concat(results));
1468     },
1469     facet_for: function (value) {
1470         var match = _(this.attrs.selection).detect(function (sel) {
1471             return sel[0] === value;
1472         });
1473         if (!match) { return $.when(null); }
1474         return $.when(facet_from(this, match));
1475     }
1476 });
1477 instance.web.search.BooleanField = instance.web.search.SelectionField.extend(/** @lends instance.web.search.BooleanField# */{
1478     /**
1479      * @constructs instance.web.search.BooleanField
1480      * @extends instance.web.search.BooleanField
1481      */
1482     init: function () {
1483         this._super.apply(this, arguments);
1484         this.attrs.selection = [
1485             [true, _t("Yes")],
1486             [false, _t("No")]
1487         ];
1488     }
1489 });
1490 /**
1491  * @class
1492  * @extends instance.web.search.DateField
1493  */
1494 instance.web.search.DateField = instance.web.search.Field.extend(/** @lends instance.web.search.DateField# */{
1495     value_from: function (facetValue) {
1496         return instance.web.date_to_str(facetValue.get('value'));
1497     },
1498     complete: function (needle) {
1499         var d = Date.parse(needle);
1500         if (!d) { return $.when(null); }
1501         var date_string = instance.web.format_value(d, this.attrs);
1502         var label = _.str.sprintf(_.str.escapeHTML(
1503             _t("Search %(field)s at: %(value)s")), {
1504                 field: '<em>' + _.escape(this.attrs.string) + '</em>',
1505                 value: '<strong>' + date_string + '</strong>'});
1506         return $.when([{
1507             label: label,
1508             facet: {
1509                 category: this.attrs.string,
1510                 field: this,
1511                 values: [{label: date_string, value: d}]
1512             }
1513         }]);
1514     }
1515 });
1516 /**
1517  * Implementation of the ``datetime`` openerp field type:
1518  *
1519  * * Uses the same widget as the ``date`` field type (a simple date)
1520  *
1521  * * Builds a slighly more complex, it's a datetime range (includes time)
1522  *   spanning the whole day selected by the date widget
1523  *
1524  * @class
1525  * @extends instance.web.DateField
1526  */
1527 instance.web.search.DateTimeField = instance.web.search.DateField.extend(/** @lends instance.web.search.DateTimeField# */{
1528     value_from: function (facetValue) {
1529         return instance.web.datetime_to_str(facetValue.get('value'));
1530     }
1531 });
1532 instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
1533     default_operator: {},
1534     init: function (view_section, field, parent) {
1535         this._super(view_section, field, parent);
1536         this.model = new instance.web.Model(this.attrs.relation);
1537     },
1538     complete: function (needle) {
1539         var self = this;
1540         // FIXME: "concurrent" searches (multiple requests, mis-ordered responses)
1541         var context = instance.web.pyeval.eval(
1542             'contexts', [this.view.dataset.get_context()]);
1543         return this.model.call('name_search', [], {
1544             name: needle,
1545             args: instance.web.pyeval.eval(
1546                 'domains', this.attrs.domain ? [this.attrs.domain] : [], context),
1547             limit: 8,
1548             context: context
1549         }).then(function (results) {
1550             if (_.isEmpty(results)) { return null; }
1551             return [{label: self.attrs.string}].concat(
1552                 _(results).map(function (result) {
1553                     return {
1554                         label: _.escape(result[1]),
1555                         facet: facet_from(self, result)
1556                     };
1557                 }));
1558         });
1559     },
1560     facet_for: function (value) {
1561         var self = this;
1562         if (value instanceof Array) {
1563             if (value.length === 2 && _.isString(value[1])) {
1564                 return $.when(facet_from(this, value));
1565             }
1566             assert(value.length <= 1,
1567                    _t("M2O search fields do not currently handle multiple default values"));
1568             // there are many cases of {search_default_$m2ofield: [id]}, need
1569             // to handle this as if it were a single value.
1570             value = value[0];
1571         }
1572         return this.model.call('name_get', [value]).then(function (names) {
1573             if (_(names).isEmpty()) { return null; }
1574             return facet_from(self, names[0]);
1575         })
1576     },
1577     value_from: function (facetValue) {
1578         return facetValue.get('label');
1579     },
1580     make_domain: function (name, operator, facetValue) {
1581         switch(operator){
1582         case this.default_operator:
1583             return [[name, '=', facetValue.get('value')]];
1584         case 'child_of':
1585             return [[name, 'child_of', facetValue.get('value')]];
1586         }
1587         return this._super(name, operator, facetValue);
1588     },
1589     get_context: function (facet) {
1590         var values = facet.values;
1591         if (_.isEmpty(this.attrs.context) && values.length === 1) {
1592             var c = {};
1593             c['default_' + this.attrs.name] = values.at(0).get('value');
1594             return c;
1595         }
1596         return this._super(facet);
1597     }
1598 });
1599
1600 instance.web.search.CustomFilters = instance.web.search.Input.extend({
1601     template: 'SearchView.CustomFilters',
1602     _in_drawer: true,
1603     init: function () {
1604         this.is_ready = $.Deferred();
1605         this._super.apply(this, arguments);
1606     },
1607     start: function () {
1608         var self = this;
1609         this.model = new instance.web.Model('ir.filters');
1610         this.filters = {};
1611         this.$filters = {};
1612         this.view.query
1613             .on('remove', function (facet) {
1614                 if (!facet.get('is_custom_filter')) {
1615                     return;
1616                 }
1617                 self.clear_selection();
1618             })
1619             .on('reset', this.proxy('clear_selection'));
1620         this.$el.on('submit', 'form', this.proxy('save_current'));
1621         this.$el.on('click', 'input[type=checkbox]', function() {
1622             $(this).siblings('input[type=checkbox]').prop('checked', false);
1623         });
1624         this.$el.on('click', 'h4', function () {
1625             self.$el.toggleClass('oe_opened');
1626         });
1627         return this.model.call('get_filters', [this.view.model])
1628             .then(this.proxy('set_filters'))
1629             .done(function () { self.is_ready.resolve(); })
1630             .fail(function () { self.is_ready.reject.apply(self.is_ready, arguments); });
1631     },
1632     /**
1633      * Special implementation delaying defaults until CustomFilters is loaded
1634      */
1635     facet_for_defaults: function () {
1636         return this.is_ready;
1637     },
1638     /**
1639      * Generates a mapping key (in the filters and $filter mappings) for the
1640      * filter descriptor object provided (as returned by ``get_filters``).
1641      *
1642      * The mapping key is guaranteed to be unique for a given (user_id, name)
1643      * pair.
1644      *
1645      * @param {Object} filter
1646      * @param {String} filter.name
1647      * @param {Number|Pair<Number, String>} [filter.user_id]
1648      * @return {String} mapping key corresponding to the filter
1649      */
1650     key_for: function (filter) {
1651         var user_id = filter.user_id;
1652         var uid = (user_id instanceof Array) ? user_id[0] : user_id;
1653         return _.str.sprintf('(%s)%s', uid, filter.name);
1654     },
1655     /**
1656      * Generates a :js:class:`~instance.web.search.Facet` descriptor from a
1657      * filter descriptor
1658      *
1659      * @param {Object} filter
1660      * @param {String} filter.name
1661      * @param {Object} [filter.context]
1662      * @param {Array} [filter.domain]
1663      * @return {Object}
1664      */
1665     facet_for: function (filter) {
1666         return {
1667             category: _t("Custom Filter"),
1668             icon: 'M',
1669             field: {
1670                 get_context: function () { return filter.context; },
1671                 get_groupby: function () { return [filter.context]; },
1672                 get_domain: function () { return filter.domain; }
1673             },
1674             _id: filter['id'],
1675             is_custom_filter: true,
1676             values: [{label: filter.name, value: null}]
1677         };
1678     },
1679     clear_selection: function () {
1680         this.$('li.oe_selected').removeClass('oe_selected');
1681     },
1682     append_filter: function (filter) {
1683         var self = this;
1684         var key = this.key_for(filter);
1685         var warning = _t("This filter is global and will be removed for everybody if you continue.");
1686
1687         var $filter;
1688         if (key in this.$filters) {
1689             $filter = this.$filters[key];
1690         } else {
1691             var id = filter.id;
1692             this.filters[key] = filter;
1693             $filter = this.$filters[key] = $('<li></li>')
1694                 .appendTo(this.$('.oe_searchview_custom_list'))
1695                 .addClass(filter.user_id ? 'oe_searchview_custom_private'
1696                                          : 'oe_searchview_custom_public')
1697                 .toggleClass('oe_searchview_custom_default', filter.is_default)
1698                 .text(filter.name);
1699
1700             $('<a class="oe_searchview_custom_delete">x</a>')
1701                 .click(function (e) {
1702                     e.stopPropagation();
1703                     if (!(filter.user_id || confirm(warning))) {
1704                         return;
1705                     }
1706                     self.model.call('unlink', [id]).done(function () {
1707                         $filter.remove();
1708                         delete self.$filters[key];
1709                         delete self.filters[key];
1710                     });
1711                 })
1712                 .appendTo($filter);
1713         }
1714
1715         $filter.unbind('click').click(function () {
1716             self.toggle_filter(filter);
1717         });
1718     },
1719     toggle_filter: function (filter, preventSearch) {
1720         var current = this.view.query.find(function (facet) {
1721             return facet.get('_id') === filter.id;
1722         });
1723         if (current) {
1724             this.view.query.remove(current);
1725             this.$filters[this.key_for(filter)].removeClass('oe_selected');
1726             return;
1727         }
1728         this.view.query.reset([this.facet_for(filter)], {
1729             preventSearch: preventSearch || false});
1730         this.$filters[this.key_for(filter)].addClass('oe_selected');
1731     },
1732     set_filters: function (filters) {
1733         _(filters).map(_.bind(this.append_filter, this));
1734     },
1735     save_current: function () {
1736         var self = this;
1737         var $name = this.$('input:first');
1738         var private_filter = !this.$('#oe_searchview_custom_public').prop('checked');
1739         var set_as_default = this.$('#oe_searchview_custom_default').prop('checked');
1740         if (_.isEmpty($name.val())){
1741             this.do_warn(_t("Error"), _t("Filter name is required."));
1742             return false;
1743         }
1744         var search = this.view.build_search_data();
1745         instance.web.pyeval.eval_domains_and_contexts({
1746             domains: search.domains,
1747             contexts: search.contexts,
1748             group_by_seq: search.groupbys || []
1749         }).done(function (results) {
1750             if (!_.isEmpty(results.group_by)) {
1751                 results.context.group_by = results.group_by;
1752             }
1753             // Don't save user_context keys in the custom filter, otherwise end
1754             // up with e.g. wrong uid or lang stored *and used in subsequent
1755             // reqs*
1756             var ctx = results.context;
1757             _(_.keys(instance.session.user_context)).each(function (key) {
1758                 delete ctx[key];
1759             });
1760             var filter = {
1761                 name: $name.val(),
1762                 user_id: private_filter ? instance.session.uid : false,
1763                 model_id: self.view.model,
1764                 context: results.context,
1765                 domain: results.domain,
1766                 is_default: set_as_default
1767             };
1768             // FIXME: current context?
1769             return self.model.call('create_or_replace', [filter]).done(function (id) {
1770                 filter.id = id;
1771                 self.append_filter(filter);
1772                 self.$el
1773                     .removeClass('oe_opened')
1774                     .find('form')[0].reset();
1775             });
1776         });
1777         return false;
1778     }
1779 });
1780
1781 instance.web.search.Filters = instance.web.search.Input.extend({
1782     template: 'SearchView.Filters',
1783     _in_drawer: true,
1784     start: function () {
1785         var self = this;
1786         var running_count = 0;
1787         // get total filters count
1788         var is_group = function (i) { return i instanceof instance.web.search.FilterGroup; };
1789         var visible_filters = _(this.view.controls).chain().reject(function (group) {
1790             return _(_(group.children).filter(is_group)).isEmpty()
1791                 || group.modifiers.invisible;
1792         });
1793         var filters_count = visible_filters
1794             .pluck('children')
1795             .flatten()
1796             .filter(is_group)
1797             .map(function (i) { return i.filters.length; })
1798             .sum()
1799             .value();
1800
1801         var col1 = [], col2 = visible_filters.map(function (group) {
1802                 var filters = _(group.children).filter(is_group);
1803                 return {
1804                     name: _.str.sprintf("<span class='oe_i'>%s</span> %s",
1805                             group.icon, group.name),
1806                     filters: filters,
1807                     length: _(filters).chain().map(function (i) {
1808                         return i.filters.length; }).sum().value()
1809                 };
1810             }).value();
1811
1812         while (col2.length) {
1813             // col1 + group should be smaller than col2 + group
1814             if ((running_count + col2[0].length) <= (filters_count - running_count)) {
1815                 running_count += col2[0].length;
1816                 col1.push(col2.shift());
1817             } else {
1818                 break;
1819             }
1820         }
1821
1822         return $.when(
1823             this.render_column(col1, $('<div>').appendTo(this.$el)),
1824             this.render_column(col2, $('<div>').appendTo(this.$el)));
1825     },
1826     render_column: function (column, $el) {
1827         return $.when.apply(null, _(column).map(function (group) {
1828             $('<h3>').html(group.name).appendTo($el);
1829             return $.when.apply(null,
1830                 _(group.filters).invoke('appendTo', $el));
1831         }));
1832     }
1833 });
1834
1835 instance.web.search.Advanced = instance.web.search.Input.extend({
1836     template: 'SearchView.advanced',
1837     _in_drawer: true,
1838     start: function () {
1839         var self = this;
1840         this.$el
1841             .on('keypress keydown keyup', function (e) { e.stopPropagation(); })
1842             .on('click', 'h4', function () {
1843                 self.$el.toggleClass('oe_opened');
1844             }).on('click', 'button.oe_add_condition', function () {
1845                 self.append_proposition();
1846             }).on('submit', 'form', function (e) {
1847                 e.preventDefault();
1848                 self.commit_search();
1849             });
1850         return $.when(
1851             this._super(),
1852             new instance.web.Model(this.view.model).call('fields_get', {
1853                     context: this.view.dataset.context
1854                 }).done(function(data) {
1855                     self.fields = {
1856                         id: { string: 'ID', type: 'id' }
1857                     };
1858                     _.each(data, function(field_def, field_name) {
1859                         if (field_def.selectable !== false && field_name != 'id') {
1860                             self.fields[field_name] = field_def;
1861                         }
1862                     });
1863         })).done(function () {
1864             self.append_proposition();
1865         });
1866     },
1867     append_proposition: function () {
1868         var self = this;
1869         return (new instance.web.search.ExtendedSearchProposition(this, this.fields))
1870             .appendTo(this.$('ul')).done(function () {
1871                 self.$('button.oe_apply').prop('disabled', false);
1872             });
1873     },
1874     remove_proposition: function (prop) {
1875         // removing last proposition, disable apply button
1876         if (this.getChildren().length <= 1) {
1877             this.$('button.oe_apply').prop('disabled', true);
1878         }
1879         prop.destroy();
1880     },
1881     commit_search: function () {
1882         // Get domain sections from all propositions
1883         var children = this.getChildren();
1884         var propositions = _.invoke(children, 'get_proposition');
1885         var domain = _(propositions).pluck('value');
1886         for (var i = domain.length; --i;) {
1887             domain.unshift('|');
1888         }
1889
1890         this.view.query.add({
1891             category: _t("Advanced"),
1892             values: propositions,
1893             field: {
1894                 get_context: function () { },
1895                 get_domain: function () { return domain;},
1896                 get_groupby: function () { }
1897             }
1898         });
1899
1900         // remove all propositions
1901         _.invoke(children, 'destroy');
1902         // add new empty proposition
1903         this.append_proposition();
1904         // TODO: API on searchview
1905         this.view.$el.removeClass('oe_searchview_open_drawer');
1906     }
1907 });
1908
1909 instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @lends instance.web.search.ExtendedSearchProposition# */{
1910     template: 'SearchView.extended_search.proposition',
1911     events: {
1912         'change .searchview_extended_prop_field': 'changed',
1913         'change .searchview_extended_prop_op': 'operator_changed',
1914         'click .searchview_extended_delete_prop': function (e) {
1915             e.stopPropagation();
1916             this.getParent().remove_proposition(this);
1917         }
1918     },
1919     /**
1920      * @constructs instance.web.search.ExtendedSearchProposition
1921      * @extends instance.web.Widget
1922      *
1923      * @param parent
1924      * @param fields
1925      */
1926     init: function (parent, fields) {
1927         this._super(parent);
1928         this.fields = _(fields).chain()
1929             .map(function(val, key) { return _.extend({}, val, {'name': key}); })
1930             .filter(function (field) { return !field.deprecated && (field.store === void 0 || field.store || field.fnct_search); })
1931             .sortBy(function(field) {return field.string;})
1932             .value();
1933         this.attrs = {_: _, fields: this.fields, selected: null};
1934         this.value = null;
1935     },
1936     start: function () {
1937         return this._super().done(this.proxy('changed'));
1938     },
1939     changed: function() {
1940         var nval = this.$(".searchview_extended_prop_field").val();
1941         if(this.attrs.selected == null || nval != this.attrs.selected.name) {
1942             this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
1943         }
1944     },
1945     operator_changed: function (e) {
1946         var $value = this.$('.searchview_extended_prop_value');
1947         switch ($(e.target).val()) {
1948         case '∃':
1949         case '∄':
1950             $value.hide();
1951             break;
1952         default:
1953             $value.show();
1954         }
1955     },
1956     /**
1957      * Selects the provided field object
1958      *
1959      * @param field a field descriptor object (as returned by fields_get, augmented by the field name)
1960      */
1961     select_field: function(field) {
1962         var self = this;
1963         if(this.attrs.selected != null) {
1964             this.value.destroy();
1965             this.value = null;
1966             this.$('.searchview_extended_prop_op').html('');
1967         }
1968         this.attrs.selected = field;
1969         if(field == null) {
1970             return;
1971         }
1972
1973         var type = field.type;
1974         var Field = instance.web.search.custom_filters.get_object(type);
1975         if(!Field) {
1976             Field = instance.web.search.custom_filters.get_object("char");
1977         }
1978         this.value = new Field(this, field);
1979         _.each(this.value.operators, function(operator) {
1980             $('<option>', {value: operator.value})
1981                 .text(String(operator.text))
1982                 .appendTo(self.$('.searchview_extended_prop_op'));
1983         });
1984         var $value_loc = this.$('.searchview_extended_prop_value').show().empty();
1985         this.value.appendTo($value_loc);
1986
1987     },
1988     get_proposition: function() {
1989         if ( this.attrs.selected == null)
1990             return null;
1991         var field = this.attrs.selected;
1992         var op_select = this.$('.searchview_extended_prop_op')[0];
1993         var operator = op_select.options[op_select.selectedIndex];
1994
1995         return {
1996             label: this.value.get_label(field, operator),
1997             value: this.value.get_domain(field, operator),
1998         };
1999     }
2000 });
2001
2002 instance.web.search.ExtendedSearchProposition.Field = instance.web.Widget.extend({
2003     init: function (parent, field) {
2004         this._super(parent);
2005         this.field = field;
2006     },
2007     get_label: function (field, operator) {
2008         var format;
2009         switch (operator.value) {
2010         case '∃': case '∄': format = _t('%(field)s %(operator)s'); break;
2011         default: format = _t('%(field)s %(operator)s "%(value)s"'); break;
2012         }
2013         return this.format_label(format, field, operator);
2014     },
2015     format_label: function (format, field, operator) {
2016         return _.str.sprintf(format, {
2017             field: field.string,
2018             // According to spec, HTMLOptionElement#label should return
2019             // HTMLOptionElement#text when not defined/empty, but it does
2020             // not in older Webkit (between Safari 5.1.5 and Chrome 17) and
2021             // Gecko (pre Firefox 7) browsers, so we need a manual fallback
2022             // for those
2023             operator: operator.label || operator.text,
2024             value: this
2025         });
2026     },
2027     get_domain: function (field, operator) {
2028         switch (operator.value) {
2029         case '∃': return this.make_domain(field.name, '!=', false);
2030         case '∄': return this.make_domain(field.name, '=', false);
2031         default: return this.make_domain(
2032             field.name, operator.value, this.get_value());
2033         }
2034     },
2035     make_domain: function (field, operator, value) {
2036         return [field, operator, value];
2037     },
2038     /**
2039      * Returns a human-readable version of the value, in case the "logical"
2040      * and the "semantic" values of a field differ (as for selection fields,
2041      * for instance).
2042      *
2043      * The default implementation simply returns the value itself.
2044      *
2045      * @return {String} human-readable version of the value
2046      */
2047     toString: function () {
2048         return this.get_value();
2049     }
2050 });
2051 instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({
2052     template: 'SearchView.extended_search.proposition.char',
2053     operators: [
2054         {value: "ilike", text: _lt("contains")},
2055         {value: "not ilike", text: _lt("doesn't contain")},
2056         {value: "=", text: _lt("is equal to")},
2057         {value: "!=", text: _lt("is not equal to")},
2058         {value: "∃", text: _lt("is set")},
2059         {value: "∄", text: _lt("is not set")}
2060     ],
2061     get_value: function() {
2062         return this.$el.val();
2063     }
2064 });
2065 instance.web.search.ExtendedSearchProposition.DateTime = instance.web.search.ExtendedSearchProposition.Field.extend({
2066     template: 'SearchView.extended_search.proposition.empty',
2067     operators: [
2068         {value: "=", text: _lt("is equal to")},
2069         {value: "!=", text: _lt("is not equal to")},
2070         {value: ">", text: _lt("greater than")},
2071         {value: "<", text: _lt("less than")},
2072         {value: ">=", text: _lt("greater or equal than")},
2073         {value: "<=", text: _lt("less or equal than")},
2074         {value: "∃", text: _lt("is set")},
2075         {value: "∄", text: _lt("is not set")}
2076     ],
2077     /**
2078      * Date widgets live in view_form which is not yet loaded when this is
2079      * initialized -_-
2080      */
2081     widget: function () { return instance.web.DateTimeWidget; },
2082     get_value: function() {
2083         return this.datewidget.get_value();
2084     },
2085     toString: function () {
2086         return instance.web.format_value(this.get_value(), { type:"datetime" });
2087     },
2088     start: function() {
2089         var ready = this._super();
2090         this.datewidget = new (this.widget())(this);
2091         this.datewidget.appendTo(this.$el);
2092         return ready;
2093     }
2094 });
2095 instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.DateTime.extend({
2096     widget: function () { return instance.web.DateWidget; },
2097     toString: function () {
2098         return instance.web.format_value(this.get_value(), { type:"date" });
2099     }
2100 });
2101 instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({
2102     template: 'SearchView.extended_search.proposition.integer',
2103     operators: [
2104         {value: "=", text: _lt("is equal to")},
2105         {value: "!=", text: _lt("is not equal to")},
2106         {value: ">", text: _lt("greater than")},
2107         {value: "<", text: _lt("less than")},
2108         {value: ">=", text: _lt("greater or equal than")},
2109         {value: "<=", text: _lt("less or equal than")},
2110         {value: "∃", text: _lt("is set")},
2111         {value: "∄", text: _lt("is not set")}
2112     ],
2113     toString: function () {
2114         return this.$el.val();
2115     },
2116     get_value: function() {
2117         try {
2118             var val =this.$el.val();
2119             return instance.web.parse_value(val == "" ? 0 : val, {'widget': 'integer'});
2120         } catch (e) {
2121             return "";
2122         }
2123     }
2124 });
2125 instance.web.search.ExtendedSearchProposition.Id = instance.web.search.ExtendedSearchProposition.Integer.extend({
2126     operators: [{value: "=", text: _lt("is")}]
2127 });
2128 instance.web.search.ExtendedSearchProposition.Float = instance.web.search.ExtendedSearchProposition.Field.extend({
2129     template: 'SearchView.extended_search.proposition.float',
2130     operators: [
2131         {value: "=", text: _lt("is equal to")},
2132         {value: "!=", text: _lt("is not equal to")},
2133         {value: ">", text: _lt("greater than")},
2134         {value: "<", text: _lt("less than")},
2135         {value: ">=", text: _lt("greater or equal than")},
2136         {value: "<=", text: _lt("less or equal than")},
2137         {value: "∃", text: _lt("is set")},
2138         {value: "∄", text: _lt("is not set")}
2139     ],
2140     toString: function () {
2141         return this.$el.val();
2142     },
2143     get_value: function() {
2144         try {
2145             var val =this.$el.val();
2146             return instance.web.parse_value(val == "" ? 0.0 : val, {'widget': 'float'});
2147         } catch (e) {
2148             return "";
2149         }
2150     }
2151 });
2152 instance.web.search.ExtendedSearchProposition.Selection = instance.web.search.ExtendedSearchProposition.Field.extend({
2153     template: 'SearchView.extended_search.proposition.selection',
2154     operators: [
2155         {value: "=", text: _lt("is")},
2156         {value: "!=", text: _lt("is not")},
2157         {value: "∃", text: _lt("is set")},
2158         {value: "∄", text: _lt("is not set")}
2159     ],
2160     toString: function () {
2161         var select = this.$el[0];
2162         var option = select.options[select.selectedIndex];
2163         return option.label || option.text;
2164     },
2165     get_value: function() {
2166         return this.$el.val();
2167     }
2168 });
2169 instance.web.search.ExtendedSearchProposition.Boolean = instance.web.search.ExtendedSearchProposition.Field.extend({
2170     template: 'SearchView.extended_search.proposition.empty',
2171     operators: [
2172         {value: "=", text: _lt("is true")},
2173         {value: "!=", text: _lt("is false")}
2174     ],
2175     get_label: function (field, operator) {
2176         return this.format_label(
2177             _t('%(field)s %(operator)s'), field, operator);
2178     },
2179     get_value: function() {
2180         return true;
2181     }
2182 });
2183
2184 instance.web.search.custom_filters = new instance.web.Registry({
2185     'char': 'instance.web.search.ExtendedSearchProposition.Char',
2186     'text': 'instance.web.search.ExtendedSearchProposition.Char',
2187     'one2many': 'instance.web.search.ExtendedSearchProposition.Char',
2188     'many2one': 'instance.web.search.ExtendedSearchProposition.Char',
2189     'many2many': 'instance.web.search.ExtendedSearchProposition.Char',
2190
2191     'datetime': 'instance.web.search.ExtendedSearchProposition.DateTime',
2192     'date': 'instance.web.search.ExtendedSearchProposition.Date',
2193     'integer': 'instance.web.search.ExtendedSearchProposition.Integer',
2194     'float': 'instance.web.search.ExtendedSearchProposition.Float',
2195     'boolean': 'instance.web.search.ExtendedSearchProposition.Boolean',
2196     'selection': 'instance.web.search.ExtendedSearchProposition.Selection',
2197
2198     'id': 'instance.web.search.ExtendedSearchProposition.Id'
2199 });
2200
2201 };
2202
2203 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: