Browse Source

[FIX] Compatibilize web_widget_domain_v11 with web_advanced_search_x2x

pull/672/head
Jairo Llopis 7 years ago
committed by Pedro M. Baeza
parent
commit
2cc0d8d52f
  1. 4
      web_advanced_search_x2x/__manifest__.py
  2. 14
      web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.less
  3. 70
      web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js
  4. 9
      web_advanced_search_x2x/static/src/xml/web_advanced_search_x2x.xml
  5. 13
      web_widget_domain_v11/README.rst
  6. 1
      web_widget_domain_v11/__manifest__.py
  7. BIN
      web_widget_domain_v11/static/description/icon.png
  8. 1
      web_widget_domain_v11/static/src/copied-js/model_field_selector.js
  9. 11
      web_widget_domain_v11/static/src/js/domain_field.js
  10. 19
      web_widget_domain_v11/views/ir_filters.xml

4
web_advanced_search_x2x/__manifest__.py

@ -5,7 +5,7 @@
{
"name": "Search x2x fields",
"version": "10.0.1.0.0",
"version": "10.0.2.0.0",
"author": "Therp BV, "
"Tecnativa, "
"Odoo Community Association (OCA)",
@ -13,7 +13,7 @@
"category": "Usability",
"summary": "Use a search widget in advanced search for x2x fields",
"depends": [
'web',
'web_widget_domain_v11',
],
"data": [
'views/templates.xml',

14
web_advanced_search_x2x/static/src/css/web_advanced_search_x2x.less

@ -1,7 +1,9 @@
.openerp {
.oe-search-options {
.searchview_extended_prop_value {
.oe_form {
.o_search_options {
.o_filters_menu {
.o_filter_condition {
max-width: inherit;
.o_searchview_extended_prop_value {
.ui-autocomplete-input {
.form-control();
}
@ -10,6 +12,10 @@
top: 6px;
right: 2px;
}
.o_form_field_domain {
min-width: 400px;
}
}
}
}

70
web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js

@ -15,8 +15,8 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
var X2XAdvancedSearchPropositionMixin = {
template: "web_advanced_search_x2x.proposition",
init: function()
{
init: function () {
// Make equal and not equal appear 1st and 2nd
this.operators = _.sortBy(
this.operators,
@ -38,28 +38,35 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
});
return this._super.apply(this, arguments);
},
get_field_desc: function()
{
return this.field;
},
/**
* Add the right relational field to the template.
* Add x2x widget after rendering.
*/
renderElement: function () {
try {
this._x2x_field.destroy();
} catch (error) {}
this.relational = this.x2x_widget_name();
this._super.apply(this, arguments);
if (this.relational) {
renderElement: function() {
var result = this._super.apply(this, arguments);
if (this.x2x_widget_name()) {
this.x2x_field().appendTo(this.$el);
this._x2x_field.$el.on(
"autocompleteopen",
this.proxy('x2x_autocomplete_open')
);
}
delete this.relational;
return result;
},
/**
* Re-render widget when operator changes.
*/
show_inputs: function () {
this.renderElement();
return this._super.apply(this, arguments);
},
/**
* Create a relational field for the user.
*
@ -77,12 +84,13 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
this.x2x_field_create_options()
);
this._x2x_field.on(
"change:value",
"domain_selected",
this,
this.proxy("x2x_value_changed")
);
return this._x2x_field;
},
x2x_field_create_options: function () {
return {
attrs: {
@ -95,6 +103,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
},
};
},
x2x_value_changed: function () {
switch (this.x2x_widget_name()) {
case "char_domain":
@ -103,10 +112,18 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
break;
}
},
x2x_widget: function () {
var name = this.x2x_widget_name();
return name && core.form_widget_registry.get(name);
},
/**
* Return the widget that should be used to render this proposition.
*
* If it returns `undefined`, it means you should use a simple
* `<input type="text"/>`.
*/
x2x_widget_name: function () {
switch (this.get_operator()) {
case "=":
@ -116,6 +133,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
return "char_domain";
}
},
x2x_autocomplete_open: function()
{
var widget = this._x2x_field.$input.autocomplete("widget");
@ -123,6 +141,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
event.stopPropagation();
});
},
get_domain: function () {
// Special way to get domain if user chose "domain" filter
if (this.get_operator() == "domain") {
@ -141,10 +160,12 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
return this._super.apply(this, arguments);
}
},
get_operator: function () {
return !this.isDestroyed() &&
this.getParent().$('.o_searchview_extended_prop_op').val();
},
get_value: function () {
try {
return this._x2x_field.get_value();
@ -152,6 +173,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
return this._super.apply(this, arguments);
}
},
format_label: function (format, field, operator) {
if (this.x2x_widget()) {
var value = String(this._x2x_field.get_value());
@ -180,30 +202,6 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
X2XAdvancedSearchPropositionMixin
);
ExtendedSearchProposition.include({
/**
* Force re-rendering the value widget if needed.
*/
operator_changed: function (event) {
if (this.value instanceof X2XAdvancedSearchProposition) {
this.value_rerender();
}
return this._super.apply(this, arguments);
},
/**
* Re-render proposition's value widget.
*
* @return {jQuery.Deferred}
*/
value_rerender: function () {
this.value._x2x_field && this.value._x2x_field.destroy();
delete this.value._x2x_field;
return this.value.appendTo(
this.$(".o_searchview_extended_prop_value").show().empty()
);
},
});
// Register this search proposition for relational fields
$.each(affected_types, function (index, value) {
core.search_filters_registry.add(value, X2XAdvancedSearchProposition);

9
web_advanced_search_x2x/static/src/xml/web_advanced_search_x2x.xml

@ -3,12 +3,11 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<templates>
<t t-name="web_advanced_search_x2x.proposition">
<t t-if="widget.relational">
<!-- This wrapper fixes CSS styiling -->
<div class="oe_form"/>
<t t-if="widget.x2x_widget_name()">
<div class="x2x_container"/>
</t>
<t t-if="!widget.relational">
<t t-call="SearchView.extended_search.proposition" />
<t t-if="!widget.x2x_widget_name()">
<input type="text"/>
</t>
</t>
</templates>

13
web_widget_domain_v11/README.rst

@ -14,9 +14,14 @@ Usage
To use this module, you need to:
#. Install any addon that makes use of the domain widget (i.e.
``mass_mailing``).
#. You will be able to use the updated version.
#. Enable the developer mode.
#· Go to *Settings > Technical > User interface > User-defined Filters* and
choose or create one.
#. Choose a model if there is none.
#. You will be able to choose the domain using the updated domain widget.
Install any addon that makes use of the domain widget (i.e. ``mass_mailing``)
and you will be also able to use the new widget there.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
@ -26,7 +31,7 @@ Known issues / Roadmap
======================
* This addon replaces the built-in ``char_domain`` widget, so it can break
compatibility with other addons that use it.
compatibility with other addons that use or extend it.
Bug Tracker
===========

1
web_widget_domain_v11/__manifest__.py

@ -16,6 +16,7 @@
],
"data": [
"templates/assets.xml",
"views/ir_filters.xml",
],
"qweb": [
"static/src/copied-xml/templates.xml",

BIN
web_widget_domain_v11/static/description/icon.png

Before

Width: 128  |  Height: 128  |  Size: 9.2 KiB

After

Width: 390  |  Height: 390  |  Size: 24 KiB

1
web_widget_domain_v11/static/src/copied-js/model_field_selector.js

@ -28,6 +28,7 @@ var ModelFieldSelector = Widget.extend({
this.goToNextPage(this._getLastPageField($(e.currentTarget).data("name")));
},
"click li.o_field_selector_select_button": function (e) {
e.stopPropagation();
this.selectField(this._getLastPageField($(e.currentTarget).data("name")));
},

11
web_widget_domain_v11/static/src/js/domain_field.js

@ -49,9 +49,6 @@ var FieldDomain = common.AbstractField.extend(common.ReinitializeFieldMixin).ext
model: undefined, // this option is mandatory !
fs_filters: {}, // Field selector filters (to only show a subset of available fields @see FieldSelector)
});
if (this.options.model_field && !this.options.model) {
this.options.model = this.options.model_field;
}
},
start: function() {
this.model = _get_model.call(this); // TODO get the model another way ?
@ -66,10 +63,12 @@ var FieldDomain = common.AbstractField.extend(common.ReinitializeFieldMixin).ext
return this._super.apply(this, arguments);
function _get_model() {
if (this.field_manager.fields[this.options.model]) {
return this.field_manager.get_field_value(this.options.model);
if (this.options.model) {
return this.options.model;
}
if (this.field_manager.fields[this.options.model_field]) {
return this.field_manager.get_field_value(this.options.model_field);
}
return this.options.model;
}
},
initialize_content: function () {

19
web_widget_domain_v11/views/ir_filters.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<record id="ir_filters_view_form" model="ir.ui.view">
<field name="name">Use domain widget</field>
<field name="model">ir.filters</field>
<field name="inherit_id" ref="base.ir_filters_view_form"/>
<field name="arch" type="xml">
<field name="domain" position="attributes">
<attribute name="widget">char_domain</attribute>
<attribute name="options">{'model_field': 'model_id'}</attribute>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save