From e090b19ddae2d5c5ba68d775c12234f4b7b5217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poincelet?= Date: Fri, 6 Dec 2024 11:03:43 +0100 Subject: [PATCH] fix several issues about drag n drop and saving after d'n'd --- index.html | 4 ++-- js/mviewerstudio.js | 12 +++++------- lib/mv.js | 11 ++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 320a39bd..0ae6f9f2 100755 --- a/index.html +++ b/index.html @@ -1087,7 +1087,7 @@ diff --git a/js/mviewerstudio.js b/js/mviewerstudio.js index e0b3a0bc..1ad20610 100644 --- a/js/mviewerstudio.js +++ b/js/mviewerstudio.js @@ -390,7 +390,7 @@ var addLayer = function (title, layerid, themeid, groupid) {
- +
`); return item; @@ -425,8 +425,7 @@ var editLayer = function (item, themeid, layerid) { if (!layerid) { layerid = element.attr("data-layerid"); } - var groupid = element.attr("data-groupid"); - mv.setCurrentGroupId(groupid); + var groupid = mv.getCurrentGroupId(); if (layerid != "undefined") { $("#mod-layerOptions").modal("show"); @@ -552,9 +551,8 @@ function initializeNestedSortables() { const toThemeId = evt.to.closest(".themes-list-item")?.id; const toGroupId = evt.to.closest(".group-item")?.id ? evt.to.closest(".group-item").id - : null; + : "undefined"; const newIndex = evt.newIndex; - item.setAttribute("data-groupid", toGroupId); item.setAttribute("data-themeid", toThemeId); @@ -572,7 +570,7 @@ function initializeNestedSortables() { if (!config.themes[fromThemeId].layers) config.themes[fromThemeId].layers = []; // Si le groupe d'arrivé n'a pas de layers, on set group.layers à [] - if (toGroupId) + if (toGroupId !== "undefined") if ( !config.themes[toThemeId].groups.find((group) => group.id === toGroupId) .layers @@ -585,7 +583,7 @@ function initializeNestedSortables() { .find((group) => group.id === fromGroupId) .layers.splice(index, 1) : config.themes[fromThemeId].layers.splice(index, 1); - toGroupId + toGroupId !== "undefined" ? config.themes[toThemeId].groups .find((group) => group.id === toGroupId) .layers.splice(newIndex, 0, itemToMove) diff --git a/lib/mv.js b/lib/mv.js index 3c68bae4..f6ba6ff4 100755 --- a/lib/mv.js +++ b/lib/mv.js @@ -80,7 +80,7 @@ var mv = (function () { var _currentThemeId = ""; var _currentLayerId = ""; - var _currentGroupId = ""; + var _currentGroupId = "undefined"; var _newTheme = false; var _userInfo = { @@ -117,7 +117,9 @@ var mv = (function () { return _currentLayerId; }, - setCurrentGroupId: (groupId) => { + setCurrentGroupId: (btn) => { + const parent = $(btn).closest(".layer_item"); + const groupId = parent ? $(parent).attr("data-groupid") : "undefined"; _currentGroupId = groupId; }, @@ -689,7 +691,7 @@ var mv = (function () { } }, - showLayerOptions: function (el, themeid, layerid, groupid) { + showLayerOptions: function (el, themeid, layerid) { // Init params display [...document.querySelectorAll("#mod-layerOptions .layerOption-wms")].forEach((e) => e.classList.add("d-none") @@ -714,6 +716,7 @@ var mv = (function () { function getLayerbyId(l) { return l.id === layerid; } + const groupid = el.attr("data-groupid") || "undefined"; var layer = groupid === "undefined" ? config.themes[themeid].layers.find(getLayerbyId) @@ -896,6 +899,8 @@ var mv = (function () { var layerid = mv.getCurrentLayerId(); const themeid = mv.getCurrentThemeId(); const groupid = mv.getCurrentGroupId(); + console.log({ groupid }); + function getLayerbyId(l) { return l.id === layerid; }