diff options
author | Andrew Dolgov <[email protected]> | 2017-07-26 14:15:12 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-07-26 14:15:12 +0300 |
commit | 73b159aa7864a29d2ed13f5b28382b37c649d840 (patch) | |
tree | 1a99f4d9cd92f904cb7dcaad6f6714dc68059b96 /js/index.js | |
parent | d7d4b51384451a978637e147efe10a7cb4164772 (diff) |
confirm removing book from favs
Diffstat (limited to 'js/index.js')
-rw-r--r-- | js/index.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/js/index.js b/js/index.js index 301f619..28e1227 100644 --- a/js/index.js +++ b/js/index.js @@ -18,23 +18,26 @@ function cache_refresh(force) { function toggle_fav(elem) { var bookId = elem.getAttribute("data-book-id"); - $.post("backend.php", {op: "togglefav", id: bookId}, function(data) { - if (data) { - var msg = "[Error]"; + if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) { - if (data.status == 0) { - msg = "Add to favorites"; - } else if (data.status == 1) { - msg = "Remove from favorites"; - } + $.post("backend.php", {op: "togglefav", id: bookId}, function(data) { + if (data) { + var msg = "[Error]"; - $(elem).html(msg); + if (data.status == 0) { + msg = "Add to favorites"; + } else if (data.status == 1) { + msg = "Remove from favorites"; + } - if (index_mode == "favorites" && data.status == 0) { - $("#cell-" + bookId).remove(); + $(elem).html(msg).attr('data-is-fav', data.status); + + if (index_mode == "favorites" && data.status == 0) { + $("#cell-" + bookId).remove(); + } } - } - }); + }); + } return false; } |