|
|
@ -2,178 +2,199 @@
|
|
|
|
* Created by SpeedProg on 05.04.2015.
|
|
|
|
* Created by SpeedProg on 05.04.2015.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
|
|
|
|
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
|
|
|
|
and returns the completions it gets from the bloodhound engine prefixed.
|
|
|
|
and returns the completions it gets from the bloodhound engine prefixed.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function prefixed_source(prefix, query, cb, bh_adapter) {
|
|
|
|
function prefixed_source(prefix, query, cb, bh_adapter) {
|
|
|
|
bh_adapter(query, function(retArray){
|
|
|
|
bh_adapter(query, function(retArray){
|
|
|
|
var matches = [];
|
|
|
|
var matches = [];
|
|
|
|
for (var i = 0; i < retArray.length; i++) {
|
|
|
|
for (var i = 0; i < retArray.length; i++) {
|
|
|
|
var obj = {name : prefix + retArray[i].name};
|
|
|
|
var obj = {name : prefix + retArray[i].name};
|
|
|
|
matches.push(obj);
|
|
|
|
matches.push(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(matches);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var authors = new Bloodhound({
|
|
|
|
|
|
|
|
name: 'authors',
|
|
|
|
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
|
|
|
|
return [datum.name];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
|
|
|
remote: {
|
|
|
|
|
|
|
|
url: '/get_authors_json?q=%QUERY'
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
function authors_source(query, cb) {
|
|
|
|
var bh_adapter = authors.ttAdapter();
|
|
|
|
var bh_adapter = authors.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
var tokens = query.split("&");
|
|
|
|
var tokens = query.split("&");
|
|
|
|
var current_author = tokens[tokens.length-1].trim();
|
|
|
|
var current_author = tokens[tokens.length-1].trim();
|
|
|
|
|
|
|
|
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
var prefix = "";
|
|
|
|
var prefix = "";
|
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
var author = tokens[i].trim();
|
|
|
|
var author = tokens[i].trim();
|
|
|
|
prefix += author + " & ";
|
|
|
|
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(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#bookAuthor").typeahead(
|
|
|
|
$("#bookAuthor").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 1,
|
|
|
|
highlight: true, minLength: 1,
|
|
|
|
hint: true
|
|
|
|
hint: true
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: 'authors', displayKey: 'name',
|
|
|
|
name: 'authors', displayKey: 'name',
|
|
|
|
source: authors_source
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#series").typeahead(
|
|
|
|
$("#series").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
hint: true
|
|
|
|
hint: true
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: 'series', displayKey: 'name',
|
|
|
|
name: 'series', displayKey: 'name',
|
|
|
|
source: series.ttAdapter()
|
|
|
|
source: series.ttAdapter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var tags = new Bloodhound({
|
|
|
|
var tags = new Bloodhound({
|
|
|
|
name: 'tags',
|
|
|
|
name: 'tags',
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer: function(query) {
|
|
|
|
queryTokenizer: function(query) {
|
|
|
|
tokens = query.split(",");
|
|
|
|
tokens = query.split(",");
|
|
|
|
tokens = [tokens[tokens.length-1].trim()];
|
|
|
|
tokens = [tokens[tokens.length-1].trim()];
|
|
|
|
return tokens
|
|
|
|
return tokens
|
|
|
|
},
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: '/get_tags_json?q=%QUERY'
|
|
|
|
url: get_path()+'/get_tags_json?q=%QUERY'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function tag_source(query, cb) {
|
|
|
|
|
|
|
|
var bh_adapter = tags.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tokens = query.split(",");
|
|
|
|
function tag_source(query, cb) {
|
|
|
|
var current_tag = tokens[tokens.length-1].trim();
|
|
|
|
var bh_adapter = tags.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
var tokens = query.split(",");
|
|
|
|
var prefix = "";
|
|
|
|
var current_tag = tokens[tokens.length-1].trim();
|
|
|
|
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);
|
|
|
|
promise.done(function(){
|
|
|
|
}
|
|
|
|
$("#tags").typeahead(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
|
|
|
|
hint: true
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
name: 'tags', displayKey: 'name',
|
|
|
|
|
|
|
|
source: tag_source
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var languages = new Bloodhound({
|
|
|
|
var promise = tags.initialize();
|
|
|
|
name: 'languages',
|
|
|
|
promise.done(function(){
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
$("#tags").typeahead(
|
|
|
|
return [datum.name];
|
|
|
|
{
|
|
|
|
},
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
queryTokenizer: function(query) {
|
|
|
|
hint: true
|
|
|
|
return [query];
|
|
|
|
}, {
|
|
|
|
},
|
|
|
|
name: 'tags', displayKey: 'name',
|
|
|
|
remote: {
|
|
|
|
source: tag_source
|
|
|
|
url: '/get_languages_json?q=',
|
|
|
|
|
|
|
|
replace: function(url, query) {
|
|
|
|
|
|
|
|
url_query = url+encodeURIComponent(query);
|
|
|
|
|
|
|
|
return url_query;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tokens = query.split(",");
|
|
|
|
function language_source(query, cb) {
|
|
|
|
var current_language = tokens[tokens.length-1].trim();
|
|
|
|
var bh_adapter = languages.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
var tokens = query.split(",");
|
|
|
|
var prefix = "";
|
|
|
|
var current_language = tokens[tokens.length-1].trim();
|
|
|
|
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(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#languages").typeahead(
|
|
|
|
$("#languages").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
hint: true
|
|
|
|
hint: true
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: 'languages', displayKey: 'name',
|
|
|
|
name: 'languages', displayKey: 'name',
|
|
|
|
source: language_source
|
|
|
|
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');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|