diff --git a/cps/editbooks.py b/cps/editbooks.py index 230b6ec5..45cec33f 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -525,6 +525,27 @@ def delete_selected_books(): return json.dumps({'success': True}) return "" +@editbook.route("/ajax/readselectedbooks", methods=['POST']) +@user_login_required +@edit_required +def read_selected_books(): + vals = request.get_json().get('selections') + markAsRead = request.get_json().get('markAsRead') + if vals: + try: + for book_id in vals: + ret = helper.edit_book_read_status(book_id, markAsRead) + + except (OperationalError, IntegrityError, StaleDataError) as e: + calibre_db.session.rollback() + log.error_or_exception("Database error: {}".format(e)) + ret = Response(json.dumps({'success': False, + 'msg': 'Database error: {}'.format(e.orig if hasattr(e, "orig") else e)}), + mimetype='application/json') + + return json.dumps({'success': True}) + return "" + @editbook.route("/ajax/mergebooks", methods=['POST']) @user_login_required @edit_required diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 73ebc2f1..24a1c685 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -90,6 +90,12 @@ $(function() { $("#unarchive_selected_books").removeClass("disabled"); $("#unarchive_selected_books").attr("aria-disabled", false); + + $("#read_selected_books").removeClass("disabled"); + $("#read_selected_books").attr("aria-disabled", false); + + $("#unread_selected_books").removeClass("disabled"); + $("#unread_selected_books").attr("aria-disabled", false); } else { $("#delete_selected_books").addClass("disabled"); $("#delete_selected_books").attr("aria-disabled", true); @@ -99,6 +105,12 @@ $(function() { $("#unarchive_selected_books").addClass("disabled"); $("#unarchive_selected_books").attr("aria-disabled", true); + + $("#read_selected_books").addClass("disabled"); + $("#read_selected_books").attr("aria-disabled", true); + + $("#unread_selected_books").addClass("disabled"); + $("#unread_selected_books").attr("aria-disabled", true); } if (selections.length < 1) { $("#delete_selection").addClass("disabled"); @@ -154,7 +166,7 @@ $(function() { }); }); - $("#archive_selected_books").click(function(event) { + $(document).on('click', '#archive_selected_books', function(event) { if ($(this).hasClass("disabled")) { event.stopPropagation() } else { @@ -176,7 +188,7 @@ $(function() { }); }); - $("#archive_selected_confirm").click(function(event) { + $(document).on('click', '#archive_selected_confirm', function(event) { $.ajax({ method:"post", contentType: "application/json; charset=utf-8", @@ -190,7 +202,7 @@ $(function() { }); }); - $("#unarchive_selected_books").click(function(event) { + $(document).on('click', '#unarchive_selected_books', function(event) { if ($(this).hasClass("disabled")) { event.stopPropagation() } else { @@ -212,7 +224,7 @@ $(function() { }); }); - $("#unarchive_selected_confirm").click(function(event) { + $(document).on('click', '#unarchive_selected_confirm', function(event) { $.ajax({ method:"post", contentType: "application/json; charset=utf-8", @@ -226,7 +238,7 @@ $(function() { }); }); - $("#delete_selected_books").click(function(event) { + $(document).on('click', '#delete_selected_books', function(event) { if ($(this).hasClass("disabled")) { event.stopPropagation() } else { @@ -248,7 +260,7 @@ $(function() { }); }); - $("#delete_selected_confirm").click(function(event) { + $(document).on('click', '#delete_selected_confirm', function(event) { $.ajax({ method:"post", contentType: "application/json; charset=utf-8", @@ -262,6 +274,78 @@ $(function() { }); }); + $(document).on('click', '#read_selected_books', function(event) { + if ($(this).hasClass("disabled")) { + event.stopPropagation() + } else { + $('#read_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-read-selected-books').empty(); + $.each(booTitles.books, function(i, item) { + $("- " + item + "

").appendTo("#display-read-selected-books"); + }); + + } + }); + }); + + $(document).on('click', '#read_selected_confirm', function(event) { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/readselectedbooks", + data: JSON.stringify({"selections":selections, "markAsRead": true}), + success: function success(booTitles) { + $("#books-table").bootstrapTable("refresh"); + $("#books-table").bootstrapTable("uncheckAll"); + } + }); + }); + + $(document).on('click', '#unread_selected_books', function(event) { + if ($(this).hasClass("disabled")) { + event.stopPropagation() + } else { + $('#unread_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-unread-selected-books').empty(); + $.each(booTitles.books, function(i, item) { + $("- " + item + "

").appendTo("#display-unread-selected-books"); + }); + + } + }); + }); + + $(document).on('click', '#unread_selected_confirm', function(event) { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../ajax/readselectedbooks", + data: JSON.stringify({"selections":selections, "markAsRead": false}), + 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 61bdced1..396a812d 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -15,14 +15,26 @@ {%- endmacro %} {% macro book_checkbox_row(parameter, show_text, sort) -%} - - {% if parameter == "is_archived"%} -
{{_('Archive selected books')}}
+ {% if parameter == "is_archived" %} +
+ {{_('Archive selected books')}} +

-
{{_('Unarchive selected books')}}
+
+ {{_('Unarchive selected books')}} +
+
+ {% elif parameter == "read_status" %} +
+ {{_('Mark selected books as read')}} +
+
+
+ {{_('Mark selected books as unread')}}

{% endif %} {{show_text}} @@ -40,8 +52,12 @@
-
{{_('Merge selected books')}}
-
{{_('Clear selections')}}
+
+ {{_('Merge selected books')}} +
+
+ {{_('Clear selections')}} +
{{_('Exchange author and title')}}
@@ -103,7 +119,13 @@ {% endif %} {% endfor %} {% if current_user.role_delete_books() and current_user.role_edit()%} -
{{_('Delete selected books')}}

{{_('Delete')}} + +
+ {{_('Delete selected books')}} +
+
+ {{_('Delete')}} + {% endif %} @@ -130,7 +152,7 @@
@@ -149,7 +171,7 @@

@@ -169,7 +191,7 @@

@@ -189,13 +211,53 @@

+ + + + {% endif %} {% endblock %}