3
0
Fork 0

[IMP] web_widget_domain_editor_dialog: black, isort, prettier

14.0
Carlos Roca 2020-09-25 11:47:16 +02:00 committed by hkapatel
parent 889892cd8c
commit ce7ab5f9f0
4 changed files with 62 additions and 64 deletions

View File

@ -1,19 +1,14 @@
# Copyright 2019 Tecnativa - David Vidal # Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'Web Widget Domain Editor Dialog', "name": "Web Widget Domain Editor Dialog",
'summary': 'Recovers the Domain Editor Dialog functionality', "summary": "Recovers the Domain Editor Dialog functionality",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'category': 'Web', "category": "Web",
'author': 'Tecnativa,' "author": "Tecnativa," "Odoo Community Association (OCA)",
'Odoo Community Association (OCA)', "website": "https://github.com/OCA/web",
'website': 'https://github.com/OCA/web', "license": "AGPL-3",
'license': 'AGPL-3', "depends": ["web"],
'depends': [ "data": ["views/templates.xml"],
'web', "installable": True,
],
'data': [
'views/templates.xml',
],
'installable': True,
} }

View File

@ -1,41 +1,40 @@
/* Copyright 2019 Tecnativa - David Vidal /* Copyright 2019 Tecnativa - David Vidal
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_widget_domain_editor_dialog.basic_fields", function (require) { odoo.define("web_widget_domain_editor_dialog.basic_fields", function(require) {
"use strict"; "use strict";
var core = require("web.core"); var core = require("web.core");
var basic_fields = require("web.basic_fields"); var basic_fields = require("web.basic_fields");
var DomainEditorDialog = require( var DomainEditorDialog = require("web_widget_domain_editor_dialog.DomainEditorDialog");
"web_widget_domain_editor_dialog.DomainEditorDialog");
var _t = core._t; var _t = core._t;
basic_fields.FieldDomain.include({ basic_fields.FieldDomain.include({
_onShowSelectionButtonClick: function (event) { _onShowSelectionButtonClick: function(event) {
event.preventDefault(); event.preventDefault();
var _this = this; var _this = this;
if (this.mode === 'readonly') { if (this.mode === "readonly") {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
} }
var dialog = new DomainEditorDialog(this, { var dialog = new DomainEditorDialog(this, {
title: _t('Select records...'), title: _t("Select records..."),
res_model: this._domainModel, res_model: this._domainModel,
default_domain: this.value, default_domain: this.value,
readonly: false, readonly: false,
disable_multiple_selection: false, disable_multiple_selection: false,
no_create: true, no_create: true,
on_selected: function (selected_ids) { on_selected: function(selected_ids) {
_this.domainSelector _this.domainSelector
.setDomain(this.get_domain(selected_ids)) .setDomain(this.get_domain(selected_ids))
.then(_this._replaceContent.bind(_this)); .then(_this._replaceContent.bind(_this));
_this.trigger_up( _this.trigger_up("domain_changed", {
'domain_changed', child: _this,
{child: _this, alreadyRedrawn: true}); alreadyRedrawn: true,
});
}, },
}).open(); }).open();
this.trigger("dialog_opened", dialog); this.trigger("dialog_opened", dialog);
return dialog; return dialog;
}, },
}); });
}); });

View File

@ -1,30 +1,30 @@
/* Copyright 2019 Tecnativa - David Vidal /* Copyright 2019 Tecnativa - David Vidal
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function (require) { odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function(require) {
"use strict"; "use strict";
var core = require("web.core"); var core = require("web.core");
var view_dialogs = require('web.view_dialogs'); var view_dialogs = require("web.view_dialogs");
var SearchView = require('web.SearchView'); var SearchView = require("web.SearchView");
var _t = core._t; var _t = core._t;
var DomainEditorDialog = view_dialogs.SelectCreateDialog.extend({ var DomainEditorDialog = view_dialogs.SelectCreateDialog.extend({
init: function () { init: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
var _this = this; var _this = this;
this.options = _.defaults(this.options, { this.options = _.defaults(this.options, {
initial_facet: { initial_facet: {
category: _t("Custom Filter"), category: _t("Custom Filter"),
icon: 'fa-circle', icon: "fa-circle",
field: { field: {
get_context: function () { get_context: function() {
return _this.options.context; return _this.options.context;
}, },
get_groupby: function () { get_groupby: function() {
return []; return [];
}, },
get_domain: function () { get_domain: function() {
return _this.options.default_domain; return _this.options.default_domain;
}, },
}, },
@ -33,11 +33,10 @@ odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function (requ
}); });
}, },
start: function () { start: function() {
var search_view = _.find( var search_view = _.find(this.getChildren(), function(x) {
this.getChildren(), function (x) { return x instanceof SearchView;
return x instanceof SearchView; });
});
if (this.options.initial_facet && search_view) { if (this.options.initial_facet && search_view) {
search_view.query.reset([this.options.initial_facet], { search_view.query.reset([this.options.initial_facet], {
preventSearch: true, preventSearch: true,
@ -47,36 +46,37 @@ odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function (requ
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
get_domain: function (selected_ids) { get_domain: function(selected_ids) {
var group_domain = []; var group_domain = [];
var search_data = this.list_controller.renderer.state; var search_data = this.list_controller.renderer.state;
var domain = search_data.domain; var domain = search_data.domain;
if (this.$('.o_list_record_selector input').prop('checked')) { if (this.$(".o_list_record_selector input").prop("checked")) {
if (search_data.groupedBy.length) { if (search_data.groupedBy.length) {
group_domain = _.filter( group_domain = _.filter(search_data.data, function(x) {
search_data.data, function (x) { return x.res_ids.length;
return x.res_ids.length; }).map(function(x) {
}) return x.domain;
.map(function (x) { });
return x.domain;
});
group_domain = _.flatten(group_domain, true); group_domain = _.flatten(group_domain, true);
// Compute domain difference // Compute domain difference
_.each(domain, function (d) { _.each(domain, function(d) {
group_domain = _.without( group_domain = _.without(
group_domain, _.filter(group_domain, function (x) { group_domain,
_.filter(group_domain, function(x) {
return _.isEqual(x, d); return _.isEqual(x, d);
})[0]); })[0]
);
}); });
// Strip operators to leave just the group domains // Strip operators to leave just the group domains
group_domain = _.without(group_domain, "&"); group_domain = _.without(group_domain, "&");
// Add OR operators if there is more than one group // Add OR operators if there is more than one group
group_domain = _.times( group_domain = _.times(
group_domain.length - 1, group_domain.length - 1,
_.constant('|')).concat(group_domain); _.constant("|")
).concat(group_domain);
} }
} else { } else {
var ids = selected_ids.map(function (x) { var ids = selected_ids.map(function(x) {
return x.id; return x.id;
}); });
domain = domain.concat([["id", "in", ids]]); domain = domain.concat([["id", "in", ids]]);
@ -84,13 +84,13 @@ odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function (requ
return domain.concat(group_domain); return domain.concat(group_domain);
}, },
on_view_list_loaded: function () { on_view_list_loaded: function() {
this.$('.o_list_record_selector input').prop('checked', true); this.$(".o_list_record_selector input").prop("checked", true);
this.$footer.find(".o_selectcreatepopup_search_select") this.$footer
.prop('disabled', false); .find(".o_selectcreatepopup_search_select")
.prop("disabled", false);
}, },
}); });
return DomainEditorDialog; return DomainEditorDialog;
}); });

View File

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<odoo> <odoo>
<template id="assets_backend" inherit_id="web.assets_backend"> <template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js"/> <script
<script type="text/javascript" src="/web_widget_domain_editor_dialog/static/src/js/basic_fields.js"/> type="text/javascript"
src="/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js"
/>
<script
type="text/javascript"
src="/web_widget_domain_editor_dialog/static/src/js/basic_fields.js"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>