CC-84: Smart Playlists
-added in 'Add' and 'Remove' form elements functionality on the UI
This commit is contained in:
parent
72dd48e33e
commit
4301a221b7
|
@ -3,13 +3,6 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
{
|
||||
public function init()
|
||||
{
|
||||
//temporary solution
|
||||
//get criteria ids
|
||||
$ids = array(1,2,3);
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', 'ids' => $ids))
|
||||
));
|
||||
|
||||
$criteriaOptions = array(
|
||||
0 => "Select criteria",
|
||||
|
@ -43,20 +36,22 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
);
|
||||
|
||||
$stringCriteriaOptions = array(
|
||||
"contains",
|
||||
"does not contain",
|
||||
"is",
|
||||
"is not",
|
||||
"starts with",
|
||||
"ends with"
|
||||
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(
|
||||
"is",
|
||||
"is not",
|
||||
"is greater than",
|
||||
"is less than",
|
||||
"is in the range"
|
||||
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(
|
||||
|
@ -64,6 +59,11 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
"minutes",
|
||||
"items"
|
||||
);
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml',
|
||||
'criteriasLength' => count($criteriaOptions)))
|
||||
));
|
||||
|
||||
$spType = new Zend_Form_Element_Radio('sp_type');
|
||||
$spType->setLabel('Set smart playlist type:');
|
||||
|
@ -75,27 +75,23 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$spType->setValue('Static');
|
||||
$this->addElement($spType);
|
||||
|
||||
foreach($ids as $id) {
|
||||
$criteria = new Zend_Form_Element_Select('sp_criteria_'.$id);
|
||||
$criteria->setAttrib('id', $id);
|
||||
$numElements = count($criteriaOptions);
|
||||
for($i = 1; $i <= $numElements; $i++) {
|
||||
$criteria = new Zend_Form_Element_Select('sp_criteria_'.$i);
|
||||
$criteria->setAttrib('class', 'input_select');
|
||||
$criteria->setValue(0);
|
||||
$criteria->setDecorators(array('viewHelper'));
|
||||
$criteria->setMultiOptions($criteriaOptions);
|
||||
$this->addElement($criteria);
|
||||
}
|
||||
|
||||
$criteriaModifers = new Zend_Form_Element_Select('sp_criteria_modifier_'.$i);
|
||||
$criteriaModifers->setValue(0);
|
||||
$criteriaModifers->setAttrib('class', 'input_select');
|
||||
$criteriaModifers->setDecorators(array('viewHelper'));
|
||||
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
|
||||
$this->addElement($criteriaModifers);
|
||||
|
||||
foreach($ids as $id) {
|
||||
$criteriaOptions = new Zend_Form_Element_Select('sp_criteria_options_'.$id);
|
||||
$criteriaOptions->setAttrib('id', $id);
|
||||
$criteriaOptions->setAttrib('class', 'input_select');
|
||||
$criteriaOptions->setDecorators(array('viewHelper'));
|
||||
$criteriaOptions->setMultiOptions($stringCriteriaOptions);
|
||||
$this->addElement($criteriaOptions);
|
||||
}
|
||||
|
||||
foreach($ids as $id) {
|
||||
$criteriaValue = new Zend_Form_Element_Text('sp_criteria_value_'.$id);
|
||||
$criteriaValue->setAttrib('id', $id);
|
||||
$criteriaValue = new Zend_Form_Element_Text('sp_criteria_value_'.$i);
|
||||
$criteriaValue->setAttrib('class', 'input_text');
|
||||
$criteriaValue->setDecorators(array('viewHelper'));
|
||||
$this->addElement($criteriaValue);
|
||||
|
|
|
@ -17,14 +17,19 @@
|
|||
</dd>
|
||||
|
||||
<dd id='sp_criteria-element'>
|
||||
<?php foreach($this->ids as $id) {?>
|
||||
<?php echo $this->element->getElement('sp_criteria_'.$id) ?>
|
||||
<?php echo $this->element->getElement('sp_criteria_options_'.$id) ?>
|
||||
<?php echo $this->element->getElement('sp_criteria_value_'.$id) ?>
|
||||
<a href='#' class='criteria-remove' id=<?php echo $id ?>>Remove</a>
|
||||
<br />
|
||||
<?php for($i = 1; $i <= $this->criteriasLength; $i++) {?>
|
||||
<div <?php if(($i > 1) && ($this->element->getElement('sp_criteria_'.$i)->getValue() == "0" &&
|
||||
$this->element->getElement('sp_criteria_modifier_'.$i)->getValue() == "0")) {
|
||||
echo 'style=display:none';
|
||||
} ?>>
|
||||
|
||||
<?php echo $this->element->getElement('sp_criteria_'.$i) ?>
|
||||
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
|
||||
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?>
|
||||
<a href='#' id='criteria_remove_<?php echo $i ?>'>Remove</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<a href='#' class='criteria-add'>Add</a>
|
||||
<a href='#' id='criteria_add'>Add</a>
|
||||
</dd>
|
||||
|
||||
<dd id='sp_limit-element'>
|
||||
|
|
|
@ -5,8 +5,43 @@ $(document).ready(function() {
|
|||
function setSmartPlaylistEvents() {
|
||||
var form = $('#smart-playlist-form');
|
||||
|
||||
form.find('a[class="criteria-add"]').click(function(){
|
||||
|
||||
form.find('a[id="criteria_add"]').click(function(){
|
||||
var div = $('dd[id="sp_criteria-element"]').children('div:visible:last').next();
|
||||
|
||||
div.show();
|
||||
div = div.next();
|
||||
if(div.length === 0) {
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
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 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);
|
||||
|
||||
curr = next;
|
||||
next = curr.next();
|
||||
}
|
||||
|
||||
list.find("div:visible:last")
|
||||
.find('[name^="sp_criteria"]').val('').end()
|
||||
.find('[name^="sp_criteria_modifier"]').val('').end()
|
||||
.find('[name^="sp_criteria_value"]').val('')
|
||||
.end().hide();
|
||||
|
||||
list.next().show();
|
||||
});
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue