From 8d2926aeeda2dcd70e0ccfccfcfa191792326d18 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 10 Mar 2014 18:33:07 -0400 Subject: [PATCH] CC-5727 : History search range using incorrect timezone offset (also Nowplaying) sending the timestamp string back for nowplaying as well. added error class to history page if end is < start. --- .../controllers/ShowbuilderController.php | 75 +++++++++++++----- airtime_mvc/public/css/history_styles.css | 4 + .../js/airtime/playouthistory/historytable.js | 79 +++++++++++-------- .../js/airtime/showbuilder/main_builder.js | 3 +- .../public/js/airtime/utilities/utilities.js | 34 +++++--- 5 files changed, 129 insertions(+), 66 deletions(-) diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index dd1a19e13..c7de2cdc6 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -235,24 +235,61 @@ class ShowbuilderController extends Zend_Controller_Action $this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml'); } + + private function getStartEnd() + { + $request = $this->getRequest(); + + $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); + $utcTimezone = new DateTimeZone("UTC"); + $utcNow = new DateTime("now", $utcTimezone); + + $start = $request->getParam("start"); + $end = $request->getParam("end"); + + if (empty($start) || empty($end)) { + $startsDT = clone $utcNow; + $startsDT->sub(new DateInterval("P1D")); + $endsDT = clone $utcNow; + } + else { + + try { + $startsDT = new DateTime($start, $userTimezone); + $startsDT->setTimezone($utcTimezone); + + $endsDT = new DateTime($end, $userTimezone); + $endsDT->setTimezone($utcTimezone); + + if ($startsDT > $endsDT) { + throw new Exception("start greater than end"); + } + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + + $startsDT = clone $utcNow; + $startsDT->sub(new DateInterval("P1D")); + $endsDT = clone $utcNow; + } + + } + + return array($startsDT, $endsDT); + } public function checkBuilderFeedAction() { - $request = $this->getRequest(); - $current_time = time(); - - $starts_epoch = $request->getParam("start", $current_time); - //default ends is 24 hours after starts. - $ends_epoch = $request->getParam("end", $current_time + (60*60*24)); + $request = $this->getRequest(); $show_filter = intval($request->getParam("showFilter", 0)); - $my_shows = intval($request->getParam("myShows", 0)); - $timestamp = intval($request->getParam("timestamp", -1)); - $instances = $request->getParam("instances", array()); + $my_shows = intval($request->getParam("myShows", 0)); + $timestamp = intval($request->getParam("timestamp", -1)); + $instances = $request->getParam("instances", array()); - $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); - $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); + list($startsDT, $endsDT) = $this->getStartEnd(); - $opts = array("myShows" => $my_shows, "showFilter" => $show_filter); + $opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); //only send the schedule back if updates have been made. @@ -263,18 +300,14 @@ class ShowbuilderController extends Zend_Controller_Action public function builderFeedAction() { - $request = $this->getRequest(); - $current_time = time(); - - $starts_epoch = $request->getParam("start", $current_time); - //default ends is 24 hours after starts. - $ends_epoch = $request->getParam("end", $current_time + (60*60*24)); + $current_time = time(); + + $request = $this->getRequest(); $show_filter = intval($request->getParam("showFilter", 0)); $show_instance_filter = intval($request->getParam("showInstanceFilter", 0)); - $my_shows = intval($request->getParam("myShows", 0)); + $my_shows = intval($request->getParam("myShows", 0)); - $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); - $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); + list($startsDT, $endsDT) = $this->getStartEnd(); $opts = array("myShows" => $my_shows, "showFilter" => $show_filter, diff --git a/airtime_mvc/public/css/history_styles.css b/airtime_mvc/public/css/history_styles.css index fb44d4677..2d0c70d58 100644 --- a/airtime_mvc/public/css/history_styles.css +++ b/airtime_mvc/public/css/history_styles.css @@ -194,3 +194,7 @@ #history_content .ui-tabs .ui-tabs-panel { padding-top: 10px; } + +div.his-timerange input.error { + background-color: rgba(255,0,0,0.2); +} diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index b5a43e38c..854b0dfc4 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -60,6 +60,30 @@ var AIRTIME = (function(AIRTIME) { oTableShow, inShowsTab = false; + function validateTimeRange() { + var oRange, + inputs = $('.his-timerange > input'), + start, end; + + oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); + + start = oRange.start; + end = oRange.end; + + if (end >= start) { + inputs.removeClass('error'); + } + else { + inputs.addClass('error'); + } + + return { + start: start, + end: end, + isValid: end >= start + }; + } + function getSelectedLogItems() { var items = Object.keys(selectedLogItems); @@ -545,7 +569,8 @@ var AIRTIME = (function(AIRTIME) { dayNamesMin: i18n_days_short, onSelect: function(sDate, oDatePicker) { $(this).datepicker( "setDate", sDate ); - } + }, + onClose: validateTimeRange }; oBaseTimePickerSettings = { @@ -555,13 +580,25 @@ var AIRTIME = (function(AIRTIME) { showLeadingZero: false, defaultTime: '0:00', hourText: $.i18n._("Hour"), - minuteText: $.i18n._("Minute") + minuteText: $.i18n._("Minute"), + onClose: validateTimeRange }; - $historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings); - $historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings); - $historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings); - $historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings); + $historyContentDiv.find(dateStartId) + .datepicker(oBaseDatePickerSettings) + .blur(validateTimeRange); + + $historyContentDiv.find(timeStartId) + .timepicker(oBaseTimePickerSettings) + .blur(validateTimeRange); + + $historyContentDiv.find(dateEndId) + .datepicker(oBaseDatePickerSettings) + .blur(validateTimeRange); + + $historyContentDiv.find(timeEndId) + .timepicker(oBaseTimePickerSettings) + .blur(validateTimeRange); $historyContentDiv.on("click", "#his_create", function(e) { var url = baseUrl+"playouthistory/edit-list-item/format/json" ; @@ -711,35 +748,9 @@ var AIRTIME = (function(AIRTIME) { }); }); - function getStartEnd() { - var start, - end, - time; + function getStartEnd() { - start = $(dateStartId).val(); - start = start === "" ? null : start; - - time = $(timeStartId).val(); - time = time === "" ? "00:00" : time; - - if (start) { - start = start + " " + time; - } - - end = $(dateEndId).val(); - end = end === "" ? null : end; - - time = $(timeEndId).val(); - time = time === "" ? "00:00" : time; - - if (end) { - end = end + " " + time; - } - - return { - start: start, - end: end - }; + return AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); } $historyContentDiv.find("#his_submit").click(function(ev){ diff --git a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js index f59d0f32a..625464bb0 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js @@ -46,7 +46,8 @@ AIRTIME = (function(AIRTIME) { showLeadingZero: false, defaultTime: '0:00', hourText: $.i18n._("Hour"), - minuteText: $.i18n._("Minute") + minuteText: $.i18n._("Minute"), + onClose: validateTimeRange }; function setWidgetSize() { diff --git a/airtime_mvc/public/js/airtime/utilities/utilities.js b/airtime_mvc/public/js/airtime/utilities/utilities.js index 148f81fb1..4084e0e3b 100644 --- a/airtime_mvc/public/js/airtime/utilities/utilities.js +++ b/airtime_mvc/public/js/airtime/utilities/utilities.js @@ -90,20 +90,34 @@ var AIRTIME = (function(AIRTIME){ * * @return Object {"start", "end", "range"} */ - mod.fnGetScheduleRange = function(dateStart, timeStart, dateEnd, timeEnd) { - var iStart, - iEnd, - iRange; + mod.fnGetScheduleRange = function(dateStartId, timeStartId, dateEndId, timeEndId) { + var start, + end, + time; - iStart = AIRTIME.utilities.fnGetTimestamp(dateStart, timeStart); - iEnd = AIRTIME.utilities.fnGetTimestamp(dateEnd, timeEnd); + start = $(dateStartId).val(); + start = start === "" ? null : start; - iRange = iEnd - iStart; + time = $(timeStartId).val(); + time = time === "" ? "00:00" : time; + + if (start) { + start = start + " " + time; + } + + end = $(dateEndId).val(); + end = end === "" ? null : end; + + time = $(timeEndId).val(); + time = time === "" ? "00:00" : time; + + if (end) { + end = end + " " + time; + } return { - start: iStart, - end: iEnd, - range: iRange + start: start, + end: end }; };