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 'html': 'instance.web.search.CharField',
792 'boolean': 'instance.web.search.BooleanField',
793 'integer': 'instance.web.search.IntegerField',
794 'id': 'instance.web.search.IntegerField',
795 'float': 'instance.web.search.FloatField',
796 'selection': 'instance.web.search.SelectionField',
797 'datetime': 'instance.web.search.DateTimeField',
798 'date': 'instance.web.search.DateField',
799 'many2one': 'instance.web.search.ManyToOneField',
800 'many2many': 'instance.web.search.CharField',
801 'one2many': 'instance.web.search.CharField'
803 instance.web.search.Invalid = instance.web.Class.extend( /** @lends instance.web.search.Invalid# */{
805 * Exception thrown by search widgets when they hold invalid values,
806 * which they can not return when asked.
808 * @constructs instance.web.search.Invalid
809 * @extends instance.web.Class
811 * @param field the name of the field holding an invalid value
812 * @param value the invalid value
813 * @param message validation failure message
815 init: function (field, value, message) {
818 this.message = message;
820 toString: function () {
821 return _.str.sprintf(
822 _t("Incorrect value for field %(fieldname)s: [%(value)s] is %(message)s"),
823 {fieldname: this.field, value: this.value, message: this.message}
827 instance.web.search.Widget = instance.web.Widget.extend( /** @lends instance.web.search.Widget# */{
830 * Root class of all search widgets
832 * @constructs instance.web.search.Widget
833 * @extends instance.web.Widget
835 * @param view the ancestor view of this widget
837 init: function (view) {
842 instance.web.search.add_expand_listener = function($root) {
843 $root.find('a.searchview_group_string').click(function (e) {
844 $root.toggleClass('folded expanded');
849 instance.web.search.Group = instance.web.search.Widget.extend({
850 template: 'SearchView.group',
851 init: function (view_section, view, fields) {
853 this.attrs = view_section.attrs;
854 this.lines = view.make_widgets(
855 view_section.children, fields);
859 instance.web.search.Input = instance.web.search.Widget.extend( /** @lends instance.web.search.Input# */{
862 * @constructs instance.web.search.Input
863 * @extends instance.web.search.Widget
867 init: function (view) {
869 this.view.inputs.push(this);
870 this.style = undefined;
873 * Fetch auto-completion values for the widget.
875 * The completion values should be an array of objects with keys category,
876 * label, value prefixed with an object with keys type=section and label
878 * @param {String} value value to complete
879 * @returns {jQuery.Deferred<null|Array>}
881 complete: function (value) {
885 * Returns a Facet instance for the provided defaults if they apply to
886 * this widget, or null if they don't.
888 * This default implementation will try calling
889 * :js:func:`instance.web.search.Input#facet_for` if the widget's name
890 * matches the input key
892 * @param {Object} defaults
893 * @returns {jQuery.Deferred<null|Object>}
895 facet_for_defaults: function (defaults) {
897 !(this.attrs.name in defaults && defaults[this.attrs.name])) {
900 return this.facet_for(defaults[this.attrs.name]);
902 in_drawer: function () {
903 return !!this._in_drawer;
905 get_context: function () {
907 "get_context not implemented for widget " + this.attrs.type);
909 get_groupby: function () {
911 "get_groupby not implemented for widget " + this.attrs.type);
913 get_domain: function () {
915 "get_domain not implemented for widget " + this.attrs.type);
917 load_attrs: function (attrs) {
918 if (attrs.modifiers) {
919 attrs.modifiers = JSON.parse(attrs.modifiers);
920 attrs.invisible = attrs.modifiers.invisible || false;
921 if (attrs.invisible) {
922 this.style = 'display: none;'
928 instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{
929 template: 'SearchView.filters',
931 completion_label: _lt("Filter on: %s"),
933 * Inclusive group of filters, creates a continuous "button" with clickable
934 * sections (the normal display for filters is to be a self-contained button)
936 * @constructs instance.web.search.FilterGroup
937 * @extends instance.web.search.Input
939 * @param {Array<instance.web.search.Filter>} filters elements of the group
940 * @param {instance.web.SearchView} view view in which the filters are contained
942 init: function (filters, view) {
943 // If all filters are group_by and we're not initializing a GroupbyGroup,
944 // create a GroupbyGroup instead of the current FilterGroup
945 if (!(this instanceof instance.web.search.GroupbyGroup) &&
946 _(filters).all(function (f) {
947 return f.attrs.context && f.attrs.context.group_by; })) {
948 return new instance.web.search.GroupbyGroup(filters, view);
951 this.filters = filters;
952 this.view.query.on('add remove change reset', this.proxy('search_change'));
955 this.$el.on('click', 'li', this.proxy('toggle_filter'));
959 * Handles change of the search query: any of the group's filter which is
960 * in the search query should be visually checked in the drawer
962 search_change: function () {
964 var $filters = this.$el.find('> li').removeClass('oe_selected');
965 var facet = this.view.query.find(_.bind(this.match_facet, this));
966 if (!facet) { return; }
967 facet.values.each(function (v) {
968 var i = _(self.filters).indexOf(v.get('value'));
969 if (i === -1) { return; }
970 $filters.eq(i).addClass('oe_selected');
974 * Matches the group to a facet, in order to find if the group is
975 * represented in the current search query
977 match_facet: function (facet) {
978 return facet.get('field') === this;
980 make_facet: function (values) {
982 category: _t("Filter"),
988 make_value: function (filter) {
990 label: filter.attrs.string || filter.attrs.help || filter.attrs.name,
994 facet_for_defaults: function (defaults) {
996 var fs = _(this.filters).chain()
997 .filter(function (f) {
998 return f.attrs && f.attrs.name && !!defaults[f.attrs.name];
999 }).map(function (f) {
1000 return self.make_value(f);
1002 if (_.isEmpty(fs)) { return $.when(null); }
1003 return $.when(this.make_facet(fs));
1006 * Fetches contexts for all enabled filters in the group
1008 * @param {openerp.web.search.Facet} facet
1009 * @return {*} combined contexts of the enabled filters in this group
1011 get_context: function (facet) {
1012 var contexts = facet.values.chain()
1013 .map(function (f) { return f.get('value').attrs.context; })
1017 if (!contexts.length) { return; }
1018 if (contexts.length === 1) { return contexts[0]; }
1019 return _.extend(new instance.web.CompoundContext, {
1020 __contexts: contexts
1024 * Fetches group_by sequence for all enabled filters in the group
1026 * @param {VS.model.SearchFacet} facet
1027 * @return {Array} enabled filters in this group
1029 get_groupby: function (facet) {
1030 return facet.values.chain()
1031 .map(function (f) { return f.get('value').attrs.context; })
1036 * Handles domains-fetching for all the filters within it: groups them.
1038 * @param {VS.model.SearchFacet} facet
1039 * @return {*} combined domains of the enabled filters in this group
1041 get_domain: function (facet) {
1042 var domains = facet.values.chain()
1043 .map(function (f) { return f.get('value').attrs.domain; })
1047 if (!domains.length) { return; }
1048 if (domains.length === 1) { return domains[0]; }
1049 for (var i=domains.length; --i;) {
1050 domains.unshift(['|']);
1052 return _.extend(new instance.web.CompoundDomain(), {
1056 toggle_filter: function (e) {
1057 this.toggle(this.filters[$(e.target).index()]);
1059 toggle: function (filter) {
1060 this.view.query.toggle(this.make_facet([this.make_value(filter)]));
1062 complete: function (item) {
1064 item = item.toLowerCase();
1065 var facet_values = _(this.filters).chain()
1066 .filter(function (filter) {
1068 string: filter.attrs.string || '',
1069 help: filter.attrs.help || '',
1070 name: filter.attrs.name || ''
1072 var include = _.str.include;
1073 return include(at.string.toLowerCase(), item)
1074 || include(at.help.toLowerCase(), item)
1075 || include(at.name.toLowerCase(), item);
1077 .map(this.make_value)
1079 if (_(facet_values).isEmpty()) { return $.when(null); }
1080 return $.when(_.map(facet_values, function (facet_value) {
1082 label: _.str.sprintf(self.completion_label.toString(),
1084 facet: self.make_facet([facet_value])
1089 instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
1091 completion_label: _lt("Group by: %s"),
1092 init: function (filters, view) {
1093 this._super(filters, view);
1094 // Not flanders: facet unicity is handled through the
1095 // (category, field) pair of facet attributes. This is all well and
1096 // good for regular filter groups where a group matches a facet, but for
1097 // groupby we want a single facet. So cheat: add an attribute on the
1098 // view which proxies to the first GroupbyGroup, so it can be used
1099 // for every GroupbyGroup and still provides the various methods needed
1100 // by the search view. Use weirdo name to avoid risks of conflicts
1101 if (!this.getParent()._s_groupby) {
1102 this.getParent()._s_groupby = {
1103 help: "See GroupbyGroup#init",
1104 get_context: this.proxy('get_context'),
1105 get_domain: this.proxy('get_domain'),
1106 get_groupby: this.proxy('get_groupby')
1110 match_facet: function (facet) {
1111 return facet.get('field') === this.getParent()._s_groupby;
1113 make_facet: function (values) {
1115 category: _t("GroupBy"),
1118 field: this.getParent()._s_groupby
1122 instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
1123 template: 'SearchView.filter',
1125 * Implementation of the OpenERP filters (button with a context and/or
1126 * a domain sent as-is to the search view)
1128 * Filters are only attributes holder, the actual work (compositing
1129 * domains and contexts, converting between facets and filters) is
1130 * performed by the filter group.
1132 * @constructs instance.web.search.Filter
1133 * @extends instance.web.search.Input
1138 init: function (node, view) {
1140 this.load_attrs(node.attrs);
1142 facet_for: function () { return $.when(null); },
1143 get_context: function () { },
1144 get_domain: function () { },
1146 instance.web.search.Field = instance.web.search.Input.extend( /** @lends instance.web.search.Field# */ {
1147 template: 'SearchView.field',
1148 default_operator: '=',
1150 * @constructs instance.web.search.Field
1151 * @extends instance.web.search.Input
1153 * @param view_section
1157 init: function (view_section, field, view) {
1159 this.load_attrs(_.extend({}, field, view_section.attrs));
1161 facet_for: function (value) {
1164 category: this.attrs.string || this.attrs.name,
1165 values: [{label: String(value), value: value}]
1168 value_from: function (facetValue) {
1169 return facetValue.get('value');
1171 get_context: function (facet) {
1173 // A field needs a context to send when active
1174 var context = this.attrs.context;
1175 if (_.isEmpty(context) || !facet.values.length) {
1178 var contexts = facet.values.map(function (facetValue) {
1179 return new instance.web.CompoundContext(context)
1180 .set_eval_context({self: self.value_from(facetValue)});
1183 if (contexts.length === 1) { return contexts[0]; }
1185 return _.extend(new instance.web.CompoundContext, {
1186 __contexts: contexts
1189 get_groupby: function () { },
1191 * Function creating the returned domain for the field, override this
1192 * methods in children if you only need to customize the field's domain
1193 * without more complex alterations or tests (and without the need to
1194 * change override the handling of filter_domain)
1196 * @param {String} name the field's name
1197 * @param {String} operator the field's operator (either attribute-specified or default operator for the field
1198 * @param {Number|String} value parsed value for the field
1199 * @returns {Array<Array>} domain to include in the resulting search
1201 make_domain: function (name, operator, facet) {
1202 return [[name, operator, this.value_from(facet)]];
1204 get_domain: function (facet) {
1205 if (!facet.values.length) { return; }
1207 var value_to_domain;
1209 var domain = this.attrs['filter_domain'];
1211 value_to_domain = function (facetValue) {
1212 return new instance.web.CompoundDomain(domain)
1213 .set_eval_context({self: self.value_from(facetValue)});
1216 value_to_domain = function (facetValue) {
1217 return self.make_domain(
1219 self.attrs.operator || self.default_operator,
1223 var domains = facet.values.map(value_to_domain);
1225 if (domains.length === 1) { return domains[0]; }
1226 for (var i = domains.length; --i;) {
1227 domains.unshift(['|']);
1230 return _.extend(new instance.web.CompoundDomain, {
1236 * Implementation of the ``char`` OpenERP field type:
1238 * * Default operator is ``ilike`` rather than ``=``
1240 * * The Javascript and the HTML values are identical (strings)
1243 * @extends instance.web.search.Field
1245 instance.web.search.CharField = instance.web.search.Field.extend( /** @lends instance.web.search.CharField# */ {
1246 default_operator: 'ilike',
1247 complete: function (value) {
1248 if (_.isEmpty(value)) { return $.when(null); }
1249 var label = _.str.sprintf(_.str.escapeHTML(
1250 _t("Search %(field)s for: %(value)s")), {
1251 field: '<em>' + this.attrs.string + '</em>',
1252 value: '<strong>' + _.str.escapeHTML(value) + '</strong>'});
1256 category: this.attrs.string,
1258 values: [{label: value, value: value}]
1263 instance.web.search.NumberField = instance.web.search.Field.extend(/** @lends instance.web.search.NumberField# */{
1264 value_from: function () {
1265 if (!this.$el.val()) {
1268 var val = this.parse(this.$el.val()),
1269 check = Number(this.$el.val());
1270 if (isNaN(val) || val !== check) {
1271 this.$el.addClass('error');
1272 throw new instance.web.search.Invalid(
1273 this.attrs.name, this.$el.val(), this.error_message);
1275 this.$el.removeClass('error');
1281 * @extends instance.web.search.NumberField
1283 instance.web.search.IntegerField = instance.web.search.NumberField.extend(/** @lends instance.web.search.IntegerField# */{
1284 error_message: _t("not a valid integer"),
1285 parse: function (value) {
1287 return instance.web.parse_value(value, {'widget': 'integer'});
1295 * @extends instance.web.search.NumberField
1297 instance.web.search.FloatField = instance.web.search.NumberField.extend(/** @lends instance.web.search.FloatField# */{
1298 error_message: _t("not a valid number"),
1299 parse: function (value) {
1301 return instance.web.parse_value(value, {'widget': 'float'});
1309 * Utility function for m2o & selection fields taking a selection/name_get pair
1310 * (value, name) and converting it to a Facet descriptor
1312 * @param {instance.web.search.Field} field holder field
1313 * @param {Array} pair pair value to convert
1315 function facet_from(field, pair) {
1318 category: field['attrs'].string,
1319 values: [{label: pair[1], value: pair[0]}]
1325 * @extends instance.web.search.Field
1327 instance.web.search.SelectionField = instance.web.search.Field.extend(/** @lends instance.web.search.SelectionField# */{
1328 // This implementation is a basic <select> field, but it may have to be
1329 // altered to be more in line with the GTK client, which uses a combo box
1330 // (~ jquery.autocomplete):
1331 // * If an option was selected in the list, behave as currently
1332 // * If something which is not in the list was entered (via the text input),
1333 // the default domain should become (`ilike` string_value) but **any
1334 // ``context`` or ``filter_domain`` becomes falsy, idem if ``@operator``
1335 // is specified. So at least get_domain needs to be quite a bit
1336 // overridden (if there's no @value and there is no filter_domain and
1337 // there is no @operator, return [[name, 'ilike', str_val]]
1338 template: 'SearchView.field.selection',
1340 this._super.apply(this, arguments);
1341 // prepend empty option if there is no empty option in the selection list
1342 this.prepend_empty = !_(this.attrs.selection).detect(function (item) {
1346 complete: function (needle) {
1348 var results = _(this.attrs.selection).chain()
1349 .filter(function (sel) {
1350 var value = sel[0], label = sel[1];
1351 if (!value) { return false; }
1352 return label.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
1354 .map(function (sel) {
1357 facet: facet_from(self, sel)
1360 if (_.isEmpty(results)) { return $.when(null); }
1361 return $.when.call(null, [{
1362 label: this.attrs.string
1363 }].concat(results));
1365 facet_for: function (value) {
1366 var match = _(this.attrs.selection).detect(function (sel) {
1367 return sel[0] === value;
1369 if (!match) { return $.when(null); }
1370 return $.when(facet_from(this, match));
1373 instance.web.search.BooleanField = instance.web.search.SelectionField.extend(/** @lends instance.web.search.BooleanField# */{
1375 * @constructs instance.web.search.BooleanField
1376 * @extends instance.web.search.BooleanField
1379 this._super.apply(this, arguments);
1380 this.attrs.selection = [
1388 * @extends instance.web.search.DateField
1390 instance.web.search.DateField = instance.web.search.Field.extend(/** @lends instance.web.search.DateField# */{
1391 value_from: function (facetValue) {
1392 return instance.web.date_to_str(facetValue.get('value'));
1394 complete: function (needle) {
1395 var d = Date.parse(needle);
1396 if (!d) { return $.when(null); }
1397 var date_string = instance.web.format_value(d, this.attrs);
1398 var label = _.str.sprintf(_.str.escapeHTML(
1399 _t("Search %(field)s at: %(value)s")), {
1400 field: '<em>' + this.attrs.string + '</em>',
1401 value: '<strong>' + date_string + '</strong>'});
1405 category: this.attrs.string,
1407 values: [{label: date_string, value: d}]
1413 * Implementation of the ``datetime`` openerp field type:
1415 * * Uses the same widget as the ``date`` field type (a simple date)
1417 * * Builds a slighly more complex, it's a datetime range (includes time)
1418 * spanning the whole day selected by the date widget
1421 * @extends instance.web.DateField
1423 instance.web.search.DateTimeField = instance.web.search.DateField.extend(/** @lends instance.web.search.DateTimeField# */{
1424 value_from: function (facetValue) {
1425 return instance.web.datetime_to_str(facetValue.get('value'));
1428 instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
1429 default_operator: {},
1430 init: function (view_section, field, view) {
1431 this._super(view_section, field, view);
1432 this.model = new instance.web.Model(this.attrs.relation);
1434 complete: function (needle) {
1437 // FIXME: "concurrent" searches (multiple requests, mis-ordered responses)
1438 return this.model.call('name_search', [], {
1442 }).pipe(function (results) {
1443 if (_.isEmpty(results)) { return null; }
1444 return [{label: self.attrs.string}].concat(
1445 _(results).map(function (result) {
1448 facet: facet_from(self, result)
1453 facet_for: function (value) {
1455 if (value instanceof Array) {
1456 if (value.length === 2 && _.isString(value[1])) {
1457 return $.when(facet_from(this, value));
1459 assert(value.length <= 1,
1460 _t("M2O search fields do not currently handle multiple default values"));
1461 // there are many cases of {search_default_$m2ofield: [id]}, need
1462 // to handle this as if it were a single value.
1465 return this.model.call('name_get', [value]).pipe(function (names) {
1466 if (_(names).isEmpty()) { return null; }
1467 return facet_from(self, names[0]);
1470 value_from: function (facetValue) {
1471 return facetValue.get('label');
1473 make_domain: function (name, operator, facetValue) {
1474 if (operator === this.default_operator) {
1475 return [[name, '=', facetValue.get('value')]];
1477 return this._super(name, operator, facetValue);
1479 get_context: function (facet) {
1480 var values = facet.values;
1481 if (_.isEmpty(this.attrs.context) && values.length === 1) {
1483 c['default_' + this.attrs.name] = values.at(0).get('value');
1486 return this._super(facet);
1490 instance.web.search.CustomFilters = instance.web.search.Input.extend({
1491 template: 'SearchView.CustomFilters',
1493 start: function () {
1495 this.model = new instance.web.Model('ir.filters');
1498 .on('remove', function (facet) {
1499 if (!facet.get('is_custom_filter')) {
1502 self.clear_selection();
1504 .on('reset', this.proxy('clear_selection'));
1505 this.$el.on('submit', 'form', this.proxy('save_current'));
1506 this.$el.on('click', 'h4', function () {
1507 self.$el.toggleClass('oe_opened');
1509 // FIXME: local eval of domain and context to get rid of special endpoint
1510 return this.rpc('/web/searchview/get_filters', {
1511 model: this.view.model
1512 }).pipe(this.proxy('set_filters'));
1514 clear_selection: function () {
1515 this.$el.find('li.oe_selected').removeClass('oe_selected');
1517 append_filter: function (filter) {
1519 var key = _.str.sprintf('(%s)%s', filter.user_id, filter.name);
1522 if (key in this.filters) {
1523 $filter = this.filters[key];
1526 $filter = this.filters[key] = $('<li></li>')
1527 .appendTo(this.$el.find('.oe_searchview_custom_list'))
1528 .addClass(filter.user_id ? 'oe_searchview_custom_private'
1529 : 'oe_searchview_custom_public')
1532 $('<a class="oe_searchview_custom_delete">x</a>')
1533 .click(function (e) {
1534 e.stopPropagation();
1535 self.model.call('unlink', [id]).then(function () {
1542 $filter.unbind('click').click(function () {
1543 self.view.query.reset([{
1544 category: _t("Custom Filter"),
1547 get_context: function () { return filter.context; },
1548 get_groupby: function () { return [filter.context]; },
1549 get_domain: function () { return filter.domain; }
1551 is_custom_filter: true,
1552 values: [{label: filter.name, value: null}]
1554 $filter.addClass('oe_selected');
1557 set_filters: function (filters) {
1558 _(filters).map(_.bind(this.append_filter, this));
1560 save_current: function () {
1562 var $name = this.$el.find('input:first');
1563 var private_filter = !this.$el.find('input:last').prop('checked');
1565 var search = this.view.build_search_data();
1566 this.rpc('/web/session/eval_domain_and_context', {
1567 domains: search.domains,
1568 contexts: search.contexts,
1569 group_by_seq: search.groupbys || []
1570 }).then(function (results) {
1571 if (!_.isEmpty(results.group_by)) {
1572 results.context.group_by = results.group_by;
1576 user_id: private_filter ? instance.session.uid : false,
1577 model_id: self.view.model,
1578 context: results.context,
1579 domain: results.domain
1581 // FIXME: current context?
1582 return self.model.call('create_or_replace', [filter]).then(function (id) {
1584 self.append_filter(filter);
1586 .removeClass('oe_opened')
1587 .find('form')[0].reset();
1594 instance.web.search.Filters = instance.web.search.Input.extend({
1595 template: 'SearchView.Filters',
1597 start: function () {
1599 var running_count = 0;
1600 // get total filters count
1601 var is_group = function (i) { return i instanceof instance.web.search.FilterGroup; };
1602 var filters_count = _(this.view.controls).chain()
1605 .map(function (i) { return i.filters.length; })
1609 var col1 = [], col2 = _(this.view.controls).map(function (inputs, group) {
1610 var filters = _(inputs).filter(is_group);
1612 name: group === 'null' ? "<span class='oe_i'>q</span> " + _t("Filters") : "<span class='oe_i'>w</span> " + group,
1614 length: _(filters).chain().map(function (i) {
1615 return i.filters.length; }).sum().value()
1619 while (col2.length) {
1620 // col1 + group should be smaller than col2 + group
1621 if ((running_count + col2[0].length) <= (filters_count - running_count)) {
1622 running_count += col2[0].length;
1623 col1.push(col2.shift());
1630 this.render_column(col1, $('<div>').appendTo(this.$el)),
1631 this.render_column(col2, $('<div>').appendTo(this.$el)));
1633 render_column: function (column, $el) {
1634 return $.when.apply(null, _(column).map(function (group) {
1635 $('<h3>').html(group.name).appendTo($el);
1636 return $.when.apply(null,
1637 _(group.filters).invoke('appendTo', $el));
1642 instance.web.search.Advanced = instance.web.search.Input.extend({
1643 template: 'SearchView.advanced',
1645 start: function () {
1648 .on('keypress keydown keyup', function (e) { e.stopPropagation(); })
1649 .on('click', 'h4', function () {
1650 self.$el.toggleClass('oe_opened');
1651 }).on('click', 'button.oe_add_condition', function () {
1652 self.append_proposition();
1653 }).on('submit', 'form', function (e) {
1655 self.commit_search();
1659 this.rpc("/web/searchview/fields_get", {model: this.view.model}).then(function(data) {
1660 self.fields = _.extend({
1661 id: { string: 'ID', type: 'id' }
1663 })).then(function () {
1664 self.append_proposition();
1667 append_proposition: function () {
1668 return (new instance.web.search.ExtendedSearchProposition(this, this.fields))
1669 .appendTo(this.$el.find('ul'));
1671 commit_search: function () {
1673 // Get domain sections from all propositions
1674 var children = this.getChildren();
1675 var propositions = _.invoke(children, 'get_proposition');
1676 var domain = _(propositions).pluck('value');
1677 for (var i = domain.length; --i;) {
1678 domain.unshift('|');
1681 this.view.query.add({
1682 category: _t("Advanced"),
1683 values: propositions,
1685 get_context: function () { },
1686 get_domain: function () { return domain;},
1687 get_groupby: function () { }
1691 // remove all propositions
1692 _.invoke(children, 'destroy');
1693 // add new empty proposition
1694 this.append_proposition();
1695 // TODO: API on searchview
1696 this.view.$el.removeClass('oe_searchview_open_drawer');
1700 instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @lends instance.web.search.ExtendedSearchProposition# */{
1701 template: 'SearchView.extended_search.proposition',
1703 * @constructs instance.web.search.ExtendedSearchProposition
1704 * @extends instance.web.Widget
1709 init: function (parent, fields) {
1710 this._super(parent);
1711 this.fields = _(fields).chain()
1712 .map(function(val, key) { return _.extend({}, val, {'name': key}); })
1713 .sortBy(function(field) {return field.string;})
1715 this.attrs = {_: _, fields: this.fields, selected: null};
1718 start: function () {
1720 this.$el.find(".searchview_extended_prop_field").change(function() {
1723 this.$el.find('.searchview_extended_delete_prop').click(function () {
1728 changed: function() {
1729 var nval = this.$el.find(".searchview_extended_prop_field").val();
1730 if(this.attrs.selected == null || nval != this.attrs.selected.name) {
1731 this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
1735 * Selects the provided field object
1737 * @param field a field descriptor object (as returned by fields_get, augmented by the field name)
1739 select_field: function(field) {
1741 if(this.attrs.selected != null) {
1742 this.value.destroy();
1744 this.$el.find('.searchview_extended_prop_op').html('');
1746 this.attrs.selected = field;
1751 var type = field.type;
1752 var Field = instance.web.search.custom_filters.get_object(type);
1754 Field = instance.web.search.custom_filters.get_object("char");
1756 this.value = new Field(this, field);
1757 _.each(this.value.operators, function(operator) {
1758 $('<option>', {value: operator.value})
1759 .text(String(operator.text))
1760 .appendTo(self.$el.find('.searchview_extended_prop_op'));
1762 var $value_loc = this.$el.find('.searchview_extended_prop_value').empty();
1763 this.value.appendTo($value_loc);
1766 get_proposition: function() {
1767 if ( this.attrs.selected == null)
1769 var field = this.attrs.selected;
1770 var op = this.$el.find('.searchview_extended_prop_op')[0];
1771 var operator = op.options[op.selectedIndex];
1773 label: _.str.sprintf(_t('%(field)s %(operator)s "%(value)s"'), {
1774 field: field.string,
1775 // According to spec, HTMLOptionElement#label should return
1776 // HTMLOptionElement#text when not defined/empty, but it does
1777 // not in older Webkit (between Safari 5.1.5 and Chrome 17) and
1778 // Gecko (pre Firefox 7) browsers, so we need a manual fallback
1780 operator: operator.label || operator.text,
1781 value: this.value}),
1782 value: [field.name, operator.value, this.value.get_value()]
1787 instance.web.search.ExtendedSearchProposition.Field = instance.web.Widget.extend({
1788 init: function (parent, field) {
1789 this._super(parent);
1793 * Returns a human-readable version of the value, in case the "logical"
1794 * and the "semantic" values of a field differ (as for selection fields,
1797 * The default implementation simply returns the value itself.
1799 * @return {String} human-readable version of the value
1801 toString: function () {
1802 return this.get_value();
1805 instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({
1806 template: 'SearchView.extended_search.proposition.char',
1808 {value: "ilike", text: _lt("contains")},
1809 {value: "not ilike", text: _lt("doesn't contain")},
1810 {value: "=", text: _lt("is equal to")},
1811 {value: "!=", text: _lt("is not equal to")}
1813 get_value: function() {
1814 return this.$el.val();
1817 instance.web.search.ExtendedSearchProposition.DateTime = instance.web.search.ExtendedSearchProposition.Field.extend({
1818 template: 'SearchView.extended_search.proposition.empty',
1820 {value: "=", text: _lt("is equal to")},
1821 {value: "!=", text: _lt("is not equal to")},
1822 {value: ">", text: _lt("greater than")},
1823 {value: "<", text: _lt("less than")},
1824 {value: ">=", text: _lt("greater or equal than")},
1825 {value: "<=", text: _lt("less or equal than")}
1828 * Date widgets live in view_form which is not yet loaded when this is
1831 widget: function () { return instance.web.DateTimeWidget; },
1832 get_value: function() {
1833 return this.datewidget.get_value();
1836 var ready = this._super();
1837 this.datewidget = new (this.widget())(this);
1838 this.datewidget.appendTo(this.$el);
1842 instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.DateTime.extend({
1843 widget: function () { return instance.web.DateWidget; }
1845 instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({
1846 template: 'SearchView.extended_search.proposition.integer',
1848 {value: "=", text: _lt("is equal to")},
1849 {value: "!=", text: _lt("is not equal to")},
1850 {value: ">", text: _lt("greater than")},
1851 {value: "<", text: _lt("less than")},
1852 {value: ">=", text: _lt("greater or equal than")},
1853 {value: "<=", text: _lt("less or equal than")}
1855 toString: function () {
1856 return this.$el.val();
1858 get_value: function() {
1860 return instance.web.parse_value(this.$el.val(), {'widget': 'integer'});
1866 instance.web.search.ExtendedSearchProposition.Id = instance.web.search.ExtendedSearchProposition.Integer.extend({
1867 operators: [{value: "=", text: _lt("is")}]
1869 instance.web.search.ExtendedSearchProposition.Float = instance.web.search.ExtendedSearchProposition.Field.extend({
1870 template: 'SearchView.extended_search.proposition.float',
1872 {value: "=", text: _lt("is equal to")},
1873 {value: "!=", text: _lt("is not equal to")},
1874 {value: ">", text: _lt("greater than")},
1875 {value: "<", text: _lt("less than")},
1876 {value: ">=", text: _lt("greater or equal than")},
1877 {value: "<=", text: _lt("less or equal than")}
1879 toString: function () {
1880 return this.$el.val();
1882 get_value: function() {
1884 return instance.web.parse_value(this.$el.val(), {'widget': 'float'});
1890 instance.web.search.ExtendedSearchProposition.Selection = instance.web.search.ExtendedSearchProposition.Field.extend({
1891 template: 'SearchView.extended_search.proposition.selection',
1893 {value: "=", text: _lt("is")},
1894 {value: "!=", text: _lt("is not")}
1896 toString: function () {
1897 var select = this.$el[0];
1898 var option = select.options[select.selectedIndex];
1899 return option.label || option.text;
1901 get_value: function() {
1902 return this.$el.val();
1905 instance.web.search.ExtendedSearchProposition.Boolean = instance.web.search.ExtendedSearchProposition.Field.extend({
1906 template: 'SearchView.extended_search.proposition.empty',
1908 {value: "=", text: _lt("is true")},
1909 {value: "!=", text: _lt("is false")}
1911 toString: function () { return ''; },
1912 get_value: function() {
1917 instance.web.search.custom_filters = new instance.web.Registry({
1918 'char': 'instance.web.search.ExtendedSearchProposition.Char',
1919 'text': 'instance.web.search.ExtendedSearchProposition.Char',
1920 'one2many': 'instance.web.search.ExtendedSearchProposition.Char',
1921 'many2one': 'instance.web.search.ExtendedSearchProposition.Char',
1922 'many2many': 'instance.web.search.ExtendedSearchProposition.Char',
1924 'datetime': 'instance.web.search.ExtendedSearchProposition.DateTime',
1925 'date': 'instance.web.search.ExtendedSearchProposition.Date',
1926 'integer': 'instance.web.search.ExtendedSearchProposition.Integer',
1927 'float': 'instance.web.search.ExtendedSearchProposition.Float',
1928 'boolean': 'instance.web.search.ExtendedSearchProposition.Boolean',
1929 'selection': 'instance.web.search.ExtendedSearchProposition.Selection',
1931 'id': 'instance.web.search.ExtendedSearchProposition.Id'
1936 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: