From e3f52ad968486d44b4a1a0ef331e450effbcc844 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Tue, 15 Aug 2017 23:25:11 -0400 Subject: [PATCH 01/15] added a time unit to SmartBlockCriteria --- .../application/forms/SmartBlockCriteria.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 25070006b..4298aff06 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -114,6 +114,22 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm return $this->numericCriteriaOptions; } + + 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") + ); + } + return $this->timePeriodCriteriaOptions; + } + + private function getLimitOptions() { if (!isset($this->limitOptions)) { From 0b80a429b37aa8ea71d07cecc8a1690b91656caf Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Wed, 16 Aug 2017 14:55:48 -0400 Subject: [PATCH 02/15] added comments to document smartblock functions and added new options to permit datetime based select fields --- .../controllers/PlaylistController.php | 1 + .../application/forms/SmartBlockCriteria.php | 58 +++++++++++++++++-- airtime_mvc/application/models/Block.php | 10 ++++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 84848d301..35b486cd3 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -555,6 +555,7 @@ class PlaylistController extends Zend_Controller_Action if ($form->isValid($params)) { $this->setPlaylistNameDescAction(); $bl->saveSmartBlockCriteria($params['data']); + // Logging::info($params['data']); $this->createUpdateResponse($bl); $this->view->result = 0; diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 4298aff06..0461142ea 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -24,9 +24,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm "description" => "s", "artist_name" => "s", "encoded_by" => "s", - "utime" => "n", - "mtime" => "n", - "lptime" => "n", + "utime" => "d", + "mtime" => "d", + "lptime" => "d", "genre" => "s", "isrc_number" => "s", "label" => "s", @@ -115,6 +115,25 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } + private function getDateTimeCriteriaOptions() + { + if (!isset($this->dateTimeCriteriaOptions)) { + $this->dateTimeCriteriaOptions = array( + "0" => _("Select modifier"), + "before" => _("before"), + "after" => _("after"), + "between" => _("between"), + "is" => _("is"), + "is not" => _("is not"), + "is greater than" => _("is greater than"), + "is less than" => _("is less than"), + "is in the range" => _("is in the range") + ); + } + return $this->dateTimeCriteriaOptions; + } + + private function getTimePeriodCriteriaOptions() { if (!isset($this->timePeriodCriteriaOptions)) { $this->timePeriodCriteriaOptions = array( @@ -183,6 +202,18 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } } + /* + * This function takes a blockID as param and creates the datastructure for the form displayed with the view + * smart-block-criteria.phtml + * + * A description of the dataflow. First it loads the block and determines if it is a static or dynamic smartblock. + * Next it adds a radio selector for static or dynamic type. + * Then it loads the criteria via the getCriteria() function, which returns an array for each criteria. + * + * + */ + + public function startForm($p_blockId, $p_isValid = false) { // load type @@ -220,20 +251,25 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $openSmartBlockOption = true; } + // this returns a number indexed array for each criteria found in the database $criteriaKeys = array(); if (isset($storedCrit["crit"])) { $criteriaKeys = array_keys($storedCrit["crit"]); } $numElements = count($this->getCriteriaOptions()); + // loop through once for each potential criteria option ie album, composer, track + for ($i = 0; $i < $numElements; $i++) { $criteriaType = ""; + // if there is a criteria found then count the number of rows for this specific criteria ie > 1 track title if (isset($criteriaKeys[$i])) { $critCount = count($storedCrit["crit"][$criteriaKeys[$i]]); } else { $critCount = 1; } + // store the number of items with the same key in the ModRowMap $modRowMap[$i] = $critCount; /* Loop through all criteria with the same field @@ -241,6 +277,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm */ for ($j = 0; $j < $critCount; $j++) { /****************** CRITERIA ***********/ + // hide the criteria drop down select on any rows after the first if ($j > 0) { $invisible = ' sp-invisible'; } else { @@ -252,17 +289,23 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm ->setValue('Select criteria') ->setDecorators(array('viewHelper')) ->setMultiOptions($this->getCriteriaOptions()); + // if this isn't the first criteria and there isn't an entry for it already disable it if ($i != 0 && !isset($criteriaKeys[$i])) { $criteria->setAttrib('disabled', 'disabled'); } - + // add the numbering to the form ie the i loop for each specific criteria and + // the j loop starts at 0 and grows for each item matching the same criteria + // look up the criteria type using the criteriaTypes function from above based upon the criteria value if (isset($criteriaKeys[$i])) { $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]]; $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]); } $this->addElement($criteria); + /****************** MODIFIER ***********/ + // every element has an optional modifier dropdown select + $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$i."_".$j); $criteriaModifers->setValue('Select modifier') ->setAttrib('class', 'input_select sp_input_select') @@ -270,10 +313,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm if ($i != 0 && !isset($criteriaKeys[$i])) { $criteriaModifers->setAttrib('disabled', 'disabled'); } + // determine the modifier based upon criteria type which is looked up based upon an array if (isset($criteriaKeys[$i])) { if ($criteriaType == "s") { $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); - } else { + } + elseif ($criteriaType == "d") { + $criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions()); + } + else { $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); } $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]); diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index d07a636f0..1ca0e354b 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1350,6 +1350,13 @@ SQL; return $insertList; } + /** + * Parses each row in the database for the criteria associated with this block and renders human readable labels. + * Returns it as an array with each criteria_name and modifier_name added based upon options array lookup. + * + */ + + public function getCriteria() { $criteriaOptions = array( @@ -1393,6 +1400,9 @@ SQL; "is not" => _("is not"), "starts with" => _("starts with"), "ends with" => _("ends with"), + "before" => _("before"), + "after" => _("after"), + "between" => _("between"), "is" => _("is"), "is not" => _("is not"), "is greater than" => _("is greater than"), From c630a69b895de9b1fe876561f6109a27346c412a Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Wed, 16 Aug 2017 20:05:02 -0400 Subject: [PATCH 03/15] Added ability to text input relative date times w/o validation --- .../application/forms/SmartBlockCriteria.php | 40 ++++++++++++------- airtime_mvc/application/models/Block.php | 35 ++++++++++++++-- .../js/airtime/playlist/smart_blockbuilder.js | 28 +++++++++++-- 3 files changed, 81 insertions(+), 22 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 0461142ea..e16c41eb1 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -4,6 +4,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm private $criteriaOptions; private $stringCriteriaOptions; private $numericCriteriaOptions; + private $dateTimeCriteriaOptions; private $sortOptions; private $limitOptions; @@ -629,25 +630,18 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $element->addError(_("'Length' should be in '00:00:00' format")); $isValid = false; } + // this looks up the column type for the criteria the modified time, upload time etc. } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { - $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); - $isValid = false; - } else { - $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']); - if (!$result["success"]) { - // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) - $element->addError($result["errMsg"]); - $isValid = false; + // need to check for relative modifiers first - bypassing currently + if (in_array($d['sp_criteria_modifier'], array('before','ago','between'))) { + //if the modifier is before ago or between we skip validation until we confirm format } - } - - if (isset($d['sp_criteria_extra'])) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) { + else { + if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); $isValid = false; } else { - $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']); + $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']); if (!$result["success"]) { // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) $element->addError($result["errMsg"]); @@ -655,6 +649,24 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } } } + if (isset($d['sp_criteria_extra'])) { + if ($d['sp_criteria_modifier'] == 'between') { + //disabling validation as this doesn't require the same format + } + else { + if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) { + $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); + $isValid = false; + } else { + $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']); + if (!$result["success"]) { + // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) + $element->addError($result["errMsg"]); + $isValid = false; + } + } + } + } } elseif ($column->getType() == PropelColumnTypes::INTEGER && $d['sp_criteria_field'] != 'owner_id') { if (!is_numeric($d['sp_criteria_value'])) { diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 1ca0e354b..0fe87df43 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -51,7 +51,10 @@ class Application_Model_Block implements Application_Model_LibraryEditable "ends with" => Criteria::ILIKE, "is greater than" => Criteria::GREATER_THAN, "is less than" => Criteria::LESS_THAN, - "is in the range" => Criteria::CUSTOM); + "is in the range" => Criteria::CUSTOM, + "before" => Criteria::CUSTOM, + "after" => Criteria::CUSTOM, + "between" => Criteria::CUSTOM); private static $criteria2PeerMap = array( 0 => "Select criteria", @@ -1197,9 +1200,13 @@ SQL; $field = $d['sp_criteria_field']; $value = $d['sp_criteria_value']; + $modifier = $d['sp_criteria_modifier']; if ($field == 'utime' || $field == 'mtime' || $field == 'lptime') { - $value = Application_Common_DateHelper::UserTimezoneStringToUTCString($value); + // if the date isn't relative we want to convert the value to a specific UTC date + if (!in_array($modifier,array('before','ago','between'))) { + $value = Application_Common_DateHelper::UserTimezoneStringToUTCString($value); + } } $qry = new CcBlockcriteria(); @@ -1463,9 +1470,9 @@ SQL; //data should already be in UTC, do we have to do anything special here anymore? if ($column->getType() == PropelColumnTypes::TIMESTAMP) { - + $spCriteriaValue = $criteria['value']; - + if (isset($criteria['extra'])) { $spCriteriaExtra = $criteria['extra']; } @@ -1511,6 +1518,26 @@ SQL; } elseif ($spCriteriaModifier == "is in the range") { $spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$spCriteriaExtra'"; } + elseif ($spCriteriaModifier == "before") { + // need to pull in the current time and subtract the value or figure out how to make it relative + $relativedate = new DateTime($spCriteriaValue); + $dt = $relativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria <= '$dt'"; + Logging::info($spCriteriaValue); + } + elseif ($spCriteriaModifier == "after") { + $relativedate = new DateTime($spCriteriaValue); + $dt = $relativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria >= '$dt'"; + Logging::info($spCriteriaValue); + } elseif ($spCriteriaModifier == "between") { + $fromrelativedate = new DateTime($spCriteriaValue); + $fdt = $fromrelativedate->format(DateTime::ISO8601); + + $torelativedate = new DateTime($spCriteriaValue); + $tdt = $fromrelativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria >= '$fdt' AND $spCriteria <= '$tdt'"; + } $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 0bbc16852..910c67256 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -484,7 +484,15 @@ function populateModifierSelect(e, popAllMods) { .attr('value', key) .text(value)); }); - } else { + } + else if(criteria_type == 'd') { + $.each(dateTimeCriteriaOptions, function(key, value){ + $(div).append($('') + .attr('value', key) + .text(value)); + }); + } + else { $.each(numericCriteriaOptions, function(key, value){ $(div).append($('') .attr('value', key) @@ -610,9 +618,9 @@ var criteriaTypes = { "description" : "s", "artist_name" : "s", "encoded_by" : "s", - "utime" : "n", - "mtime" : "n", - "lptime" : "n", + "utime" : "d", + "mtime" : "d", + "lptime" : "d", "genre" : "s", "isrc_number" : "s", "label" : "s", @@ -647,3 +655,15 @@ var numericCriteriaOptions = { "is less than" : $.i18n._("is less than"), "is in the range" : $.i18n._("is in the range") }; + +var dateTimeCriteriaOptions = { + "0" : $.i18n._("Select modifier"), + "before" : $.i18n._("before"), + "after" : $.i18n._("after"), + "between" : $.i18n._("between"), + "is" : $.i18n._("is"), + "is not" : $.i18n._("is not"), + "is greater than" : $.i18n._("is greater than"), + "is less than" : $.i18n._("is less than"), + "is in the range" : $.i18n._("is in the range") +}; From c78979c19c116d7fe433b3daf78279fead1fc9c4 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 24 Aug 2017 10:27:13 -0400 Subject: [PATCH 04/15] 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"); From 6c6b33b5538922570674bc0595d7d8329ed72688 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Fri, 13 Oct 2017 18:54:04 -0400 Subject: [PATCH 05/15] fixed jquery javascript regarding datetime select dynamic modification --- .../js/airtime/playlist/smart_blockbuilder.js | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 047882080..780a7b12d 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -90,18 +90,26 @@ function setSmartBlockEvents() { var item_to_hide; var prev; var index; - //remove error message from current row, if any var error_element = curr.find('span[class="errors sp-errors"]'); if (error_element.is(':visible')) { error_element.remove(); } + /* In the case that there is only one element we need to remove the + * date_select drop down. + */ + + if (count == 0) { + disableAndHideDateTimeDropdown(curr.find(':first-child'), index); + } + /* assign next row to current row for all rows below and including * the row getting removed */ + + for (var i=0; i Date: Sat, 14 Oct 2017 01:00:06 -0400 Subject: [PATCH 06/15] working relative dates with drop down selects --- .../application/forms/SmartBlockCriteria.php | 93 ++++++++++++++----- airtime_mvc/application/models/Block.php | 27 ++++-- .../scripts/form/smart-block-criteria.phtml | 2 + .../js/airtime/playlist/smart_blockbuilder.js | 80 +++++++++++++--- 4 files changed, 162 insertions(+), 40 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 517c48efb..8b9680fa7 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -192,21 +192,23 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm if (isset($criteria[$column])) { foreach ($criteria[$column] as &$constraint) { - - $constraint['value'] = - Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']); - - if (isset($constraint['extra'])) { - $constraint['extra'] = - Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']); - } + // convert to appropriate timezone timestamps only if the modifier is not a relative time + if (!in_array($constraint['modifier'], array('before','after','between'))) { + $constraint['value'] = + Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']); + + if (isset($constraint['extra'])) { + $constraint['extra'] = + Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']); + } + } } } } } /* - * This function takes a blockID as param and creates the datastructure for the form displayed with the view + * This function takes a blockID as param and creates the data structure for the form displayed with the view * smart-block-criteria.phtml * * A description of the dataflow. First it loads the block and determines if it is a static or dynamic smartblock. @@ -334,6 +336,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $this->addElement($criteriaModifers); /****************** VALUE ***********/ + /* The challenge here is that datetime */ $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$i."_".$j); $criteriaValue->setAttrib('class', 'input_text sp_input_text') ->setDecorators(array('viewHelper')); @@ -341,7 +344,17 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaValue->setAttrib('disabled', 'disabled'); } if (isset($criteriaKeys[$i])) { - $criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]); + /* + * Need to parse relative dates in a special way to populate select box down below + */ + $modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]; + if(isset($criteriaType) && $criteriaType == "d" && + preg_match('/before|after|between/', $modifierTest) == 1) { + // 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)); + } else { + $criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]); + } } $this->addElement($criteriaValue); @@ -353,18 +366,24 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm 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'); + // check if the value is stored and it is a relative datetime field + if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]) + && isset($criteriaType) && $criteriaType == "d" && + preg_match('/before|after|between/', $modifierTest) == 1) { + // need to remove the leading numbers stored in the database + $dateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]); + // need to strip white from front and ago from the end to match with the value of the time unit select dropdown + $dateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $dateTimeSelectValue)); + $criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); + $criteriaDatetimeSelect->setValue($dateTimeSelectValue); + $criteriaDatetimeSelect->setAttrib('enabled', 'enabled'); + } + else { + $criteriaDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time'))); + $criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); + } - /* TODO FIX THIS */ - $criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); -// $criteriaDatetimeSelect->setMultiOptions(array('0' => _('Select modifier'))); $this->addElement($criteriaDatetimeSelect); /****************** EXTRA ***********/ @@ -372,13 +391,42 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') ->setDecorators(array('viewHelper')); if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) { - $criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]); + // need to check if this is a relative date time value + if(isset($criteriaType) && $criteriaType == "d" && $modifierTest == 'between') { + // the criteria value will be a number followed by time unit and ago so set input to number part + $criteriaExtra->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"], FILTER_SANITIZE_NUMBER_INT)); + } + else { + $criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]); + } $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text'); } else { $criteriaExtra->setAttrib('disabled', 'disabled'); } $this->addElement($criteriaExtra); + /****************** DATETIME SELECT EXTRA **********/ + $criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_".$i."_".$j); + $criteriaExtraDatetimeSelect->setAttrib('class','input_select sp_input_select') + ->setDecorators(array('viewHelper')); + + if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]) + && $modifierTest == 'between') { + // need to remove the leading numbers stored in the database + $extraDateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]); + // need to strip white from front and ago from the end to match with the value of the time unit select dropdown + $extraDateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $extraDateTimeSelectValue)); + $criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); + Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT'); + $criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue); + $criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled'); + + } else { + $criteriaExtraDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time'))); + $criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); + $criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled'); + } + $this->addElement($criteriaExtraDatetimeSelect); }//for }//for @@ -657,7 +705,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm // this looks up the column type for the criteria the modified time, upload time etc. } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { // need to check for relative modifiers first - bypassing currently - if (in_array($d['sp_criteria_modifier'], array('before','ago','between'))) { + if (in_array($d['sp_criteria_modifier'], array('before','after','between'))) { + // TODO validate this on numeric input with whatever parsing also do for extra //if the modifier is before ago or between we skip validation until we confirm format } else { diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 0fe87df43..3c001eb80 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1191,22 +1191,30 @@ SQL; { // delete criteria under $p_blockId CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete(); - //Logging::info($p_criteriaData); + // Logging::info($p_criteriaData); //insert modifier rows if (isset($p_criteriaData['criteria'])) { $critKeys = array_keys($p_criteriaData['criteria']); for ($i = 0; $i < count($critKeys); $i++) { foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) { - + Logging::info($d); $field = $d['sp_criteria_field']; $value = $d['sp_criteria_value']; $modifier = $d['sp_criteria_modifier']; + if (isset($d['sp_criteria_extra'])) { $extra = $d['sp_criteria_extra']; } + $datetimeunit = $d['sp_criteria_datetime_select']; + if (isset($d['sp_criteria_extra_datetime_select'])) {$extradatetimeunit = $d['sp_criteria_extra_datetime_select'];} if ($field == 'utime' || $field == 'mtime' || $field == 'lptime') { // if the date isn't relative we want to convert the value to a specific UTC date - if (!in_array($modifier,array('before','ago','between'))) { + if (!(in_array($modifier,array('before','after','between')))) { $value = Application_Common_DateHelper::UserTimezoneStringToUTCString($value); } + else { + $value = $value . ' ' . $datetimeunit . ' ago'; + // Logging::info($value); + + } } $qry = new CcBlockcriteria(); @@ -1218,10 +1226,17 @@ SQL; if (isset($d['sp_criteria_extra'])) { if ($field == 'utime' || $field == 'mtime' || $field == 'lptime') { - $d['sp_criteria_extra'] = Application_Common_DateHelper::UserTimezoneStringToUTCString($d['sp_criteria_extra']); + // if the date isn't relative we want to convert the value to a specific UTC date + if (!(in_array($modifier,array('before','after','between')))) { + $extra = Application_Common_DateHelper::UserTimezoneStringToUTCString($extra); + } + else { + $extra = $extra . ' ' . $extradatetimeunit. ' ago'; + } + } - $qry->setDbExtra($d['sp_criteria_extra']); + $qry->setDbExtra($extra); } $qry->save(); } @@ -1611,7 +1626,7 @@ SQL; } public static function organizeSmartPlaylistCriteria($p_criteria) { - $fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra'); + $fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra', 'sp_criteria_datetime_select', 'sp_criteria_extra_datetime_select'); $output = array(); foreach ($p_criteria as $ele) { 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 23aac603f..114cfd919 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -103,6 +103,8 @@ element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_'.$i."_".$j) ?> + element->getElement("sp_criteria_extra_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_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 780a7b12d..ade445237 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -102,6 +102,8 @@ function setSmartBlockEvents() { if (count == 0) { disableAndHideDateTimeDropdown(curr.find(':first-child'), index); + disableAndHideExtraDateTimeDropdown(curr.find(':first-child'),index); + disableAndHideExtraField(curr.find(':first-child'),index); } /* assign next row to current row for all rows below and including @@ -178,6 +180,29 @@ function setSmartBlockEvents() { curr.find('[name^="sp_criteria_datetime_select"]').val(criteria_datetime); } + /* if current and next row have the extra_date_time_select_criteria visible + * then show the current and it from the next row + */ + if (curr.find('[name^="sp_criteria_extra_datetime_select"]').attr("disabled") != "disabled" + && next.find('#extra_datetime_select').is(':visible')) { + + var extra_criteria_datetime = next.find('[name^="sp_criteria_extra_datetime_select"]').val(); + curr.find('[name^="sp_criteria_extra_datetime_select"]').val(extra_criteria_datetime); + disableAndHideExtraDateTimeDropdown(next.find('first-child'), getRowIndex(next)); + /* if only the current row has the extra criteria value, + * then just remove the current row's extra criteria element + */ + } else if (curr.find('[name^="sp_criteria_extra_datetime_select"]').attr("disabled") != "disabled" + && next.find('#extra_datetime_select').not(':visible')) { + disableAndHideExtraDateTimeDropdown(curr.find(':first-child'), index); + /* if only the next row has date_time_select then just enable it on the current row + */ + } else if (next.find('#datetime_select').is(':visible')) { + criteria_datetime = next.find('[name^="sp_criteria_extra_datetime_select"]').val(); + enableAndShowExtraDateTimeDropdown(curr.find(':first-child'), index); + curr.find('[name^="sp_criteria_extra_datetime_select"]').val(criteria_datetime); + } + /* determine if current row is a modifier row * if it is, make the criteria select invisible */ @@ -286,29 +311,29 @@ function setSmartBlockEvents() { var criteria_value = $(this).next(), index_num = getRowIndex($(this).parent()); - if ($(this).val().match('before|after|between')) { + if ($(this).val().match('before|after')) { enableAndShowDateTimeDropdown(criteria_value, index_num); console.log($(this).val()); - - if ($(this).val() == 'between') { - console.log('yah') - enableAndShowExtraField(criteria_value,index_num); - } - else { - console.log('huh') - disableAndHideExtraField(criteria_value, index_num); - } } else { disableAndHideDateTimeDropdown(criteria_value, index_num); + disableAndHideExtraDateTimeDropdown(criteria_value,index_num); } - if ($(this).val() == 'is in the range') { + if ($(this).val().match('is in the range')) { enableAndShowExtraField(criteria_value, index_num); } else { disableAndHideExtraField(criteria_value, index_num); } + if ($(this).val().match('between')) { + enableAndShowExtraField(criteria_value, index_num); + enableAndShowDateTimeDropdown(criteria_value,index_num); + enableAndShowExtraDateTimeDropdown(criteria_value,index_num); + } + else { + disableAndHideExtraDateTimeDropdown(criteria_value,index_num); + } }); setupUI(); @@ -498,8 +523,10 @@ function setupUI() { * and shows the criteria drop-down */ function enableAndShowDateTimeDropdown(valEle, index) { + console.log('datetime show'); var spanDatetime = valEle.nextAll("#datetime_select"); spanDatetime.children('#sp_criteria_datetime_select_'+index).removeAttr("disabled"); + spanDatetime.children('#sp_criteria_extra_datetime_select_'+index).removeAttr("disabled"); spanDatetime.show(); //make value input smaller since we have extra element now @@ -513,6 +540,7 @@ function enableAndShowDateTimeDropdown(valEle, index) { */ function disableAndHideDateTimeDropdown(valEle, index) { + console.log('datetime hide'); var spanDatetime = valEle.nextAll("#datetime_select"); spanDatetime.children('#sp_criteria_datetime_select_'+index).val("").attr("disabled", "disabled"); spanDatetime.hide(); @@ -522,10 +550,37 @@ function disableAndHideDateTimeDropdown(valEle, index) { sizeTextBoxes(criteria_value, 'sp_extra_input_text', 'sp_input_text'); } +/* Utilizing jQuery this function finds the #datetime_select element on the given row + * and shows the criteria drop-down + */ +function enableAndShowExtraDateTimeDropdown(valEle, index) { + console.log('datetime show'); + var spanDatetime = valEle.nextAll("#extra_datetime_select"); + spanDatetime.children('#sp_criteria_extra_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'); +} +/* Utilizing jQuery this function finds the #datetime_select element on the given row + * and hides the datetime criteria drop-down + */ + +function disableAndHideExtraDateTimeDropdown(valEle, index) { + console.log('datetime hide'); + var spanDatetime = valEle.nextAll("#extra_datetime_select"); + spanDatetime.children('#sp_criteria_extra_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"); - console.log(spanExtra); + console.log('shown'); spanExtra.children('#sp_criteria_extra_'+index).removeAttr("disabled"); spanExtra.show(); @@ -538,6 +593,7 @@ function disableAndHideExtraField(valEle, index) { var spanExtra = valEle.nextAll("#extra_criteria"); spanExtra.children('#sp_criteria_extra_'+index).val("").attr("disabled", "disabled"); spanExtra.hide(); + console.log('hidden'); //make value input larger since we don't have extra field now var criteria_value = $('#sp_criteria_value_'+index); From 67807bb4b3091df8dee395947e3d765ad78cd5ed Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sat, 14 Oct 2017 21:01:58 -0400 Subject: [PATCH 07/15] fixed blatant errors in jquery and php validation --- airtime_mvc/application/forms/SmartBlockCriteria.php | 2 +- airtime_mvc/application/models/Block.php | 2 +- .../public/js/airtime/playlist/smart_blockbuilder.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 8b9680fa7..6078f29f1 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -363,7 +363,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $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])) { + if (!isset($criteriaKeys[$i])) { $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); } // check if the value is stored and it is a relative datetime field diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 3c001eb80..74fad484a 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1202,7 +1202,7 @@ SQL; $value = $d['sp_criteria_value']; $modifier = $d['sp_criteria_modifier']; if (isset($d['sp_criteria_extra'])) { $extra = $d['sp_criteria_extra']; } - $datetimeunit = $d['sp_criteria_datetime_select']; + if (isset($d['sp_criteria_datetime_select'])) { $datetimeunit = $d['sp_criteria_datetime_select']; } if (isset($d['sp_criteria_extra_datetime_select'])) {$extradatetimeunit = $d['sp_criteria_extra_datetime_select'];} if ($field == 'utime' || $field == 'mtime' || $field == 'lptime') { diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index ade445237..5442de35c 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -19,6 +19,8 @@ function setSmartBlockEvents() { appendAddButton(); appendModAddButton(); removeButtonCheck(); + disableAndHideDateTimeDropdown(newRowVal); + } else { @@ -34,6 +36,8 @@ function setSmartBlockEvents() { appendAddButton(); appendModAddButton(); removeButtonCheck(); + disableAndHideDateTimeDropdown(newRowVal); + } }); @@ -67,6 +71,7 @@ function setSmartBlockEvents() { newRowExtra.val(''); disableAndHideExtraField(newRowVal); disableAndHideDateTimeDropdown(newRowVal); + disableAndHideExtraDateTimeDropdown(newRowVal); sizeTextBoxes(newRowVal, 'sp_extra_input_text', 'sp_input_text'); //remove the 'criteria add' button from new modifier row @@ -303,6 +308,7 @@ function setSmartBlockEvents() { // disable extra field and hide the span disableAndHideExtraField($(this), index); disableAndHideDateTimeDropdown($(this), index); + disableAndHideExtraDateTimeDropdown($(this),index); populateModifierSelect(this, true); }); From 8807dbcbfb9a34964c86a4c0615b770182ae02fe Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sat, 14 Oct 2017 23:15:47 -0400 Subject: [PATCH 08/15] Added input validation and fixed between relative date validation --- .../application/forms/SmartBlockCriteria.php | 32 ++++++++++++++++--- airtime_mvc/application/models/Block.php | 12 ++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 6078f29f1..a30f3f4fe 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -417,7 +417,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm // need to strip white from front and ago from the end to match with the value of the time unit select dropdown $extraDateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $extraDateTimeSelectValue)); $criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions()); - Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT'); + // Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT'); $criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue); $criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled'); @@ -527,6 +527,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $eleMod->setMultiOptions($this->getStringCriteriaOptions()); } elseif ($criteriaType == "n") { $eleMod->setMultiOptions($this->getNumericCriteriaOptions()); + } elseif ($criteriaType == "d") { + $eleMod->setMultiOptions($this->getDateTimeCriteriaOptions()); } else { $eleMod->setMultiOptions(array('0' => _('Select modifier'))); } @@ -565,6 +567,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); } elseif ($criteriaType == "n") { $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); + } + elseif ($criteriaType == "d") { + $criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions()); } else { $criteriaModifers->setMultiOptions(array('0' => _('Select modifier'))); } @@ -610,6 +615,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $this->populate($formData); + // Logging::info($formData); return $data; } @@ -706,10 +712,17 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { // need to check for relative modifiers first - bypassing currently if (in_array($d['sp_criteria_modifier'], array('before','after','between'))) { - // TODO validate this on numeric input with whatever parsing also do for extra - //if the modifier is before ago or between we skip validation until we confirm format + if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_value'])) { + $element->addError(_("Only non-negative integer numbers are allowed (e.g 1 or 5) for the text value")); + $isValid = false; + // TODO validate this on numeric input with whatever parsing also do for extra + //if the modifier is before ago or between we skip validation until we confirm format } - else { + elseif (isSet($d['sp_criteria_datetime_select']) && $d['sp_criteria_datetime_select'] == "0") { + $element->addError(_("You must select a time unit for a relative datetime.")); + $isValid = false; + } + } else { if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); $isValid = false; @@ -724,7 +737,16 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } if (isset($d['sp_criteria_extra'])) { if ($d['sp_criteria_modifier'] == 'between') { - //disabling validation as this doesn't require the same format + // validate that the input value only contains a number if using relative date times + if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_extra'])) { + $element->addError(_("Only non-negative integer numbers are allowed for a relative date time")); + $isValid = false; + } + // also need to check to make sure they chose a time unit from the dropdown + elseif ($d['sp_criteria_extra_datetime_select'] == "0") { + $element->addError(_("You must select a time unit for a relative datetime.")); + $isValid = false; + } } else { if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) { diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 74fad484a..306dc7b80 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1197,7 +1197,7 @@ SQL; $critKeys = array_keys($p_criteriaData['criteria']); for ($i = 0; $i < count($critKeys); $i++) { foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) { - Logging::info($d); + // Logging::info($d); $field = $d['sp_criteria_field']; $value = $d['sp_criteria_value']; $modifier = $d['sp_criteria_modifier']; @@ -1538,19 +1538,21 @@ SQL; $relativedate = new DateTime($spCriteriaValue); $dt = $relativedate->format(DateTime::ISO8601); $spCriteriaValue = "$spCriteria <= '$dt'"; - Logging::info($spCriteriaValue); + // Logging::info($spCriteriaValue); } elseif ($spCriteriaModifier == "after") { $relativedate = new DateTime($spCriteriaValue); $dt = $relativedate->format(DateTime::ISO8601); $spCriteriaValue = "$spCriteria >= '$dt'"; - Logging::info($spCriteriaValue); + // Logging::info($spCriteriaValue); } elseif ($spCriteriaModifier == "between") { $fromrelativedate = new DateTime($spCriteriaValue); $fdt = $fromrelativedate->format(DateTime::ISO8601); + // Logging::info($fdt); - $torelativedate = new DateTime($spCriteriaValue); - $tdt = $fromrelativedate->format(DateTime::ISO8601); + $torelativedate = new DateTime($spCriteriaExtra); + $tdt = $torelativedate->format(DateTime::ISO8601); + // Logging::info($tdt); $spCriteriaValue = "$spCriteria >= '$fdt' AND $spCriteria <= '$tdt'"; } From d314117a09ad96ec2ad7937125473d29aa0ee738 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sat, 14 Oct 2017 23:51:18 -0400 Subject: [PATCH 09/15] Added check to hide datetime select on existing forms without relative smartblocks --- airtime_mvc/application/forms/SmartBlockCriteria.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index a30f3f4fe..138a54e00 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -347,9 +347,13 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm /* * Need to parse relative dates in a special way to populate select box down below */ + // this is used below to test whether the datetime select should be shown or hidden + $relativeDateTime = false; $modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]; if(isset($criteriaType) && $criteriaType == "d" && preg_match('/before|after|between/', $modifierTest) == 1) { + // set relativeDatetime boolean to true so that the datetime select is displayed below + $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)); } else { @@ -363,7 +367,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$i."_".$j); $criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select') ->setDecorators(array('viewHelper')); - if (!isset($criteriaKeys[$i])) { + if (!isset($criteriaKeys[$i]) || !$relativeDateTime) { $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); } // check if the value is stored and it is a relative datetime field From a541d1397c3b8749e34e661d6933f6736cbfbffb Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sun, 15 Oct 2017 00:03:36 -0400 Subject: [PATCH 10/15] Added months to date time units --- airtime_mvc/application/forms/SmartBlockCriteria.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 138a54e00..1e0c55613 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -145,6 +145,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm "hour" => _("hour(s)"), "day" => _("day(s)"), "week" => _("week(s)"), + "month" => _("month(s)"), "year" => _("year(s)") ); } From fc4f82a83a5ccc47eb61f65f0e93e57623261241 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 4 Jan 2018 15:49:03 -0500 Subject: [PATCH 11/15] fixed smart block criteria view to show dropdown based upon current values vs. database values to fix display when form is invalid --- .../views/scripts/form/smart-block-criteria.phtml | 15 ++++++++++----- .../js/airtime/playlist/smart_blockbuilder.js | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) 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 114cfd919..91d1cb6c2 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -92,19 +92,24 @@
0) && */ $disabled) { echo 'style=display:none'; } ?> > - element->getElement("sp_criteria_field_".$i."_".$j) ?> - element->getElement("sp_criteria_modifier_".$i."_".$j) /* @todo finish this */?> + element->getElement("sp_criteria_field_".$i."_".$j) ?> + element->getElement("sp_criteria_modifier_".$i."_".$j); Logging::info($this->element->getElement('sp_criteria_modifier_'.$i.'_'.$j)->getValue());?> 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) ?> + element->getElement("sp_criteria_modifier_".$i."_".$j)->getValue()) == 1) + ) {echo('style="display:none;"'); }?>> + element->getElement('sp_criteria_datetime_select_'.$i."_".$j) ?> element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_'.$i."_".$j) ?> - element->getElement("sp_criteria_extra_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_datetime_select_'.$i."_".$j) ?> - + element->getElement("sp_criteria_modifier_".$i."_".$j)->getValue() == 'between')) { echo 'style="display:none;"'; }?>>element->getElement('sp_criteria_extra_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 5442de35c..c70abbef9 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -529,7 +529,6 @@ function setupUI() { * and shows the criteria drop-down */ function enableAndShowDateTimeDropdown(valEle, index) { - console.log('datetime show'); var spanDatetime = valEle.nextAll("#datetime_select"); spanDatetime.children('#sp_criteria_datetime_select_'+index).removeAttr("disabled"); spanDatetime.children('#sp_criteria_extra_datetime_select_'+index).removeAttr("disabled"); From 5848d307da764797f2fb62ef87ca09cdde502b7f Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 4 Jan 2018 15:49:32 -0500 Subject: [PATCH 12/15] changing the default smartblock color to white for improved visibility --- airtime_mvc/public/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 70641a0cb..0bb54b6c2 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -734,7 +734,7 @@ input.input_text.sp_extra_input_text{ .sp_text_font{ font-size: 13px; font-family: Helvetica, Arial, sans-serif; - color: #5B5B5B; + color: #FFFFFF; } .sp_text_font_bold{ From 5e7a5b3e1d48d1db17488a7c2d27396b1757d39d Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sun, 7 Jan 2018 15:27:58 -0500 Subject: [PATCH 13/15] Revert "fixed smart block criteria view to show dropdown based upon current values vs. database values to fix display when form is invalid" This reverts commit fc4f82a83a5ccc47eb61f65f0e93e57623261241. --- .../views/scripts/form/smart-block-criteria.phtml | 15 +++++---------- .../js/airtime/playlist/smart_blockbuilder.js | 1 + 2 files changed, 6 insertions(+), 10 deletions(-) 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 91d1cb6c2..114cfd919 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -92,24 +92,19 @@
0) && */ $disabled) { echo 'style=display:none'; } ?> > - element->getElement("sp_criteria_field_".$i."_".$j) ?> - element->getElement("sp_criteria_modifier_".$i."_".$j); Logging::info($this->element->getElement('sp_criteria_modifier_'.$i.'_'.$j)->getValue());?> + element->getElement("sp_criteria_field_".$i."_".$j) ?> + element->getElement("sp_criteria_modifier_".$i."_".$j) /* @todo finish this */?> element->getElement("sp_criteria_value_".$i."_".$j) ?> - element->getElement("sp_criteria_modifier_".$i."_".$j)->getValue()) == 1) - ) {echo('style="display:none;"'); }?>> - element->getElement('sp_criteria_datetime_select_'.$i."_".$j) ?> + element->getElement("sp_criteria_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_datetime_select_'.$i."_".$j) ?> element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_'.$i."_".$j) ?> - element->getElement("sp_criteria_modifier_".$i."_".$j)->getValue() == 'between')) { echo 'style="display:none;"'; }?>>element->getElement('sp_criteria_extra_datetime_select_'.$i."_".$j) ?> + element->getElement("sp_criteria_extra_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_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 c70abbef9..5442de35c 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -529,6 +529,7 @@ function setupUI() { * and shows the criteria drop-down */ function enableAndShowDateTimeDropdown(valEle, index) { + console.log('datetime show'); var spanDatetime = valEle.nextAll("#datetime_select"); spanDatetime.children('#sp_criteria_datetime_select_'+index).removeAttr("disabled"); spanDatetime.children('#sp_criteria_extra_datetime_select_'+index).removeAttr("disabled"); From 144f1b5561dc4f4863af40565b02578f0249bd21 Mon Sep 17 00:00:00 2001 From: Robbt Date: Mon, 8 Jan 2018 21:48:31 -0500 Subject: [PATCH 14/15] Fixed form validation and display after errors and when removing rows --- .../application/forms/SmartBlockCriteria.php | 72 +++++++++++++++++-- .../scripts/form/smart-block-criteria.phtml | 2 +- .../js/airtime/playlist/smart_blockbuilder.js | 7 +- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 1e0c55613..3fa73de97 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -195,9 +195,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm foreach ($criteria[$column] as &$constraint) { // convert to appropriate timezone timestamps only if the modifier is not a relative time if (!in_array($constraint['modifier'], array('before','after','between'))) { - $constraint['value'] = - Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']); - + $constraint['value'] = + Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']); if (isset($constraint['extra'])) { $constraint['extra'] = Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']); @@ -368,14 +367,17 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$i."_".$j); $criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select') ->setDecorators(array('viewHelper')); - if (!isset($criteriaKeys[$i]) || !$relativeDateTime) { + if (isset($criteriaKeys[$i]) && $relativeDateTime) { + $criteriaDatetimeSelect->setAttrib('enabled', 'enabled'); + } + else { $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); } // check if the value is stored and it is a relative datetime field if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]) && isset($criteriaType) && $criteriaType == "d" && preg_match('/before|after|between/', $modifierTest) == 1) { - // need to remove the leading numbers stored in the database + // need to remove any leading numbers stored in the database $dateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]); // need to strip white from front and ago from the end to match with the value of the time unit select dropdown $dateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $dateTimeSelectValue)); @@ -507,6 +509,12 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm 'showPoolCount' => $showPoolCount)) )); } + /* + * This is a simple function that determines if a modValue should enable a datetime + */ + public function enableDateTimeUnit($modValue) { + return (preg_match('/before|after|between/', $modValue) == 1); + } public function preValidation($params) { @@ -540,6 +548,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $eleMod->setValue($modInfo['sp_criteria_modifier']); $eleMod->setAttrib("disabled", null); + $eleDatetime = $this->getElement("sp_criteria_datetime_select_".$critKey."_".$modKey); + if ($this->enableDateTimeUnit($eleMod->getValue())) { + $eleDatetime->setAttrib("enabled", "enabled"); + $eleDatetime->setValue($modInfo['sp_criteria_datetime_select']); + $eleDatetime->setAttrib("disabled", null); + } + else { + $eleDatetime->setAttrib("disabled","disabled"); + } $eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey); $eleValue->setValue($modInfo['sp_criteria_value']); $eleValue->setAttrib("disabled", null); @@ -550,6 +567,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $eleValue->setAttrib('class', 'input_text sp_extra_input_text'); $eleExtra->setAttrib("disabled", null); } + $eleExtraDatetime = $this->getElement("sp_criteria_extra_datetime_select_".$critKey."_".$modKey); + if ($eleMod->getValue() == 'between') { + $eleExtraDatetime->setAttrib("enabled", "enabled"); + $eleExtraDatetime->setValue($modInfo['sp_criteria_extra_datetime_select']); + $eleExtraDatetime->setAttrib("disabled", null); + } + else { + $eleExtraDatetime->setAttrib("disabled","disabled"); + } } else { $criteria = new Zend_Form_Element_Select("sp_criteria_field_".$critKey."_".$modKey); @@ -587,7 +613,20 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm ->setDecorators(array('viewHelper')); $criteriaValue->setValue($modInfo['sp_criteria_value']); $this->addElement($criteriaValue); + /****************** DATETIME UNIT SELECT ***********/ + $criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$critKey."_".$modKey); + $criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select') + ->setDecorators(array('viewHelper')); + if ($this->enableDateTimeUnit($criteriaValue->getValue())) { + $criteriaDatetimeSelect->setAttrib('enabled', 'enabled'); + $criteriaDatetimeSelect->setAttrib('disabled', null); + $criteriaDatetimeSelect->setValue($modInfo['sp_criteria_datetime_select']); + $this->addElement($criteriaDatetimeSelect); + } + else { + $criteriaDatetimeSelect->setAttrib('disabled', 'disabled'); + } /****************** EXTRA ***********/ $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey); $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') @@ -599,6 +638,21 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteriaExtra->setAttrib('disabled', 'disabled'); } $this->addElement($criteriaExtra); + + /****************** EXTRA DATETIME UNIT SELECT ***********/ + + $criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_".$critKey."_".$modKey); + $criteriaExtraDatetimeSelect->setAttrib('class','input_select sp_input_select') + ->setDecorators(array('viewHelper')); + if ($criteriaValue->getValue() == 'between') { + $criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled'); + $criteriaExtraDatetimeSelect->setAttrib('disabled', null); + $criteriaExtraDatetimeSelect->setValue($modInfo['sp_criteria_extra_datetime_select']); + $this->addElement($criteriaExtraDatetimeSelect); + } + else { + $criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled'); + } $count++; } } @@ -624,6 +678,14 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm return $data; } + /* + * This function will enable or disable form criteria elements based upon the current form + * This is necessary after validation fails and the elements loaded from startForm are different from + * the current form data + * + */ + public function reValidate(){ + } public function isValid($params) { $isValid = true; 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 114cfd919..b9f205fe8 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -67,7 +67,7 @@
- criteriasLength; $i++) { + criteriasLength; $i++) { // modRowMap holds the number of modifier rows for each criteria element // i.e. if we have 'Album contains 1' and 'Album contains 2' the modRowMap // for Album is 2 diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 5442de35c..3fe1c6ea3 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -233,13 +233,18 @@ function setSmartBlockEvents() { */ item_to_hide = list.find('div:visible:last'); item_to_hide.children().attr('disabled', 'disabled'); + item_to_hide.find('[name^="sp_criteria_datetime_select"]').attr('disabled', 'disabled'); + item_to_hide.find('[name^="sp_criteria_extra"]').attr('disabled', 'disabled'); + item_to_hide.find('[name^="sp_criteria_extra_datetime_select"]').attr('disabled', 'disabled'); if (item_to_hide.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) { item_to_hide.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible'); } item_to_hide.find('[name^="sp_criteria_field"]').val(0).end() .find('[name^="sp_criteria_modifier"]').val(0).end() + .find('[name^="sp_criteria_datetime_select"]').end() .find('[name^="sp_criteria_value"]').val('').end() - .find('[name^="sp_criteria_extra"]').val(''); + .find('[name^="sp_criteria_extra"]').val('') + .find('[name^="sp_criteria_extra_datetime_select"]').end(); sizeTextBoxes(item_to_hide.find('[name^="sp_criteria_value"]'), 'sp_extra_input_text', 'sp_input_text'); item_to_hide.hide(); From 98ee6bafe65a43ddf7640d9a9d52c386a3b7b571 Mon Sep 17 00:00:00 2001 From: Robbt Date: Mon, 8 Jan 2018 21:50:06 -0500 Subject: [PATCH 15/15] Removed unneeded function prototype --- airtime_mvc/application/forms/SmartBlockCriteria.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 3fa73de97..7f1237909 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -678,14 +678,6 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm return $data; } - /* - * This function will enable or disable form criteria elements based upon the current form - * This is necessary after validation fails and the elements loaded from startForm are different from - * the current form data - * - */ - public function reValidate(){ - } public function isValid($params) { $isValid = true;