Skip to content

Commit

Permalink
Undo check of read checkbox in case of error
Browse files Browse the repository at this point in the history
Display error message in details modal dialog
Bugfix set archive bit in booktable
Translate error message readstatus change
  • Loading branch information
OzzieIsaacs committed Mar 12, 2022
1 parent 8e2536c commit 3b5e5f9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions cps/editbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,11 @@ def edit_list_book(param):
'newValue': ' & '.join([author.replace('|',',') for author in input_authors])}),
mimetype='application/json')
elif param == 'is_archived':
change_archived_books(book.id, vals['value'] == "True")
ret = ""
is_archived = change_archived_books(book.id, vals['value'] == "True",
message="Book {} archivebit set to: {}".format(book.id, vals['value']))
if is_archived:
kobo_sync_status.remove_synced_book(book.id)
return ""
elif param == 'read_status':
ret = helper.edit_book_read_status(book.id, vals['value'] == "True")
if ret:
Expand Down
2 changes: 1 addition & 1 deletion cps/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def edit_book_read_status(book_id, read_status=None):
except (OperationalError, InvalidRequestError) as e:
calibre_db.session.rollback()
log.error(u"Read status could not set: {}".format(e))
return "Read status could not set: {}".format(e), 400
return _("Read status could not set: {}".format(e.orig))
return ""

# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
Expand Down
22 changes: 16 additions & 6 deletions cps/static/js/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ $("#have_read_cb").on("change", function() {
data: $(this).closest("form").serialize(),
error: function(response) {
var data = [{type:"danger", message:response.responseText}]
$("#flash_success").remove();
// $("#flash_success").parent().remove();
$("#flash_danger").remove();
$(".row-fluid.text-center").remove();
if (!jQuery.isEmptyObject(data)) {
data.forEach(function (item) {
$(".navbar").after('<div class="row-fluid text-center" >' +
'<div id="flash_' + item.type + '" class="alert alert-' + item.type + '">' + item.message + '</div>' +
'</div>');
});
$("#have_read_cb").prop("checked", !$("#have_read_cb").prop("checked"));
if($("#bookDetailsModal").is(":visible")) {
data.forEach(function (item) {
$(".modal-header").after('<div id="flash_' + item.type +
'" class="text-center alert alert-' + item.type + '">' + item.message + '</div>');
});
} else
{
data.forEach(function (item) {
$(".navbar").after('<div class="row-fluid text-center" >' +
'<div id="flash_' + item.type + '" class="alert alert-' + item.type + '">' + item.message + '</div>' +
'</div>');
});
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions cps/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ $(function() {

$("#bookDetailsModal")
.on("show.bs.modal", function(e) {
$("#flash_danger").remove();
var $modalBody = $(this).find(".modal-body");

// Prevent static assets from loading multiple times
Expand Down
2 changes: 2 additions & 0 deletions cps/static/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,13 @@ function checkboxChange(checkbox, userId, field, field_index) {

function BookCheckboxChange(checkbox, userId, field) {
var value = checkbox.checked ? "True" : "False";
var element = checkbox;
$.ajax({
method: "post",
url: getPath() + "/ajax/editbooks/" + field,
data: {"pk": userId, "value": value},
error: function(data) {
element.checked = !element.checked;
handleListServerResponse([{type:"danger", message:data.responseText}])
},
success: handleListServerResponse
Expand Down

0 comments on commit 3b5e5f9

Please sign in to comment.