Better handle removing a bookmark

This commit is contained in:
Neil Brommer 2017-12-29 20:52:32 -08:00
parent a6c5fdb044
commit 7e48ac502a

View file

@ -111,12 +111,11 @@ function bookmarkMoved(dropEvt) {
} }
function deleteBookmark(e) { function deleteBookmark(e) {
var item = $(this); var item = $(this).parent();
var group = item.data("group"); var groupName = item.parent().data("group");
var key = item.data("key"); var groupIndex = item.parent().data("group-index");
var groupIndex = item.data("group-index"); var bookmarkIndex = item.index();
var bookmarkItem = $("#" + groupName + "-" + bookmarkIndex);
var bookmarkItem = $("#" + group + "-" + key);
var openDBRequest = window.indexedDB.open("bookmarks"); var openDBRequest = window.indexedDB.open("bookmarks");
@ -127,13 +126,7 @@ function deleteBookmark(e) {
groupsStore.get(groupIndex).onsuccess = function (getEvt) { groupsStore.get(groupIndex).onsuccess = function (getEvt) {
var groupData = getEvt.target.result; var groupData = getEvt.target.result;
// remove the bookmark from the group object groupData.bookmarks = removeFromArray(groupData.bookmarks, bookmarkIndex);
var bookmarkData = {name: bookmarkItem.data("name"), address: bookmarkItem.data("address")};
groupData.bookmarks = groupData.bookmarks.filter(function (item) {
if (item.name != bookmarkData.name && item.address != bookmarkData.address)
return true;
return false;
});
groupsStore.put(groupData); groupsStore.put(groupData);
bookmarkItem.remove(); bookmarkItem.remove();