basic autocomplete support for metatags

This commit is contained in:
Daku 2016-06-19 10:07:56 +01:00
parent 03240220d4
commit f973fcc9fa
2 changed files with 38 additions and 13 deletions

View File

@ -1,16 +1,36 @@
$(function(){ $(function(){
var metatags = ['order:id', 'order:width', 'order:height', 'order:filesize', 'order:filename'];
$('[name=search]').tagit({ $('[name=search]').tagit({
singleFieldDelimiter: ' ', singleFieldDelimiter: ' ',
beforeTagAdded: function(event, ui) { beforeTagAdded: function(event, ui) {
if(metatags.indexOf(ui.tagLabel) !== -1) {
ui.tag.addClass('tag-metatag');
} else {
console.log(ui.tagLabel);
// give special class to negative tags // give special class to negative tags
if(ui.tagLabel[0] === '-') { if(ui.tagLabel[0] === '-') {
ui.tag.addClass('tag-negative'); ui.tag.addClass('tag-negative');
}else{ }else{
ui.tag.addClass('tag-positive'); ui.tag.addClass('tag-positive');
} }
}
}, },
autocomplete : ({ autocomplete : ({
source: function (request, response) { source: function (request, response) {
var ac_metatags = $.map(
$.grep(metatags, function(s) {
// Only show metatags for strings longer than one character
return (request.term.length > 1 && s.indexOf(request.term) === 0);
}),
function(item) {
return {
label : item + ' [metatag]',
value : item
};
}
);
var isNegative = (request.term[0] === '-'); var isNegative = (request.term[0] === '-');
$.ajax({ $.ajax({
url: base_href + '/api/internal/autocomplete', url: base_href + '/api/internal/autocomplete',
@ -18,13 +38,17 @@ $(function(){
dataType : 'json', dataType : 'json',
type : 'GET', type : 'GET',
success : function (data) { success : function (data) {
response($.map(data, function (count, item) { response(
$.merge(ac_metatags,
$.map(data, function (count, item) {
item = (isNegative ? '-'+item : item); item = (isNegative ? '-'+item : item);
return { return {
label : item + ' ('+count+')', label : item + ' ('+count+')',
value : item value : item
}; };
})); })
)
);
}, },
error : function (request, status, error) { error : function (request, status, error) {
alert(error); alert(error);

View File

@ -6,3 +6,4 @@ input[name=search] ~ input[type=submit] { display: inline-block !important; }
.tag-negative { background: #ff8080 !important; } .tag-negative { background: #ff8080 !important; }
.tag-positive { background: #40bf40 !important; } .tag-positive { background: #40bf40 !important; }
.tag-metatag { background: #eaa338 !important; }