|
|
@ -32,7 +32,7 @@ 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 prefixedSource(prefix, query, cb, bhAdapter) {
|
|
|
|
function prefixedSource(prefix, query, cb, bhAdapter) {
|
|
|
|
bhAdapter(query, function(retArray){
|
|
|
|
bhAdapter(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};
|
|
|
@ -41,7 +41,7 @@ function prefixedSource(prefix, query, cb, bhAdapter) {
|
|
|
|
cb(matches);
|
|
|
|
cb(matches);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getPath(){
|
|
|
|
function getPath() {
|
|
|
|
var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file 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
|
|
|
|
jsFileLocation = jsFileLocation.replace("/static/js/edit_books.js", ""); // the js folder path
|
|
|
|
return jsFileLocation;
|
|
|
|
return jsFileLocation;
|
|
|
@ -49,7 +49,7 @@ function getPath(){
|
|
|
|
|
|
|
|
|
|
|
|
var authors = new Bloodhound({
|
|
|
|
var authors = new Bloodhound({
|
|
|
|
name: "authors",
|
|
|
|
name: "authors",
|
|
|
|
datumTokenizer(datum) {
|
|
|
|
datumTokenizer: function datumTokenizer(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
@ -60,15 +60,15 @@ var authors = new Bloodhound({
|
|
|
|
|
|
|
|
|
|
|
|
var series = new Bloodhound({
|
|
|
|
var series = new Bloodhound({
|
|
|
|
name: "series",
|
|
|
|
name: "series",
|
|
|
|
datumTokenizer(datum) {
|
|
|
|
datumTokenizer: function datumTokenizer(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer(query) {
|
|
|
|
queryTokenizer: function queryTokenizer(query) {
|
|
|
|
return [query];
|
|
|
|
return [query];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: getPath()+"/get_series_json?q=",
|
|
|
|
url: getPath()+"/get_series_json?q=",
|
|
|
|
replace(url, query) {
|
|
|
|
replace: function replace(url, query) {
|
|
|
|
return url+encodeURIComponent(query);
|
|
|
|
return url+encodeURIComponent(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,10 +77,10 @@ var series = new Bloodhound({
|
|
|
|
|
|
|
|
|
|
|
|
var tags = new Bloodhound({
|
|
|
|
var tags = new Bloodhound({
|
|
|
|
name: "tags",
|
|
|
|
name: "tags",
|
|
|
|
datumTokenizer(datum) {
|
|
|
|
datumTokenizer: function datumTokenizer(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer(query) {
|
|
|
|
queryTokenizer: function queryTokenizer(query) {
|
|
|
|
var tokens = query.split(",");
|
|
|
|
var tokens = query.split(",");
|
|
|
|
tokens = [tokens[tokens.length-1].trim()];
|
|
|
|
tokens = [tokens[tokens.length-1].trim()];
|
|
|
|
return tokens;
|
|
|
|
return tokens;
|
|
|
@ -92,15 +92,15 @@ var tags = new Bloodhound({
|
|
|
|
|
|
|
|
|
|
|
|
var languages = new Bloodhound({
|
|
|
|
var languages = new Bloodhound({
|
|
|
|
name: "languages",
|
|
|
|
name: "languages",
|
|
|
|
datumTokenizer(datum) {
|
|
|
|
datumTokenizer: function datumTokenizer(datum) {
|
|
|
|
return [datum.name];
|
|
|
|
return [datum.name];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
queryTokenizer(query) {
|
|
|
|
queryTokenizer: function queryTokenizer(query) {
|
|
|
|
return [query];
|
|
|
|
return [query];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
remote: {
|
|
|
|
url: getPath()+"/get_languages_json?q=",
|
|
|
|
url: getPath()+"/get_languages_json?q=",
|
|
|
|
replace(url, query) {
|
|
|
|
replace: function replace(url, query) {
|
|
|
|
return url+encodeURIComponent(query);
|
|
|
|
return url+encodeURIComponent(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,9 +115,9 @@ function sourceSplit(query, cb, split, source) {
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
tokens.splice(tokens.length-1, 1); // remove last element
|
|
|
|
var prefix = "";
|
|
|
|
var prefix = "";
|
|
|
|
var newSplit;
|
|
|
|
var newSplit;
|
|
|
|
if (split === "&"){
|
|
|
|
if (split === "&") {
|
|
|
|
newSplit = " " + split + " ";
|
|
|
|
newSplit = " " + split + " ";
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
newSplit = split + " ";
|
|
|
|
newSplit = split + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
@ -127,7 +127,7 @@ function sourceSplit(query, cb, split, source) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var promiseAuthors = authors.initialize();
|
|
|
|
var promiseAuthors = authors.initialize();
|
|
|
|
promiseAuthors.done(function(){
|
|
|
|
promiseAuthors.done(function() {
|
|
|
|
$("#bookAuthor").typeahead(
|
|
|
|
$("#bookAuthor").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 1,
|
|
|
|
highlight: true, minLength: 1,
|
|
|
@ -135,14 +135,15 @@ var promiseAuthors = authors.initialize();
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: "authors",
|
|
|
|
name: "authors",
|
|
|
|
displayKey: "name",
|
|
|
|
displayKey: "name",
|
|
|
|
source(query, cb){
|
|
|
|
source: function source(query, cb) {
|
|
|
|
return sourceSplit(query, cb, "&", authors); //sourceSplit //("&")
|
|
|
|
return sourceSplit(query, cb, "&", authors); //sourceSplit //("&")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var promiseSeries = series.initialize();
|
|
|
|
var promiseSeries = series.initialize();
|
|
|
|
promiseSeries.done(function(){
|
|
|
|
promiseSeries.done(function() {
|
|
|
|
$("#series").typeahead(
|
|
|
|
$("#series").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
highlight: true, minLength: 0,
|
|
|
@ -156,7 +157,7 @@ var promiseSeries = series.initialize();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var promiseTags = tags.initialize();
|
|
|
|
var promiseTags = tags.initialize();
|
|
|
|
promiseTags.done(function(){
|
|
|
|
promiseTags.done(function() {
|
|
|
|
$("#tags").typeahead(
|
|
|
|
$("#tags").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
highlight: true, minLength: 0,
|
|
|
@ -164,14 +165,15 @@ var promiseTags = tags.initialize();
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: "tags",
|
|
|
|
name: "tags",
|
|
|
|
displayKey: "name",
|
|
|
|
displayKey: "name",
|
|
|
|
source(query, cb){
|
|
|
|
source: function source(query, cb) {
|
|
|
|
return sourceSplit(query, cb, ",", tags);
|
|
|
|
return sourceSplit(query, cb, ",", tags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var promiseLanguages = languages.initialize();
|
|
|
|
var promiseLanguages = languages.initialize();
|
|
|
|
promiseLanguages.done(function(){
|
|
|
|
promiseLanguages.done(function() {
|
|
|
|
$("#languages").typeahead(
|
|
|
|
$("#languages").typeahead(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
highlight: true, minLength: 0,
|
|
|
|
highlight: true, minLength: 0,
|
|
|
@ -179,13 +181,14 @@ var promiseLanguages = languages.initialize();
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
name: "languages",
|
|
|
|
name: "languages",
|
|
|
|
displayKey: "name",
|
|
|
|
displayKey: "name",
|
|
|
|
source(query, cb){
|
|
|
|
source: function source(query, cb) {
|
|
|
|
return sourceSplit(query, cb, ",", languages); //(",")
|
|
|
|
return sourceSplit(query, cb, ",", languages); //(",")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$("#search").on("change input.typeahead:selected", function(){
|
|
|
|
$("#search").on("change input.typeahead:selected", function() {
|
|
|
|
var form = $("form").serialize();
|
|
|
|
var form = $("form").serialize();
|
|
|
|
$.getJSON( getPath()+"/get_matching_tags", form, function( data ) {
|
|
|
|
$.getJSON( getPath()+"/get_matching_tags", form, function( data ) {
|
|
|
|
$(".tags_click").each(function() {
|
|
|
|
$(".tags_click").each(function() {
|
|
|
@ -193,8 +196,7 @@ $("#search").on("change input.typeahead:selected", function(){
|
|
|
|
if (!($(this).hasClass("active"))) {
|
|
|
|
if (!($(this).hasClass("active"))) {
|
|
|
|
$(this).addClass("disabled");
|
|
|
|
$(this).addClass("disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
$(this).removeClass("disabled");
|
|
|
|
$(this).removeClass("disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|