[IMP] web_widget_domain_editor_dialog: black, isort, prettier

pull/1698/head
Carlos Roca 2020-09-25 11:47:16 +02:00
parent 827f717083
commit 8b039ff3bb
4 changed files with 62 additions and 64 deletions

View File

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

View File

@ -1,41 +1,40 @@
/* 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";
var core = require("web.core");
var basic_fields = require("web.basic_fields");
var DomainEditorDialog = require(
"web_widget_domain_editor_dialog.DomainEditorDialog");
var DomainEditorDialog = require("web_widget_domain_editor_dialog.DomainEditorDialog");
var _t = core._t;
basic_fields.FieldDomain.include({
_onShowSelectionButtonClick: function (event) {
_onShowSelectionButtonClick: function(event) {
event.preventDefault();
var _this = this;
if (this.mode === 'readonly') {
if (this.mode === "readonly") {
return this._super.apply(this, arguments);
}
var dialog = new DomainEditorDialog(this, {
title: _t('Select records...'),
title: _t("Select records..."),
res_model: this._domainModel,
default_domain: this.value,
readonly: false,
disable_multiple_selection: false,
no_create: true,
on_selected: function (selected_ids) {
on_selected: function(selected_ids) {
_this.domainSelector
.setDomain(this.get_domain(selected_ids))
.then(_this._replaceContent.bind(_this));
_this.trigger_up(
'domain_changed',
{child: _this, alreadyRedrawn: true});
_this.trigger_up("domain_changed", {
child: _this,
alreadyRedrawn: true,
});
},
}).open();
this.trigger("dialog_opened", dialog);
return dialog;
},
});
});

View File

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

View File

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script 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"/>
<script
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>
</template>
</odoo>