diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index a26b20a9..0d6665ba 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -2,178 +2,199 @@ * Created by SpeedProg on 05.04.2015. */ - /* - Takes a prefix, query typeahead callback, Bloodhound typeahead adapter - and returns the completions it gets from the bloodhound engine prefixed. - */ - function prefixed_source(prefix, query, cb, bh_adapter) { - bh_adapter(query, function(retArray){ - var matches = []; - for (var i = 0; i < retArray.length; i++) { - var obj = {name : prefix + retArray[i].name}; - matches.push(obj); - } - cb(matches); - }); +/* +Takes a prefix, query typeahead callback, Bloodhound typeahead adapter + and returns the completions it gets from the bloodhound engine prefixed. + */ +function prefixed_source(prefix, query, cb, bh_adapter) { + bh_adapter(query, function(retArray){ + var matches = []; + for (var i = 0; i < retArray.length; i++) { + var obj = {name : prefix + retArray[i].name}; + matches.push(obj); + } + cb(matches); + }); +} +function get_path(){ + var jsFileLocation = $('script[src*=edit_books]').attr('src'); // the js file path + jsFileLocation = jsFileLocation.replace('/static/js/edit_books.js', ''); // the js folder path + return jsFileLocation; +} + +var authors = new Bloodhound({ + name: 'authors', + datumTokenizer: function(datum) { + return [datum.name]; + }, + queryTokenizer: Bloodhound.tokenizers.whitespace, + remote: { + url: get_path()+'/get_authors_json?q=%QUERY' + } +}); + +function authors_source(query, cb) { + var bh_adapter = authors.ttAdapter(); + + var tokens = query.split("&"); + var current_author = tokens[tokens.length-1].trim(); + + tokens.splice(tokens.length-1, 1); // remove last element + var prefix = ""; + for (var i = 0; i < tokens.length; i++) { + var author = tokens[i].trim(); + prefix += author + " & "; } - var authors = new Bloodhound({ - name: 'authors', - datumTokenizer: function(datum) { - return [datum.name]; - }, - queryTokenizer: Bloodhound.tokenizers.whitespace, - remote: { - url: '/get_authors_json?q=%QUERY' - } - }); - - function authors_source(query, cb) { - var bh_adapter = authors.ttAdapter(); - - var tokens = query.split("&"); - var current_author = tokens[tokens.length-1].trim(); - - tokens.splice(tokens.length-1, 1); // remove last element - var prefix = ""; - for (var i = 0; i < tokens.length; i++) { - var author = tokens[i].trim(); - prefix += author + " & "; - } - - prefixed_source(prefix, current_author, cb, bh_adapter); - } + prefixed_source(prefix, current_author, cb, bh_adapter); +} - var promise = authors.initialize(); +var promise = authors.initialize(); promise.done(function(){ - $("#bookAuthor").typeahead( - { - highlight: true, minLength: 1, - hint: true - }, { - name: 'authors', displayKey: 'name', - source: authors_source - } - ) - }); - - var series = new Bloodhound({ - name: 'series', - datumTokenizer: function(datum) { - return [datum.name]; - }, - queryTokenizer: function(query) { - return [query]; - }, - remote: { - url: '/get_series_json?q=', - replace: function(url, query) { - url_query = url+encodeURIComponent(query); - return url_query; + $("#bookAuthor").typeahead( + { + highlight: true, minLength: 1, + hint: true + }, { + name: 'authors', displayKey: 'name', + source: authors_source } + ) +}); + +var series = new Bloodhound({ + name: 'series', + datumTokenizer: function(datum) { + return [datum.name]; + }, + queryTokenizer: function(query) { + return [query]; + }, + remote: { + url: get_path()+'/get_series_json?q=', + replace: function(url, query) { + url_query = url+encodeURIComponent(query); + return url_query; } - }); - var promise = series.initialize(); + } +}); +var promise = series.initialize(); promise.done(function(){ - $("#series").typeahead( - { - highlight: true, minLength: 0, - hint: true - }, { - name: 'series', displayKey: 'name', - source: series.ttAdapter() - } - ) - }); + $("#series").typeahead( + { + highlight: true, minLength: 0, + hint: true + }, { + name: 'series', displayKey: 'name', + source: series.ttAdapter() + } + ) +}); - var tags = new Bloodhound({ - name: 'tags', - datumTokenizer: function(datum) { - return [datum.name]; - }, - queryTokenizer: function(query) { - tokens = query.split(","); - tokens = [tokens[tokens.length-1].trim()]; - return tokens - }, - remote: { - url: '/get_tags_json?q=%QUERY' - } - }); +var tags = new Bloodhound({ + name: 'tags', + datumTokenizer: function(datum) { + return [datum.name]; + }, + queryTokenizer: function(query) { + tokens = query.split(","); + tokens = [tokens[tokens.length-1].trim()]; + return tokens + }, + remote: { + url: get_path()+'/get_tags_json?q=%QUERY' + } +}); - function tag_source(query, cb) { - var bh_adapter = tags.ttAdapter(); +function tag_source(query, cb) { + var bh_adapter = tags.ttAdapter(); - var tokens = query.split(","); - var current_tag = tokens[tokens.length-1].trim(); + var tokens = query.split(","); + var current_tag = tokens[tokens.length-1].trim(); - tokens.splice(tokens.length-1, 1); // remove last element - var prefix = ""; - for (var i = 0; i < tokens.length; i++) { - var tag = tokens[i].trim(); - prefix += tag + ", "; - } - - prefixed_source(prefix, current_tag, cb, bh_adapter); + tokens.splice(tokens.length-1, 1); // remove last element + var prefix = ""; + for (var i = 0; i < tokens.length; i++) { + var tag = tokens[i].trim(); + prefix += tag + ", "; } - var promise = tags.initialize(); + prefixed_source(prefix, current_tag, cb, bh_adapter); +} + +var promise = tags.initialize(); promise.done(function(){ - $("#tags").typeahead( - { - highlight: true, minLength: 0, - hint: true - }, { - name: 'tags', displayKey: 'name', - source: tag_source - } - ) - }); - - var languages = new Bloodhound({ - name: 'languages', - datumTokenizer: function(datum) { - return [datum.name]; - }, - queryTokenizer: function(query) { - return [query]; - }, - remote: { - url: '/get_languages_json?q=', - replace: function(url, query) { - url_query = url+encodeURIComponent(query); - return url_query; + $("#tags").typeahead( + { + highlight: true, minLength: 0, + hint: true + }, { + name: 'tags', displayKey: 'name', + source: tag_source } + ) +}); + +var languages = new Bloodhound({ + name: 'languages', + datumTokenizer: function(datum) { + return [datum.name]; + }, + queryTokenizer: function(query) { + return [query]; + }, + remote: { + url: get_path()+'/get_languages_json?q=', + replace: function(url, query) { + url_query = url+encodeURIComponent(query); + return url_query; } - }); + } +}); - function language_source(query, cb) { - var bh_adapter = languages.ttAdapter(); +function language_source(query, cb) { + var bh_adapter = languages.ttAdapter(); - var tokens = query.split(","); - var current_language = tokens[tokens.length-1].trim(); + var tokens = query.split(","); + var current_language = tokens[tokens.length-1].trim(); - tokens.splice(tokens.length-1, 1); // remove last element - var prefix = ""; - for (var i = 0; i < tokens.length; i++) { - var tag = tokens[i].trim(); - prefix += tag + ", "; - } - - prefixed_source(prefix, current_language, cb, bh_adapter); + tokens.splice(tokens.length-1, 1); // remove last element + var prefix = ""; + for (var i = 0; i < tokens.length; i++) { + var tag = tokens[i].trim(); + prefix += tag + ", "; } - var promise = languages.initialize(); + prefixed_source(prefix, current_language, cb, bh_adapter); +} + +var promise = languages.initialize(); promise.done(function(){ - $("#languages").typeahead( - { - highlight: true, minLength: 0, - hint: true - }, { - name: 'languages', displayKey: 'name', - source: language_source - } - ) + $("#languages").typeahead( + { + highlight: true, minLength: 0, + hint: true + }, { + name: 'languages', displayKey: 'name', + source: language_source + } + ) +}); + +$('form').on('change input typeahead:selected', function(data){ + form = $('form').serialize(); + $.getJSON( get_path()+"/get_matching_tags", form, function( data ) { + $('.tags_click').each(function() { + if ($.inArray(parseInt($(this).children('input').first().val(), 10), data.tags) == -1 ) { + if (!($(this).hasClass('active'))) { + $(this).addClass('disabled'); + } + } + else { + $(this).removeClass('disabled'); + } + }); }); +}); diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 31e82237..a2d56c9e 100755 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -25,6 +25,39 @@ $(function() { $this.text('Please wait...'); $this.addClass('disabled'); }); + $("#restart").click(function() { + $.ajax({ + dataType: 'json', + url: window.location.pathname+"/../../shutdown", + data: {"parameter":0}, + success: function(data) { + return alert(data.text);} + }); + }); + $("#shutdown").click(function() { + $.ajax({ + dataType: 'json', + url: window.location.pathname+"/../../shutdown", + data: {"parameter":1}, + success: function(data) { + return alert(data.text);} + }); + }); + $("#check_for_update").click(function() { + var button_text = $("#check_for_update").html(); + $("#check_for_update").html('Checking...'); + $.ajax({ + dataType: 'json', + url: window.location.pathname+"/../../get_update_status", + success: function(data) { + if (data.status == true) { + $("#check_for_update").addClass('hidden'); + $("#perform_update").removeClass('hidden'); + }else{ + $("#check_for_update").html(button_text); + };} + }); + }); }); diff --git a/cps/templates/admin.html b/cps/templates/admin.html index 48343a76..2b70e17b 100644 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -115,40 +115,3 @@ {% endblock %} -{% block js %} - -{% endblock %} diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 90cda322..bcc67e23 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -4,7 +4,7 @@
{% if book.has_cover %} - + {% else %} {% endif %} diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index 36edc704..0961cf8c 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -40,7 +40,7 @@ {% endfor %}
- +
{% for serie in series %} @@ -81,21 +81,6 @@ {% endblock %} {% block header %} diff --git a/cps/web.py b/cps/web.py index 59216e0b..465b7baa 100755 --- a/cps/web.py +++ b/cps/web.py @@ -421,6 +421,7 @@ def before_request(): g.user = current_user g.allow_registration = config.config_public_reg g.allow_upload = config.config_uploading + g.public_shelfes = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1).all() if not config.db_configured and request.endpoint not in ('basic_configuration', 'login') and '/static/' not in request.path: return redirect(url_for('basic_configuration'))