1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-04 10:19:25 +02:00

[FEATURE] #280 Add possibility to search for metadata

This commit is contained in:
René Bigler 2015-01-10 00:19:45 +01:00
parent af03777cc8
commit 7ee67d721e
2 changed files with 90 additions and 32 deletions

View file

@ -1,4 +1,4 @@
// vim:set softtabstop=4 shiftwidth=4 expandtab:
// vim:set softtabstop=4 shiftwidth=4 expandtab:
//
// Copyright 2010 - 2015 Ampache.org
// All rights reserved.
@ -6,7 +6,7 @@
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License v2
// as published by the Free Software Foundation.
//
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -21,7 +21,7 @@ var rowIter = 1;
var rowCount = 0;
var SearchRow = {
add: function(ruleType, operator, input) {
add: function (ruleType, operator, input, subtype) {
if (typeof(ruleType) != 'string') {
ruleType = 0;
}
@ -54,8 +54,12 @@ var SearchRow = {
for (var i = 0 ; i < 5 ; i++) {
cells[i] = document.createElement('td');
}
cells[0].appendChild(SearchRow.constructOptions(ruleType, rowIter));
var select = SearchRow.createSubtypeOptions(ruleType, rowIter, subtype);
if (select) {
cells[0].appendChild(select);
}
cells[1].appendChild(SearchRow.constructOperators(ruleType, rowIter, operator));
cells[2].appendChild(SearchRow.constructInput(ruleType, rowIter, input));
cells[3].innerHTML = removeIcon;
@ -70,7 +74,7 @@ var SearchRow = {
$(cells[3]).on('click', function(){if(rowCount > 1) { this.parentNode.remove(); rowCount--; }});
rowIter++;
},
},
constructInput: function(ruleType, ruleNumber, input) {
if (input === null || input === undefined) {
input = '';
@ -86,7 +90,7 @@ var SearchRow = {
case 'input':
inputNode.setAttribute('type', widget['1']);
inputNode.setAttribute('value', input);
break;
break;
case 'select':
jQuery.each(widget['1'], function(i) {
var option = document.createElement('option');
@ -103,7 +107,14 @@ var SearchRow = {
option.innerHTML = widget['1'][i];
inputNode.appendChild(option);
});
break;
break;
case 'subtypes':
inputNode = document.createElement(widget[1][0]);
inputNode.id = 'rule_' + ruleNumber + '_input';
inputNode.name = 'rule_' + ruleNumber + '_input';
inputNode.setAttribute('type', widget[1][1]);
inputNode.setAttribute('value', input);
break;
}
return inputNode;
@ -159,8 +170,26 @@ var SearchRow = {
operator_cell.append(SearchRow.constructOperators(this.selectedIndex, targetID));
}
var input = $('#rule_' + targetID + '_input');
var type = $(this).val();
jQuery.each(types, function (index, value) {
if (value.name == type) {
type = value
return false;
}
});
if (type['widget'][0] == 'subtypes') {
var $select = SearchRow.createSelect({
name: 'rule_' + targetID + '_subtype'
}, type['subtypes']);
$(this).after($select);
}
else {
$(this).closest('tr').find('select[name="subtype"]').remove();
}
var input = $('#rule_' + targetID + '_input');
if (input.type == 'text') {
var oldinput = input.value;
}
@ -168,5 +197,28 @@ var SearchRow = {
var input_cell = input.parent();
input.remove();
input_cell.append(SearchRow.constructInput(this.selectedIndex, targetID, oldinput));
}
},
createSelect: function (attributes, options, selected) {
var $select = $('<select>');
$.each(attributes, function (key, value) {
$select.attr(key, value);
});
$.each(options, function (key, value) {
$('<option>').attr('value', key).text(value).appendTo($select);
});
$select.val(selected);
return $select;
},
createSubtypeOptions: function (ruleType, ruleNumber, subtype) {
var type = types[ruleType];
var input;
if (type['widget'][0] == 'subtypes') {
var $input = SearchRow.createSelect({
name: 'rule_' + ruleNumber + '_subtype'
}, type['subtypes'], subtype);
return $input[0];
}
}
};