Skip to content

Commit

Permalink
[IMP] web_advanced_search. Restore 'in selection' operator
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 committed Sep 22, 2021
1 parent 70fc6b5 commit e594010
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
4 changes: 4 additions & 0 deletions web_advanced_search/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
* `DynApps NV <https://www.dynapps.be>`_:

* Raf Ven

* `Therp BV <https://therp.nl>`_:

* Ronald Portier
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
odoo.define("web_advanced_search.AdvancedSelectDialog", function (require) {
"use strict";

const { _lt, _t } = require("web.core");
const Context = require("web.Context");
const dialogs = require("web.view_dialogs");

const AdvancedSelectDialog = dialogs.SelectCreateDialog.extend({
/**
* prepare buttons for dialog footer based on options
*
* Fully overide funtion to just show Select and Use Criteria.
*
* @private
*/
_prepareButtons: function () {
this.__buttons = [
{
text: _t("Select"),
classes: "btn-primary o_select_button",
disabled: true,
close: true,
click: function () {
const records = this.viewController.getSelectedRecords();
const ids = records.map(record => record.res_id);
const names = records.map(record => record.data.display_name);
this.trigger_up(
"domain_selected",
{ domain: [['id', 'in', ids]], names: names }
);
},
},
{
text: _t("Use criteria"),
classes: "btn-primary",
// TODO: get somehow the criteria selected...
click: this.create_edit_record.bind(this)
},
{
text: _t("Cancel"),
classes: "btn-secondary o_form_button_cancel",
close: true,
},
];
},
});

return {
AdvancedSelectDialog: AdvancedSelectDialog
};
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
odoo.define("web_advanced_search.CustomFilterItem", function (require) {
"use strict";

const { _lt, _t } = require("web.core");
const dialogs = require("web_advanced_search.AdvancedSelectDialog");
const CustomFilterItem = require("web.CustomFilterItem");
const FieldMany2One = require("web.relational_fields").FieldMany2One;
const Relational = require("web_advanced_search.RelationalOwl");
Expand All @@ -16,6 +18,9 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) {
this.state.field = false;
this.OPERATORS.relational = this.OPERATORS.char;
this.FIELD_TYPES.many2one = "relational";
this.OPERATORS.relational.push(
{ symbol: "domain", description: _lt("is in selection") }
);
useListener("m2xchange", this._onM2xDataChanged);
}

Expand Down Expand Up @@ -61,6 +66,9 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) {
this.trigger("operatorChange");
this.state.operator = ev.target[ev.target.selectedIndex].value;
super._onOperatorSelect(...arguments);
if (this.state.operator === "domain") {
this.action_open_list_view();
}
}
_onM2xDataChanged(event) {
const fieldindex = this.fields
Expand All @@ -77,7 +85,7 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) {
}
}
_onApply() {
/* Patch onApply to add displayedValue to discriptionArray */
/* Patch onApply to add displayedValue to descriptionArray */
const preFilters = this.state.conditions.map((condition) => {
const field = this.fields[condition.field];
const type = this.FIELD_TYPES[field.type];
Expand Down Expand Up @@ -129,6 +137,40 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) {
this.state.conditions = [];
this._addDefaultCondition();
}
async action_open_list_view() {
const model = this.state.field.relation;
const options = {
viewType: 'tree',
res_model: model,
initial_view: "search",
on_close: () => this.trigger('reload'),
no_create: true,
};
const select_dialog = new dialogs.AdvancedSelectDialog(this, options);
select_dialog.on("domain_selected", this, function (e) {
const domain = e.data.domain;
domain[0][0] = this.state.field.name;
const preFilter = {
description: e.data.names.join(),
domain: Domain.prototype.arrayToString(e.data.domain),
type: "filter",
};
this.model.dispatch("createNewFilters", [preFilter]);
});
return select_dialog.open();
}
/**
* Mocks _trigger_up to redirect Odoo legacy events to OWL events.
*
* @private
* @param {OdooEvent} ev
*/
_trigger_up(ev) {
const evType = ev.name;
const payload = ev.data;
payload.__targetWidget = ev.target;
this.trigger(evType.replace(/_/g, "-"), payload);
}
}

return AdvancedCustomFilterItem;
Expand Down
7 changes: 6 additions & 1 deletion web_advanced_search/views/templates.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2017-2018 Jairo Llopis <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_advanced_search/static/src/js/control_panel/advanced_filter_item.js"
/>
<script
type="text/javascript"
src="/web_advanced_search/static/src/js/control_panel/advanced_select_dialog.js"
/>
<script
type="text/javascript"
src="/web_advanced_search/static/src/js/control_panel/filter_menu.js"
Expand Down

0 comments on commit e594010

Please sign in to comment.