diff --git a/cps/db.py b/cps/db.py
index bf27b4d9..2e3fa29e 100644
--- a/cps/db.py
+++ b/cps/db.py
@@ -631,21 +631,26 @@ class CalibreDB(threading.Thread):
.filter(and_(Books.authors.any(and_(*q)), func.lower(Books.title).ilike("%" + title + "%"))).first()
# read search results from calibre-database and return it (function is used for feed and simple search
- def get_search_results(self, term, order=None, limit=-1):
+ def get_search_results(self, term, offset=None, order=None, limit=None):
order = order or [Books.sort]
+ if offset != None and limit != None:
+ offset = int(offset)
+ limit = offset + int(limit)
term.strip().lower()
self.session.connection().connection.connection.create_function("lower", 1, lcase)
q = list()
authorterms = re.split("[, ]+", term)
for authorterm in authorterms:
q.append(Books.authors.any(func.lower(Authors.name).ilike("%" + authorterm + "%")))
- return self.session.query(Books).filter(self.common_filters(True)).filter(
+ result = self.session.query(Books).filter(self.common_filters(True)).filter(
or_(Books.tags.any(func.lower(Tags.name).ilike("%" + term + "%")),
Books.series.any(func.lower(Series.name).ilike("%" + term + "%")),
Books.authors.any(and_(*q)),
Books.publishers.any(func.lower(Publishers.name).ilike("%" + term + "%")),
func.lower(Books.title).ilike("%" + term + "%")
- )).order_by(*order).limit(limit).all()
+ )).order_by(*order).all()
+ result_count = len(result)
+ return result[offset:limit], result_count
# Creates for all stored languages a translated speaking name in the array for the UI
def speaking_language(self, languages=None):
diff --git a/cps/opds.py b/cps/opds.py
index 5f6cf88d..ac0e103b 100644
--- a/cps/opds.py
+++ b/cps/opds.py
@@ -408,7 +408,7 @@ def get_metadata_calibre_companion(uuid, library):
def feed_search(term):
if term:
- entries = calibre_db.get_search_results(term)
+ entries, __ = calibre_db.get_search_results(term)
entriescount = len(entries) if len(entries) > 0 else 1
pagination = Pagination(1, entriescount, entriescount)
return render_xml_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
diff --git a/cps/static/js/table.js b/cps/static/js/table.js
index 479c7815..879c80eb 100644
--- a/cps/static/js/table.js
+++ b/cps/static/js/table.js
@@ -100,6 +100,33 @@ $(function() {
$(e.currentTarget).find("#btndeletedomain").data("domainId", domainId);
});
+ $("#delete_confirm").click(function() {
+ //get data-id attribute of the clicked element
+ var deleteId = $(this).data("deleteid");
+ $.ajax({
+ method:"get",
+ url: window.location.pathname + "/../../delete"/+deleteId,
+ });
+ });
+
+ //triggered when modal is about to be shown
+ $("#deleteModal").on("show.bs.modal", function(e) {
+ //get data-id attribute of the clicked element and store in button
+ var bookId = $(e.relatedTarget).data("delete-id");
+ $(e.currentTarget).find("#delete_confirm").data("deleteid", bookId);
+ });
+ // receive result from request, dismiss modal dialog, show flash message
+ // insert after navbar
+ /*$("#deleteModal").on("hidden.bs.modal", function () {
+
*/
+
+ // to save current setting
+ // coresponding event: onColumnSwitch
+ //$table.bootstrapTable('getVisibleColumns')
+ //$table.bootstrapTable('getHiddenColumns').
+
$("#restrictModal").on("hidden.bs.modal", function () {
// Destroy table and remove hooks for buttons
$("#restrict-elements-table").unbind();
@@ -223,9 +250,8 @@ function RestrictionActions (value, row) {
/* Function for deleting books */
function EbookActions (value, row) {
return [
- "",
+ "
",
"",
"
"
].join("");
}
-
diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html
index 14bc590a..1f7b57b4 100644
--- a/cps/templates/book_edit.html
+++ b/cps/templates/book_edit.html
@@ -192,34 +192,7 @@
{% endblock %}
{% block modal %}
-{% if g.user.role_delete_books() %}
-
-
-
-
-
-
- {{_('This book will be permanently erased from database')}}
- {{_('and hard disk')}}
-
- {% if config.config_kobo_sync %}
-
- {{_('Important Kobo Note: deleted books will remain on any paired Kobo device.')}}
- {{_('Books must first be archived and the device synced before a book can safely be deleted.')}}
-
- {% endif %}
-
-
-
-
-
-
-{% endif %}
+{{ delete_book(book.id) }}
{% endmacro %}
+{% macro delete_book(bookid) %}
+{% if g.user.role_delete_books() %}
+
+
+
+
+
+
+ {{_('This book will be permanently erased from database')}}
+ {{_('and hard disk')}}
+
+ {% if config.config_kobo_sync %}
+
+ {{_('Important Kobo Note: deleted books will remain on any paired Kobo device.')}}
+ {{_('Books must first be archived and the device synced before a book can safely be deleted.')}}
+
+ {% endif %}
+
+
+
+
+
+
+{% endif %}
+{% endmacro %}
diff --git a/cps/templates/search.html b/cps/templates/search.html
index da59efa6..b0dbc4af 100644
--- a/cps/templates/search.html
+++ b/cps/templates/search.html
@@ -5,7 +5,7 @@
{{_('No Results Found')}} {{adv_searchterm}}
{{_('Search Term:')}} {{adv_searchterm}}
{% else %}
-
{{entries|length}} {{_('Results for:')}} {{adv_searchterm}}
+
{{result_count}} {{_('Results for:')}} {{adv_searchterm}}
{% if g.user.is_authenticated %}
{% if g.user.shelf.all() or g.shelves_access %}
diff --git a/cps/web.py b/cps/web.py
index c7a0dc5c..d4e5d7c2 100644
--- a/cps/web.py
+++ b/cps/web.py
@@ -832,13 +832,13 @@ def render_language_books(page, name, order):
@web.route("/table")
-@login_required_if_no_ano
+@login_required
def books_table():
# __, __, pagination = calibre_db.fill_indexpage(1, 0, db.Books, True, [db.Books.timestamp.asc()])
return render_title_template('book_table.html', title=_(u"Books list"), page="book_table") #, pagination=pagination)
@web.route("/ajax/listbooks")
-@login_required_if_no_ano
+@login_required
def list_books():
off = request.args.get("offset") or 0
limit = request.args.get("limit") or config.config_books_per_page
@@ -850,9 +850,7 @@ def list_books():
search = request.args.get("search")
total_count = calibre_db.session.query(db.Books).count()
if search:
- entries = calibre_db.get_search_results(search, order, limit)
- #ToDo not right web.py 1259
- filtered_count = len(entries)
+ entries, filtered_count = calibre_db.get_search_results(search, off, order, limit)
else:
entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1), limit, db.Books, True, order)
filtered_count = total_count
@@ -1035,7 +1033,7 @@ def reconnect():
def search():
term = request.args.get("query")
if term:
- entries = calibre_db.get_search_results(term)
+ entries, result_count = calibre_db.get_search_results(term)
ids = list()
for element in entries:
ids.append(element.id)
@@ -1044,11 +1042,13 @@ def search():
searchterm=term,
adv_searchterm=term,
entries=entries,
+ result_count=result_count,
title=_(u"Search"),
page="search")
else:
return render_title_template('search.html',
searchterm="",
+ result_count=0,
title=_(u"Search"),
page="search")
@@ -1192,7 +1192,7 @@ def advanced_search():
ids.append(element.id)
searched_ids[current_user.id] = ids
return render_title_template('search.html', adv_searchterm=searchterm,
- entries=q, title=_(u"search"), page="search")
+ entries=q, result_count=len(q), title=_(u"search"), page="search")
# prepare data for search-form
tags = calibre_db.session.query(db.Tags)\
.join(db.books_tags_link)\