From c78979c19c116d7fe433b3daf78279fead1fc9c4 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 24 Aug 2017 10:27:13 -0400 Subject: [PATCH] work in progress - need to write rules to parse when to show vs hide datetime select and add it to value field --- .../application/forms/SmartBlockCriteria.php | 36 +++++++++++--- .../scripts/form/smart-block-criteria.phtml | 5 +- .../js/airtime/playlist/smart_blockbuilder.js | 48 ++++++++++++++++++- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index e16c41eb1..517c48efb 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -5,6 +5,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm private $stringCriteriaOptions; private $numericCriteriaOptions; private $dateTimeCriteriaOptions; + private $timePeriodCriteriaOptions; private $sortOptions; private $limitOptions; @@ -135,15 +136,16 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } - private function getTimePeriodCriteriaOptions() { + private function getTimePeriodCriteriaOptions() + { if (!isset($this->timePeriodCriteriaOptions)) { $this->timePeriodCriteriaOptions = array( "0" => _("Select unit of time"), - "minute" => _("minute"), - "hour" => _("hour"), - "day" => _("day"), - "week" => _("week"), - "year" => _("year") + "minute" => _("minute(s)"), + "hour" => _("hour(s)"), + "day" => _("day(s)"), + "week" => _("week(s)"), + "year" => _("year(s)") ); } return $this->timePeriodCriteriaOptions; @@ -343,6 +345,28 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } $this->addElement($criteriaValue); + + /****************** DATETIME SELECT *************/ + $criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$i."_".$j); + $criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select') + ->setDecorators(array('viewHelper')); + if ($i != 0 && !isset($criteriaKeys[$i])) { + $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); + } + // need to determine how this is stored in the database if using plaintext need to parse the value + /* @todo figure this out */ + if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) { + $criteriaDatetimeSelect->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]); + $criteriaDatetimeSelect->setAttrib('class', 'input_text sp_datetime_input_select'); + } else { + $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); + } + + /* TODO FIX THIS */ + $criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); +// $criteriaDatetimeSelect->setMultiOptions(array('0' => _('Select modifier'))); + $this->addElement($criteriaDatetimeSelect); + /****************** EXTRA ***********/ $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$i."_".$j); $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml index 032ae669f..23aac603f 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -93,8 +93,11 @@ echo 'style=display:none'; } ?> > element->getElement("sp_criteria_field_".$i."_".$j) ?> - element->getElement("sp_criteria_modifier_".$i."_".$j) ?> + element->getElement("sp_criteria_modifier_".$i."_".$j) /* @todo finish this */?> + element->getElement("sp_criteria_value_".$i."_".$j) ?> + element->getElement("sp_criteria_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_datetime_select_'.$i."_".$j) ?> + diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 910c67256..047882080 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -66,6 +66,7 @@ function setSmartBlockEvents() { newRowVal.val(''); newRowExtra.val(''); disableAndHideExtraField(newRowVal); + disableAndHideDateTimeDropdown(newRowVal); sizeTextBoxes(newRowVal, 'sp_extra_input_text', 'sp_input_text'); //remove the 'criteria add' button from new modifier row @@ -112,7 +113,10 @@ function setSmartBlockEvents() { var criteria_value = next.find('[name^="sp_criteria_value"]').val(); curr.find('[name^="sp_criteria_value"]').val(criteria_value); - + + /* @todo need to add something regarding hiding datetime_select here */ + + /* if current and next row have the extra criteria value * (for 'is in the range' modifier), then assign the next * extra value to current and remove that element from @@ -241,6 +245,7 @@ function setSmartBlockEvents() { // disable extra field and hide the span disableAndHideExtraField($(this), index); + disableAndHideDateTimeDropdown($(this), index); populateModifierSelect(this, true); }); @@ -248,7 +253,22 @@ function setSmartBlockEvents() { form.find('select[id^="sp_criteria_modifier"]').live("change", function(){ var criteria_value = $(this).next(), index_num = getRowIndex($(this).parent()); - + + if ($(this).val().match('before|after|between')) { + enableAndShowDateTimeDropdown(criteria_value, index_num); + + if ($(this).val() == 'between') { + enableAndShowExtraField(criteria_value,index_num); + } + else { + disableAndHideExtraField(criteria_value, index_num); + } + } + else { + disableAndHideDateTimeDropdown(criteria_value, index_num); + + } + if ($(this).val() == 'is in the range') { enableAndShowExtraField(criteria_value, index_num); } else { @@ -439,6 +459,30 @@ function setupUI() { }); } + +function enableAndShowDateTimeDropdown(valEle, index) { + alert('enabled') + var spanDatetime = valEle.nextAll("#datetime_select"); + spanDatetime.children('#sp_criteria_datetime_select_'+index).removeAttr("disabled"); + spanDatetime.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 disableAndHideDateTimeDropdown(valEle, index) { + alert('disabled') + var spanDatetime = valEle.nextAll("#datetime_select"); + spanDatetime.children('#sp_criteria_datetime_select_'+index).val("").attr("disabled", "disabled"); + spanDatetime.hide(); + + //make value input larger since 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 enableAndShowExtraField(valEle, index) { var spanExtra = valEle.nextAll("#extra_criteria"); spanExtra.children('#sp_criteria_extra_'+index).removeAttr("disabled");