CC-84: Smart Playlists
-added in save/generate functionality in the UI
This commit is contained in:
parent
4bed5e647e
commit
1afe1e4d32
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -41,6 +41,10 @@
|
|||
</label>
|
||||
</dd>
|
||||
|
||||
<dd id='sp_save'>
|
||||
<?php echo $this->element->getElement('save_button') ?>
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</fieldset>
|
||||
</form>
|
|
@ -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() {
|
||||
|
||||
}
|
Loading…
Reference in New Issue