CC-84: Smart Playlists
- temp commit
This commit is contained in:
parent
55fd4e5d50
commit
207582eb7e
5 changed files with 84 additions and 36 deletions
|
@ -78,6 +78,7 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
|
|
||||||
$form = new Application_Form_SmartPlaylistCriteria();
|
$form = new Application_Form_SmartPlaylistCriteria();
|
||||||
$form->removeDecorator('DtDdWrapper');
|
$form->removeDecorator('DtDdWrapper');
|
||||||
|
$form->loadCriteria($pl->getId());
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
|
|
||||||
$this->view->pl = $pl;
|
$this->view->pl = $pl;
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
||||||
|
|
||||||
$numElements = count($criteriaOptions);
|
$numElements = count($criteriaOptions);
|
||||||
for ($i = 0; $i < $numElements; $i++) {
|
for ($i = 0; $i < $numElements; $i++) {
|
||||||
$criteria = new Zend_Form_Element_Select('sp_criteria_'.$i);
|
$criteria = new Zend_Form_Element_Select('sp_criteria_field_'.$i);
|
||||||
$criteria->setAttrib('class', 'input_select');
|
$criteria->setAttrib('class', 'input_select');
|
||||||
$criteria->setValue('Select criteria');
|
$criteria->setValue('Select criteria');
|
||||||
$criteria->setDecorators(array('viewHelper'));
|
$criteria->setDecorators(array('viewHelper'));
|
||||||
|
@ -84,6 +84,12 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
||||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||||
}
|
}
|
||||||
$this->addElement($criteriaValue);
|
$this->addElement($criteriaValue);
|
||||||
|
|
||||||
|
$criteriaExtra = new Zend_Form_Element_Text('sp_criteria_extra_'.$i);
|
||||||
|
$criteriaExtra->setAttrib('class', 'input_text');
|
||||||
|
$criteriaExtra->setDecorators(array('viewHelper'));
|
||||||
|
$criteriaExtra->setAttrib('disabled', 'disabled');
|
||||||
|
$this->addElement($criteriaExtra);
|
||||||
}
|
}
|
||||||
|
|
||||||
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
||||||
|
@ -104,4 +110,31 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
||||||
$save->setLabel('Generate');
|
$save->setLabel('Generate');
|
||||||
$this->addElement($save);
|
$this->addElement($save);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadCriteria($p_playlistId)
|
||||||
|
{
|
||||||
|
$c = new Criteria();
|
||||||
|
$c->add(CcPlaylistcriteriaPeer::PLAYLIST_ID, $p_playlistId);
|
||||||
|
$out = CcPlaylistcriteriaPeer::doSelect($c);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
foreach ($out as $crit) {
|
||||||
|
$criteria = $crit->getDbCriteria();
|
||||||
|
$modifier = $crit->getDbModifier();
|
||||||
|
$value = $crit->getDbValue();
|
||||||
|
$extra = $crit->getDbExtra();
|
||||||
|
|
||||||
|
if($criteria == "limit"){
|
||||||
|
$this->getElement("sp_limit_options")->setValue($modifier);
|
||||||
|
$this->getElement("sp_limit_value")->setValue($value);
|
||||||
|
}else{
|
||||||
|
$this->getElement("sp_criteria_$i")->setValue($criteria);
|
||||||
|
$this->getElement("sp_criteria_modifier_$i")->setValue($criteria);
|
||||||
|
$this->getElement("sp_criteria_value_$i")->setValue($criteria);
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logging::log($out);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -880,10 +880,8 @@ class Application_Model_Playlist {
|
||||||
if (count($error) > 0){
|
if (count($error) > 0){
|
||||||
$errors[] = array("element"=>"sp_limit_value", "msg"=>$error);
|
$errors[] = array("element"=>"sp_limit_value", "msg"=>$error);
|
||||||
}
|
}
|
||||||
Logging::log($errors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging::log($errors);
|
|
||||||
// format validation
|
// format validation
|
||||||
foreach ($data['criteria'] as $key=>$d){
|
foreach ($data['criteria'] as $key=>$d){
|
||||||
$error = array();
|
$error = array();
|
||||||
|
@ -921,7 +919,6 @@ class Application_Model_Playlist {
|
||||||
|
|
||||||
public static function storeCriteriaIntoDb($p_criteriaData, $p_playlistId){
|
public static function storeCriteriaIntoDb($p_criteriaData, $p_playlistId){
|
||||||
// delete criteria under $p_playlistId
|
// delete criteria under $p_playlistId
|
||||||
Logging::log($p_criteriaData);
|
|
||||||
$deleteCrit = new Criteria();
|
$deleteCrit = new Criteria();
|
||||||
$deleteCrit->add(CcPlaylistcriteriaPeer::PLAYLIST_ID, $p_playlistId);
|
$deleteCrit->add(CcPlaylistcriteriaPeer::PLAYLIST_ID, $p_playlistId);
|
||||||
CcPlaylistcriteriaPeer::doDelete($deleteCrit);
|
CcPlaylistcriteriaPeer::doDelete($deleteCrit);
|
||||||
|
@ -964,7 +961,6 @@ class Application_Model_Playlist {
|
||||||
public static function generateSmartPlaylist($p_criteria, $p_playlistId)
|
public static function generateSmartPlaylist($p_criteria, $p_playlistId)
|
||||||
{
|
{
|
||||||
$result = self::saveSmartPlaylistCriteria($p_criteria, $p_playlistId);
|
$result = self::saveSmartPlaylistCriteria($p_criteria, $p_playlistId);
|
||||||
Logging::log($result);
|
|
||||||
if ($result['result'] != 0) {
|
if ($result['result'] != 0) {
|
||||||
return $result;
|
return $result;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
|
|
||||||
<dd id='sp_criteria-element'>
|
<dd id='sp_criteria-element'>
|
||||||
<?php for ($i = 0; $i < $this->criteriasLength; $i++) {?>
|
<?php for ($i = 0; $i < $this->criteriasLength; $i++) {?>
|
||||||
<div <?php if (($i > 0) && ($this->element->getElement('sp_criteria_'.$i)->getAttrib('disabled') == 'disabled')) {
|
<div <?php if (($i > 0) && ($this->element->getElement('sp_criteria_field_'.$i)->getAttrib('disabled') == 'disabled')) {
|
||||||
echo 'style=display:none';
|
echo 'style=display:none';
|
||||||
} ?>>
|
} ?>>
|
||||||
|
|
||||||
<?php echo $this->element->getElement('sp_criteria_'.$i) ?>
|
<?php echo $this->element->getElement('sp_criteria_field_'.$i) ?>
|
||||||
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
|
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
|
||||||
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?>
|
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?><span id="extra_criteria" style="display:none;"> to <?php echo $this->element->getElement('sp_criteria_extra_'.$i) ?></span>
|
||||||
<?php if ($i != 0) { ?>
|
<?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 { ?>
|
<?php } else { ?>
|
||||||
|
|
|
@ -37,51 +37,54 @@ function setSmartPlaylistEvents() {
|
||||||
/* assign next row to current row for all rows below and including
|
/* assign next row to current row for all rows below and including
|
||||||
* the row getting removed
|
* the row getting removed
|
||||||
*/
|
*/
|
||||||
for (var i=0; i<=count; i++) {
|
for (var i=0; i<count; i++) {
|
||||||
var criteria = next.find('[name^="sp_criteria"]').val();
|
var criteria = next.find('[name^="sp_criteria_field"]').val();
|
||||||
curr.find('[name^="sp_criteria"]').val(criteria);
|
curr.find('[name^="sp_criteria_field"]').val(criteria);
|
||||||
|
|
||||||
var modifier = next.find('[name^="sp_criteria_modifier"]').val();
|
var modifier = next.find('[name^="sp_criteria_modifier"]').val();
|
||||||
populateModifierSelect(curr.find('[name^="sp_criteria"]'));
|
populateModifierSelect(curr.find('[name^="sp_criteria_field"]'));
|
||||||
curr.find('[name^="sp_criteria_modifier"]').val(modifier);
|
curr.find('[name^="sp_criteria_modifier"]').val(modifier);
|
||||||
|
|
||||||
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
|
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
|
||||||
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
|
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
|
||||||
|
|
||||||
|
var id = curr.find('[name^="sp_criteria"]').attr('id');
|
||||||
|
var index = id.charAt(id.length-1);
|
||||||
/* if current and next row have the extra criteria value
|
/* if current and next row have the extra criteria value
|
||||||
* (for 'is in the range' modifier), then assign the next
|
* (for 'is in the range' modifier), then assign the next
|
||||||
* extra value to current and remove that element from
|
* extra value to current and remove that element from
|
||||||
* next row
|
* next row
|
||||||
*/
|
*/
|
||||||
if (curr.find('[name^="sp_criteria_extra"]').length > 0
|
if (curr.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled"
|
||||||
&& next.find('[name^="sp_criteria_extra"]').length > 0) {
|
&& next.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled") {
|
||||||
|
|
||||||
var criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
var criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||||
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
||||||
next.find('[name^="sp_criteria_extra"]').remove();
|
disableAndHideExtraField(next.find(':first-child'), index+1);
|
||||||
next.find('span[id="sp_criteria_extra_label"]').remove();
|
/*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,
|
/* if only the current row has the extra criteria value,
|
||||||
* then just remove the current row's extra criteria element
|
* then just remove the current row's extra criteria element
|
||||||
*/
|
*/
|
||||||
} else if (curr.find('[name^="sp_criteria_extra"]').length > 0
|
} else if (curr.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled"
|
||||||
&& next.find('[name^="sp_criteria_extra"]').length == 0) {
|
&& next.find('[name^="sp_criteria_extra"]').attr("disabled") == "disabled") {
|
||||||
curr.find('[name^="sp_criteria_extra"]').remove();
|
disableAndHideExtraField(curr.find(':first-child'), index);
|
||||||
curr.find('span[id="sp_criteria_extra_label"]').remove();
|
/*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,
|
/* if only the next row has the extra criteria value,
|
||||||
* then add the extra criteria element to current row
|
* then add the extra criteria element to current row
|
||||||
* and assign next row's value to it
|
* and assign next row's value to it
|
||||||
*/
|
*/
|
||||||
} else if (next.find('[name^="sp_criteria_extra"]').length > 0) {
|
} else if (next.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled") {
|
||||||
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();
|
criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||||
|
enableAndShowExtraField(curr.find(':first-child'), index);
|
||||||
curr.find('[name^="sp_criteria_value"]')
|
/*curr.find('[name^="sp_criteria_value"]')
|
||||||
.after($('<input type="text" class="input_text">')
|
.after($('<input type="text" class="input_text">')
|
||||||
.attr('id', 'sp_criteria_extra_'+index_num)
|
.attr('id', 'sp_criteria_extra_'+index_num)
|
||||||
.attr('name', 'sp_criteria_extra_'+index_num)).after('<span id="sp_criteria_extra_label"> to </span>');
|
.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.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,13 +139,16 @@ function setSmartPlaylistEvents() {
|
||||||
$('button[id="save_button"]').text(button_text);
|
$('button[id="save_button"]').text(button_text);
|
||||||
});
|
});
|
||||||
|
|
||||||
form.find('select[id^="sp_criteria"]').live("change", function(){
|
form.find('select[id^="sp_criteria"]:not([id^="sp_criteria_modifier"])').live("change", function(){
|
||||||
var index_name = $(this).attr('id'),
|
var index_name = $(this).attr('id'),
|
||||||
index_num = index_name.charAt(index_name.length-1);
|
index_num = index_name.charAt(index_name.length-1);
|
||||||
if ($('#sp_criteria_extra_'+index_num).length > 0) {
|
|
||||||
|
// disalbe extra field and hide the span
|
||||||
|
disableAndHideExtraField($(this), index_num);
|
||||||
|
/*if ($('#sp_criteria_extra_'+index_num).length > 0) {
|
||||||
$('#sp_criteria_extra_'+index_num).remove();
|
$('#sp_criteria_extra_'+index_num).remove();
|
||||||
$('#sp_criteria_extra_label_'+index_num).remove();
|
$('#sp_criteria_extra_label_'+index_num).remove();
|
||||||
}
|
}*/
|
||||||
populateModifierSelect(this);
|
populateModifierSelect(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -152,20 +158,34 @@ function setSmartPlaylistEvents() {
|
||||||
index_num = index_name.charAt(index_name.length-1);
|
index_num = index_name.charAt(index_name.length-1);
|
||||||
|
|
||||||
if ($(this).val() == 'is in the range') {
|
if ($(this).val() == 'is in the range') {
|
||||||
criteria_value.after($('<input type="text" class="input_text">')
|
enableAndShowExtraField(criteria_value, index_num);
|
||||||
|
/*after($('<input type="text" class="input_text">')
|
||||||
.attr('id', 'sp_criteria_extra_'+index_num)
|
.attr('id', 'sp_criteria_extra_'+index_num)
|
||||||
.attr('name', 'sp_criteria_extra_'+index_num)).after('<span id="sp_criteria_extra_label_'+index_num+'"> to </span>');
|
.attr('name', 'sp_criteria_extra_'+index_num)).after('<span id="sp_criteria_extra_label_'+index_num+'"> to </span>');*/
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ($('#sp_criteria_extra_'+index_num).length > 0) {
|
disableAndHideExtraField(criteria_value, index_num);
|
||||||
|
/*if ($('#sp_criteria_extra_'+index_num).length > 0) {
|
||||||
$('#sp_criteria_extra_'+index_num).remove();
|
$('#sp_criteria_extra_'+index_num).remove();
|
||||||
$('#sp_criteria_extra_label_'+index_num).remove();
|
$('#sp_criteria_extra_label_'+index_num).remove();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableAndShowExtraField(valEle, index) {
|
||||||
|
var spanExtra = valEle.nextAll("#extra_criteria");
|
||||||
|
spanExtra.children('#sp_criteria_extra_'+index).removeAttr("disabled");
|
||||||
|
spanExtra.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableAndHideExtraField(valEle, index) {
|
||||||
|
var spanExtra = valEle.nextAll("#extra_criteria");
|
||||||
|
spanExtra.children('#sp_criteria_extra_'+index).val("").attr("disabled", "disabled");
|
||||||
|
spanExtra.hide();
|
||||||
|
}
|
||||||
|
|
||||||
function populateModifierSelect(e) {
|
function populateModifierSelect(e) {
|
||||||
var criteria = $(e).val(),
|
var criteria = $(e).val(),
|
||||||
criteria_type = criteriaTypes[criteria],
|
criteria_type = criteriaTypes[criteria],
|
||||||
|
@ -194,7 +214,6 @@ function staticCallback(data) {
|
||||||
form.find(' span[id="sp-errors"]').remove();
|
form.find(' span[id="sp-errors"]').remove();
|
||||||
var json = $.parseJSON(data);
|
var json = $.parseJSON(data);
|
||||||
if (json.result == "1") {
|
if (json.result == "1") {
|
||||||
var error_element;
|
|
||||||
$.each(json.errors, function(index, error){
|
$.each(json.errors, function(index, error){
|
||||||
$.each(error.msg, function(index, message){
|
$.each(error.msg, function(index, message){
|
||||||
$('#'+error.element).parent().append("<span class='sp-errors'>"+message+"</span><span id='sp-errors'><br /></span>");
|
$('#'+error.element).parent().append("<span class='sp-errors'>"+message+"</span><span id='sp-errors'><br /></span>");
|
||||||
|
@ -206,7 +225,6 @@ function staticCallback(data) {
|
||||||
function dynamicCallback(json) {
|
function dynamicCallback(json) {
|
||||||
var json = $.parseJSON(data);
|
var json = $.parseJSON(data);
|
||||||
if (json.result == "1") {
|
if (json.result == "1") {
|
||||||
var error_element;
|
|
||||||
$.each(json.errors, function(index, error){
|
$.each(json.errors, function(index, error){
|
||||||
$.each(error.msg, function(index, message){
|
$.each(error.msg, function(index, message){
|
||||||
$('#'+error.element).parent().append("<span class='errors'>"+message+"<br /></span>");
|
$('#'+error.element).parent().append("<span class='errors'>"+message+"<br /></span>");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue