From 1afe1e4d32b6f68a176803c85c3af17bee3e31a3 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 11 Jul 2012 11:50:40 -0400 Subject: [PATCH] CC-84: Smart Playlists -added in save/generate functionality in the UI --- .../forms/SmartPlaylistCriteria.php | 10 ++- .../form/smart-playlist-criteria.phtml | 4 + .../airtime/playlist/smart_playlistbuilder.js | 84 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js diff --git a/airtime_mvc/application/forms/SmartPlaylistCriteria.php b/airtime_mvc/application/forms/SmartPlaylistCriteria.php index 7bfbfc43a..3ff51a60e 100644 --- a/airtime_mvc/application/forms/SmartPlaylistCriteria.php +++ b/airtime_mvc/application/forms/SmartPlaylistCriteria.php @@ -69,8 +69,8 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm $spType->setLabel('Set smart playlist type:'); $spType->setDecorators(array('viewHelper')); $spType->setMultiOptions(array( - 'Static', - 'Dynamic' + 'static' => 'Static', + 'dynamic' => 'Dynamic' )); $spType->setValue('Static'); $this->addElement($spType); @@ -113,5 +113,11 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm $limitValue->setAttrib('class', 'input_text'); $limitValue->setDecorators(array('viewHelper')); $this->addElement($limitValue); + + $save = new Zend_Form_Element_Button('save_button'); + $save->setAttrib('class', 'ui-button ui-state-default right-floated'); + $save->setIgnore(true); + $save->setLabel('Save'); + $this->addElement($save); } } \ No newline at end of file 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 6bd922203..8d5978d28 100644 --- a/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-playlist-criteria.phtml @@ -41,6 +41,10 @@ +
+ element->getElement('save_button') ?> +
+ \ No newline at end of file diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js new file mode 100644 index 000000000..329e0d856 --- /dev/null +++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js @@ -0,0 +1,84 @@ +$(document).ready(function() { + setSmartPlaylistEvents(); +}); + +function setSmartPlaylistEvents() { + 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(); + + 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(); + }); + + form.find('button[id="save_button"]').click(function(event){ + var playlist_type = form.find('input:radio[name=sp_type]:checked').val(), + data = $('form').serializeArray(), + static_action = 'Playlist/smart-playlist-criteria-save', + dynamic_action ='Playlist/smart-playlist-criteria-generate', + action, + callback; + + if (playlist_type == "0") { + action = static_action; + callback = staticCallback; + } else { + action = dynamic_action; + callback = dynamicCallback; + } + $.post(action, {format: "json", data: data}, callback); + }); + + form.find('dd[id="sp_type-element"]').change(function(){ + var playlist_type = $('input:radio[name=sp_type]:checked').val(), + button_text; + if (playlist_type == "0") { + button_text = 'Save'; + } else { + button_text = 'Generate'; + } + $('button[id="save_button"]').text(button_text); + }); + +} + +function staticCallback() { + +} + +function dynamicCallback() { + +} \ No newline at end of file