diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 7c768d8f09c..14577c9d0ab 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -71,7 +71,10 @@ openerp.base.KeyNotFound = openerp.base.NotFound.extend( * @param {String} key the key which could not be found */ init: function (key) { - self.key = key; + this.key = key; + }, + toString: function () { + return "The key " + this.key + " was not found"; } }); openerp.base.ObjectNotFound = openerp.base.NotFound.extend( @@ -85,7 +88,10 @@ openerp.base.ObjectNotFound = openerp.base.NotFound.extend( * @param {String} path the invalid object path */ init: function (path) { - self.path = path; + this.path = path; + }, + toString: function () { + return "Could not find any object of path " + this.path; } }); openerp.base.Registry = Class.extend( diff --git a/addons/base/static/src/js/search.js b/addons/base/static/src/js/search.js index 52c501bcc77..5d6b175ac88 100644 --- a/addons/base/static/src/js/search.js +++ b/addons/base/static/src/js/search.js @@ -371,7 +371,7 @@ openerp.base.search.ExtendedSearch = openerp.base.BaseWidget.extend({ this._super(parent); this.fields = fields; }, - add_group: function(group) { + add_group: function() { var group = new openerp.base.search.ExtendedSearchGroup(this, this.fields); var render = group.render({}); this.$element.find('.searchview_extended_groups_list').append(render); @@ -382,10 +382,8 @@ openerp.base.search.ExtendedSearch = openerp.base.BaseWidget.extend({ var _this = this; openerp.base.search.add_expand_listener(this.$element); this.add_group(); - this.$element.find('.searchview_extended_add_group').click(function (e) { + this.$element.find('.searchview_extended_add_group').click(function () { _this.add_group(); - e.stopPropagation(); - e.preventDefault(); }); }, get_context: function() { @@ -395,9 +393,8 @@ openerp.base.search.ExtendedSearch = openerp.base.BaseWidget.extend({ if(this.$element.hasClass("folded")) { return null; } - var domain = _.reduce(this.children, - function(mem, x) { return mem.concat(x.get_domain());}, []); - return domain; + return _.reduce(this.children, + function(mem, x) { return mem.concat(x.get_domain());}, []); } }); @@ -418,16 +415,12 @@ openerp.base.search.ExtendedSearchGroup = openerp.base.BaseWidget.extend({ this._super(); var _this = this; this.add_prop(); - this.$element.find('.searchview_extended_add_proposition').click(function (e) { + this.$element.find('.searchview_extended_add_proposition').click(function () { _this.add_prop(); - e.stopPropagation(); - e.preventDefault(); }); var delete_btn = this.$element.find('.searchview_extended_delete_group'); delete_btn.click(function (e) { _this.stop(); - e.stopPropagation(); - e.preventDefault(); }); }, get_domain: function() { @@ -436,30 +429,16 @@ openerp.base.search.ExtendedSearchGroup = openerp.base.BaseWidget.extend({ }).compact().value(); var choice = this.$element.find(".searchview_extended_group_choice").val(); var op = choice == "all" ? "&" : "|"; - var domain = [].concat(choice == "none" ? ['!'] : [], - _.map(_.range(_.max([0,props.length - 1])), function(x) { return op; }), - props); - return domain; + return [].concat(choice == "none" ? ['!'] : [], + _.map(_.range(_.max([0,props.length - 1])), function() { return op; }), + props); } }); -openerp.base.search.extended_filters_types = { - char: { - operators: [ - {value: "ilike", text: "contains"}, - {value: "not like", text: "doesn't contain"}, - {value: "=", text: "is equal to"}, - {value: "!=", text: "is not equal to"}, - {value: ">", text: "greater than"}, - {value: "<", text: "less than"}, - {value: ">=", text: "greater or equal than"}, - {value: "<=", text: "less or equal than"}, - ], - build_component: function(parent) { - return new openerp.base.search.ExtendedSearchProposition.Char(parent); - } - } -}; +openerp.base.search.custom_filters = new openerp.base.Registry({ + 'char': 'openerp.base.search.ExtendedSearchProposition.Char', + 'datetime': 'openerp.base.search.ExtendedSearchProposition.DateTime' +}); openerp.base.search.ExtendedSearchProposition = openerp.base.BaseWidget.extend({ template: 'SearchView.extended_search.proposition', @@ -467,64 +446,72 @@ openerp.base.search.ExtendedSearchProposition = openerp.base.BaseWidget.extend({ init: function (parent, fields) { this._super(parent); this.fields = _(fields).chain() - .map(function(val,key) {return {name:key, obj:val};}) - .sortBy(function(x) {return x.obj.string;}).value(); + .map(function(val, key) { return _.extend({}, val, {'name': key}); }) + .sortBy(function(field) {return field.string;}) + .value(); this.attrs = {_: _, fields: this.fields, selected: null}; - this.value_component = null; + this.value = null; }, start: function () { this._super(); - this.set_selected(this.fields.length > 0 ? this.fields[0] : null); + this.select_field(this.fields.length > 0 ? this.fields[0] : null); var _this = this; - this.$element.find(".searchview_extended_prop_field").change(function(e) { + this.$element.find(".searchview_extended_prop_field").change(function() { _this.changed(); - e.stopPropagation(); - e.preventDefault(); }); var delete_btn = this.$element.find('.searchview_extended_delete_prop'); - delete_btn.click(function (e) { + delete_btn.click(function () { _this.stop(); - e.stopPropagation(); - e.preventDefault(); }); }, changed: function() { var nval = this.$element.find(".searchview_extended_prop_field").val(); if(this.attrs.selected == null || nval != this.attrs.selected.name) { - this.set_selected(_.detect(this.fields, function(x) {return x.name == nval;})); + this.select_field(_.detect(this.fields, function(x) {return x.name == nval;})); } }, - set_selected: function(selected) { + /** + * Selects the provided field object + * + * @param field a field descriptor object (as returned by fields_get, augmented by the field name) + */ + select_field: function(field) { var _this = this; if(this.attrs.selected != null) { - this.value_component.stop(); - this.value_component = null; + this.value.stop(); + this.value = null; this.$element.find('.searchview_extended_prop_op').html(''); } - this.attrs.selected = selected; - if(selected == null) { + this.attrs.selected = field; + if(field == null) { return; } - var type = selected.obj.type; - var extended_filters_types = openerp.base.search.extended_filters_types; - type = type in extended_filters_types ? type : "char"; - _.each(extended_filters_types[type].operators, function(operator) { - var option = jQuery('