diff --git a/front/core/components/treeview/child.html b/front/core/components/treeview/child.html
index 2b3f1e60f..437e7ca7d 100644
--- a/front/core/components/treeview/child.html
+++ b/front/core/components/treeview/child.html
@@ -1,5 +1,5 @@
- -
+
-
-
diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js
index 69cbb4f26..6449ec450 100644
--- a/front/core/components/treeview/index.js
+++ b/front/core/components/treeview/index.js
@@ -74,7 +74,7 @@ export default class Treeview extends Component {
for (let i = 0; i < childs.length; i++) {
childs[i].included = false;
- if ((node.selected || node.included && this.hasCheckedParents(childs[i])) && !childs[i].selected)
+ if (((node.selected || node.included && this.hasCheckedParents(childs[i])) && !childs[i].selected) && !node.excluded)
childs[i].included = true;
this.repaintDesc(childs[i]);
@@ -107,6 +107,13 @@ export default class Treeview extends Component {
}
onSelection(item) {
+ let canBeExcluded = this.hasCheckedChilds(item) || this.hasCheckedParents(item);
+
+ if (!item.selected && item.included && canBeExcluded)
+ item.excluded = true;
+ else
+ item.excluded = false;
+
item.selected = !item.selected;
if (item.selected && item.included)
diff --git a/modules/agency/back/methods/zone-included/toggleIsIncluded.js b/modules/agency/back/methods/zone-included/toggleIsIncluded.js
index dd9e89d28..766c51835 100644
--- a/modules/agency/back/methods/zone-included/toggleIsIncluded.js
+++ b/modules/agency/back/methods/zone-included/toggleIsIncluded.js
@@ -23,13 +23,30 @@ module.exports = Self => {
});
Self.toggleIsIncluded = async(zoneFk, geoFk) => {
+ const models = Self.app.models;
+ const geo = await models.ZoneTreeview.findById(geoFk);
const isIncluded = await Self.findOne({
where: {zoneFk, geoFk}
});
+ const hasCheckedParents = await Self.rawSql(
+ `SELECT id
+ FROM vn.zoneTreeview zt
+ JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id
+ WHERE zt.lft < ? AND zt.rgt > ?`, [geo.lft, geo.rgt]
+ );
+ const hasCheckedChilds = await Self.rawSql(
+ `SELECT id
+ FROM vn.zoneTreeview zt
+ JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id
+ WHERE zt.lft > ? AND zt.rgt < ?`, [geo.lft, geo.rgt]
+ );
+
+ const isExcluded = hasCheckedParents.length || hasCheckedChilds.length;
+
if (isIncluded)
return Self.destroyAll({zoneFk, geoFk});
else
- return Self.upsert({zoneFk, geoFk});
+ return Self.upsert({zoneFk, geoFk, isIncluded: isExcluded});
};
};
diff --git a/modules/agency/back/methods/zone-treeview/getLeaves.js b/modules/agency/back/methods/zone-treeview/getLeaves.js
index 06a878411..08774aa6c 100644
--- a/modules/agency/back/methods/zone-treeview/getLeaves.js
+++ b/modules/agency/back/methods/zone-treeview/getLeaves.js
@@ -78,7 +78,8 @@ module.exports = Self => {
pt.depth,
pt.sons,
ti.id IS NOT NULL hasCheckedChilds,
- zi.geoFk IS NOT NULL AS selected
+ zi.geoFk IS NOT NULL AS selected,
+ zi.isIncluded AS excluded
FROM zoneTreeview pt
LEFT JOIN vn.zoneIncluded zi
ON zi.geoFk = pt.id AND zi.zoneFk = ?
diff --git a/modules/agency/front/summary/index.html b/modules/agency/front/summary/index.html
index 9d4ad04e8..ea565b21b 100644
--- a/modules/agency/front/summary/index.html
+++ b/modules/agency/front/summary/index.html
@@ -1,8 +1,6 @@
+
{{$ctrl.summary.name}}
-
- {{$ctrl.summary.name}}
-