Track Type Select Menu in Smartblock
This commit is contained in:
parent
339fddf652
commit
00e860183a
|
@ -141,6 +141,14 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
|
||||||
$view->headScript()->appendScript("var COMPANY_NAME = '" . COMPANY_NAME . "';");
|
$view->headScript()->appendScript("var COMPANY_NAME = '" . COMPANY_NAME . "';");
|
||||||
//Each page refresh or tab open has uniqID, not to be used for security
|
//Each page refresh or tab open has uniqID, not to be used for security
|
||||||
$view->headScript()->appendScript("var UNIQID = '" . uniqid() . "';");
|
$view->headScript()->appendScript("var UNIQID = '" . uniqid() . "';");
|
||||||
|
|
||||||
|
$track_type_options = array();
|
||||||
|
$track_types = Application_Model_Tracktype::getTracktypes();
|
||||||
|
foreach ($track_types as $key => $tt) {
|
||||||
|
$track_type_options[$tt['code']] = $tt['type_name'];
|
||||||
|
}
|
||||||
|
$ttarr = json_encode($track_type_options, JSON_FORCE_OBJECT);
|
||||||
|
$view->headScript()->appendScript("var TRACKTYPES = " . $ttarr . ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _initHeadLink()
|
protected function _initHeadLink()
|
||||||
|
|
|
@ -8,6 +8,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
private $timePeriodCriteriaOptions;
|
private $timePeriodCriteriaOptions;
|
||||||
private $sortOptions;
|
private $sortOptions;
|
||||||
private $limitOptions;
|
private $limitOptions;
|
||||||
|
private $isOrNotCriteriaOptions;
|
||||||
|
private $trackTypeOptions;
|
||||||
|
|
||||||
/* We need to know if the criteria value will be a string
|
/* We need to know if the criteria value will be a string
|
||||||
* or numeric value in order to populate the modifier
|
* or numeric value in order to populate the modifier
|
||||||
|
@ -43,7 +45,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
"track_number" => "n",
|
"track_number" => "n",
|
||||||
"info_url" => "s",
|
"info_url" => "s",
|
||||||
"year" => "n",
|
"year" => "n",
|
||||||
"track_type" => "s"
|
"track_type" => "tt"
|
||||||
);
|
);
|
||||||
|
|
||||||
private function getCriteriaOptions($option = null)
|
private function getCriteriaOptions($option = null)
|
||||||
|
@ -174,13 +176,36 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
"random" => _("Randomly"),
|
"random" => _("Randomly"),
|
||||||
"newest" => _("Newest"),
|
"newest" => _("Newest"),
|
||||||
"oldest" => _("Oldest"),
|
"oldest" => _("Oldest"),
|
||||||
"mostrecentplay" => ("Most recently played"),
|
"mostrecentplay" => _("Most recently played"),
|
||||||
"leastrecentplay" => ("Least recently played")
|
"leastrecentplay" => _("Least recently played")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $this->sortOptions;
|
return $this->sortOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getIsNotOptions()
|
||||||
|
{
|
||||||
|
if (!isset($this->isOrNotCriteriaOptions)) {
|
||||||
|
$this->isOrNotCriteriaOptions = array(
|
||||||
|
"0" => _("Select modifier"),
|
||||||
|
"is" => _("is"),
|
||||||
|
"is not" => _("is not")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $this->isOrNotCriteriaOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTracktypeOptions()
|
||||||
|
{
|
||||||
|
if (!isset($this->trackTypeOptions)) {
|
||||||
|
$tracktypes = Application_Model_Tracktype::getTracktypes();
|
||||||
|
$names[] = _("Select Track Type");
|
||||||
|
foreach($tracktypes as $arr => $a){
|
||||||
|
$names[$a["code"]] = $tracktypes[$arr]["type_name"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
@ -339,6 +364,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
||||||
} elseif ($criteriaType == "d") {
|
} elseif ($criteriaType == "d") {
|
||||||
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||||
|
} elseif ($criteriaType == "tt") {
|
||||||
|
$criteriaModifers->setMultiOptions($this->getIsNotOptions());
|
||||||
} else {
|
} else {
|
||||||
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
||||||
}
|
}
|
||||||
|
@ -350,11 +377,33 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
|
|
||||||
/****************** VALUE ***********/
|
/****************** VALUE ***********/
|
||||||
/* The challenge here is that datetime */
|
/* The challenge here is that datetime */
|
||||||
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
|
if (isset($criteriaKeys[$i])) {
|
||||||
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
|
||||||
->setDecorators(array('viewHelper'));
|
if (isset($criteriaType) && $criteriaType == "tt" &&
|
||||||
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
preg_match('/is|is not/', $modifierTest) == 1) {
|
||||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
|
||||||
|
$criteriaValue = new Zend_Form_Element_Select("sp_criteria_value_" . $i . "_" . $j);
|
||||||
|
$criteriaValue->setAttrib('class', 'input_select sp_input_select')->setDecorators(array('viewHelper'));
|
||||||
|
|
||||||
|
if (isset($criteriaKeys[$i]) ) { //do if $relativeTT above
|
||||||
|
$criteriaValue->setAttrib('enabled', 'enabled');
|
||||||
|
} else {
|
||||||
|
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
|
||||||
|
$criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
|
||||||
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||||
|
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
|
||||||
|
$criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
|
||||||
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||||
|
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($criteriaKeys[$i])) {
|
if (isset($criteriaKeys[$i])) {
|
||||||
/*
|
/*
|
||||||
|
@ -367,8 +416,24 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
preg_match('/before|after|between/', $modifierTest) == 1) {
|
preg_match('/before|after|between/', $modifierTest) == 1) {
|
||||||
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
||||||
$relativeDateTime = true;
|
$relativeDateTime = true;
|
||||||
// the criteria value will be a number followed by time unit and ago so set input to number part
|
|
||||||
$criteriaValue->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"], FILTER_SANITIZE_NUMBER_INT));
|
$criteriaValue->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"], FILTER_SANITIZE_NUMBER_INT));
|
||||||
|
} elseif (isset($criteriaType) && $criteriaType == "tt" &&
|
||||||
|
preg_match('/is|is not/', $modifierTest) == 1) {
|
||||||
|
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
||||||
|
$relativeDateTime = false;
|
||||||
|
|
||||||
|
$tracktypeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||||
|
$tracktypeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $tracktypeSelectValue));
|
||||||
|
$criteriaValue->setMultiOptions($this->getTracktypeOptions());
|
||||||
|
|
||||||
|
if ($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]){
|
||||||
|
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||||
|
} else {
|
||||||
|
$criteriaValue->setMultiOptions(array('0' => _('Select track type')));
|
||||||
|
$criteriaValue->setMultiOptions($this->getTracktypeOptions());
|
||||||
|
$criteriaValue->setValue($tracktypeSelectValue);
|
||||||
|
}
|
||||||
|
$criteriaValue->setAttrib('enabled', 'enabled');
|
||||||
} else {
|
} else {
|
||||||
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||||
}
|
}
|
||||||
|
@ -554,6 +619,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
$eleMod->setMultiOptions($this->getNumericCriteriaOptions());
|
$eleMod->setMultiOptions($this->getNumericCriteriaOptions());
|
||||||
} elseif ($criteriaType == "d") {
|
} elseif ($criteriaType == "d") {
|
||||||
$eleMod->setMultiOptions($this->getDateTimeCriteriaOptions());
|
$eleMod->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||||
|
} elseif ($criteriaType == "tt") {
|
||||||
|
$eleMod->setMultiOptions($this->getIsNotOptions());
|
||||||
} else {
|
} else {
|
||||||
$eleMod->setMultiOptions(array('0' => _('Select modifier')));
|
$eleMod->setMultiOptions(array('0' => _('Select modifier')));
|
||||||
}
|
}
|
||||||
|
@ -613,6 +680,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||||
}
|
}
|
||||||
elseif ($criteriaType == "d") {
|
elseif ($criteriaType == "d") {
|
||||||
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||||
|
} elseif ($criteriaType == "tt") {
|
||||||
|
$criteriaModifers->setMultiOptions($this->getIsNotOptions());
|
||||||
} else {
|
} else {
|
||||||
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,7 +339,20 @@ function setSmartBlockEvents() {
|
||||||
disableAndHideExtraField($(this), index);
|
disableAndHideExtraField($(this), index);
|
||||||
disableAndHideDateTimeDropdown($(this), index);
|
disableAndHideDateTimeDropdown($(this), index);
|
||||||
disableAndHideExtraDateTimeDropdown($(this),index);
|
disableAndHideExtraDateTimeDropdown($(this),index);
|
||||||
populateModifierSelect(this, true);
|
|
||||||
|
// disable extra field and hide the span
|
||||||
|
disableAndHideExtraField($(this), index);
|
||||||
|
disableAndHideDateTimeDropdown($(this), index);
|
||||||
|
disableAndHideExtraDateTimeDropdown($(this),index);
|
||||||
|
|
||||||
|
if ($( "#sp_criteria_field_" + index +" option:selected" ).val() === 'track_type') {
|
||||||
|
//console.log("Track Type is set);
|
||||||
|
populateTracktypeSelect(this, false);
|
||||||
|
} else {
|
||||||
|
//console.log("Track Type is not set");
|
||||||
|
populateModifierSelect(this, true);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/********** MODIFIER CHANGE **********/
|
/********** MODIFIER CHANGE **********/
|
||||||
|
@ -370,6 +383,30 @@ function setSmartBlockEvents() {
|
||||||
else {
|
else {
|
||||||
disableAndHideExtraDateTimeDropdown(criteria_value,index_num);
|
disableAndHideExtraDateTimeDropdown(criteria_value,index_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var get_crit_field = $(this).siblings(':first-child');
|
||||||
|
var crit_field = get_crit_field[0]["id"];
|
||||||
|
if ($( "#" + crit_field +" option:selected" ).val() === 'track_type') {
|
||||||
|
|
||||||
|
if ($(this).val() == "is" || $(this).val() == "is not") {
|
||||||
|
console.log("Criteria is set to Track Type, Modifier uses (stringIsNotOptions)");
|
||||||
|
enableAndShowTracktypeDropdown(criteria_value, index_num);
|
||||||
|
} else {
|
||||||
|
console.log("Criteria is set to Track Type, Modifier not using (stringIsNotOptions)");
|
||||||
|
disableAndHideTracktypeDropdown(criteria_value, index_num);
|
||||||
|
}
|
||||||
|
//populateTracktypeSelect(this, true);
|
||||||
|
}
|
||||||
|
if ($( "#" + crit_field +" option:selected" ).val() !== 'track_type') {
|
||||||
|
//disableAndHideTracktypeDropdown(criteria_value, index_num);
|
||||||
|
//populateTracktypeSelect(this, false);
|
||||||
|
console.log("Criteria is not set to Track Type");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/********** VALUE CHANGE (if value field is a select menu) **********/
|
||||||
|
form.find('select[id^="sp_criteria_value"]').live("change", function(){
|
||||||
|
console.log("VALUE CHANGED");
|
||||||
});
|
});
|
||||||
|
|
||||||
setupUI();
|
setupUI();
|
||||||
|
@ -451,6 +488,8 @@ function reindexElements() {
|
||||||
$(div).find('select[name^="sp_criteria_modifier"]').attr('id', 'sp_criteria_modifier_'+index+'_'+modIndex);
|
$(div).find('select[name^="sp_criteria_modifier"]').attr('id', 'sp_criteria_modifier_'+index+'_'+modIndex);
|
||||||
$(div).find('input[name^="sp_criteria_value"]').attr('name', 'sp_criteria_value_'+index+'_'+modIndex);
|
$(div).find('input[name^="sp_criteria_value"]').attr('name', 'sp_criteria_value_'+index+'_'+modIndex);
|
||||||
$(div).find('input[name^="sp_criteria_value"]').attr('id', 'sp_criteria_value_'+index+'_'+modIndex);
|
$(div).find('input[name^="sp_criteria_value"]').attr('id', 'sp_criteria_value_'+index+'_'+modIndex);
|
||||||
|
$(div).find('select[name^="sp_criteria_value"]').attr('name', 'sp_criteria_value_'+index+'_'+modIndex);
|
||||||
|
$(div).find('select[name^="sp_criteria_value"]').attr('id', 'sp_criteria_value_'+index+'_'+modIndex);
|
||||||
$(div).find('input[name^="sp_criteria_extra"]').attr('name', 'sp_criteria_extra_'+index+'_'+modIndex);
|
$(div).find('input[name^="sp_criteria_extra"]').attr('name', 'sp_criteria_extra_'+index+'_'+modIndex);
|
||||||
$(div).find('input[name^="sp_criteria_extra"]').attr('id', 'sp_criteria_extra_'+index+'_'+modIndex);
|
$(div).find('input[name^="sp_criteria_extra"]').attr('id', 'sp_criteria_extra_'+index+'_'+modIndex);
|
||||||
$(div).find('a[name^="modifier_add"]').attr('id', 'modifier_add_'+index);
|
$(div).find('a[name^="modifier_add"]').attr('id', 'modifier_add_'+index);
|
||||||
|
@ -586,6 +625,19 @@ function setupUI() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableAndShowTracktypeDropdown(valEle, index) {
|
||||||
|
//console.log("enable tracktype:"+index);
|
||||||
|
$("#sp_criteria_value_"+index).replaceWith('<select name="sp_criteria_value_'+index+'" id="sp_criteria_value_'+index+'" class="input_select sp_input_select"></select>');
|
||||||
|
$.each(stringTracktypeOptions, function(key, value){
|
||||||
|
$("#sp_criteria_value_"+index).append($('<option></option>').attr('value', key).text(value));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableAndHideTracktypeDropdown(valEle, index) {
|
||||||
|
//console.log("disable tracktype:"+index);
|
||||||
|
$("#sp_criteria_value_"+index).replaceWith('<input type="text" name="sp_criteria_value_'+index+'" id="sp_criteria_value_'+index+'" value="" class="input_text sp_input_text">');
|
||||||
|
}
|
||||||
|
|
||||||
/* Utilizing jQuery this function finds the #datetime_select element on the given row
|
/* Utilizing jQuery this function finds the #datetime_select element on the given row
|
||||||
* and shows the criteria drop-down
|
* and shows the criteria drop-down
|
||||||
*/
|
*/
|
||||||
|
@ -682,6 +734,7 @@ function sizeTextBoxes(ele, classToRemove, classToAdd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateModifierSelect(e, popAllMods) {
|
function populateModifierSelect(e, popAllMods) {
|
||||||
|
|
||||||
var criteria_type = getCriteriaOptionType(e),
|
var criteria_type = getCriteriaOptionType(e),
|
||||||
index = getRowIndex($(e).parent()),
|
index = getRowIndex($(e).parent()),
|
||||||
divs;
|
divs;
|
||||||
|
@ -708,6 +761,13 @@ function populateModifierSelect(e, popAllMods) {
|
||||||
.text(value));
|
.text(value));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else if(criteria_type == 'tt') {
|
||||||
|
$.each(stringIsNotOptions, function(key, value){
|
||||||
|
$(div).append($('<option></option>')
|
||||||
|
.attr('value', key)
|
||||||
|
.text(value));
|
||||||
|
});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$.each(numericCriteriaOptions, function(key, value){
|
$.each(numericCriteriaOptions, function(key, value){
|
||||||
$(div).append($('<option></option>')
|
$(div).append($('<option></option>')
|
||||||
|
@ -718,11 +778,37 @@ function populateModifierSelect(e, popAllMods) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populateTracktypeSelect(e, popAllMods) {
|
||||||
|
|
||||||
|
var criteria_type = getTracktype(e),
|
||||||
|
index = getRowIndex($(e).parent()),
|
||||||
|
divs;
|
||||||
|
|
||||||
|
if (popAllMods) {
|
||||||
|
index = index.substring(0, 1);
|
||||||
|
}
|
||||||
|
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]');
|
||||||
|
$.each(divs, function(i, div){
|
||||||
|
$(div).children().remove();
|
||||||
|
$.each(stringIsNotOptions, function(key, value){
|
||||||
|
$(div).append($('<option></option>')
|
||||||
|
.attr('value', key)
|
||||||
|
.text(value));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getCriteriaOptionType(e) {
|
function getCriteriaOptionType(e) {
|
||||||
var criteria = $(e).val();
|
var criteria = $(e).val();
|
||||||
return criteriaTypes[criteria];
|
return criteriaTypes[criteria];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTracktype(e) {
|
||||||
|
var type = $(e).val();
|
||||||
|
return stringTracktypeOptions[type];
|
||||||
|
}
|
||||||
|
|
||||||
function callback(json, type) {
|
function callback(json, type) {
|
||||||
var dt = $('table[id="library_display"]').dataTable(),
|
var dt = $('table[id="library_display"]').dataTable(),
|
||||||
form = $('.active-tab .smart-block-form');
|
form = $('.active-tab .smart-block-form');
|
||||||
|
@ -875,7 +961,7 @@ var criteriaTypes = {
|
||||||
"track_number" : "n",
|
"track_number" : "n",
|
||||||
"info_url" : "s",
|
"info_url" : "s",
|
||||||
"year" : "n",
|
"year" : "n",
|
||||||
"track_type" : "s"
|
"track_type" : "tt"
|
||||||
};
|
};
|
||||||
|
|
||||||
var stringCriteriaOptions = {
|
var stringCriteriaOptions = {
|
||||||
|
@ -908,3 +994,11 @@ var dateTimeCriteriaOptions = {
|
||||||
"is less than" : $.i18n._("is less than"),
|
"is less than" : $.i18n._("is less than"),
|
||||||
"is in the range" : $.i18n._("is in the range")
|
"is in the range" : $.i18n._("is in the range")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var stringIsNotOptions = {
|
||||||
|
"0" : $.i18n._("Select modifier"),
|
||||||
|
"is" : $.i18n._("is"),
|
||||||
|
"is not" : $.i18n._("is not")
|
||||||
|
};
|
||||||
|
|
||||||
|
var stringTracktypeOptions = TRACKTYPES;
|
Loading…
Reference in New Issue