3
0
Fork 0

[MIG] web_group_expand: Migration to 15.0

15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
BT-aestebanez 2022-04-22 15:53:55 +02:00
parent 4f6bd75d09
commit 3fa3f971c0
4 changed files with 100 additions and 110 deletions

View File

@ -1,7 +1,7 @@
{
"name": "Group Expand Buttons",
"category": "Web",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "OpenERP SA, "
"AvanzOSC, "
@ -11,6 +11,12 @@
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"qweb": ["static/src/xml/expand_buttons.xml"],
"data": ["views/templates.xml"],
"assets": {
"web.assets_backend": [
"/web_group_expand/static/src/js/web_group_expand.esm.js",
],
"web.assets_qweb": [
"/web_group_expand/static/src/xml/expand_buttons.xml",
],
},
}

View File

@ -0,0 +1,91 @@
/** @odoo-module */
import ListController from "web.ListController";
import ListRenderer from "web.ListRenderer";
import core from "web.core";
const qweb = core.qweb;
ListController.include({
start: function () {
this.$expandGroupButtons = $(qweb.render("web_group_expand.Buttons"));
this.$expandGroupButtons
.find("#oe_group_by_expand")
.on("click", this.expandAllGroups.bind(this));
this.$expandGroupButtons
.find("#oe_group_by_collapse")
.on("click", this.collapseAllGroups.bind(this));
return this._super.apply(this, arguments);
},
renderButtons: function () {
this._super.apply(this, arguments);
this.$expandGroupButtons.toggleClass("o_hidden", !this.renderer.isGrouped);
this.$buttons.append(this.$expandGroupButtons);
},
expandAllGroups: function () {
// We expand layer by layer. So first we need to find the highest
// layer that's not already fully expanded.
let layer = this.renderer.state.data;
while (layer.length) {
const closed = layer.filter(function (group) {
return !group.isOpen;
});
if (closed.length) {
// This layer is not completely expanded, expand it
this._toggleGroups(closed);
break;
}
// This layer is completely expanded, move to the next
layer = _.flatten(
layer.map(function (group) {
return group.data;
}),
true
);
}
},
collapseAllGroups: function () {
// We collapse layer by layer. So first we need to find the deepest
// layer that's not already fully collapsed.
let layer = this.renderer.state.data.filter(function (group) {
return group.isOpen;
});
while (layer.length) {
const next = _.flatten(
layer.map(function (group) {
return group.data;
}),
true
).filter(function (group) {
return group.isOpen;
});
if (!next.length) {
// Next layer is fully collapsed, so collapse this one
this._toggleGroups(layer);
break;
}
layer = next;
}
},
_toggleGroups: function (groups) {
const self = this;
const defs = groups.map(function (group) {
return self.model.toggleGroup(group.id);
});
$.when(...defs).then(
this.update.bind(this, {}, {keepSelection: true, reload: false})
);
},
});
ListRenderer.include({
updateState: function () {
const res = this._super.apply(this, arguments);
$("nav.oe_group_by_expand_buttons").toggleClass("o_hidden", !this.isGrouped);
return res;
},
});

View File

@ -1,92 +0,0 @@
odoo.define("web.web_group_expand", function (require) {
"use strict";
var qweb = require("web.core").qweb;
require("web.ListController").include({
start: function () {
this.$expandGroupButtons = $(qweb.render("web_group_expand.Buttons"));
this.$expandGroupButtons
.find("#oe_group_by_expand")
.on("click", this.expandAllGroups.bind(this));
this.$expandGroupButtons
.find("#oe_group_by_collapse")
.on("click", this.collapseAllGroups.bind(this));
return this._super.apply(this, arguments);
},
renderButtons: function () {
this._super.apply(this, arguments);
this.$expandGroupButtons.toggleClass("o_hidden", !this.renderer.isGrouped);
this.$buttons.append(this.$expandGroupButtons);
},
expandAllGroups: function () {
// We expand layer by layer. So first we need to find the highest
// layer that's not already fully expanded.
var layer = this.renderer.state.data;
while (layer.length) {
var closed = layer.filter(function (group) {
return !group.isOpen;
});
if (closed.length) {
// This layer is not completely expanded, expand it
this._toggleGroups(closed);
break;
}
// This layer is completely expanded, move to the next
layer = _.flatten(
layer.map(function (group) {
return group.data;
}),
true
);
}
},
collapseAllGroups: function () {
// We collapse layer by layer. So first we need to find the deepest
// layer that's not already fully collapsed.
var layer = this.renderer.state.data.filter(function (group) {
return group.isOpen;
});
while (layer.length) {
var next = _.flatten(
layer.map(function (group) {
return group.data;
}),
true
).filter(function (group) {
return group.isOpen;
});
if (!next.length) {
// Next layer is fully collapsed, so collapse this one
this._toggleGroups(layer);
break;
}
layer = next;
}
},
_toggleGroups: function (groups) {
var self = this;
var defs = groups.map(function (group) {
return self.model.toggleGroup(group.id);
});
$.when(...defs).then(
this.update.bind(this, {}, {keepSelection: true, reload: false})
);
},
});
require("web.ListRenderer").include({
updateState: function () {
var res = this._super.apply(this, arguments);
$("nav.oe_group_by_expand_buttons").toggleClass(
"o_hidden",
!this.isGrouped
);
return res;
},
});
});

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="assets_backend"
name="web_groupby_expand assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_group_expand/static/src/js/web_group_expand.js"
/>
</xpath>
</template>
</odoo>