web_advanced_search_x2x module

This commit is contained in:
cubells
2017-02-14 15:11:51 +01:00
committed by Pedro M. Baeza
parent 26e660c3ba
commit a1ff073d9f
5 changed files with 57 additions and 166 deletions

View File

@@ -19,11 +19,18 @@
//
//############################################################################
openerp.web_advanced_search_x2x = function(instance)
{
instance.web_advanced_search_x2x.ExtendedSearchPropositionMany2One =
instance.web.search.ExtendedSearchProposition.Char.extend(
instance.web.form.FieldManagerMixin,
odoo.define('web_advanced_search_x2x.search_filters', function (require) {
"use strict";
var filters = require('web.search_filters');
var form_common = require('web.form_common');
var SearchView = require('web.SearchView');
var data = require('web.data');
var session = require('web.session');
var core = require('web.core');
var searchfilters = filters.ExtendedSearchProposition.Char.extend(
form_common.FieldManagerMixin,
{
template: 'web_advanced_search_x2x.extended_search.proposition.many2one',
searchfield: null,
@@ -44,7 +51,7 @@ openerp.web_advanced_search_x2x = function(instance)
}
});
this.operators.push({
'value': 'domain', 'text': instance.web._lt('is in selection'),
'value': 'domain', 'text': data._lt('is in selection'),
});
return this._super.apply(this, arguments);
},
@@ -74,7 +81,7 @@ openerp.web_advanced_search_x2x = function(instance)
{
this.searchfield.destroy();
}
this.searchfield = new instance.web.form.FieldMany2One(
this.searchfield = new form_common.FieldMany2One(
this, this.create_searchfield_node());
return this.searchfield;
},
@@ -154,11 +161,11 @@ openerp.web_advanced_search_x2x = function(instance)
var self = this;
if(!this.domain || this.domain.length == 0)
{
throw new instance.web.search.Invalid(
throw new filters.Invalid(
this.field.string, this.domain_representation,
instance.web._lt('invalid search domain'));
data._lt('invalid search domain'));
}
return _.extend(new instance.web.CompoundDomain(), {
return _.extend(new data.CompoundDomain(), {
__domains: [
_.map(this.domain, function(leaf)
{
@@ -180,7 +187,7 @@ openerp.web_advanced_search_x2x = function(instance)
popup_domain_selection: function()
{
var self = this,
popup = new instance.web_advanced_search_x2x.SelectCreatePopup(this);
popup = new form_common.SelectCreatePopup(this);
popup.on('domain_selected', this, function(domain, domain_representation)
{
self.$el.filter('.web_advanced_search_x2x_domain').text(
@@ -190,100 +197,13 @@ openerp.web_advanced_search_x2x = function(instance)
});
popup.select_element(
this.field.relation, {}, this.field.domain,
new instance.web.CompoundContext(
instance.session.user_context, this.field.context));
new data.CompoundContext(
session.user_context, this.field.context));
},
});
instance.web.search.custom_filters.add(
'one2many',
'instance.web_advanced_search_x2x.ExtendedSearchPropositionMany2One');
instance.web.search.custom_filters.add(
'many2many',
'instance.web_advanced_search_x2x.ExtendedSearchPropositionMany2One');
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('<button/>')
.addClass('oe_highlight')
.addClass('oe_selectcreatepopup-search-select-domain')
.text(instance.web._lt('Use criteria'))
.click(self.proxy(self.select_domain))
);
self.$buttonpane.find('.oe_selectcreatepopup-search-select-domain')
.prop('disabled', self.searchview.build_search_data().domains.length == 0);
self.$buttonpane.find(".oe_selectcreatepopup-search-select")
.unbind('click')
.click(function()
{
self.select_elements(self.selected_ids)
.then(function()
{
self.destroy();
});
});
self.view_list.select_record = function(index)
{
self.select_elements([self.view_list.dataset.ids[index]])
.then(function()
{
self.destroy();
});
};
});
});
},
select_domain: function()
{
var self = this,
search = this.searchview.build_search_data();
instance.web.pyeval.eval_domains_and_contexts({
domains: search.domains,
contexts: search.contexts,
groupbys: search.groupbys || []
}).then(function(search)
{
var representation = self.searchview.query.reduce(function(memo, term)
{
return _.str.sprintf(
'%s%s(%s: %s)', memo, (memo ? ' ' : ''),
term.attributes.category,
_.reduce(term.get('values'), function(memo, value)
{
return memo + (memo ? ', ' : '') + value.label;
}, ''));
}, '');
self.trigger('domain_selected', search.domain, representation);
self.destroy();
})
},
select_elements: function(ids)
{
var self = this;
return this.dataset.name_get(ids).then(function(name_gets)
{
var names = _.reduce(name_gets, function(memo, name_get)
{
return memo + (memo ? ', ' : '') + name_get[1];
}, '');
self.trigger('domain_selected', [['id', 'in', ids]], names);
});
},
});
instance.web.SearchView.include({
SearchView.include({
build_search_data: function()
{
//Advanced.commit_search can only cope with propositions
@@ -300,7 +220,7 @@ openerp.web_advanced_search_x2x = function(instance)
var compound_domains = [], leaves = [];
_.each(domain, function(leaf)
{
if(leaf instanceof instance.web.CompoundDomain)
if(leaf instanceof data.CompoundDomain)
{
compound_domains.push(leaf);
}
@@ -311,7 +231,7 @@ openerp.web_advanced_search_x2x = function(instance)
});
if(compound_domains.length)
{
var combined = new instance.web.CompoundDomain();
var combined = new data.CompoundDomain();
_.each(compound_domains, function(domain)
{
combined.add(domain.eval());
@@ -326,5 +246,4 @@ openerp.web_advanced_search_x2x = function(instance)
return result;
},
})
}
});