From 777c9d3eea4d125acbff6c483af3df470bbd4739 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 26 May 2015 15:33:30 +0200 Subject: [PATCH] [ADD] support selecting domains on x2x fields --- .../src/css/web_advanced_search_x2x.css | 24 +++ .../static/src/js/web_advanced_search_x2x.js | 192 +++++++++++++++++- .../src/xml/web_advanced_search_x2x.xml | 3 + 3 files changed, 213 insertions(+), 6 deletions(-) diff --git a/web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.css b/web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.css index 71ecad25..a2585b83 100644 --- a/web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.css +++ b/web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.css @@ -2,3 +2,27 @@ { position: relative; } +/* copy search view's button style */ +.openerp .oe_searchview_drawer .web_advanced_search_x2x_search:before +{ + font: 21px "mnmliconsRegular"; + content: "r"; + color: #a3a3a3; +} +.openerp .oe_searchview_drawer .web_advanced_search_x2x_search +{ + font-size: 1px; + letter-spacing: -1px; + color: transparent; + text-shadow: none; + font-weight: normal; + -moz-box-shadow: none; + -webkit-box-shadow: none; + box-shadow: none; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + padding: 0; + border: none; + background: transparent; +} diff --git a/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js b/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js index 37a5d2f2..7d42bd04 100644 --- a/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js +++ b/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js @@ -43,6 +43,9 @@ openerp.web_advanced_search_x2x = function(instance) return 0; } }); + this.operators.push({ + 'value': 'domain', 'text': instance.web._lt('is in selection'), + }); return this._super.apply(this, arguments); }, start: function() @@ -77,22 +80,40 @@ openerp.web_advanced_search_x2x = function(instance) }, operator_changed: function(e) { + if(this.searchfield) + { + this.searchfield.destroy(); + } this.renderElement(); if(this.show_searchfield()) { this.create_searchfield().appendTo(this.$el.empty()); } + if(this.show_domain_selection()) + { + this.$el.filter('input').remove(); + this.$el.filter('button.web_advanced_search_x2x_search').click( + this.proxy(this.popup_domain_selection)); + this.popup_domain_selection(); + } }, - show_searchfield: function() + get_operator: function() { if(this.isDestroyed()) { return false; } - var operator = this.getParent().$('.searchview_extended_prop_op') - .val(); + return this.getParent().$('.searchview_extended_prop_op').val(); + }, + show_searchfield: function() + { + var operator = this.get_operator() return operator == '=' || operator == '!='; }, + show_domain_selection: function() + { + return this.get_operator() == 'domain'; + }, get_value: function() { if(this.show_searchfield() && this.searchfield) @@ -103,22 +124,70 @@ openerp.web_advanced_search_x2x = function(instance) }, format_label: function(format, field, operator) { + var value = null; if(this.show_searchfield() && this.searchfield) + { + value = this.searchfield.display_value[ + String(this.searchfield.get_value())]; + } + if(this.show_domain_selection() && this.domain_representation) + { + value = this.domain_representation; + } + if(value) { return _.str.sprintf( format, { field: field.string, operator: operator.label || operator.text, - value: this.searchfield.display_value[ - String(this.searchfield.get_value())], - + value: value, } ); } return this._super.apply(this, arguments); }, + get_domain: function() + { + if(this.show_domain_selection() && this.domain) + { + var self = this; + return _.extend(new instance.web.CompoundDomain(), { + __domains: [ + _.map(this.domain, function(leaf) + { + if(_.isArray(leaf) && leaf.length == 3) + { + return [ + self.field.name + '.' + leaf[0], + leaf[1], + leaf[2] + ] + } + return leaf; + }), + ], + }) + } + return this._super.apply(this, arguments); + }, + popup_domain_selection: function() + { + var self = this, + popup = new instance.web_advanced_search_x2x.SelectCreatePopup(this); + popup.on('domain_selected', this, function(domain, domain_representation) + { + self.$el.filter('.web_advanced_search_x2x_domain').text( + domain_representation); + self.domain = domain; + self.domain_representation = domain_representation; + }); + popup.select_element( + this.field.relation, {}, this.field.domain, + this.field.context); + }, }); + instance.web.search.custom_filters.add( 'one2many', 'instance.web_advanced_search_x2x.ExtendedSearchPropositionMany2One'); @@ -128,4 +197,115 @@ openerp.web_advanced_search_x2x = function(instance) instance.web.search.custom_filters.add( 'many2one', 'instance.web_advanced_search_x2x.ExtendedSearchPropositionMany2One'); + + instance.web_advanced_search_x2x.SelectCreatePopup = instance.web.form.SelectCreatePopup.extend({ + setup_search_view: function() + { + var self = this; + this._super.apply(this, arguments); + this.searchview.on("search_view_loaded", this, function() + { + self.view_list.on("list_view_loaded", self, function() + { + self.$buttonpane.find(".oe_selectcreatepopup-search-create").remove(); + self.$buttonpane.prepend( + jQuery(' +