Fix a bug where a group's card data wasn't updated when a group is deleted

This commit is contained in:
Neil Brommer 2017-12-31 19:09:26 -08:00
parent 11b99d8289
commit 6f2925d0cf

View file

@ -32,6 +32,13 @@ function groupMoved(dropEvt) {
if (g.groupIndex > oldIndex && g.groupIndex <= newIndex) { if (g.groupIndex > oldIndex && g.groupIndex <= newIndex) {
g.groupIndex--; g.groupIndex--;
groupsStore.put(g); 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 } else { // oldIndex > newIndex
@ -39,12 +46,28 @@ function groupMoved(dropEvt) {
if (g.groupIndex < oldIndex && g.groupIndex >= newIndex) { if (g.groupIndex < oldIndex && g.groupIndex >= newIndex) {
g.groupIndex++; g.groupIndex++;
groupsStore.put(g); 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; var movedGroupData = groups[oldIndex];
groupsStore.put(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(); db.close();
} }