From f2add3f788d7cff431dc666e460a842cabeda7ca Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Sat, 22 Aug 2020 10:27:09 +0200 Subject: [PATCH] Migration of view settings working in User database Book Merge gives now feedback on what is done --- cps/editbooks.py | 17 ++++++++++++++++- cps/static/js/table.js | 22 ++++++++++++++++++++-- cps/templates/book_table.html | 13 +++++++++---- cps/ub.py | 5 +++-- cps/web.py | 3 ++- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 48e4fe23..1021356b 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -987,12 +987,26 @@ def get_sorted_entry(field, bookid): return "" +@editbook.route("/ajax/simulatemerge", methods=['POST']) +@login_required +def simulate_merge_list_book(): + vals = request.get_json().get('Merge_books') + if vals: + to_book = calibre_db.get_book(vals[0]).title + vals.pop(0) + if to_book: + for book_id in vals: + from_book = [] + from_book.append(calibre_db.get_book(book_id).title) + return json.dumps({'to': to_book, 'from': from_book}) + return "" + @editbook.route("/ajax/mergebooks", methods=['POST']) @login_required def merge_list_book(): vals = request.get_json().get('Merge_books') - to_file= list() + to_file = list() if vals: # load all formats from target book to_book = calibre_db.get_book(vals[0]) @@ -1020,4 +1034,5 @@ def merge_list_book(): element.uncompressed_size, to_name)) delete_book(from_book.id,"", True) # json_resp = + return json.dumps({'success': True}) return "" diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 8d5633e2..cbfe58e7 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -1,5 +1,5 @@ /* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) - * Copyright (C) 2018 OzzieIsaacs + * Copyright (C) 2020 OzzieIsaacs * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -63,7 +63,25 @@ $(function() { url: window.location.pathname + "/../../ajax/mergebooks", data: JSON.stringify({"Merge_books":selections}), success: function success() { - // ToDo: + $('#books-table').bootstrapTable('refresh'); + $("#books-table").bootstrapTable('uncheckAll'); + } + }); + }); + + $("#merge_books").click(function() { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../../ajax/simulatemerge", + data: JSON.stringify({"Merge_books":selections}), + success: function success(book_titles) { + $.each(book_titles.from, function(i, item) { + $("- " + item + "").appendTo("#merge_from"); + }); + $('#merge_to').text("- " + book_titles.to); + } }); }); diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 4c86504f..f93a3af6 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -69,10 +69,15 @@ -