diff --git a/cps/db.py b/cps/db.py index 2e3fa29e..51182a6d 100644 --- a/cps/db.py +++ b/cps/db.py @@ -240,7 +240,10 @@ class Languages(Base): self.lang_code = lang_code def get(self): - return self.lang_code + if self.language_name: + return self.language_name + else: + return self.lang_code def __repr__(self): return u"".format(self.lang_code) diff --git a/cps/editbooks.py b/cps/editbooks.py index 14d311c6..70577771 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -27,6 +27,7 @@ import json from shutil import copyfile from uuid import uuid4 +from babel import Locale as LC from flask import Blueprint, request, flash, redirect, url_for, abort, Markup, Response from flask_babel import gettext as _ from flask_login import current_user, login_required @@ -892,7 +893,7 @@ def convert_bookformat(book_id): @login_required_if_no_ano def edit_list_book(param): vals = request.form.to_dict() - #calibre_db.update_title_sort(config) + # calibre_db.update_title_sort(config) #calibre_db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4())) book = calibre_db.get_book(vals['pk']) if param =='series_index': @@ -902,16 +903,17 @@ def edit_list_book(param): elif param =='series': edit_book_series(vals['value'], book) elif param =='publishers': - edit_book_publisher(vals['value'], book) - # ToDo: edit books + vals['publisher'] = vals['value'] + edit_book_publisher(vals, book) elif param =='languages': edit_book_languages(vals['value'], book) + elif param =='author_sort': + book.author_sort = vals['value'] elif param =='title': - edit_book_languages(vals['value'], book) + book.title = vals['value'] elif param =='sort': - edit_book_languages(vals['value'], book) - elif param =='author_sort': - edit_book_languages(vals['value'], book) + book.sort = vals['value'] + # ToDo: edit books elif param =='authors': edit_book_languages(vals['value'], book) @@ -919,7 +921,18 @@ def edit_list_book(param): calibre_db.session.commit() return "" +@editbook.route("/ajax/sort_value") +@login_required +def get_sorted_entry(): + pass + @editbook.route("/ajax/deletebooks") -@login_required_if_no_ano +@login_required def delete_list_book(): pass + +@editbook.route("/ajax/mergebooks", methods=['POST']) +@login_required +def merge_list_book(): + vals = request.get_json() + return "" diff --git a/cps/static/css/style.css b/cps/static/css/style.css index e99d45b2..e2cd4ec7 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -51,9 +51,9 @@ body h2 { color:#444; } -a, .danger, .editable-empty, .editable-empty:hover { color: #45b29d; } +a, .danger,.book-remove, .editable-empty, .editable-empty:hover { color: #45b29d; } -.danger:hover { color: #23527c; } +.book-remove:hover { color: #23527c; } .btn-default a { color: #444; } diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 1c7e6807..33bc2897 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -15,16 +15,150 @@ * along with this program. If not, see . */ -/* exported TableActions, RestrictionActions, EbookActions*/ +/* exported TableActions, RestrictionActions, EbookActions, responseHandler */ + +var selections = []; $(function() { - $("#books-table").bootstrapTable({ + $("#books-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", + function (e, rowsAfter, rowsBefore) { + var rows = rowsAfter; + + if (e.type === "uncheck-all") { + rows = rowsBefore; + } + + var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { + return row.id; + }); + + var func = $.inArray(e.type, ["check", "check-all"]) > -1 ? "union" : "difference"; + selections = window._[func](selections, ids); + if (selections.length >= 2) { + $("#merge_books").removeClass("disabled"); + $("#merge_books").attr("aria-disabled", false); + } else { + $("#merge_books").addClass("disabled"); + $("#merge_books").attr("aria-disabled", true); + } + }); + + $("#merge_books").click(function() { + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: window.location.pathname + "/../../ajax/mergebooks", + data: JSON.stringify({"Merge_books":selections}), + success: function success() { + // ToDo: + } + }); + }); + /*$("#books-table").bootstrapTable({ + }); + test = $("#books-table").bootstrapTable('getOptions'); + var column = test.columns[0] + column.forEach(function(item){ + if ('editableValidate' in item) { + item.editable = { + mode: 'inline', + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + } + } + }); + $("#books-table").bootstrapTable('refreshOptions', {columns: [column]});*/ + + var column = []; + $('#table1 > thead > tr > th').each(function(){ + if ($(this).attr('data-edit')) { + if ($(this).attr('data-edit-validate')) { + column.push({ + editable: { + mode: 'inline', + emptytext: "", + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + } + }); + } else { + column.push({ + editable: { + mode: 'inline', + emptytext: "", + } + }); + } + } else { + column.push({}); + } + }); + $("#table1").bootstrapTable({ + sidePagination: "server", + pagination: true, + paginationDetailHAlign: " hidden", + paginationHAlign: "left", + /*url: window.location.pathname + "/../../ajax/listbooks",*/ + idField: "id", + search: true, + showColumns: true, + searchAlign: "left", + showSearchButton : false, + searchOnEnterKey: true, + checkboxHeader: false, + maintainMetaData: true, + responseHandler: responseHandler, + columns: column, + /*editable-mode="inline" + editable-emptytext="">*/ + /*columns: [ + {}, + {}, { + editable: { + mode: 'inline', + emptytext: "", + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + }, + }, { + editable: { + mode: 'inline', + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + }, + }, { + editable: { + mode: 'inline', + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + } + }, { + editable: { + mode: 'inline', + emptytext: "", + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + }, + }, { + editable: { + mode: 'inline', + emptytext: "", + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + }, + }, { + editable: { + mode: 'inline', + emptytext: "", + validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, + }, + }],*/ formatNoMatches: function () { return ""; - } + }, }); + /*var $table = $('#books-table'); + $('#books-table').bootstrapTable('getOptions')*/ + /*$('#books-table').bootstrapTable('editable')*/ + /*{ field: 'aimValue', title: 'Aim
Value', class: 'danger',editable: { mode: 'inline', validate: function (v) { return validateData(this, v); }, }, },*/ + + $("#domain_allow_submit").click(function(event) { event.preventDefault(); $("#domain_add_allow").ajaxForm(); @@ -105,7 +239,7 @@ $(function() { var deleteId = $(this).data("deleteid"); $.ajax({ method:"get", - url: window.location.pathname + "/../../delete"/+deleteId, + url: window.location.pathname + "/../../delete/" + deleteId, }); }); @@ -238,6 +372,7 @@ function TableActions (value, row) { ].join(""); } + /* Function for deleting domain restrictions */ function RestrictionActions (value, row) { return [ @@ -250,8 +385,22 @@ function RestrictionActions (value, row) { /* Function for deleting books */ function EbookActions (value, row) { return [ - "
", + "
", "", "
" ].join(""); } + +/* Function for keeping checked rows */ +function responseHandler(res) { + $.each(res.rows, function (i, row) { + row.state = $.inArray(row.id, selections) !== -1; + }); + return res; +} + +function validato(value) { + if($.trim(value) == '') return 'This field is required'; +} + +/*function validateVal(value) { if($.trim(value) == '') return 'This field is required'; }*/ diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index e8150e16..3801bbe5 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -1,6 +1,14 @@ {% extends "layout.html" %} -{% macro text_table_row(parameter, edit_text, show_text) -%} -{{ show_text }} +{% macro text_table_row(parameter, edit_text, show_text, validate) -%} +{{ show_text }} {%- endmacro %} {% block header %} @@ -9,13 +17,14 @@ {% endblock %} {% block body %}

{{_(title)}}

- + +
{{_('Merge selected books')}}
+
{% if g.user.role_edit() %} {% endif %} - {{ text_table_row('title', _('Enter Title'),_('Title')) }} - {{ text_table_row('sort', _('Enter Titlesort'),_('Sort')) }} - {{ text_table_row('author_sort', _('Enter Authorsort'),_('Authors Sort')) }} - {{ text_table_row('authors', _('Enter Authors'),_('Authors')) }} - {{ text_table_row('tags', _('Enter Tags'),_('Tags')) }} - {{ text_table_row('series', _('Enter Series'),_('Series')) }} + {{ text_table_row('title', _('Enter Title'),_('Title'), true) }} + {{ text_table_row('sort', _('Enter Titlesort'),_('Sort'), false) }} + {{ text_table_row('author_sort', _('Enter Authorsort'),_('Authors Sort'), false) }} + {{ text_table_row('authors', _('Enter Authors'),_('Authors'), false) }} + {{ text_table_row('tags', _('Enter Tags'),_('Tags'), false) }} + {{ text_table_row('series', _('Enter Series'),_('Series'), false) }} - {{ text_table_row('languages', _('Enter Languages'),_('Languages')) }} - - {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers')) }} + {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} + + {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {% if g.user.role_edit() %} {% endif %} @@ -60,32 +72,5 @@ {% endblock %} diff --git a/cps/web.py b/cps/web.py index bf6e25da..1f47e7c2 100644 --- a/cps/web.py +++ b/cps/web.py @@ -30,8 +30,8 @@ import traceback import binascii import re -from babel import Locale as LC from babel.dates import format_date +from babel import Locale as LC from babel.core import UnknownLocaleError from flask import Blueprint from flask import render_template, request, redirect, send_from_directory, make_response, g, flash, abort, url_for @@ -849,6 +849,14 @@ def list_books(): else: entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1), limit, db.Books, True, order) filtered_count = total_count + for entry in entries: + for index in range(0, len(entry.languages)): + try: + entry.languages[index].language_name = LC.parse(entry.languages[index].lang_code)\ + .get_language_name(get_locale()) + except UnknownLocaleError: + entry.languages[index].language_name = _( + isoLanguages.get(part3=entry.languages[index].lang_code).name) table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": entries} js_list = json.dumps(table_entries, cls=db.AlchemyEncoder) #js_list = json.dumps(entries, cls=db.AlchemyEncoder)
{{_('Series Index')}}Publishing DatePublishing Date