1 openerp.web.search = function(instance) {
2 var QWeb = instance.web.qweb,
4 _lt = instance.web._lt;
6 sum: function (obj) { return _.reduce(obj, function (a, b) { return a + b; }, 0); }
10 var my = instance.web.search = {};
13 my.FacetValue = B.Model.extend({
16 my.FacetValues = B.Collection.extend({
19 my.Facet = B.Model.extend({
20 initialize: function (attrs) {
21 var values = attrs.values;
24 B.Model.prototype.initialize.apply(this, arguments);
26 this.values = new my.FacetValues(values || []);
27 this.values.on('add remove change reset', function () {
28 this.trigger('change', this);
32 if (key !== 'values') {
33 return B.Model.prototype.get.call(this, key);
35 return this.values.toJSON();
37 set: function (key, value) {
38 if (key !== 'values') {
39 return B.Model.prototype.set.call(this, key, value);
41 this.values.reset(value);
45 var attrs = this.attributes;
46 for(var att in attrs) {
47 if (!attrs.hasOwnProperty(att) || att === 'field') {
50 out[att] = attrs[att];
52 out.values = this.values.toJSON();
56 my.SearchQuery = B.Collection.extend({
58 initialize: function () {
59 B.Collection.prototype.initialize.apply(
61 this.on('change', function (facet) {
62 if(!facet.values.isEmpty()) { return; }
64 this.remove(facet, {silent: true});
67 add: function (values, options) {
68 options || (options = {});
69 if (!(values instanceof Array)) {
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');
80 previous.values.add(model.get('values'));
83 B.Collection.prototype.add.call(this, model, options);
87 toggle: function (value, options) {
88 options || (options = {});
90 var facet = this.detect(function (facet) {
91 return facet.get('category') === value.category
92 && facet.get('field') === value.field;
95 return this.add(value, options);
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;
106 facet.values.remove(already_value, {silent: true});
108 facet.values.add(val, {silent: true});
112 // "Commit" changes to values array as a single call, so observers of
113 // change event don't get misled by intermediate incomplete toggling
115 facet.trigger('change', facet);
120 function assert(condition, message) {
122 throw new Error(message);
125 my.InputView = instance.web.Widget.extend({
126 template: 'SearchView.InputView',
128 var p = this._super.apply(this, arguments);
129 this.$el.on('focus', this.proxy('onFocus'));
130 this.$el.on('blur', this.proxy('onBlur'));
131 this.$el.on('keydown', this.proxy('onKeydown'));
134 onFocus: function () {
135 this.trigger('focused', this);
137 onBlur: function () {
139 this.trigger('blurred', this);
141 getSelection: function () {
143 var root = this.$el[0].childNodes[0];
144 if (!root || !root.textContent) {
145 // if input does not have a child node, or the child node is an
146 // empty string, then the selection can only be (0, 0)
147 return {start: 0, end: 0};
149 if (window.getSelection) {
150 var domRange = window.getSelection().getRangeAt(0);
151 assert(domRange.startContainer === root,
152 "selection should be in the input view");
153 assert(domRange.endContainer === root,
154 "selection should be in the input view");
156 start: domRange.startOffset,
157 end: domRange.endOffset
159 } else if (document.selection) {
160 var ieRange = document.selection.createRange();
161 var rangeParent = ieRange.parentElement();
162 assert(rangeParent === root,
163 "selection should be in the input view");
164 var offsetRange = document.body.createTextRange();
165 offsetRange = offsetRange.moveToElementText(rangeParent);
166 offsetRange.setEndPoint("EndToStart", ieRange);
167 var start = offsetRange.text.length;
170 end: start + ieRange.text.length
173 throw new Error("Could not get caret position");
175 onKeydown: function (e) {
178 // Do not insert newline, but let it bubble so searchview can use it
179 case $.ui.keyCode.ENTER:
183 // FIXME: may forget content if non-empty but caret at index 0, ok?
184 case $.ui.keyCode.BACKSPACE:
185 sel = this.getSelection();
186 if (sel.start === 0 && sel.start === sel.end) {
188 var preceding = this.getParent().siblingSubview(this, -1);
189 if (preceding && (preceding instanceof my.FacetView)) {
190 preceding.model.destroy();
195 // let left/right events propagate to view if caret is at input border
196 // and not a selection
197 case $.ui.keyCode.LEFT:
198 sel = this.getSelection();
199 if (sel.start !== 0 || sel.start !== sel.end) {
203 case $.ui.keyCode.RIGHT:
204 sel = this.getSelection();
205 var len = this.$el.text().length;
206 if (sel.start !== len || sel.start !== sel.end) {
213 my.FacetView = instance.web.Widget.extend({
214 template: 'SearchView.FacetView',
215 init: function (parent, model) {
218 this.model.on('change', this.model_changed, this);
220 destroy: function () {
221 this.model.off('change', this.model_changed, this);
226 this.$el.on('focus', function () { self.trigger('focused', self); });
227 this.$el.on('blur', function () { self.trigger('blurred', self); });
228 this.$el.on('click', function (e) {
229 if ($(e.target).is('.oe_facet_remove')) {
230 self.model.destroy();
236 this.$el.on('keydown', function (e) {
237 var keys = $.ui.keyCode;
241 self.model.destroy();
245 var $e = self.$el.find('> span:last-child');
246 var q = $.when(this._super());
247 return q.pipe(function () {
248 var values = self.model.values.map(function (value) {
249 return new my.FacetValueView(self, value).appendTo($e);
252 return $.when.apply(null, values);
255 model_changed: function () {
256 this.$el.text(this.$el.text() + '*');
259 my.FacetValueView = instance.web.Widget.extend({
260 template: 'SearchView.FacetView.Value',
261 init: function (parent, model) {
264 this.model.on('change', this.model_changed, this);
266 destroy: function () {
267 this.model.off('change', this.model_changed, this);
270 model_changed: function () {
271 this.$el.text(this.$el.text() + '*');
275 instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.SearchView# */{
276 template: "SearchView",
278 * @constructs instance.web.SearchView
279 * @extends instance.web.Widget
287 init: function(parent, dataset, view_id, defaults, hidden) {
289 this.dataset = dataset;
290 this.model = dataset.model;
291 this.view_id = view_id;
293 this.defaults = defaults || {};
294 this.has_defaults = !_.isEmpty(this.defaults);
299 this.hidden = !!hidden;
300 this.headless = this.hidden && !this.has_defaults;
302 this.input_subviews = [];
304 this.ready = $.Deferred();
308 var p = this._super();
310 this.setup_global_completion();
311 this.query = new my.SearchQuery()
312 .on('add change reset remove', this.proxy('do_search'))
313 .on('add change reset remove', this.proxy('renderFacets'));
319 this.ready.resolve();
321 var load_view = this.rpc("/web/searchview/load", {
323 view_id: this.view_id,
324 context: this.dataset.get_context() });
328 self.search_view_loaded(r)
329 }).fail(function () {
330 self.ready.reject.apply(null, arguments);
334 // Launch a search on clicking the oe_searchview_search button
335 this.$el.on('click', 'button.oe_searchview_search', function (e) {
336 e.stopImmediatePropagation();
340 this.$el.on('keydown',
341 '.oe_searchview_input, .oe_searchview_facet', function (e) {
343 case $.ui.keyCode.LEFT:
344 self.focusPreceding(this);
347 case $.ui.keyCode.RIGHT:
348 self.focusFollowing(this);
354 this.$el.on('click', '.oe_searchview_clear', function (e) {
355 e.stopImmediatePropagation();
358 this.$el.on('click', '.oe_searchview_unfold_drawer', function (e) {
359 e.stopImmediatePropagation();
360 self.$el.toggleClass('oe_searchview_open_drawer');
362 instance.web.bus.on('click', this, function(ev) {
363 if ($(ev.target).parents('.oe_searchview').length === 0) {
364 self.$el.removeClass('oe_searchview_open_drawer');
367 // Focus last input if the view itself is clicked (empty section of
369 this.$el.on('click', function (e) {
370 if (e.target === self.$el.find('.oe_searchview_facets')[0]) {
371 self.$el.find('.oe_searchview_input:last').focus();
374 // when the completion list opens/refreshes, automatically select the
375 // first completion item so if the user just hits [RETURN] or [TAB] it
376 // automatically selects it
377 this.$el.on('autocompleteopen', function () {
378 var menu = self.$el.data('autocomplete').menu;
380 $.Event({ type: "mouseenter" }),
381 menu.element.children().first());
384 return $.when(p, this.ready);
393 subviewForRoot: function (subview_root) {
394 return _(this.input_subviews).detect(function (subview) {
395 return subview.$el[0] === subview_root;
398 siblingSubview: function (subview, direction, wrap_around) {
399 var index = _(this.input_subviews).indexOf(subview) + direction;
400 if (wrap_around && index < 0) {
401 index = this.input_subviews.length - 1;
402 } else if (wrap_around && index >= this.input_subviews.length) {
405 return this.input_subviews[index];
407 focusPreceding: function (subview_root) {
408 return this.siblingSubview(
409 this.subviewForRoot(subview_root), -1, true)
412 focusFollowing: function (subview_root) {
413 return this.siblingSubview(
414 this.subviewForRoot(subview_root), +1, true)
419 * Sets up thingie where all the mess is put?
421 select_for_drawer: function () {
422 return _(this.inputs).filter(function (input) {
423 return input.in_drawer();
427 * Sets up search view's view-wide auto-completion widget
429 setup_global_completion: function () {
432 // autocomplete only correctly handles being initialized on the actual
433 // editable element (and only an element with a @value in 1.8 e.g.
434 // input or textarea), cheat by setting val() on $el
435 this.$el.on('keydown', function () {
436 // keydown is triggered *before* the element's value is set, so
437 // delay this. Pray that setTimeout are executed in FIFO (if they
438 // have the same delay) as autocomplete uses the exact same trick.
439 // FIXME: brittle as fuck
440 setTimeout(function () {
441 self.$el.val(self.currentInputValue());
446 this.$el.autocomplete({
447 source: this.proxy('complete_global_search'),
448 select: this.proxy('select_completion'),
449 focus: function (e) { e.preventDefault(); },
453 }).data('autocomplete')._renderItem = function (ul, item) {
454 // item of completion list
455 var $item = $( "<li></li>" )
456 .data( "item.autocomplete", item )
459 if (item.facet !== undefined) {
460 // regular completion item
463 ? $('<a>').html(item.label)
464 : $('<a>').text(item.value));
466 return $item.text(item.label)
468 borderTop: '1px solid #cccccc',
479 * Gets value out of the currently focused "input" (a
480 * div[contenteditable].oe_searchview_input)
482 currentInputValue: function () {
483 return this.$el.find('div.oe_searchview_input:focus').text();
486 * Provide auto-completion result for req.term (an array to `resp`)
488 * @param {Object} req request to complete
489 * @param {String} req.term searched term to complete
490 * @param {Function} resp response callback
492 complete_global_search: function (req, resp) {
493 $.when.apply(null, _(this.inputs).chain()
494 .invoke('complete', req.term)
495 .value()).then(function () {
496 resp(_(_(arguments).compact()).flatten(true));
501 * Action to perform in case of selection: create a facet (model)
502 * and add it to the search collection
504 * @param {Object} e selection event, preventDefault to avoid setting value on object
505 * @param {Object} ui selection information
506 * @param {Object} ui.item selected completion item
508 select_completion: function (e, ui) {
511 var input_index = _(this.input_subviews).indexOf(
513 this.$el.find('div.oe_searchview_input:focus')[0]));
514 this.query.add(ui.item.facet, {at: input_index / 2});
516 childFocused: function () {
517 this.$el.addClass('oe_focused');
519 childBlurred: function () {
520 var val = this.$el.val();
522 var complete = this.$el.data('autocomplete');
523 if ((val && complete.term === undefined) || complete.previous !== undefined) {
524 throw new Error("new jquery.ui version altering implementation" +
525 " details relied on");
527 delete complete.term;
528 this.$el.removeClass('oe_focused')
533 * @param {openerp.web.search.SearchQuery | openerp.web.search.Facet} _1
534 * @param {openerp.web.search.Facet} [_2]
535 * @param {Object} [options]
537 renderFacets: function (_1, _2, options) {
538 // _1: model if event=change, otherwise collection
539 // _2: undefined if event=change, otherwise model
542 var $e = this.$el.find('div.oe_searchview_facets');
543 _.invoke(this.input_subviews, 'destroy');
544 this.input_subviews = [];
546 var i = new my.InputView(this);
547 started.push(i.appendTo($e));
548 this.input_subviews.push(i);
549 this.query.each(function (facet) {
550 var f = new my.FacetView(this, facet);
551 started.push(f.appendTo($e));
552 self.input_subviews.push(f);
554 var i = new my.InputView(this);
555 started.push(i.appendTo($e));
556 self.input_subviews.push(i);
558 _.each(this.input_subviews, function (childView) {
559 childView.on('focused', self, self.proxy('childFocused'));
560 childView.on('blurred', self, self.proxy('childBlurred'));
563 $.when.apply(null, started).then(function () {
565 // options.at: facet inserted at given index, focus next input
566 // otherwise just focus last input
567 if (!options || typeof options.at !== 'number') {
568 input_to_focus = _.last(self.input_subviews);
570 input_to_focus = self.input_subviews[(options.at + 1) * 2];
573 input_to_focus.$el.focus();
578 * Builds a list of widget rows (each row is an array of widgets)
580 * @param {Array} items a list of nodes to convert to widgets
581 * @param {Object} fields a mapping of field names to (ORM) field attributes
582 * @param {String} [group_name] name of the group to put the new controls in
584 make_widgets: function (items, fields, group_name) {
585 group_name = group_name || null;
586 if (!(group_name in this.controls)) {
587 this.controls[group_name] = [];
589 var self = this, group = this.controls[group_name];
591 _.each(items, function (item) {
592 if (filters.length && item.tag !== 'filter') {
593 group.push(new instance.web.search.FilterGroup(filters, this));
598 case 'separator': case 'newline':
601 filters.push(new instance.web.search.Filter(item, this));
604 self.make_widgets(item.children, fields, item.attrs.string);
607 group.push(this.make_field(item, fields[item['attrs'].name]));
609 self.make_widgets(item.children, fields, group_name);
614 if (filters.length) {
615 group.push(new instance.web.search.FilterGroup(filters, this));
619 * Creates a field for the provided field descriptor item (which comes
620 * from fields_view_get)
622 * @param {Object} item fields_view_get node for the field
623 * @param {Object} field fields_get result for the field
624 * @returns instance.web.search.Field
626 make_field: function (item, field) {
627 var obj = instance.web.search.fields.get_any( [item.attrs.widget, field.type]);
629 return new (obj) (item, field, this);
631 console.group('Unknown field type ' + field.type);
632 console.error('View node', item);
633 console.info('View field', field);
634 console.info('In view', this);
640 add_common_inputs: function() {
641 // add Filters to this.inputs, need view.controls filled
642 (new instance.web.search.Filters(this));
643 // add custom filters to this.inputs
644 (new instance.web.search.CustomFilters(this));
645 // add Advanced to this.inputs
646 (new instance.web.search.Advanced(this));
649 search_view_loaded: function(data) {
651 this.fields_view = data.fields_view;
652 if (data.fields_view.type !== 'search' ||
653 data.fields_view.arch.tag !== 'search') {
654 throw new Error(_.str.sprintf(
655 "Got non-search view after asking for a search view: type %s, arch root %s",
656 data.fields_view.type, data.fields_view.arch.tag));
659 data.fields_view['arch'].children,
660 data.fields_view.fields);
662 this.add_common_inputs();
665 var drawer_started = $.when.apply(
666 null, _(this.select_for_drawer()).invoke(
667 'appendTo', this.$el.find('.oe_searchview_drawer')));
670 var defaults_fetched = $.when.apply(null, _(this.inputs).invoke(
671 'facet_for_defaults', this.defaults)).then(function () {
672 self.query.reset(_(arguments).compact(), {preventSearch: true});
675 return $.when(drawer_started, defaults_fetched)
677 self.trigger("search_view_loaded", data);
678 self.ready.resolve();
682 * Extract search data from the view's facets.
684 * Result is an object with 4 (own) properties:
687 * An array of any error generated during data validation and
688 * extraction, contains the validation error objects
694 * Array of domains, in groupby order rather than view order
698 build_search_data: function () {
699 var domains = [], contexts = [], groupbys = [], errors = [];
701 this.query.each(function (facet) {
702 var field = facet.get('field');
704 var domain = field.get_domain(facet);
706 domains.push(domain);
708 var context = field.get_context(facet);
710 contexts.push(context);
712 var group_by = field.get_groupby(facet);
714 groupbys.push.apply(groupbys, group_by);
717 if (e instanceof instance.web.search.Invalid) {
732 * Performs the search view collection of widget data.
734 * If the collection went well (all fields are valid), then triggers
735 * :js:func:`instance.web.SearchView.on_search`.
737 * If at least one field failed its validation, triggers
738 * :js:func:`instance.web.SearchView.on_invalid` instead.
740 do_search: function (_query, options) {
741 if (options && options.preventSearch) {
744 var search = this.build_search_data();
745 if (!_.isEmpty(search.errors)) {
746 this.on_invalid(search.errors);
749 this.trigger('search_data', search.domains, search.contexts, search.groupbys);
752 * Triggered after the SearchView has collected all relevant domains and
755 * It is provided with an Array of domains and an Array of contexts, which
756 * may or may not be evaluated (each item can be either a valid domain or
757 * context, or a string to evaluate in order in the sequence)
759 * It is also passed an array of contexts used for group_by (they are in
760 * the correct order for group_by evaluation, which contexts may not be)
763 * @param {Array} domains an array of literal domains or domain references
764 * @param {Array} contexts an array of literal contexts or context refs
765 * @param {Array} groupbys ordered contexts which may or may not have group_by keys
768 * Triggered after a validation error in the SearchView fields.
770 * Error objects have three keys:
771 * * ``field`` is the name of the invalid field
772 * * ``value`` is the invalid value
773 * * ``message`` is the (in)validation message provided by the field
776 * @param {Array} errors a never-empty array of error objects
778 on_invalid: function (errors) {
779 this.do_notify(_t("Invalid Search"), _t("triggered from search view"));
780 this.trigger('invalid_search', errors);
785 * Registry of search fields, called by :js:class:`instance.web.SearchView` to
786 * find and instantiate its field widgets.
788 instance.web.search.fields = new instance.web.Registry({
789 'char': 'instance.web.search.CharField',
790 'text': 'instance.web.search.CharField',
791 'boolean': 'instance.web.search.BooleanField',
792 'integer': 'instance.web.search.IntegerField',
793 'id': 'instance.web.search.IntegerField',
794 'float': 'instance.web.search.FloatField',
795 'selection': 'instance.web.search.SelectionField',
796 'datetime': 'instance.web.search.DateTimeField',
797 'date': 'instance.web.search.DateField',
798 'many2one': 'instance.web.search.ManyToOneField',
799 'many2many': 'instance.web.search.CharField',
800 'one2many': 'instance.web.search.CharField'
802 instance.web.search.Invalid = instance.web.Class.extend( /** @lends instance.web.search.Invalid# */{
804 * Exception thrown by search widgets when they hold invalid values,
805 * which they can not return when asked.
807 * @constructs instance.web.search.Invalid
808 * @extends instance.web.Class
810 * @param field the name of the field holding an invalid value
811 * @param value the invalid value
812 * @param message validation failure message
814 init: function (field, value, message) {
817 this.message = message;
819 toString: function () {
820 return _.str.sprintf(
821 _t("Incorrect value for field %(fieldname)s: [%(value)s] is %(message)s"),
822 {fieldname: this.field, value: this.value, message: this.message}
826 instance.web.search.Widget = instance.web.Widget.extend( /** @lends instance.web.search.Widget# */{
829 * Root class of all search widgets
831 * @constructs instance.web.search.Widget
832 * @extends instance.web.Widget
834 * @param view the ancestor view of this widget
836 init: function (view) {
841 instance.web.search.add_expand_listener = function($root) {
842 $root.find('a.searchview_group_string').click(function (e) {
843 $root.toggleClass('folded expanded');
848 instance.web.search.Group = instance.web.search.Widget.extend({
849 template: 'SearchView.group',
850 init: function (view_section, view, fields) {
852 this.attrs = view_section.attrs;
853 this.lines = view.make_widgets(
854 view_section.children, fields);
858 instance.web.search.Input = instance.web.search.Widget.extend( /** @lends instance.web.search.Input# */{
861 * @constructs instance.web.search.Input
862 * @extends instance.web.search.Widget
866 init: function (view) {
868 this.view.inputs.push(this);
869 this.style = undefined;
872 * Fetch auto-completion values for the widget.
874 * The completion values should be an array of objects with keys category,
875 * label, value prefixed with an object with keys type=section and label
877 * @param {String} value value to complete
878 * @returns {jQuery.Deferred<null|Array>}
880 complete: function (value) {
884 * Returns a Facet instance for the provided defaults if they apply to
885 * this widget, or null if they don't.
887 * This default implementation will try calling
888 * :js:func:`instance.web.search.Input#facet_for` if the widget's name
889 * matches the input key
891 * @param {Object} defaults
892 * @returns {jQuery.Deferred<null|Object>}
894 facet_for_defaults: function (defaults) {
896 !(this.attrs.name in defaults && defaults[this.attrs.name])) {
899 return this.facet_for(defaults[this.attrs.name]);
901 in_drawer: function () {
902 return !!this._in_drawer;
904 get_context: function () {
906 "get_context not implemented for widget " + this.attrs.type);
908 get_groupby: function () {
910 "get_groupby not implemented for widget " + this.attrs.type);
912 get_domain: function () {
914 "get_domain not implemented for widget " + this.attrs.type);
916 load_attrs: function (attrs) {
917 if (attrs.modifiers) {
918 attrs.modifiers = JSON.parse(attrs.modifiers);
919 attrs.invisible = attrs.modifiers.invisible || false;
920 if (attrs.invisible) {
921 this.style = 'display: none;'
927 instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{
928 template: 'SearchView.filters',
930 completion_label: _lt("Filter on: %s"),
932 * Inclusive group of filters, creates a continuous "button" with clickable
933 * sections (the normal display for filters is to be a self-contained button)
935 * @constructs instance.web.search.FilterGroup
936 * @extends instance.web.search.Input
938 * @param {Array<instance.web.search.Filter>} filters elements of the group
939 * @param {instance.web.SearchView} view view in which the filters are contained
941 init: function (filters, view) {
942 // If all filters are group_by and we're not initializing a GroupbyGroup,
943 // create a GroupbyGroup instead of the current FilterGroup
944 if (!(this instanceof instance.web.search.GroupbyGroup) &&
945 _(filters).all(function (f) {
946 return f.attrs.context && f.attrs.context.group_by; })) {
947 return new instance.web.search.GroupbyGroup(filters, view);
950 this.filters = filters;
951 this.view.query.on('add remove change reset', this.proxy('search_change'));
954 this.$el.on('click', 'li', this.proxy('toggle_filter'));
958 * Handles change of the search query: any of the group's filter which is
959 * in the search query should be visually checked in the drawer
961 search_change: function () {
963 var $filters = this.$el.find('> li').removeClass('oe_selected');
964 var facet = this.view.query.find(_.bind(this.match_facet, this));
965 if (!facet) { return; }
966 facet.values.each(function (v) {
967 var i = _(self.filters).indexOf(v.get('value'));
968 if (i === -1) { return; }
969 $filters.eq(i).addClass('oe_selected');
973 * Matches the group to a facet, in order to find if the group is
974 * represented in the current search query
976 match_facet: function (facet) {
977 return facet.get('field') === this;
979 make_facet: function (values) {
981 category: _t("Filter"),
987 make_value: function (filter) {
989 label: filter.attrs.string || filter.attrs.help || filter.attrs.name,
993 facet_for_defaults: function (defaults) {
995 var fs = _(this.filters).chain()
996 .filter(function (f) {
997 return f.attrs && f.attrs.name && !!defaults[f.attrs.name];
998 }).map(function (f) {
999 return self.make_value(f);
1001 if (_.isEmpty(fs)) { return $.when(null); }
1002 return $.when(this.make_facet(fs));
1005 * Fetches contexts for all enabled filters in the group
1007 * @param {openerp.web.search.Facet} facet
1008 * @return {*} combined contexts of the enabled filters in this group
1010 get_context: function (facet) {
1011 var contexts = facet.values.chain()
1012 .map(function (f) { return f.get('value').attrs.context; })
1016 if (!contexts.length) { return; }
1017 if (contexts.length === 1) { return contexts[0]; }
1018 return _.extend(new instance.web.CompoundContext, {
1019 __contexts: contexts
1023 * Fetches group_by sequence for all enabled filters in the group
1025 * @param {VS.model.SearchFacet} facet
1026 * @return {Array} enabled filters in this group
1028 get_groupby: function (facet) {
1029 return facet.values.chain()
1030 .map(function (f) { return f.get('value').attrs.context; })
1035 * Handles domains-fetching for all the filters within it: groups them.
1037 * @param {VS.model.SearchFacet} facet
1038 * @return {*} combined domains of the enabled filters in this group
1040 get_domain: function (facet) {
1041 var domains = facet.values.chain()
1042 .map(function (f) { return f.get('value').attrs.domain; })
1046 if (!domains.length) { return; }
1047 if (domains.length === 1) { return domains[0]; }
1048 for (var i=domains.length; --i;) {
1049 domains.unshift(['|']);
1051 return _.extend(new instance.web.CompoundDomain(), {
1055 toggle_filter: function (e) {
1056 this.toggle(this.filters[$(e.target).index()]);
1058 toggle: function (filter) {
1059 this.view.query.toggle(this.make_facet([this.make_value(filter)]));
1061 complete: function (item) {
1063 item = item.toLowerCase();
1064 var facet_values = _(this.filters).chain()
1065 .filter(function (filter) {
1067 string: filter.attrs.string || '',
1068 help: filter.attrs.help || '',
1069 name: filter.attrs.name || ''
1071 var include = _.str.include;
1072 return include(at.string.toLowerCase(), item)
1073 || include(at.help.toLowerCase(), item)
1074 || include(at.name.toLowerCase(), item);
1076 .map(this.make_value)
1078 if (_(facet_values).isEmpty()) { return $.when(null); }
1079 return $.when(_.map(facet_values, function (facet_value) {
1081 label: _.str.sprintf(self.completion_label.toString(),
1083 facet: self.make_facet([facet_value])
1088 instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
1090 completion_label: _lt("Group by: %s"),
1091 init: function (filters, view) {
1092 this._super(filters, view);
1093 // Not flanders: facet unicity is handled through the
1094 // (category, field) pair of facet attributes. This is all well and
1095 // good for regular filter groups where a group matches a facet, but for
1096 // groupby we want a single facet. So cheat: add an attribute on the
1097 // view which proxies to the first GroupbyGroup, so it can be used
1098 // for every GroupbyGroup and still provides the various methods needed
1099 // by the search view. Use weirdo name to avoid risks of conflicts
1100 if (!this.getParent()._s_groupby) {
1101 this.getParent()._s_groupby = {
1102 help: "See GroupbyGroup#init",
1103 get_context: this.proxy('get_context'),
1104 get_domain: this.proxy('get_domain'),
1105 get_groupby: this.proxy('get_groupby')
1109 match_facet: function (facet) {
1110 return facet.get('field') === this.getParent()._s_groupby;
1112 make_facet: function (values) {
1114 category: _t("GroupBy"),
1117 field: this.getParent()._s_groupby
1121 instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
1122 template: 'SearchView.filter',
1124 * Implementation of the OpenERP filters (button with a context and/or
1125 * a domain sent as-is to the search view)
1127 * Filters are only attributes holder, the actual work (compositing
1128 * domains and contexts, converting between facets and filters) is
1129 * performed by the filter group.
1131 * @constructs instance.web.search.Filter
1132 * @extends instance.web.search.Input
1137 init: function (node, view) {
1139 this.load_attrs(node.attrs);
1141 facet_for: function () { return $.when(null); },
1142 get_context: function () { },
1143 get_domain: function () { },
1145 instance.web.search.Field = instance.web.search.Input.extend( /** @lends instance.web.search.Field# */ {
1146 template: 'SearchView.field',
1147 default_operator: '=',
1149 * @constructs instance.web.search.Field
1150 * @extends instance.web.search.Input
1152 * @param view_section
1156 init: function (view_section, field, view) {
1158 this.load_attrs(_.extend({}, field, view_section.attrs));
1160 facet_for: function (value) {
1163 category: this.attrs.string || this.attrs.name,
1164 values: [{label: String(value), value: value}]
1167 value_from: function (facetValue) {
1168 return facetValue.get('value');
1170 get_context: function (facet) {
1172 // A field needs a context to send when active
1173 var context = this.attrs.context;
1174 if (_.isEmpty(context) || !facet.values.length) {
1177 var contexts = facet.values.map(function (facetValue) {
1178 return new instance.web.CompoundContext(context)
1179 .set_eval_context({self: self.value_from(facetValue)});
1182 if (contexts.length === 1) { return contexts[0]; }
1184 return _.extend(new instance.web.CompoundContext, {
1185 __contexts: contexts
1188 get_groupby: function () { },
1190 * Function creating the returned domain for the field, override this
1191 * methods in children if you only need to customize the field's domain
1192 * without more complex alterations or tests (and without the need to
1193 * change override the handling of filter_domain)
1195 * @param {String} name the field's name
1196 * @param {String} operator the field's operator (either attribute-specified or default operator for the field
1197 * @param {Number|String} value parsed value for the field
1198 * @returns {Array<Array>} domain to include in the resulting search
1200 make_domain: function (name, operator, facet) {
1201 return [[name, operator, this.value_from(facet)]];
1203 get_domain: function (facet) {
1204 if (!facet.values.length) { return; }
1206 var value_to_domain;
1208 var domain = this.attrs['filter_domain'];
1210 value_to_domain = function (facetValue) {
1211 return new instance.web.CompoundDomain(domain)
1212 .set_eval_context({self: self.value_from(facetValue)});
1215 value_to_domain = function (facetValue) {
1216 return self.make_domain(
1218 self.attrs.operator || self.default_operator,
1222 var domains = facet.values.map(value_to_domain);
1224 if (domains.length === 1) { return domains[0]; }
1225 for (var i = domains.length; --i;) {
1226 domains.unshift(['|']);
1229 return _.extend(new instance.web.CompoundDomain, {
1235 * Implementation of the ``char`` OpenERP field type:
1237 * * Default operator is ``ilike`` rather than ``=``
1239 * * The Javascript and the HTML values are identical (strings)
1242 * @extends instance.web.search.Field
1244 instance.web.search.CharField = instance.web.search.Field.extend( /** @lends instance.web.search.CharField# */ {
1245 default_operator: 'ilike',
1246 complete: function (value) {
1247 if (_.isEmpty(value)) { return $.when(null); }
1248 var label = _.str.sprintf(_.str.escapeHTML(
1249 _t("Search %(field)s for: %(value)s")), {
1250 field: '<em>' + this.attrs.string + '</em>',
1251 value: '<strong>' + _.str.escapeHTML(value) + '</strong>'});
1255 category: this.attrs.string,
1257 values: [{label: value, value: value}]
1262 instance.web.search.NumberField = instance.web.search.Field.extend(/** @lends instance.web.search.NumberField# */{
1263 value_from: function () {
1264 if (!this.$el.val()) {
1267 var val = this.parse(this.$el.val()),
1268 check = Number(this.$el.val());
1269 if (isNaN(val) || val !== check) {
1270 this.$el.addClass('error');
1271 throw new instance.web.search.Invalid(
1272 this.attrs.name, this.$el.val(), this.error_message);
1274 this.$el.removeClass('error');
1280 * @extends instance.web.search.NumberField
1282 instance.web.search.IntegerField = instance.web.search.NumberField.extend(/** @lends instance.web.search.IntegerField# */{
1283 error_message: _t("not a valid integer"),
1284 parse: function (value) {
1286 return instance.web.parse_value(value, {'widget': 'integer'});
1294 * @extends instance.web.search.NumberField
1296 instance.web.search.FloatField = instance.web.search.NumberField.extend(/** @lends instance.web.search.FloatField# */{
1297 error_message: _t("not a valid number"),
1298 parse: function (value) {
1300 return instance.web.parse_value(value, {'widget': 'float'});
1308 * Utility function for m2o & selection fields taking a selection/name_get pair
1309 * (value, name) and converting it to a Facet descriptor
1311 * @param {instance.web.search.Field} field holder field
1312 * @param {Array} pair pair value to convert
1314 function facet_from(field, pair) {
1317 category: field['attrs'].string,
1318 values: [{label: pair[1], value: pair[0]}]
1324 * @extends instance.web.search.Field
1326 instance.web.search.SelectionField = instance.web.search.Field.extend(/** @lends instance.web.search.SelectionField# */{
1327 // This implementation is a basic <select> field, but it may have to be
1328 // altered to be more in line with the GTK client, which uses a combo box
1329 // (~ jquery.autocomplete):
1330 // * If an option was selected in the list, behave as currently
1331 // * If something which is not in the list was entered (via the text input),
1332 // the default domain should become (`ilike` string_value) but **any
1333 // ``context`` or ``filter_domain`` becomes falsy, idem if ``@operator``
1334 // is specified. So at least get_domain needs to be quite a bit
1335 // overridden (if there's no @value and there is no filter_domain and
1336 // there is no @operator, return [[name, 'ilike', str_val]]
1337 template: 'SearchView.field.selection',
1339 this._super.apply(this, arguments);
1340 // prepend empty option if there is no empty option in the selection list
1341 this.prepend_empty = !_(this.attrs.selection).detect(function (item) {
1345 complete: function (needle) {
1347 var results = _(this.attrs.selection).chain()
1348 .filter(function (sel) {
1349 var value = sel[0], label = sel[1];
1350 if (!value) { return false; }
1351 return label.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
1353 .map(function (sel) {
1356 facet: facet_from(self, sel)
1359 if (_.isEmpty(results)) { return $.when(null); }
1360 return $.when.call(null, [{
1361 label: this.attrs.string
1362 }].concat(results));
1364 facet_for: function (value) {
1365 var match = _(this.attrs.selection).detect(function (sel) {
1366 return sel[0] === value;
1368 if (!match) { return $.when(null); }
1369 return $.when(facet_from(this, match));
1372 instance.web.search.BooleanField = instance.web.search.SelectionField.extend(/** @lends instance.web.search.BooleanField# */{
1374 * @constructs instance.web.search.BooleanField
1375 * @extends instance.web.search.BooleanField
1378 this._super.apply(this, arguments);
1379 this.attrs.selection = [
1387 * @extends instance.web.search.DateField
1389 instance.web.search.DateField = instance.web.search.Field.extend(/** @lends instance.web.search.DateField# */{
1390 value_from: function (facetValue) {
1391 return instance.web.date_to_str(facetValue.get('value'));
1393 complete: function (needle) {
1394 var d = Date.parse(needle);
1395 if (!d) { return $.when(null); }
1396 var date_string = instance.web.format_value(d, this.attrs);
1397 var label = _.str.sprintf(_.str.escapeHTML(
1398 _t("Search %(field)s at: %(value)s")), {
1399 field: '<em>' + this.attrs.string + '</em>',
1400 value: '<strong>' + date_string + '</strong>'});
1404 category: this.attrs.string,
1406 values: [{label: date_string, value: d}]
1412 * Implementation of the ``datetime`` openerp field type:
1414 * * Uses the same widget as the ``date`` field type (a simple date)
1416 * * Builds a slighly more complex, it's a datetime range (includes time)
1417 * spanning the whole day selected by the date widget
1420 * @extends instance.web.DateField
1422 instance.web.search.DateTimeField = instance.web.search.DateField.extend(/** @lends instance.web.search.DateTimeField# */{
1423 value_from: function (facetValue) {
1424 return instance.web.datetime_to_str(facetValue.get('value'));
1427 instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
1428 default_operator: {},
1429 init: function (view_section, field, view) {
1430 this._super(view_section, field, view);
1431 this.model = new instance.web.Model(this.attrs.relation);
1433 complete: function (needle) {
1436 // FIXME: "concurrent" searches (multiple requests, mis-ordered responses)
1437 return this.model.call('name_search', [], {
1441 }).pipe(function (results) {
1442 if (_.isEmpty(results)) { return null; }
1443 return [{label: self.attrs.string}].concat(
1444 _(results).map(function (result) {
1447 facet: facet_from(self, result)
1452 facet_for: function (value) {
1454 if (value instanceof Array) {
1455 if (value.length === 2 && _.isString(value[1])) {
1456 return $.when(facet_from(this, value));
1458 assert(value.length <= 1,
1459 _t("M2O search fields do not currently handle multiple default values"));
1460 // there are many cases of {search_default_$m2ofield: [id]}, need
1461 // to handle this as if it were a single value.
1464 return this.model.call('name_get', [value]).pipe(function (names) {
1465 if (_(names).isEmpty()) { return null; }
1466 return facet_from(self, names[0]);
1469 value_from: function (facetValue) {
1470 return facetValue.get('label');
1472 make_domain: function (name, operator, facetValue) {
1473 if (operator === this.default_operator) {
1474 return [[name, '=', facetValue.get('value')]];
1476 return this._super(name, operator, facetValue);
1478 get_context: function (facet) {
1479 var values = facet.values;
1480 if (_.isEmpty(this.attrs.context) && values.length === 1) {
1482 c['default_' + this.attrs.name] = values.at(0).get('value');
1485 return this._super(facet);
1489 instance.web.search.CustomFilters = instance.web.search.Input.extend({
1490 template: 'SearchView.CustomFilters',
1492 start: function () {
1494 this.model = new instance.web.Model('ir.filters');
1497 .on('remove', function (facet) {
1498 if (!facet.get('is_custom_filter')) {
1501 self.clear_selection();
1503 .on('reset', this.proxy('clear_selection'));
1504 this.$el.on('submit', 'form', this.proxy('save_current'));
1505 this.$el.on('click', 'h4', function () {
1506 self.$el.toggleClass('oe_opened');
1508 // FIXME: local eval of domain and context to get rid of special endpoint
1509 return this.rpc('/web/searchview/get_filters', {
1510 model: this.view.model
1511 }).pipe(this.proxy('set_filters'));
1513 clear_selection: function () {
1514 this.$el.find('li.oe_selected').removeClass('oe_selected');
1516 append_filter: function (filter) {
1518 var key = _.str.sprintf('(%s)%s', filter.user_id, filter.name);
1521 if (key in this.filters) {
1522 $filter = this.filters[key];
1525 $filter = this.filters[key] = $('<li></li>')
1526 .appendTo(this.$el.find('.oe_searchview_custom_list'))
1527 .addClass(filter.user_id ? 'oe_searchview_custom_private'
1528 : 'oe_searchview_custom_public')
1531 $('<a class="oe_searchview_custom_delete">x</a>')
1532 .click(function (e) {
1533 e.stopPropagation();
1534 self.model.call('unlink', [id]).then(function () {
1541 $filter.unbind('click').click(function () {
1542 self.view.query.reset([{
1543 category: _t("Custom Filter"),
1546 get_context: function () { return filter.context; },
1547 get_groupby: function () { return [filter.context]; },
1548 get_domain: function () { return filter.domain; }
1550 is_custom_filter: true,
1551 values: [{label: filter.name, value: null}]
1553 $filter.addClass('oe_selected');
1556 set_filters: function (filters) {
1557 _(filters).map(_.bind(this.append_filter, this));
1559 save_current: function () {
1561 var $name = this.$el.find('input:first');
1562 var private_filter = !this.$el.find('input:last').prop('checked');
1564 var search = this.view.build_search_data();
1565 this.rpc('/web/session/eval_domain_and_context', {
1566 domains: search.domains,
1567 contexts: search.contexts,
1568 group_by_seq: search.groupbys || []
1569 }).then(function (results) {
1570 if (!_.isEmpty(results.group_by)) {
1571 results.context.group_by = results.group_by;
1575 user_id: private_filter ? instance.session.uid : false,
1576 model_id: self.view.model,
1577 context: results.context,
1578 domain: results.domain
1580 // FIXME: current context?
1581 return self.model.call('create_or_replace', [filter]).then(function (id) {
1583 self.append_filter(filter);
1585 .removeClass('oe_opened')
1586 .find('form')[0].reset();
1593 instance.web.search.Filters = instance.web.search.Input.extend({
1594 template: 'SearchView.Filters',
1596 start: function () {
1598 var running_count = 0;
1599 // get total filters count
1600 var is_group = function (i) { return i instanceof instance.web.search.FilterGroup; };
1601 var filters_count = _(this.view.controls).chain()
1604 .map(function (i) { return i.filters.length; })
1608 var col1 = [], col2 = _(this.view.controls).map(function (inputs, group) {
1609 var filters = _(inputs).filter(is_group);
1611 name: group === 'null' ? "<span class='oe_i'>q</span> " + _t("Filters") : "<span class='oe_i'>w</span> " + group,
1613 length: _(filters).chain().map(function (i) {
1614 return i.filters.length; }).sum().value()
1618 while (col2.length) {
1619 // col1 + group should be smaller than col2 + group
1620 if ((running_count + col2[0].length) <= (filters_count - running_count)) {
1621 running_count += col2[0].length;
1622 col1.push(col2.shift());
1629 this.render_column(col1, $('<div>').appendTo(this.$el)),
1630 this.render_column(col2, $('<div>').appendTo(this.$el)));
1632 render_column: function (column, $el) {
1633 return $.when.apply(null, _(column).map(function (group) {
1634 $('<h3>').html(group.name).appendTo($el);
1635 return $.when.apply(null,
1636 _(group.filters).invoke('appendTo', $el));
1641 instance.web.search.Advanced = instance.web.search.Input.extend({
1642 template: 'SearchView.advanced',
1644 start: function () {
1647 .on('keypress keydown keyup', function (e) { e.stopPropagation(); })
1648 .on('click', 'h4', function () {
1649 self.$el.toggleClass('oe_opened');
1650 }).on('click', 'button.oe_add_condition', function () {
1651 self.append_proposition();
1652 }).on('submit', 'form', function (e) {
1654 self.commit_search();
1658 this.rpc("/web/searchview/fields_get", {model: this.view.model}).then(function(data) {
1659 self.fields = _.extend({
1660 id: { string: 'ID', type: 'id' }
1662 })).then(function () {
1663 self.append_proposition();
1666 append_proposition: function () {
1667 return (new instance.web.search.ExtendedSearchProposition(this, this.fields))
1668 .appendTo(this.$el.find('ul'));
1670 commit_search: function () {
1672 // Get domain sections from all propositions
1673 var children = this.getChildren();
1674 var propositions = _.invoke(children, 'get_proposition');
1675 var domain = _(propositions).pluck('value');
1676 for (var i = domain.length; --i;) {
1677 domain.unshift('|');
1680 this.view.query.add({
1681 category: _t("Advanced"),
1682 values: propositions,
1684 get_context: function () { },
1685 get_domain: function () { return domain;},
1686 get_groupby: function () { }
1690 // remove all propositions
1691 _.invoke(children, 'destroy');
1692 // add new empty proposition
1693 this.append_proposition();
1694 // TODO: API on searchview
1695 this.view.$el.removeClass('oe_searchview_open_drawer');
1699 instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @lends instance.web.search.ExtendedSearchProposition# */{
1700 template: 'SearchView.extended_search.proposition',
1702 * @constructs instance.web.search.ExtendedSearchProposition
1703 * @extends instance.web.Widget
1708 init: function (parent, fields) {
1709 this._super(parent);
1710 this.fields = _(fields).chain()
1711 .map(function(val, key) { return _.extend({}, val, {'name': key}); })
1712 .sortBy(function(field) {return field.string;})
1714 this.attrs = {_: _, fields: this.fields, selected: null};
1717 start: function () {
1719 this.$el.find(".searchview_extended_prop_field").change(function() {
1722 this.$el.find('.searchview_extended_delete_prop').click(function () {
1727 changed: function() {
1728 var nval = this.$el.find(".searchview_extended_prop_field").val();
1729 if(this.attrs.selected == null || nval != this.attrs.selected.name) {
1730 this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
1734 * Selects the provided field object
1736 * @param field a field descriptor object (as returned by fields_get, augmented by the field name)
1738 select_field: function(field) {
1740 if(this.attrs.selected != null) {
1741 this.value.destroy();
1743 this.$el.find('.searchview_extended_prop_op').html('');
1745 this.attrs.selected = field;
1750 var type = field.type;
1751 var Field = instance.web.search.custom_filters.get_object(type);
1753 Field = instance.web.search.custom_filters.get_object("char");
1755 this.value = new Field(this, field);
1756 _.each(this.value.operators, function(operator) {
1757 $('<option>', {value: operator.value})
1758 .text(String(operator.text))
1759 .appendTo(self.$el.find('.searchview_extended_prop_op'));
1761 var $value_loc = this.$el.find('.searchview_extended_prop_value').empty();
1762 this.value.appendTo($value_loc);
1765 get_proposition: function() {
1766 if ( this.attrs.selected == null)
1768 var field = this.attrs.selected;
1769 var op = this.$el.find('.searchview_extended_prop_op')[0];
1770 var operator = op.options[op.selectedIndex];
1772 label: _.str.sprintf(_t('%(field)s %(operator)s "%(value)s"'), {
1773 field: field.string,
1774 // According to spec, HTMLOptionElement#label should return
1775 // HTMLOptionElement#text when not defined/empty, but it does
1776 // not in older Webkit (between Safari 5.1.5 and Chrome 17) and
1777 // Gecko (pre Firefox 7) browsers, so we need a manual fallback
1779 operator: operator.label || operator.text,
1780 value: this.value}),
1781 value: [field.name, operator.value, this.value.get_value()]
1786 instance.web.search.ExtendedSearchProposition.Field = instance.web.Widget.extend({
1787 init: function (parent, field) {
1788 this._super(parent);
1792 * Returns a human-readable version of the value, in case the "logical"
1793 * and the "semantic" values of a field differ (as for selection fields,
1796 * The default implementation simply returns the value itself.
1798 * @return {String} human-readable version of the value
1800 toString: function () {
1801 return this.get_value();
1804 instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({
1805 template: 'SearchView.extended_search.proposition.char',
1807 {value: "ilike", text: _lt("contains")},
1808 {value: "not ilike", text: _lt("doesn't contain")},
1809 {value: "=", text: _lt("is equal to")},
1810 {value: "!=", text: _lt("is not equal to")}
1812 get_value: function() {
1813 return this.$el.val();
1816 instance.web.search.ExtendedSearchProposition.DateTime = instance.web.search.ExtendedSearchProposition.Field.extend({
1817 template: 'SearchView.extended_search.proposition.empty',
1819 {value: "=", text: _lt("is equal to")},
1820 {value: "!=", text: _lt("is not equal to")},
1821 {value: ">", text: _lt("greater than")},
1822 {value: "<", text: _lt("less than")},
1823 {value: ">=", text: _lt("greater or equal than")},
1824 {value: "<=", text: _lt("less or equal than")}
1827 * Date widgets live in view_form which is not yet loaded when this is
1830 widget: function () { return instance.web.DateTimeWidget; },
1831 get_value: function() {
1832 return this.datewidget.get_value();
1835 var ready = this._super();
1836 this.datewidget = new (this.widget())(this);
1837 this.datewidget.appendTo(this.$el);
1841 instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.DateTime.extend({
1842 widget: function () { return instance.web.DateWidget; }
1844 instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({
1845 template: 'SearchView.extended_search.proposition.integer',
1847 {value: "=", text: _lt("is equal to")},
1848 {value: "!=", text: _lt("is not equal to")},
1849 {value: ">", text: _lt("greater than")},
1850 {value: "<", text: _lt("less than")},
1851 {value: ">=", text: _lt("greater or equal than")},
1852 {value: "<=", text: _lt("less or equal than")}
1854 toString: function () {
1855 return this.$el.val();
1857 get_value: function() {
1859 return instance.web.parse_value(this.$el.val(), {'widget': 'integer'});
1865 instance.web.search.ExtendedSearchProposition.Id = instance.web.search.ExtendedSearchProposition.Integer.extend({
1866 operators: [{value: "=", text: _lt("is")}]
1868 instance.web.search.ExtendedSearchProposition.Float = instance.web.search.ExtendedSearchProposition.Field.extend({
1869 template: 'SearchView.extended_search.proposition.float',
1871 {value: "=", text: _lt("is equal to")},
1872 {value: "!=", text: _lt("is not equal to")},
1873 {value: ">", text: _lt("greater than")},
1874 {value: "<", text: _lt("less than")},
1875 {value: ">=", text: _lt("greater or equal than")},
1876 {value: "<=", text: _lt("less or equal than")}
1878 toString: function () {
1879 return this.$el.val();
1881 get_value: function() {
1883 return instance.web.parse_value(this.$el.val(), {'widget': 'float'});
1889 instance.web.search.ExtendedSearchProposition.Selection = instance.web.search.ExtendedSearchProposition.Field.extend({
1890 template: 'SearchView.extended_search.proposition.selection',
1892 {value: "=", text: _lt("is")},
1893 {value: "!=", text: _lt("is not")}
1895 toString: function () {
1896 var select = this.$el[0];
1897 var option = select.options[select.selectedIndex];
1898 return option.label || option.text;
1900 get_value: function() {
1901 return this.$el.val();
1904 instance.web.search.ExtendedSearchProposition.Boolean = instance.web.search.ExtendedSearchProposition.Field.extend({
1905 template: 'SearchView.extended_search.proposition.empty',
1907 {value: "=", text: _lt("is true")},
1908 {value: "!=", text: _lt("is false")}
1910 toString: function () { return ''; },
1911 get_value: function() {
1916 instance.web.search.custom_filters = new instance.web.Registry({
1917 'char': 'instance.web.search.ExtendedSearchProposition.Char',
1918 'text': 'instance.web.search.ExtendedSearchProposition.Char',
1919 'one2many': 'instance.web.search.ExtendedSearchProposition.Char',
1920 'many2one': 'instance.web.search.ExtendedSearchProposition.Char',
1921 'many2many': 'instance.web.search.ExtendedSearchProposition.Char',
1923 'datetime': 'instance.web.search.ExtendedSearchProposition.DateTime',
1924 'date': 'instance.web.search.ExtendedSearchProposition.Date',
1925 'integer': 'instance.web.search.ExtendedSearchProposition.Integer',
1926 'float': 'instance.web.search.ExtendedSearchProposition.Float',
1927 'boolean': 'instance.web.search.ExtendedSearchProposition.Boolean',
1928 'selection': 'instance.web.search.ExtendedSearchProposition.Selection',
1930 'id': 'instance.web.search.ExtendedSearchProposition.Id'
1935 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: