diff --git a/cps/editbooks.py b/cps/editbooks.py index 5f58cf819..f976d7eaa 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -488,6 +488,28 @@ def simulate_merge_list_book(): return json.dumps({'to': to_book, 'from': from_book}) return "" +@editbook.route("/ajax/simulatedeleteselectedbooks", methods=['POST']) +@user_login_required +@edit_required +def simulate_delete_selected_books(): + vals = request.get_json().get('selections') + books = [] + if vals: + for book_id in vals: + books.append(calibre_db.get_book(book_id).title) + return json.dumps({'books': books}) + return "" + +@editbook.route("/ajax/deleteselectedbooks", methods=['POST']) +@user_login_required +@edit_required +def delete_selected_books(): + vals = request.get_json().get('selections') + if vals: + for book_id in vals: + delete_book_from_table(book_id, "", True) + return json.dumps({'success': True}) + return "" @editbook.route("/ajax/mergebooks", methods=['POST']) @user_login_required diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 36361c3ca..1686e5349 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -81,6 +81,14 @@ $(function() { $("#merge_books").addClass("disabled"); $("#merge_books").attr("aria-disabled", true); } + if (selections.length >= 1) { + $("#delete_selected_books").removeClass("disabled"); + $("#delete_selected_books").attr("aria-disabled", false); + } else { + $("#delete_selected_books").addClass("disabled"); + $("#delete_selected_books").attr("aria-disabled", true); + + } if (selections.length < 1) { $("#delete_selection").addClass("disabled"); $("#delete_selection").attr("aria-disabled", true); @@ -135,6 +143,42 @@ $(function() { }); }); + $("#delete_selected_books").click(function(event) { + if ($(this).hasClass("disabled")) { + event.stopPropagation() + } else { + $('#delete_selected_modal').modal("show"); + } + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/simulatedeleteselectedbooks", + data: JSON.stringify({"selections":selections}), + success: function success(booTitles) { + $('#selected-books').empty(); + $.each(booTitles.books, function(i, item) { + $("- " + item + "
").appendTo("#selected-books"); + }); + + } + }); + }); + + $("#delete_selected_confirm").click(function(event) { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/deleteselectedbooks", + data: JSON.stringify({"selections":selections}), + success: function success(booTitles) { + $("#books-table").bootstrapTable("refresh"); + $("#books-table").bootstrapTable("uncheckAll"); + } + }); + }); + $("#table_xchange").click(function() { $.ajax({ method:"post", diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 16836b7b2..12c524842 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -35,6 +35,7 @@