|
|
@ -2,11 +2,11 @@
|
|
|
|
* 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++) {
|
|
|
@ -15,20 +15,25 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cb(matches);
|
|
|
|
cb(matches);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_path(){
|
|
|
|
var authors = new Bloodhound({
|
|
|
|
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',
|
|
|
|
name: 'authors',
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: '/get_authors_json?q=%QUERY'
|
|
|
|
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("&");
|
|
|
@ -42,11 +47,11 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -57,9 +62,9 @@
|
|
|
|
source: authors_source
|
|
|
|
source: authors_source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var series = new Bloodhound({
|
|
|
|
var series = new Bloodhound({
|
|
|
|
name: 'series',
|
|
|
|
name: 'series',
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
@ -68,14 +73,14 @@
|
|
|
|
return [query];
|
|
|
|
return [query];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: '/get_series_json?q=',
|
|
|
|
url: get_path()+'/get_series_json?q=',
|
|
|
|
replace: function(url, query) {
|
|
|
|
replace: function(url, query) {
|
|
|
|
url_query = url+encodeURIComponent(query);
|
|
|
|
url_query = url+encodeURIComponent(query);
|
|
|
|
return url_query;
|
|
|
|
return url_query;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var promise = series.initialize();
|
|
|
|
var promise = series.initialize();
|
|
|
|
promise.done(function(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#series").typeahead(
|
|
|
|
$("#series").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -86,9 +91,9 @@
|
|
|
|
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];
|
|
|
@ -99,11 +104,11 @@
|
|
|
|
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) {
|
|
|
|
function tag_source(query, cb) {
|
|
|
|
var bh_adapter = tags.ttAdapter();
|
|
|
|
var bh_adapter = tags.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
var tokens = query.split(",");
|
|
|
|
var tokens = query.split(",");
|
|
|
@ -117,9 +122,9 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prefixed_source(prefix, current_tag, cb, bh_adapter);
|
|
|
|
prefixed_source(prefix, current_tag, cb, bh_adapter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var promise = tags.initialize();
|
|
|
|
var promise = tags.initialize();
|
|
|
|
promise.done(function(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#tags").typeahead(
|
|
|
|
$("#tags").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -130,9 +135,9 @@
|
|
|
|
source: tag_source
|
|
|
|
source: tag_source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var languages = new Bloodhound({
|
|
|
|
var languages = new Bloodhound({
|
|
|
|
name: 'languages',
|
|
|
|
name: 'languages',
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
datumTokenizer: function(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
@ -141,15 +146,15 @@
|
|
|
|
return [query];
|
|
|
|
return [query];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: '/get_languages_json?q=',
|
|
|
|
url: get_path()+'/get_languages_json?q=',
|
|
|
|
replace: function(url, query) {
|
|
|
|
replace: function(url, query) {
|
|
|
|
url_query = url+encodeURIComponent(query);
|
|
|
|
url_query = url+encodeURIComponent(query);
|
|
|
|
return url_query;
|
|
|
|
return url_query;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function language_source(query, cb) {
|
|
|
|
function language_source(query, cb) {
|
|
|
|
var bh_adapter = languages.ttAdapter();
|
|
|
|
var bh_adapter = languages.ttAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
var tokens = query.split(",");
|
|
|
|
var tokens = query.split(",");
|
|
|
@ -163,9 +168,9 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prefixed_source(prefix, current_language, cb, bh_adapter);
|
|
|
|
prefixed_source(prefix, current_language, cb, bh_adapter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var promise = languages.initialize();
|
|
|
|
var promise = languages.initialize();
|
|
|
|
promise.done(function(){
|
|
|
|
promise.done(function(){
|
|
|
|
$("#languages").typeahead(
|
|
|
|
$("#languages").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -176,4 +181,20 @@
|
|
|
|
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');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|