From 6f2925d0cf603af39722374b834cdc9b1cf3c9d3 Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Sun, 31 Dec 2017 19:09:26 -0800 Subject: [PATCH] Fix a bug where a group's card data wasn't updated when a group is deleted --- js/editBookmarks.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/js/editBookmarks.js b/js/editBookmarks.js index 98bf66e..810e771 100644 --- a/js/editBookmarks.js +++ b/js/editBookmarks.js @@ -32,6 +32,13 @@ function groupMoved(dropEvt) { if (g.groupIndex > oldIndex && g.groupIndex <= newIndex) { g.groupIndex--; groupsStore.put(g); + + // modify the group's card + var cardContainer = $("#group-" + (g.groupIndex + 1)); + cardContainer.attr("id", "group" + g.groupIndex); + + var card = $(cardContainer.children()[0]); + card.attr("data-group-index", g.groupIndex); } } } else { // oldIndex > newIndex @@ -39,12 +46,28 @@ function groupMoved(dropEvt) { if (g.groupIndex < oldIndex && g.groupIndex >= newIndex) { g.groupIndex++; groupsStore.put(g); + + // modify the group's card + var cardContainer = $("#group-" + (g.groupIndex - 1)); + cardContainer.attr("id", "group" + g.groupIndex); + + var card = $(cardContainer.children()[0]); + card.attr("data-group-index", g.groupIndex); } } } - groups[oldIndex].groupIndex = newIndex; - groupsStore.put(groups[oldIndex]); + var movedGroupData = groups[oldIndex]; + + movedGroupData.groupIndex = newIndex; + groupsStore.put(movedGroupData); + + // modify the group's card + var cardContainer = $("#group-" + oldIndex); + cardContainer.attr("id", "group" + newIndex); + + var card = $(cardContainer.children()[0]); + card.attr("data-group-index", newIndex); db.close(); }