mirror of https://github.com/OCA/web.git
[IMP] web_group_expand: black, isort
parent
ce88ab6418
commit
c7225dbe71
|
@ -8,13 +8,7 @@
|
||||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
||||||
"Therp BV, "
|
"Therp BV, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"depends": [
|
"depends": ["web",],
|
||||||
"web",
|
"qweb": ["static/src/xml/expand_buttons.xml",],
|
||||||
],
|
"data": ["views/templates.xml",],
|
||||||
"qweb": [
|
|
||||||
"static/src/xml/expand_buttons.xml",
|
|
||||||
],
|
|
||||||
"data": [
|
|
||||||
"views/templates.xml",
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ odoo.define("web.web_group_expand", function(require) {
|
||||||
require("web.ListController").include({
|
require("web.ListController").include({
|
||||||
start: function() {
|
start: function() {
|
||||||
this.$expandGroupButtons = $(qweb.render("web_group_expand.Buttons"));
|
this.$expandGroupButtons = $(qweb.render("web_group_expand.Buttons"));
|
||||||
this.$expandGroupButtons.find("#oe_group_by_expand").on(
|
this.$expandGroupButtons
|
||||||
"click", this.expandAllGroups.bind(this)
|
.find("#oe_group_by_expand")
|
||||||
);
|
.on("click", this.expandAllGroups.bind(this));
|
||||||
this.$expandGroupButtons.find("#oe_group_by_collapse").on(
|
this.$expandGroupButtons
|
||||||
"click", this.collapseAllGroups.bind(this)
|
.find("#oe_group_by_collapse")
|
||||||
);
|
.on("click", this.collapseAllGroups.bind(this));
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -26,25 +26,39 @@ odoo.define("web.web_group_expand", function(require) {
|
||||||
// layer that's not already fully expanded.
|
// layer that's not already fully expanded.
|
||||||
var layer = this.renderer.state.data;
|
var layer = this.renderer.state.data;
|
||||||
while (layer.length) {
|
while (layer.length) {
|
||||||
var closed = layer.filter(function (group) {return !group.isOpen;});
|
var closed = layer.filter(function(group) {
|
||||||
|
return !group.isOpen;
|
||||||
|
});
|
||||||
if (closed.length) {
|
if (closed.length) {
|
||||||
// This layer is not completely expanded, expand it
|
// This layer is not completely expanded, expand it
|
||||||
this._toggleGroups(closed);
|
this._toggleGroups(closed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// This layer is completely expanded, move to the next
|
// This layer is completely expanded, move to the next
|
||||||
layer = _.flatten(layer.map(function (group) {return group.data;}), true);
|
layer = _.flatten(
|
||||||
|
layer.map(function(group) {
|
||||||
|
return group.data;
|
||||||
|
}),
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
collapseAllGroups: function() {
|
collapseAllGroups: function() {
|
||||||
// We collapse layer by layer. So first we need to find the deepest
|
// We collapse layer by layer. So first we need to find the deepest
|
||||||
// layer that's not already fully collapsed.
|
// layer that's not already fully collapsed.
|
||||||
var layer = this.renderer.state.data
|
var layer = this.renderer.state.data.filter(function(group) {
|
||||||
.filter(function (group) {return group.isOpen;});
|
return group.isOpen;
|
||||||
|
});
|
||||||
while (layer.length) {
|
while (layer.length) {
|
||||||
var next = _.flatten(layer.map(function (group) {return group.data;}), true)
|
var next = _.flatten(
|
||||||
.filter(function (group) {return group.isOpen;});
|
layer.map(function(group) {
|
||||||
|
return group.data;
|
||||||
|
}),
|
||||||
|
true
|
||||||
|
).filter(function(group) {
|
||||||
|
return group.isOpen;
|
||||||
|
});
|
||||||
if (!next.length) {
|
if (!next.length) {
|
||||||
// Next layer is fully collapsed, so collapse this one
|
// Next layer is fully collapsed, so collapse this one
|
||||||
this._toggleGroups(layer);
|
this._toggleGroups(layer);
|
||||||
|
@ -59,14 +73,19 @@ odoo.define("web.web_group_expand", function(require) {
|
||||||
var defs = groups.map(function(group) {
|
var defs = groups.map(function(group) {
|
||||||
return self.model.toggleGroup(group.id);
|
return self.model.toggleGroup(group.id);
|
||||||
});
|
});
|
||||||
$.when(...defs).then(this.update.bind(this, {}, {keepSelection: true, reload: false}));
|
$.when(...defs).then(
|
||||||
}
|
this.update.bind(this, {}, {keepSelection: true, reload: false})
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
require("web.ListRenderer").include({
|
require("web.ListRenderer").include({
|
||||||
updateState: function() {
|
updateState: function() {
|
||||||
var res = this._super.apply(this, arguments);
|
var res = this._super.apply(this, arguments);
|
||||||
$("nav.oe_group_by_expand_buttons").toggleClass("o_hidden", !this.isGrouped);
|
$("nav.oe_group_by_expand_buttons").toggleClass(
|
||||||
|
"o_hidden",
|
||||||
|
!this.isGrouped
|
||||||
|
);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,14 +2,18 @@
|
||||||
<templates>
|
<templates>
|
||||||
<t t-name="web_group_expand.Buttons">
|
<t t-name="web_group_expand.Buttons">
|
||||||
<nav class="btn-group oe_group_by_expand_buttons o_hidden">
|
<nav class="btn-group oe_group_by_expand_buttons o_hidden">
|
||||||
<button class="btn btn-secondary fa fa-expand"
|
<button
|
||||||
|
class="btn btn-secondary fa fa-expand"
|
||||||
id="oe_group_by_expand"
|
id="oe_group_by_expand"
|
||||||
title="Expand groups"
|
title="Expand groups"
|
||||||
type="button" />
|
type="button"
|
||||||
<button class="btn btn-secondary fa fa-compress"
|
/>
|
||||||
|
<button
|
||||||
|
class="btn btn-secondary fa fa-compress"
|
||||||
id="oe_group_by_collapse"
|
id="oe_group_by_collapse"
|
||||||
title="Collapse groups"
|
title="Collapse groups"
|
||||||
type="button" />
|
type="button"
|
||||||
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
</t>
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<template id="assets_backend" name="web_groupby_expand assets" inherit_id="web.assets_backend">
|
<template
|
||||||
|
id="assets_backend"
|
||||||
|
name="web_groupby_expand assets"
|
||||||
|
inherit_id="web.assets_backend"
|
||||||
|
>
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_group_expand/static/src/js/web_group_expand.js"></script>
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_group_expand/static/src/js/web_group_expand.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue