diff --git a/cps/editbooks.py b/cps/editbooks.py index f976d7ea..230b6ec5 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -472,7 +472,6 @@ def get_sorted_entry(field, bookid): return json.dumps({'authors': " & ".join([a.name for a in calibre_db.order_authors([book])])}) return "" - @editbook.route("/ajax/simulatemerge", methods=['POST']) @user_login_required @edit_required @@ -488,10 +487,10 @@ def simulate_merge_list_book(): return json.dumps({'to': to_book, 'from': from_book}) return "" -@editbook.route("/ajax/simulatedeleteselectedbooks", methods=['POST']) +@editbook.route("/ajax/displayselectedbooks", methods=['POST']) @user_login_required @edit_required -def simulate_delete_selected_books(): +def display_selected_books(): vals = request.get_json().get('selections') books = [] if vals: @@ -500,6 +499,21 @@ def simulate_delete_selected_books(): return json.dumps({'books': books}) return "" +@editbook.route("/ajax/archiveselectedbooks", methods=['POST']) +@login_required_if_no_ano +@edit_required +def archive_selected_books(): + vals = request.get_json().get('selections') + state = request.get_json().get('archive') + if vals: + for book_id in vals: + is_archived = change_archived_books(book_id, state, + message="Book {} archive bit set to: {}".format(book_id, state)) + if is_archived: + kobo_sync_status.remove_synced_book(book_id) + return json.dumps({'success': True}) + return "" + @editbook.route("/ajax/deleteselectedbooks", methods=['POST']) @user_login_required @edit_required diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 1686e534..73ebc2f1 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -84,10 +84,21 @@ $(function() { if (selections.length >= 1) { $("#delete_selected_books").removeClass("disabled"); $("#delete_selected_books").attr("aria-disabled", false); + + $("#archive_selected_books").removeClass("disabled"); + $("#archive_selected_books").attr("aria-disabled", false); + + $("#unarchive_selected_books").removeClass("disabled"); + $("#unarchive_selected_books").attr("aria-disabled", false); } else { $("#delete_selected_books").addClass("disabled"); $("#delete_selected_books").attr("aria-disabled", true); + $("#archive_selected_books").addClass("disabled"); + $("#archive_selected_books").attr("aria-disabled", true); + + $("#unarchive_selected_books").addClass("disabled"); + $("#unarchive_selected_books").attr("aria-disabled", true); } if (selections.length < 1) { $("#delete_selection").addClass("disabled"); @@ -143,6 +154,78 @@ $(function() { }); }); + $("#archive_selected_books").click(function(event) { + if ($(this).hasClass("disabled")) { + event.stopPropagation() + } else { + $('#archive_selected_modal').modal("show"); + } + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/displayselectedbooks", + data: JSON.stringify({"selections":selections}), + success: function success(booTitles) { + $('#display-archive-selected-books').empty(); + $.each(booTitles.books, function(i, item) { + $("- " + item + "
").appendTo("#display-archive-selected-books"); + }); + + } + }); + }); + + $("#archive_selected_confirm").click(function(event) { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/archiveselectedbooks", + data: JSON.stringify({"selections":selections, "archive": true}), + success: function success(booTitles) { + $("#books-table").bootstrapTable("refresh"); + $("#books-table").bootstrapTable("uncheckAll"); + } + }); + }); + + $("#unarchive_selected_books").click(function(event) { + if ($(this).hasClass("disabled")) { + event.stopPropagation() + } else { + $('#unarchive_selected_modal').modal("show"); + } + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/displayselectedbooks", + data: JSON.stringify({"selections":selections}), + success: function success(booTitles) { + $('#display-unarchive-selected-books').empty(); + $.each(booTitles.books, function(i, item) { + $("- " + item + "").appendTo("#display-unarchive-selected-books"); + }); + + } + }); + }); + + $("#unarchive_selected_confirm").click(function(event) { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/archiveselectedbooks", + data: JSON.stringify({"selections":selections, "archive": false}), + success: function success(booTitles) { + $("#books-table").bootstrapTable("refresh"); + $("#books-table").bootstrapTable("uncheckAll"); + } + }); + }); + $("#delete_selected_books").click(function(event) { if ($(this).hasClass("disabled")) { event.stopPropagation() @@ -153,12 +236,12 @@ $(function() { method:"post", contentType: "application/json; charset=utf-8", dataType: "json", - url: window.location.pathname + "/../ajax/simulatedeleteselectedbooks", + url: window.location.pathname + "/../ajax/displayselectedbooks", data: JSON.stringify({"selections":selections}), success: function success(booTitles) { - $('#selected-books').empty(); + $('#display-delete-selected-books').empty(); $.each(booTitles.books, function(i, item) { - $("- " + item + "").appendTo("#selected-books"); + $("- " + item + "").appendTo("#display-delete-selected-books"); }); } @@ -895,7 +978,6 @@ function BookCheckboxChange(checkbox, userId, field) { }); } - function selectHeader(element, field) { if (element.value !== "None") { confirmDialog(element.id, "GeneralChangeModal", 0, function () { diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 12c52484..9800cb06 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -36,6 +36,8 @@