CC-84: Smart Playlists
- code cleanup - adds 'Add' button to last row, always
This commit is contained in:
parent
601263b7a0
commit
2dae5f30f7
|
@ -129,7 +129,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
for ($i = 0; $i < $numElements; $i++) {
|
||||
$criteriaType = "";
|
||||
$criteria = new Zend_Form_Element_Select('sp_criteria_field_'.$i);
|
||||
$criteria->setAttrib('class', 'input_select')
|
||||
$criteria->setAttrib('class', 'input_select sp_input_select')
|
||||
->setValue('Select criteria')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($criteriaOptions);
|
||||
|
@ -144,7 +144,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
|
||||
$criteriaModifers = new Zend_Form_Element_Select('sp_criteria_modifier_'.$i);
|
||||
$criteriaModifers->setValue('Select modifier')
|
||||
->setAttrib('class', 'input_select')
|
||||
->setAttrib('class', 'input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if ($i != 0 && !isset($storedCrit["crit"][$i])){
|
||||
$criteriaModifers->setAttrib('disabled', 'disabled');
|
||||
|
@ -162,7 +162,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$this->addElement($criteriaModifers);
|
||||
|
||||
$criteriaValue = new Zend_Form_Element_Text('sp_criteria_value_'.$i);
|
||||
$criteriaValue->setAttrib('class', 'input_text')
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if ($i != 0 && !isset($storedCrit["crit"][$i])){
|
||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||
|
@ -173,10 +173,11 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$this->addElement($criteriaValue);
|
||||
|
||||
$criteriaExtra = new Zend_Form_Element_Text('sp_criteria_extra_'.$i);
|
||||
$criteriaExtra->setAttrib('class', 'input_text')
|
||||
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if (isset($storedCrit["crit"][$i]["extra"])) {
|
||||
$criteriaExtra->setValue($storedCrit["crit"][$i]["extra"]);
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
|
||||
}else{
|
||||
$criteriaExtra->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
|
@ -189,8 +190,6 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$limit->setMultiOptions($limitOptions);
|
||||
if (isset($storedCrit["limit"])) {
|
||||
$limit->setValue($storedCrit["limit"]["modifier"]);
|
||||
}else{
|
||||
$limit->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
$this->addElement($limit);
|
||||
|
||||
|
@ -201,8 +200,6 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$this->addElement($limitValue);
|
||||
if (isset($storedCrit["limit"])) {
|
||||
$limitValue->setValue($storedCrit["limit"]["value"]);
|
||||
}else{
|
||||
$limitValue->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
|
||||
$save = new Zend_Form_Element_Button('save_button');
|
||||
|
@ -212,29 +209,5 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
$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"){
|
||||
Zend_Form::getElement("sp_limit_options")->setValue($modifier);
|
||||
Zend_Form::getElement("sp_limit_value")->setValue($value);
|
||||
}else{
|
||||
Zend_Form::getElement("sp_criteria_$i")->setValue($criteria);
|
||||
Zend_Form::getElement("sp_criteria_modifier_$i")->setValue($criteria);
|
||||
Zend_Form::getElement("sp_criteria_value_$i")->setValue($criteria);
|
||||
Zend_Form::getElement("sp_criteria_extra_$i")->setValue($criteria);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -870,11 +870,11 @@ class Application_Model_Playlist {
|
|||
}
|
||||
if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
|
||||
if ( $data['etc']['sp_limit_value'] == "" || intval($data['etc']['sp_limit_value']) == 0) {
|
||||
$error[] = "Litmit cannot be empty or 0";
|
||||
$error[] = "Limit cannot be empty or 0";
|
||||
} else {
|
||||
$mins = $data['etc']['sp_limit_value'] * $multiplier;
|
||||
if ($mins > 14400) {
|
||||
$error[] = "Litmit cannot be more than 24 hrs";
|
||||
$error[] = "Limit cannot be more than 24 hrs";
|
||||
}
|
||||
}
|
||||
if (count($error) > 0){
|
||||
|
@ -886,11 +886,11 @@ class Application_Model_Playlist {
|
|||
foreach ($data['criteria'] as $key=>$d){
|
||||
$error = array();
|
||||
// check for not selected select box
|
||||
if ($d['sp_criteria'] == "0" || $d['sp_criteria_modifier'] == "0"){
|
||||
if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0"){
|
||||
$error[] = "You must select Criteria and Modifier";
|
||||
} else {
|
||||
// we need to take care 'length' specially since the column type is varchar
|
||||
if ($d['sp_criteria'] == 'length') {
|
||||
if ($d['sp_criteria_field'] == 'length') {
|
||||
if (!preg_match("/(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
|
||||
$error[] = "'Length' should be in '00:00:00' format";
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ class Application_Model_Playlist {
|
|||
$c = new Criteria();
|
||||
|
||||
foreach ($p_data as $criteria) {
|
||||
$spCriteria = self::$criteria2PeerMap[$criteria['sp_criteria']];
|
||||
$spCriteria = self::$criteria2PeerMap[$criteria['sp_criteria_field']];
|
||||
$spCriteriaModifier = $criteria['sp_criteria_modifier'];
|
||||
$spCriteriaValue = $criteria['sp_criteria_value'];
|
||||
if ($spCriteriaModifier == "starts with") {
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?><span id="extra_criteria" <?php echo $this->element->getElement('sp_criteria_extra_'.$i)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to <?php echo $this->element->getElement('sp_criteria_extra_'.$i) ?></span>
|
||||
<?php if ($i != 0) { ?>
|
||||
<a href='#' id='criteria_remove_<?php echo $i ?>'>Remove </a>
|
||||
<?php } else { ?>
|
||||
<a href='#' id='criteria_add' class='criteria_add'>Add</a>
|
||||
<?php } ?>
|
||||
<br />
|
||||
</div>
|
||||
|
|
|
@ -416,6 +416,18 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus, .input_t
|
|||
padding: 2px 2px 2px 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
.sp_input_select{
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
input.input_text.sp_input_text{
|
||||
width: 200px !important;
|
||||
}
|
||||
|
||||
input.input_text.sp_extra_input_text{
|
||||
width: 85px !important;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size:13px;
|
||||
color:#5b5b5b;
|
||||
|
@ -1409,7 +1421,7 @@ div.success{
|
|||
border:1px solid #488214;
|
||||
}
|
||||
|
||||
div.errors{
|
||||
div.errors, span.errors{
|
||||
color:#902d2d;
|
||||
font-size:11px;
|
||||
padding:2px 4px;
|
||||
|
@ -1418,14 +1430,9 @@ div.errors{
|
|||
border:1px solid #c83f3f;
|
||||
}
|
||||
|
||||
span.sp-errors{
|
||||
color:#902d2d;
|
||||
font-size:11px;
|
||||
padding:2px 4px;
|
||||
background:#c6b4b4;
|
||||
margin-bottom:2px;
|
||||
border:1px solid #c83f3f;
|
||||
span.errors.sp-errors{
|
||||
width: 400px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.collapsible-header, .collapsible-header-disabled {
|
||||
|
|
|
@ -320,6 +320,8 @@ var AIRTIME = (function(AIRTIME){
|
|||
.append(json.html);
|
||||
|
||||
setUpPlaylist();
|
||||
var form = $('#smart-playlist-form');
|
||||
appendAddButton(form);
|
||||
}
|
||||
|
||||
//sets events dynamically for playlist entries (each row in the playlist)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
$(document).ready(function() {
|
||||
setSmartPlaylistEvents();
|
||||
var form = $('#smart-playlist-form');
|
||||
appendAddButton(form);
|
||||
});
|
||||
|
||||
function setSmartPlaylistEvents() {
|
||||
|
@ -26,6 +28,7 @@ function setSmartPlaylistEvents() {
|
|||
var count = list_length - curr_pos;
|
||||
var next = curr.next();
|
||||
var add_button = form.find('a[id="criteria_add"]');
|
||||
var item_to_hide;
|
||||
|
||||
//remove error message from current row, if any
|
||||
var error_element = curr.find('span[class="errors sp-errors"]');
|
||||
|
@ -60,9 +63,6 @@ function setSmartPlaylistEvents() {
|
|||
var criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
|
||||
disableAndHideExtraField(next.find(':first-child'), index+1);
|
||||
/*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,
|
||||
* then just remove the current row's extra criteria element
|
||||
|
@ -70,8 +70,6 @@ function setSmartPlaylistEvents() {
|
|||
} else if (curr.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled"
|
||||
&& next.find('[name^="sp_criteria_extra"]').attr("disabled") == "disabled") {
|
||||
disableAndHideExtraField(curr.find(':first-child'), index);
|
||||
/*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,
|
||||
* then add the extra criteria element to current row
|
||||
|
@ -80,10 +78,6 @@ function setSmartPlaylistEvents() {
|
|||
} else if (next.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled") {
|
||||
criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
|
||||
enableAndShowExtraField(curr.find(':first-child'), index);
|
||||
/*curr.find('[name^="sp_criteria_value"]')
|
||||
.after($('<input type="text" class="input_text">')
|
||||
.attr('id', 'sp_criteria_extra_'+index_num)
|
||||
.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);
|
||||
}
|
||||
|
||||
|
@ -91,27 +85,27 @@ function setSmartPlaylistEvents() {
|
|||
next = curr.next();
|
||||
}
|
||||
|
||||
list.find('div:visible:last').children().attr('disabled', 'disabled');
|
||||
list.find('div:visible:last')
|
||||
.find('[name^="sp_criteria"]').val(0).end()
|
||||
.find('[name^="sp_criteria_modifier"]').val(0).end()
|
||||
.find('[name^="sp_criteria_value"]').val('');
|
||||
/* Disable the last visible row since it holds the values the user removed
|
||||
* Reset the values to empty and resize the criteria value textbox
|
||||
* in case the row had the extra criteria textbox
|
||||
*/
|
||||
item_to_hide = list.find('div:visible:last');
|
||||
item_to_hide.children().attr('disabled', 'disabled');
|
||||
item_to_hide.find('[name^="sp_criteria_field"]').val(0).end()
|
||||
.find('[name^="sp_criteria_modifier"]').val(0).end()
|
||||
.find('[name^="sp_criteria_value"]').val('');
|
||||
|
||||
if (list.find('div:visible:last').children().hasClass('criteria_add')) {
|
||||
list.find('div:visible:last').find('.criteria_add').remove();
|
||||
if (item_to_hide.children().hasClass('criteria_add')) {
|
||||
item_to_hide.find('.criteria_add').remove();
|
||||
}
|
||||
list.find('div:visible:last').hide();
|
||||
|
||||
sizeTextBoxes(item_to_hide.find('[name^="sp_criteria_value"]'), 'sp_extra_input_text', 'sp_input_text');
|
||||
item_to_hide.hide();
|
||||
|
||||
list.next().show();
|
||||
|
||||
// always put 'add' button on the last row
|
||||
if (list.find('div:visible').length > 1) {
|
||||
list.find('div:visible:last').find('a[id^="criteria_remove"]')
|
||||
.after("<a href='#' id='criteria_add' class='criteria_add'>Add</a>");
|
||||
} else {
|
||||
list.find('div:visible:last').find('[name^="sp_criteria_value"]')
|
||||
.after("<a href='#' id='criteria_add' class='criteria_add'>Add</a>");
|
||||
}
|
||||
appendAddButton(list);
|
||||
});
|
||||
|
||||
form.find('button[id="save_button"]').live("click", function(event){
|
||||
|
@ -148,12 +142,8 @@ function setSmartPlaylistEvents() {
|
|||
var index_name = $(this).attr('id'),
|
||||
index_num = index_name.charAt(index_name.length-1);
|
||||
|
||||
// disalbe extra field and hide the span
|
||||
// disable 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_label_'+index_num).remove();
|
||||
}*/
|
||||
populateModifierSelect(this);
|
||||
});
|
||||
|
||||
|
@ -164,16 +154,8 @@ function setSmartPlaylistEvents() {
|
|||
|
||||
if ($(this).val() == 'is in the range') {
|
||||
enableAndShowExtraField(criteria_value, index_num);
|
||||
/*after($('<input type="text" class="input_text">')
|
||||
.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>');*/
|
||||
|
||||
} else {
|
||||
disableAndHideExtraField(criteria_value, index_num);
|
||||
/*if ($('#sp_criteria_extra_'+index_num).length > 0) {
|
||||
$('#sp_criteria_extra_'+index_num).remove();
|
||||
$('#sp_criteria_extra_label_'+index_num).remove();
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -183,12 +165,26 @@ function enableAndShowExtraField(valEle, index) {
|
|||
var spanExtra = valEle.nextAll("#extra_criteria");
|
||||
spanExtra.children('#sp_criteria_extra_'+index).removeAttr("disabled");
|
||||
spanExtra.show();
|
||||
|
||||
//make value input smaller since we have extra element now
|
||||
var criteria_val = $('#sp_criteria_value_'+index);
|
||||
sizeTextBoxes(criteria_val, 'sp_input_text', 'sp_extra_input_text');
|
||||
}
|
||||
|
||||
function disableAndHideExtraField(valEle, index) {
|
||||
var spanExtra = valEle.nextAll("#extra_criteria");
|
||||
spanExtra.children('#sp_criteria_extra_'+index).val("").attr("disabled", "disabled");
|
||||
spanExtra.hide();
|
||||
|
||||
//make value input larger because we don't have extra field now
|
||||
var criteria_value = $('#sp_criteria_value_'+index);
|
||||
sizeTextBoxes(criteria_value, 'sp_extra_input_text', 'sp_input_text');
|
||||
}
|
||||
|
||||
function sizeTextBoxes(ele, classToRemove, classToAdd) {
|
||||
if (ele.hasClass(classToRemove)) {
|
||||
ele.removeClass(classToRemove).addClass(classToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
function populateModifierSelect(e) {
|
||||
|
@ -239,6 +235,20 @@ function dynamicCallback(json) {
|
|||
}
|
||||
}
|
||||
|
||||
function appendAddButton(rows) {
|
||||
var add_button = "<a href='#' id='criteria_add' class='criteria_add'>Add</a>";
|
||||
|
||||
if (rows.find('select[name^="sp_criteria_field"]:enabled').length > 1) {
|
||||
rows.find('select[name^="sp_criteria_field"]:enabled:last')
|
||||
.siblings('a[id^="criteria_remove"]')
|
||||
.after(add_button);
|
||||
} else {
|
||||
rows.find('select[name^="sp_criteria_field"]:enabled')
|
||||
.siblings('[name^="sp_criteria_value"]')
|
||||
.after(add_button);
|
||||
}
|
||||
}
|
||||
|
||||
var criteriaTypes = {
|
||||
0 : "",
|
||||
"album_title" : "s",
|
||||
|
|
Loading…
Reference in New Issue