1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-06-26 23:22:53 +00:00

Make edit metadata pass all data in a single REST call. Modularize editbooks

This commit is contained in:
James Armstong 2024-08-02 23:29:34 -07:00
parent 96fb2c1439
commit a335dd75a1
2 changed files with 103 additions and 48 deletions

View File

@ -350,6 +350,77 @@ def table_get_custom_enum(c_id):
@edit_required
def edit_list_book(param):
vals = request.form.to_dict()
return edit_book_param(param, vals)
@editbook.route("/ajax/editselectedbooks", methods=['POST'])
@login_required_if_no_ano
@edit_required
def edit_selected_books():
d = request.get_json()
selections = d.get('selections')
title = d.get('title')
title_sort = d.get('title_sort')
author_sort = d.get('author_sortj')
authors = d.get('authors')
categories = d.get('categories')
series = d.get('series')
languages = d.get('languages')
publishers = d.get('publishers')
comments = d.get('comments')
if len(selections) != 0:
for book_id in selections:
vals = {
"pk": book_id,
"value": None,
}
if title:
vals['value'] = title
edit_book_param('title', vals)
if title_sort:
vals['value'] = title_sort
edit_book_param('sort', vals)
if author_sort:
vals['value'] = author_sort
edit_book_param('author_sort', vals)
if authors:
vals['value'] = authors
edit_book_param('authors', vals)
if categories:
vals['value'] = categories
edit_book_param('tags', vals)
if series:
vals['value'] = series
edit_book_param('series', vals)
if languages:
vals['value'] = languages
edit_book_param('languages', vals)
if publishers:
vals['value'] = publishers
edit_book_param('publishers', vals)
if comments:
vals['value'] = comments
edit_book_param('comments', vals)
return json.dumps({'success': True})
return ""
# Separated from /editbooks so that /editselectedbooks can also use this
#
# param: the property of the book to be changed
# vals - JSON Object:
# {
# 'pk': "the book id",
# 'value': "changes value of param to what's passed here"
# 'checkA': "Optional. Used to check if autosort author is enabled. Assumed as true if not passed"
# 'checkT': "Optional. Used to check if autotitle author is enabled. Assumed as true if not passed"
# }
#
@login_required_if_no_ano
@edit_required
def edit_book_param(param, vals):
book = calibre_db.get_book(vals['pk'])
sort_param = ""
ret = ""

View File

@ -203,57 +203,41 @@ $(function() {
});
$("#edit_selected_confirm").click(function(event) {
let title = $("#title_input").val()
let title_sort = $("#title_sort_input").val()
let author_sort = $("#author_sort_input").val()
let authors = $("#authors_input").val()
let categories = $("#categories_input").val()
let series = $("#series_input").val()
let languages = $("#languages_input").val()
let publishers = $("#publishers_input").val()
let comments = $("#comments_input").val().toString()
function loopThrough(param, value)
{
selections.forEach((book_id) => {
$.ajax({
method: "post",
url: getPath() + "/ajax/editbooks/" + param,
data: { pk: book_id, value: value },
error: function (data) {
handleListServerResponse([
{ type: "danger", message: data.responseText },
]);
},
success: function success(booTitles) {
$("#books-table").bootstrapTable("refresh");
$("#books-table").bootstrapTable("uncheckAll");
$.ajax({
method:"post",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: window.location.pathname + "/../ajax/editselectedbooks",
data: JSON.stringify({
"selections": selections,
"title": $("#title_input").val(),
"title_sort": $("#title_sort_input").val(),
"author_sort": $("#author_sort_input").val(),
"authors": $("#authors_input").val(),
"categories": $("#categories_input").val(),
"series": $("#series_input").val(),
"languages": $("#languages_input").val(),
"publishers": $("#publishers_input").val(),
"comments": $("#comments_input").val().toString(),
}),
success: function success(booTitles) {
$("#books-table").bootstrapTable("refresh");
$("#books-table").bootstrapTable("uncheckAll");
$("#title_input").val("");
$("#title_sort_input").val("");
$("#author_sort_input").val("");
$("#authors_input").val("");
$("#categories_input").val("");
$("#series_input").val("");
$("#languages_input").val("");
$("#publishers_input").val("");
$("#comments_input").val("");
$("#title_input").val("");
$("#title_sort_input").val("");
$("#author_sort_input").val("");
$("#authors_input").val("");
$("#categories_input").val("");
$("#series_input").val("");
$("#languages_input").val("");
$("#publishers_input").val("");
$("#comments_input").val("");
handleListServerResponse;
},
});
})
}
if (title) loopThrough('title', title);
if (title_sort) loopThrough('sort', title_sort);
if (author_sort) loopThrough('author_sort', author_sort);
if (authors) loopThrough('authors', authors);
if (categories) loopThrough('tags', categories);
if (series) loopThrough('series', series);
if (languages) loopThrough('languages', languages);
if (publishers) loopThrough('publishers', publishers);
if (comments) loopThrough('comments', comments);
handleListServerResponse;
}
});
});
$(document).on('click', '#archive_selected_books', function(event) {