mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[IMP] web_widget_child_selector: black, isort, prettier
This commit is contained in:
committed by
Olga Marco
parent
bed16c9842
commit
361db88329
@@ -1,28 +1,37 @@
|
||||
odoo.define('web.web_widget_child_selector', function(require) {
|
||||
odoo.define("web.web_widget_child_selector", function(require) {
|
||||
"use strict";
|
||||
|
||||
var relational_fields = require('web.relational_fields');
|
||||
var field_registry = require('web.field_registry');
|
||||
var core = require('web.core');
|
||||
var relational_fields = require("web.relational_fields");
|
||||
var field_registry = require("web.field_registry");
|
||||
var core = require("web.core");
|
||||
var qweb = core.qweb;
|
||||
var FieldMany2One = relational_fields.FieldMany2One;
|
||||
|
||||
var FieldChildSelector = FieldMany2One.extend({
|
||||
template: "FieldChildSelector",
|
||||
events: _.extend({}, FieldMany2One.prototype.events, {
|
||||
'click .o_child_selection_button': '_onChildSelectionClick',
|
||||
"click .o_child_selection_button": "_onChildSelectionClick",
|
||||
}),
|
||||
start: function () {
|
||||
this.$input_dropdown = this.$('.o_input_dropdown');
|
||||
this.$input_value = this.$('.o_input_value')
|
||||
start: function() {
|
||||
this.$input_dropdown = this.$(".o_input_dropdown");
|
||||
this.$input_value = this.$(".o_input_value");
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
_renderReadonly: function () {
|
||||
var value = _.escape((this.m2o_value || "").trim()).split("\n").join("<br/>");
|
||||
_renderReadonly: function() {
|
||||
var value = _.escape((this.m2o_value || "").trim())
|
||||
.split("\n")
|
||||
.join("<br/>");
|
||||
this.$el.html(value);
|
||||
if (!this.nodeOptions.no_open && this.value) {
|
||||
this.$el.attr('href', _.str.sprintf('#id=%s&model=%s', this.value.res_id, this.field.relation));
|
||||
this.$el.addClass('o_form_uri');
|
||||
this.$el.attr(
|
||||
"href",
|
||||
_.str.sprintf(
|
||||
"#id=%s&model=%s",
|
||||
this.value.res_id,
|
||||
this.field.relation
|
||||
)
|
||||
);
|
||||
this.$el.addClass("o_form_uri");
|
||||
}
|
||||
},
|
||||
_set_childs: function() {
|
||||
@@ -32,42 +41,43 @@ odoo.define('web.web_widget_child_selector', function(require) {
|
||||
this.$input_dropdown.empty();
|
||||
this.$input_value.empty();
|
||||
var resources = [];
|
||||
if (this.value.res_id)
|
||||
resources = [this.value.res_id]
|
||||
if (this.value.res_id) resources = [this.value.res_id];
|
||||
this._rpc({
|
||||
model: this.field.relation,
|
||||
method: 'get_record_direct_childs_parents',
|
||||
method: "get_record_direct_childs_parents",
|
||||
args: [
|
||||
resources,
|
||||
this.nodeOptions,
|
||||
this.record.getDomain({fieldName: this.name}),
|
||||
],
|
||||
context: this.record.getContext(this.recordParams),
|
||||
})
|
||||
.then(function (data) {
|
||||
_.each(data['parents'], function(parent, key) {
|
||||
}).then(function(data) {
|
||||
_.each(data.parents, function(parent, key) {
|
||||
self.parents[key] = parent;
|
||||
});
|
||||
_.each(data['childs'], function(child, key) {
|
||||
_.each(data.childs, function(child, key) {
|
||||
self.childs[key] = child;
|
||||
});
|
||||
self.$input_dropdown.append(qweb.render('FieldChildSelectorChild', {
|
||||
'childs': self.childs,
|
||||
}));
|
||||
self.$input_value.append(qweb.render('FieldChildSelectorParent', {
|
||||
'parents': self.parents,
|
||||
}));
|
||||
self.$input_dropdown.append(
|
||||
qweb.render("FieldChildSelectorChild", {
|
||||
childs: self.childs,
|
||||
})
|
||||
);
|
||||
self.$input_value.append(
|
||||
qweb.render("FieldChildSelectorParent", {
|
||||
parents: self.parents,
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
_onChildSelectionClick: function(event) {
|
||||
var target = $(event.target);
|
||||
var type = target.data('type');
|
||||
if (type === 'clear') {
|
||||
var type = target.data("type");
|
||||
if (type === "clear") {
|
||||
this._setValue({id: false});
|
||||
}
|
||||
else {
|
||||
var index = target.data('index');
|
||||
var value = (type === 'child') ? this.childs[index]: this.parents[index];
|
||||
} else {
|
||||
var index = target.data("index");
|
||||
var value = type === "child" ? this.childs[index] : this.parents[index];
|
||||
this._setValue({id: value[0], display_name: value[1]});
|
||||
}
|
||||
},
|
||||
@@ -76,6 +86,6 @@ odoo.define('web.web_widget_child_selector', function(require) {
|
||||
},
|
||||
});
|
||||
|
||||
field_registry.add('child_selector', FieldChildSelector);
|
||||
field_registry.add("child_selector", FieldChildSelector);
|
||||
return FieldChildSelector;
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
.o_child_selection_button {
|
||||
cursor: pointer,
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.o_child_selection_label {
|
||||
cursor: pointer,
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.o_child_selection_clear {
|
||||
|
||||
@@ -1,25 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="FieldChildSelector">
|
||||
|
||||
<!--<div class="o_element"/>-->
|
||||
<t t-if="widget.mode === 'readonly'">
|
||||
<a t-if="!widget.nodeOptions.no_open" t-att-tabindex="widget.attrs.tabindex" class="o_form_uri" href="#"/>
|
||||
<span t-if="widget.nodeOptions.no_open"/>
|
||||
<a
|
||||
t-if="!widget.nodeOptions.no_open"
|
||||
t-att-tabindex="widget.attrs.tabindex"
|
||||
class="o_form_uri"
|
||||
href="#"
|
||||
/>
|
||||
<span t-if="widget.nodeOptions.no_open" />
|
||||
</t>
|
||||
<div t-if="widget.mode === 'edit'" class="o_field_widget">
|
||||
<span class="o_input_value"/>
|
||||
<div class="o_input_dropdown"/>
|
||||
<span class="o_input_value" />
|
||||
<div class="o_input_dropdown" />
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="FieldChildSelectorChild">
|
||||
<div class="row">
|
||||
<div t-foreach="childs" t-as="key" class="col-xl-12">
|
||||
<t t-set="id_for_label" t-value="'o_child_hierarchy_selector_' + _.uniqueId()"/>
|
||||
<input type="radio" t-att-data-id="childs[key][0]" t-att-data-index="key"
|
||||
t-att-id="id_for_label" data-type="child" class="o_child_selection_button"/>
|
||||
<label class="o_form_label o_child_selection_label" t-att-for="id_for_label">
|
||||
<t t-esc="childs[key][1]"/>
|
||||
<t
|
||||
t-set="id_for_label"
|
||||
t-value="'o_child_hierarchy_selector_' + _.uniqueId()"
|
||||
/>
|
||||
<input
|
||||
type="radio"
|
||||
t-att-data-id="childs[key][0]"
|
||||
t-att-data-index="key"
|
||||
t-att-id="id_for_label"
|
||||
data-type="child"
|
||||
class="o_child_selection_button"
|
||||
/>
|
||||
<label
|
||||
class="o_form_label o_child_selection_label"
|
||||
t-att-for="id_for_label"
|
||||
>
|
||||
<t t-esc="childs[key][1]" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -28,13 +45,21 @@
|
||||
<span>
|
||||
<t t-foreach="parents" t-as="key">
|
||||
<t t-if="key > 0"> / </t>
|
||||
<a t-att-data-id="parents[key][0]" t-att-data-index="key"
|
||||
data-type="parent" class="o_child_selection_button">
|
||||
<t t-esc="parents[key][1]"/>
|
||||
<a
|
||||
t-att-data-id="parents[key][0]"
|
||||
t-att-data-index="key"
|
||||
data-type="parent"
|
||||
class="o_child_selection_button"
|
||||
>
|
||||
<t t-esc="parents[key][1]" />
|
||||
</a>
|
||||
</t>
|
||||
<t t-if="Object.keys(parents).length > 0">
|
||||
<i class="fa fa-times o_child_selection_button o_child_selection_clear" aria-hidden="false" data-type="clear"/>
|
||||
<i
|
||||
class="fa fa-times o_child_selection_button o_child_selection_clear"
|
||||
aria-hidden="false"
|
||||
data-type="clear"
|
||||
/>
|
||||
</t>
|
||||
</span>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user