Merge branch 'cc-84-smart-playlist' of dev.sourcefabric.org:airtime into cc-84-smart-playlist
This commit is contained in:
commit
64857410a6
|
@ -34,29 +34,6 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
"year" => "Year"
|
||||
);
|
||||
|
||||
$criteriaTypes = array(
|
||||
|
||||
);
|
||||
|
||||
$stringCriteriaOptions = array(
|
||||
0 => "Select modifier",
|
||||
"contains" => "contains",
|
||||
"does not contain" => "does not contain",
|
||||
"is" => "is",
|
||||
"is not" => "is not",
|
||||
"starts with" => "starts with",
|
||||
"ends with" => "ends with"
|
||||
);
|
||||
|
||||
$numericCriteriaOptions = array(
|
||||
0 => "Select modifier",
|
||||
"is" => "is",
|
||||
"is not" => "is not",
|
||||
"is greater than" => "is greater than",
|
||||
"is less than" => "is less than",
|
||||
"is in the range" => "is in the range"
|
||||
);
|
||||
|
||||
$limitOptions = array(
|
||||
"hours" => "hours",
|
||||
"minutes" => "minutes",
|
||||
|
@ -94,7 +71,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$criteriaModifers->setValue('Select modifier');
|
||||
$criteriaModifers->setAttrib('class', 'input_select');
|
||||
$criteriaModifers->setDecorators(array('viewHelper'));
|
||||
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
|
||||
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
|
||||
if ($i != 0){
|
||||
$criteriaModifers->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
|
|
|
@ -26,11 +26,13 @@
|
|||
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
|
||||
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?>
|
||||
<?php if ($i != 0) { ?>
|
||||
<a href='#' id='criteria_remove_<?php echo $i ?>'>Remove</a>
|
||||
<a href='#' id='criteria_remove_<?php echo $i ?>'>Remove </a>
|
||||
<?php } else { ?>
|
||||
<a href='#' id='criteria_add'>Add</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<a href='#' id='criteria_add'>Add</a>
|
||||
|
||||
</dd>
|
||||
|
||||
<dd id='sp_limit-element'>
|
||||
|
|
|
@ -3,34 +3,77 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
function setSmartPlaylistEvents() {
|
||||
var form = $('#smart-playlist-form');
|
||||
var form = $('#smart-playlist-form');
|
||||
|
||||
form.find('a[id="criteria_add"]').click(function(){
|
||||
var div = $('dd[id="sp_criteria-element"]').children('div:visible:last').next();
|
||||
|
||||
form.find('a[id="criteria_add"]').click(function(){
|
||||
var div = $('dd[id="sp_criteria-element"]').children('div:visible:last').next(),
|
||||
add_button = $(this);
|
||||
|
||||
div.show();
|
||||
div.find('a[id^="criteria_remove"]').after(add_button);
|
||||
div.children().removeAttr('disabled');
|
||||
div = div.next();
|
||||
if(div.length === 0) {
|
||||
if (div.length === 0) {
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
form.find('a[id^="criteria_remove"]').click(function(){
|
||||
form.find('a[id^="criteria_remove"]').click(function(){
|
||||
var curr = $(this).parent();
|
||||
var curr_pos = curr.index();
|
||||
var list = curr.parent();
|
||||
var list_length = list.find("div:visible").length;
|
||||
var count = list_length - curr_pos;
|
||||
var next = curr.next();
|
||||
|
||||
for(var i=0; i<=count; i++) {
|
||||
var add_button = form.find('a[id="criteria_add"]');
|
||||
|
||||
/* assign next row to current row for all rows below and including
|
||||
* the row getting removed
|
||||
*/
|
||||
for (var i=0; i<=count; i++) {
|
||||
var criteria = next.find('[name^="sp_criteria"]').val();
|
||||
curr.find('[name^="sp_criteria"]').val(criteria);
|
||||
var modifier = next.find('[name^="sp_criteria_modifier"]').val();
|
||||
curr.find('[name^="sp_criteria_modifier"]').val(modifier);
|
||||
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
|
||||
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
|
||||
|
||||
/* if current and next row have the extra criteria value
|
||||
* (for 'is in the range' modifier), then assign the next
|
||||
* extra value to current and remove that element from
|
||||
* next row
|
||||
*/
|
||||
if (curr.find('[name^="sp_criteria_extra"]').length > 0
|
||||
&& next.find('[name^="sp_criteria_extra"]').length > 0) {
|
||||
|
||||
var criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
||||
next.find('[name^="sp_criteria_extra"]').remove();
|
||||
next.find('span[id="sp_criteria_extra_label"]').remove();
|
||||
|
||||
/* if only the current row has the extra criteria value,
|
||||
* then just remove the current row's extra criteria element
|
||||
*/
|
||||
} else if (curr.find('[name^="sp_criteria_extra"]').length > 0
|
||||
&& next.find('[name^="sp_criteria_extra"]').length == 0) {
|
||||
curr.find('[name^="sp_criteria_extra"]').remove();
|
||||
curr.find('span[id="sp_criteria_extra_label"]').remove();
|
||||
|
||||
/* if only the next row has the extra criteria value,
|
||||
* then add the extra criteria element to current row
|
||||
* and assign next row's value to it
|
||||
*/
|
||||
} else if (next.find('[name^="sp_criteria_extra"]').length > 0) {
|
||||
var index_name = curr.find('[name^="sp_criteria_value"]').attr('id'),
|
||||
index_num = index_name.charAt(index_name.length-1),
|
||||
criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||
|
||||
curr.find('[name^="sp_criteria_value"]')
|
||||
.after($('<input type="text" class="input_text">')
|
||||
.attr('id', 'sp_criteria_extra_'+index_num)
|
||||
.attr('name', 'sp_criteria_extra_'+index_num)).after('<span id="sp_criteria_extra_label"> to </span>');
|
||||
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
||||
}
|
||||
|
||||
curr = next;
|
||||
next = curr.next();
|
||||
|
@ -44,6 +87,13 @@ function setSmartPlaylistEvents() {
|
|||
.end().hide();
|
||||
|
||||
list.next().show();
|
||||
|
||||
// always put 'add' button on the last row
|
||||
if (list.find('div:visible').length > 1) {
|
||||
list.find('div:visible:last').find('a[id^="criteria_remove"]').after(add_button);
|
||||
} else {
|
||||
list.find('div:visible:last').find('[name^="sp_criteria_value"]').after(add_button);
|
||||
}
|
||||
});
|
||||
|
||||
form.find('button[id="save_button"]').click(function(event){
|
||||
|
@ -104,7 +154,7 @@ function setSmartPlaylistEvents() {
|
|||
|
||||
criteria_value.after($('<input type="text" class="input_text">')
|
||||
.attr('id', 'sp_criteria_extra_'+index_num)
|
||||
.attr('name', 'sp_criteria_extra_'+index_num)).after(' to ');
|
||||
.attr('name', 'sp_criteria_extra_'+index_num)).after('<span id="sp_criteria_extra_label"> to </span>');
|
||||
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue