mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 17:59:21 +02:00
Fix advanced search with jQuery and fix #34
This commit is contained in:
parent
deb8155b54
commit
24f8cf36c6
4 changed files with 65 additions and 47 deletions
|
@ -273,6 +273,15 @@ class Search extends playlist_object
|
|||
);
|
||||
}
|
||||
|
||||
if (Config::get('show_played_times')) {
|
||||
$this->types[] = array(
|
||||
'name' => 'played_times',
|
||||
'label' => T_('# Played'),
|
||||
'type' => 'numeric',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
}
|
||||
|
||||
$this->types[] = array(
|
||||
'name' => 'bitrate',
|
||||
'label' => T_('Bitrate'),
|
||||
|
@ -987,6 +996,11 @@ class Search extends playlist_object
|
|||
case 'rating':
|
||||
$where[] = "COALESCE(`rating`.`rating`,0) $sql_match_operator '$input'";
|
||||
$join['rating'] = true;
|
||||
case 'played_times':
|
||||
$where[] = "`song`.`id` IN (SELECT `object_count`.`object_id` FROM `object_count` " .
|
||||
"WHERE `object_count`.`object_type` = 'song'" .
|
||||
"GROUP BY `object_count`.`object_id` HAVING COUNT(*) $sql_match_operator '$input')";
|
||||
break;
|
||||
break;
|
||||
case 'catalog':
|
||||
$where[] = "`song`.`catalog` $sql_match_operator '$input'";
|
||||
|
@ -1019,7 +1033,7 @@ class Search extends playlist_object
|
|||
} // switch on type
|
||||
} // foreach over rules
|
||||
|
||||
$where_sql = implode(" $sql_logic_operator ", $where);
|
||||
$where_sql = implode(" $sql_logic_operator ", $where) . $group;
|
||||
|
||||
// now that we know which things we want to JOIN...
|
||||
if ($join['artist']) {
|
||||
|
|
|
@ -44,8 +44,8 @@ Header('content-type: application/x-javascript');
|
|||
|
||||
$search = new Search($_REQUEST['type']);
|
||||
|
||||
echo 'var types = $H(\'';
|
||||
echo arrayToJSON($search->types) . "'.evalJSON());\n";
|
||||
echo 'var basetypes = $H(\'';
|
||||
echo arrayToJSON($search->basetypes) . "'.evalJSON());\n";
|
||||
echo 'var types = ';
|
||||
echo arrayToJSON($search->types) . ";\n";
|
||||
echo 'var basetypes = ';
|
||||
echo arrayToJSON($search->basetypes) . ";\n";
|
||||
echo 'removeIcon = \'<a href="javascript: void(0)">' . UI::get_icon('disable', T_('Remove')) . '</a>\';';
|
||||
|
|
|
@ -26,10 +26,10 @@ var SearchRow = {
|
|||
ruleType = 0;
|
||||
}
|
||||
else {
|
||||
types.each(function(i) {
|
||||
if (i.value.name == ruleType) {
|
||||
ruleType = i.key;
|
||||
throw $break;
|
||||
jQuery.each(types, function(i) {
|
||||
if (types[i].name == ruleType) {
|
||||
ruleType = i;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -38,13 +38,16 @@ var SearchRow = {
|
|||
operator = 0;
|
||||
}
|
||||
else {
|
||||
$H(basetypes.get(types.get(ruleType).type)).each(function(i) {
|
||||
if (i.value.name == operator) {
|
||||
operator = i.key;
|
||||
throw $break;
|
||||
if (ruleType != null) {
|
||||
var opts = basetypes[types[ruleType].type];
|
||||
jQuery.each(opts, function(i) {
|
||||
if (opts[i].name == operator) {
|
||||
operator = i;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var row = document.createElement('tr');
|
||||
var cells = new Array();
|
||||
|
@ -57,14 +60,14 @@ var SearchRow = {
|
|||
cells[2].appendChild(SearchRow.constructInput(ruleType, rowIter, input));
|
||||
cells[3].innerHTML = removeIcon;
|
||||
|
||||
cells.each(function(i) {
|
||||
row.appendChild(i);
|
||||
jQuery.each(cells, function(i) {
|
||||
row.appendChild(cells[i]);
|
||||
});
|
||||
|
||||
$('searchtable').appendChild(row);
|
||||
$('#searchtable').append(row);
|
||||
rowCount++;
|
||||
|
||||
$(cells[3]).on('click', function(){if(rowCount > 1) { Element.remove(this.parentNode); rowCount--; }});
|
||||
$(cells[3]).on('click', function(){if(rowCount > 1) { this.parentNode.remove(); rowCount--; }});
|
||||
|
||||
rowIter++;
|
||||
},
|
||||
|
@ -73,31 +76,31 @@ var SearchRow = {
|
|||
input = '';
|
||||
}
|
||||
|
||||
widget = $H(types.get(ruleType).widget);
|
||||
widget = types[ruleType].widget;
|
||||
|
||||
var inputNode = document.createElement(widget.get('0'));
|
||||
var inputNode = document.createElement(widget['0']);
|
||||
inputNode.id = 'rule_' + ruleNumber + '_input';
|
||||
inputNode.name = 'rule_' + ruleNumber + '_input';
|
||||
|
||||
switch(widget.get('0')) {
|
||||
switch(widget['0']) {
|
||||
case 'input':
|
||||
inputNode.setAttribute('type', widget.get('1'));
|
||||
inputNode.setAttribute('type', widget['1']);
|
||||
inputNode.setAttribute('value', input);
|
||||
break;
|
||||
case 'select':
|
||||
$H(widget.get('1')).each(function(i) {
|
||||
jQuery.each(widget['1'], function(i) {
|
||||
var option = document.createElement('option');
|
||||
if ( isNaN(parseInt(i.value)) ) {
|
||||
realvalue = i.key;
|
||||
if ( isNaN(parseInt(widget['1'][i])) ) {
|
||||
realvalue = i;
|
||||
}
|
||||
else {
|
||||
realvalue = parseInt(i.value);
|
||||
realvalue = parseInt(widget['1'][i]);
|
||||
}
|
||||
if ( input == realvalue ) {
|
||||
option.selected = true;
|
||||
}
|
||||
option.value = realvalue;
|
||||
option.innerHTML = i.value;
|
||||
option.innerHTML = widget['1'][i];
|
||||
inputNode.appendChild(option);
|
||||
});
|
||||
break;
|
||||
|
@ -110,11 +113,11 @@ var SearchRow = {
|
|||
optionsNode.id = 'rule_' + ruleNumber;
|
||||
optionsNode.name = 'rule_' + ruleNumber;
|
||||
|
||||
types.each(function(i) {
|
||||
jQuery.each(types, function(i) {
|
||||
var option = document.createElement('option');
|
||||
option.innerHTML = i.value.label;
|
||||
option.value = i.value.name;
|
||||
if ( i.key == ruleType ) {
|
||||
option.innerHTML = types[i].label;
|
||||
option.value = types[i].name;
|
||||
if ( i == ruleType ) {
|
||||
option.selected = true;
|
||||
}
|
||||
optionsNode.appendChild(option);
|
||||
|
@ -129,14 +132,15 @@ var SearchRow = {
|
|||
operatorNode.id = 'rule_' + ruleNumber + '_operator';
|
||||
operatorNode.name = 'rule_' + ruleNumber + '_operator';
|
||||
|
||||
basetype = types.get(ruleType).type;
|
||||
basetype = types[ruleType].type;
|
||||
operatorNode.className = 'operator' + basetype;
|
||||
|
||||
$H(basetypes.get(basetype)).each(function(i) {
|
||||
var opts = basetypes[basetype];
|
||||
jQuery.each(opts, function(i) {
|
||||
var option = document.createElement('option');
|
||||
option.innerHTML = i.value.description;
|
||||
option.value = i.key;
|
||||
if (i.key == operator) {
|
||||
option.innerHTML = opts[i].description;
|
||||
option.value = i;
|
||||
if (i == operator) {
|
||||
option.selected = true;
|
||||
}
|
||||
operatorNode.appendChild(option);
|
||||
|
@ -148,21 +152,21 @@ var SearchRow = {
|
|||
var r_findID = /rule_(\d+)/;
|
||||
var targetID = r_findID.exec(this.id)[1];
|
||||
|
||||
var operator = $('rule_' + targetID + '_operator');
|
||||
if (operator.className != 'operator' + types.get(this.selectedIndex).type) {
|
||||
var operator_cell = operator.parentNode;
|
||||
Element.remove(operator);
|
||||
operator_cell.appendChild(SearchRow.constructOperators(this.selectedIndex, targetID));
|
||||
var operator = $('#rule_' + targetID + '_operator');
|
||||
if (operator.className != 'operator' + types[this.selectedIndex].type) {
|
||||
var operator_cell = operator.parent();
|
||||
operator.remove();
|
||||
operator_cell.append(SearchRow.constructOperators(this.selectedIndex, targetID));
|
||||
}
|
||||
|
||||
var input = $('rule_' + targetID + '_input');
|
||||
var input = $('#rule_' + targetID + '_input');
|
||||
|
||||
if (input.type == 'text') {
|
||||
var oldinput = input.value;
|
||||
}
|
||||
|
||||
var input_cell = input.parentNode;
|
||||
Element.remove(input);
|
||||
input_cell.appendChild(SearchRow.constructInput(this.selectedIndex, targetID, oldinput));
|
||||
var input_cell = input.parent();
|
||||
input.remove();
|
||||
input_cell.append(SearchRow.constructInput(this.selectedIndex, targetID, oldinput));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ $logic_operator = strtolower($logic_operator);
|
|||
<?php echo UI::get_icon('add'); ?>
|
||||
<?php echo T_('Add Another Rule'); ?>
|
||||
</a>
|
||||
<script type="text/javascript">$('addrowbutton').click(SearchRow.add);</script>
|
||||
<script type="text/javascript">$('#addrowbutton').on('click', SearchRow.add);</script>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue