From 4301a221b75810e153cb5c44626558fd7a2fd7f6 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 10 Jul 2012 18:20:23 -0400 Subject: [PATCH] CC-84: Smart Playlists -added in 'Add' and 'Remove' form elements functionality on the UI --- .../forms/SmartPlaylistCriteria.php | 64 +++++++++---------- .../form/smart-playlist-criteria.phtml | 19 ++++-- .../airtime/library/smart_playlistbuilder.js | 41 +++++++++++- 3 files changed, 80 insertions(+), 44 deletions(-) diff --git a/airtime_mvc/application/forms/SmartPlaylistCriteria.php b/airtime_mvc/application/forms/SmartPlaylistCriteria.php index a635963de..7bfbfc43a 100644 --- a/airtime_mvc/application/forms/SmartPlaylistCriteria.php +++ b/airtime_mvc/application/forms/SmartPlaylistCriteria.php @@ -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); diff --git a/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml index 1a1cd6398..4a9f867a5 100644 --- a/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml @@ -17,14 +17,19 @@
- ids as $id) {?> - element->getElement('sp_criteria_'.$id) ?> - element->getElement('sp_criteria_options_'.$id) ?> - element->getElement('sp_criteria_value_'.$id) ?> - >Remove -
+ criteriasLength; $i++) {?> +
1) && ($this->element->getElement('sp_criteria_'.$i)->getValue() == "0" && + $this->element->getElement('sp_criteria_modifier_'.$i)->getValue() == "0")) { + echo 'style=display:none'; + } ?>> + + element->getElement('sp_criteria_'.$i) ?> + element->getElement('sp_criteria_modifier_'.$i) ?> + element->getElement('sp_criteria_value_'.$i) ?> + Remove +
- Add + Add
diff --git a/airtime_mvc/public/js/airtime/library/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/library/smart_playlistbuilder.js index 45779a655..6336c08e3 100644 --- a/airtime_mvc/public/js/airtime/library/smart_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/library/smart_playlistbuilder.js @@ -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(); + } }); -} \ No newline at end of file + 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(); + }); + +}