diff --git a/cps/editbooks.py b/cps/editbooks.py index 8ce54267..d8dcca74 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -945,15 +945,18 @@ def get_sorted_entry(field, bookid): return json.dumps({'sort': book.sort}) elif field == 'authors': return json.dumps({'author_sort': book.author_sort}) - return '' + return "" @editbook.route("/ajax/deletebooks") @login_required def delete_list_book(): - pass + return "" @editbook.route("/ajax/mergebooks", methods=['POST']) @login_required def merge_list_book(): vals = request.get_json() + + # load first book + # load every next book, append data to first book, delete 2nd book return "" diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 2d3f0774..e310e29c 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -42,7 +42,18 @@ $(function() { $("#merge_books").addClass("disabled"); $("#merge_books").attr("aria-disabled", true); } + if (selections.length < 1) { + $("#delete_selection").addClass("disabled"); + $("#delete_selection").attr("aria-disabled", true); + } + else{ + $("#delete_selection").removeClass("disabled"); + $("#delete_selection").attr("aria-disabled", false); + } }); + $("#delete_selection").click(function() { + $("#books-table").bootstrapTable('uncheckAll'); + }); $("#merge_books").click(function() { $.ajax({ @@ -108,7 +119,7 @@ $(function() { id: row.id, field: key, value: data[key] - }) + }); console.log(data); } }); @@ -117,25 +128,39 @@ $(function() { onColumnSwitch: function (field, checked) { var visible = $("#books-table").bootstrapTable('getVisibleColumns'); var hidden = $("#books-table").bootstrapTable('getHiddenColumns'); + // to save current setting + // coresponding event: onColumnSwitch + //$table.bootstrapTable('getVisibleColumns') + //$table.bootstrapTable('getHiddenColumns'). + var visibility =[] + var st = "" + visible.forEach(function(item) { + st += "\""+ item.field + "\":\"" +"true"+ "\"," + /*var element = {}; + element[item.field] = "true"; + visibility.push(element);*/ + }); + hidden.forEach(function(item) { + st += "\""+ item.field + "\":\"" +"false"+ "\"," + /*var element = {}; + element[item.field] = "false"; + visibility.push(element);*/ + }); + /* + visibility.forEach(function(item) { + st += JSON.stringify(item) + ','; + });*/ + st = st.slice(0, -1); $.ajax({ method:"post", contentType: "application/json; charset=utf-8", dataType: "json", url: window.location.pathname + "/../../ajax/table_settings", - data: JSON.stringify({"Merge_books":selections}), - success: function success() { - // ToDo: - } - }); - - } + data: "{" + st + "}", + }); + }, }); - // to save current setting - // coresponding event: onColumnSwitch - //$table.bootstrapTable('getVisibleColumns') - //$table.bootstrapTable('getHiddenColumns'). - $("#domain_allow_submit").click(function(event) { event.preventDefault(); diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index c0065b78..1ef24d5d 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -1,10 +1,11 @@ {% extends "layout.html" %} {% macro text_table_row(parameter, edit_text, show_text, validate) -%}
{{_('Series Index')}} | +{{_('Series Index')}} | {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} -{{_('Publishing Date')}} | +{{_('Publishing Date')}} | {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {% if g.user.role_edit() %} -+ | {{_('Delete')}} | {% endif %} diff --git a/cps/ub.py b/cps/ub.py index c39b96a6..d994b408 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -218,6 +218,7 @@ class User(UserBase, Base): allowed_column_value = Column(String, default="") remote_auth_token = relationship('RemoteAuthToken', backref='user', lazy='dynamic') series_view = Column(String(10), default="list") + view_settings = Column(String, default="list") if oauth_support: @@ -259,6 +260,7 @@ class Anonymous(AnonymousUserMixin, UserBase): self.denied_column_value = data.denied_column_value self.allowed_column_value = data.allowed_column_value self.series_view = data.series_view + self.view_settings = data.view_settings def role_admin(self): return False @@ -570,6 +572,11 @@ def migrate_Database(session): except exc.OperationalError: conn = engine.connect() conn.execute("ALTER TABLE user ADD column `series_view` VARCHAR(10) DEFAULT 'list'") + try: + session.query(exists().where(User.view_settings)).scalar() + except exc.OperationalError: + conn = engine.connect() + conn.execute("ALTER TABLE user ADD column `view_settings` VARCHAR DEFAULT '{}'") if session.query(User).filter(User.role.op('&')(constants.ROLE_ANONYMOUS) == constants.ROLE_ANONYMOUS).first() \ is None: @@ -591,6 +598,7 @@ def migrate_Database(session): "sidebar_view INTEGER," "default_language VARCHAR(3)," "series_view VARCHAR(10)," + "view_settings VARCHAR," "UNIQUE (nickname)," "UNIQUE (email))") conn.execute("INSERT INTO user_id(id, nickname, email, role, password, kindle_mail,locale," diff --git a/cps/web.py b/cps/web.py index 6a3aa7f2..579403fc 100644 --- a/cps/web.py +++ b/cps/web.py @@ -829,8 +829,12 @@ def render_language_books(page, name, order): @web.route("/table") @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) + try: + visibility = json.loads(current_user.view_settings) + except Exception: + visibility = {} + return render_title_template('book_table.html', title=_(u"Books list"), page="book_table", + visiblility=visibility) @web.route("/ajax/listbooks") @login_required @@ -865,11 +869,14 @@ def list_books(): response.headers["Content-Type"] = "application/json; charset=utf-8" return response -@web.route("/ajax/table_settings") +@web.route("/ajax/table_settings", methods=['POST']) @login_required def update_table_settings(): + # vals = request.get_json() # ToDo: Save table settings - pass + current_user.view_settings = request.data + ub.session.commit() + return "" @web.route("/author") @login_required_if_no_ano
---|