Skip to content

Commit

Permalink
fix several issues about drag n drop and saving after d'n'd
Browse files Browse the repository at this point in the history
  • Loading branch information
LPoin committed Dec 6, 2024
1 parent acb1bd8 commit e090b19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ <h5 class="modal-title" i18n="modal.file.import">Ouvrir un projet existant</h5>
<div class="modal-header align-items-center">
<h5 class="modal-title" i18n="modal.layer.edit">Paramètres de la donnée</h5>
<span id="layerTypeLabel"></span>
<button type="button" onclick="mv.setCurrentThemeId('')" class="close" data-bs-toggle="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<button type="button" onclick="mv.setCurrentThemeId(''), mv.setCurrentGroupId('')" class="close" data-bs-toggle="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<ul class="nav nav-pills mb-3" id="layer_sections_menu" role="tablist">
Expand Down Expand Up @@ -1648,7 +1648,7 @@ <h2 class="accordion-header" >
<div class="modal-footer">
<button type="button" onclick="mv.form2xml()" data-bs-target="#mod-codeview" data-bs-toggle="modal" class="btn btn-outline-info advanced" i18n="view" style="display: none;">Voir</button>
<button type="button" onclick="mv.saveLayerOptions(), mv.setCurrentThemeId(''), mv.setCurrentGroupId('')" data-bs-toggle="modal" class="btn btn-primary" i18n="save">Enregistrer</button>
<button type="button" onclick="mv.setCurrentThemeId('')" class="btn btn-outline-primary" data-bs-toggle="modal" i18n="close">Fermer</button>
<button type="button" onclick="mv.setCurrentThemeId(''), mv.setCurrentGroupId('')" class="btn btn-outline-primary" data-bs-toggle="modal" i18n="close">Fermer</button>
</div>
</div>
</div>
Expand Down
12 changes: 5 additions & 7 deletions js/mviewerstudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ var addLayer = function (title, layerid, themeid, groupid) {
<div class="layer-options-btn" style="display:inline-flex; justify-content: end;">
<button class="btn btn-sm btn-secondary" onclick={mv.setCurrentThemeId("${themeid}");}><span class="layer-move moveList" i18n="move" title="Déplacer"><i class="bi bi-arrows-move"></i></span></button>
<button class="btn btn-sm btn-secondary deleteLayerButton" onclick="deleteLayerItem(this, '${themeid}');"><span class="layer-remove" i18n="delete" title="Supprimer"><i class="bi bi-x-circle"></i></span></button>
<button class="btn btn-sm btn-info" onclick="editLayer(this, '${themeid}', '${layerid}', '${groupid}'), mv.setCurrentGroupId('${groupid}');"><span class="layer-edit" i18n="edit_layer" title="Editer cette couche"><i class="bi bi-gear-fill"></i></span></button>
<button class="btn btn-sm btn-info" onclick="mv.setCurrentGroupId(this), editLayer(this, '${themeid}', '${layerid}');"><span class="layer-edit" i18n="edit_layer" title="Editer cette couche"><i class="bi bi-gear-fill"></i></span></button>
</div>
</div>`);
return item;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var mv = (function () {

var _currentThemeId = "";
var _currentLayerId = "";
var _currentGroupId = "";
var _currentGroupId = "undefined";
var _newTheme = false;

var _userInfo = {
Expand Down Expand Up @@ -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;
},

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e090b19

Please sign in to comment.