From 6a15f51aac9b489f043a786bb260b5af1458a3c5 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 6 Jun 2011 12:49:52 -0400 Subject: [PATCH] CC-2289:differentiate-between-time-and-duration - some change in date populating rules - change on start date/time triggers change in end date/time - change on end date/time will triggers background turning into red color to notify user that end date/time is earlier than start date/time. - need to do more work once I get img file from Vladmir --- airtime_mvc/application/forms/AddShowWhen.php | 3 + airtime_mvc/application/models/Nowplaying.php | 25 ++++- airtime_mvc/public/css/add-show.css | 6 ++ .../public/js/airtime/schedule/add-show.js | 97 ++++++++++++++++++- 4 files changed, 127 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 4a31554ac..38ddb7f1c 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -104,6 +104,9 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm }elseif(strpos($formData["add_show_duration"], 'h') !== false && intval(substr($formData["add_show_duration"], 0, strpos($formData["add_show_duration"], 'h'))) > 23) { $this->getElement('add_show_duration')->setErrors(array('Cannot have duration > 24h')); $valid = false; + }elseif( strstr($formData["add_show_duration"], '-') ){ + $this->getElement('add_show_duration')->setErrors(array('Cannot have duration < 0m')); + $valid = false; } return $valid; diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index 04a620c74..47769ce39 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -28,7 +28,30 @@ class Application_Model_Nowplaying //format duration $duration = explode('.', $dbRow['clip_length']); $duration = explode(':', $duration[0]); - $duration = $duration[0].'h'.$duration[1].'m'.$duration[2].'s'; + + if($duration[2] == 0){ + $duration[2] = ''; + }else{ + $duration[2] = intval($duration[2],10).'s'; + } + + if($duration[1] == 0){ + if($duration[2] == ''){ + $duration[1] = ''; + }else{ + $duration[1] = intval($duration[1],10).'m'; + } + }else{ + $duration[1] = intval($duration[1],10).'m'; + } + + if($duration[0] == 0){ + $duration[0] = ''; + }else{ + $duration[0] = intval($duration[0],10).'h'; + } + + $duration = $duration[0].$duration[1].$duration[2]; $dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0], $duration, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'], diff --git a/airtime_mvc/public/css/add-show.css b/airtime_mvc/public/css/add-show.css index 1d0cf9f5c..365a54a6c 100644 --- a/airtime_mvc/public/css/add-show.css +++ b/airtime_mvc/public/css/add-show.css @@ -114,9 +114,15 @@ label.wrapp-label input[type="checkbox"] { #add_show_start_time { float: left; + width: 100px; +} + +#add_show_end_time, #add_show_end_date_no_repeat, #add_show_start_date { + width: 100px; } #add_show_duration { background: #AAAAAA; cursor: default; + width: 100px; } diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 2406377c9..f350ded21 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -23,7 +23,7 @@ function endDpSelect(dateText, inst) { time = dateText.split("-"); date = new Date(time[0], time[1] - 1, time[2]); - $("#add_show_start_date").datepicker( "option", "maxDate", date); + //$("#add_show_start_date").datepicker( "option", "maxDate", date); if (inst.input) inst.input.trigger('change'); } @@ -318,14 +318,70 @@ function setAddShowEvents() { }); }); - // auto puplate end date and time - $('#add_show_start_time, #add_show_start_date, #add_show_end_date_no_repeat, #add_show_end_time').change(function(){ + // when start date/time changes, set end date/time to start date/time+1 hr + $('#add_show_start_date, #add_show_start_time').change(function(){ var startDate = $('#add_show_start_date').val().split('-'); var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val()); var endDate = $('#add_show_end_date_no_repeat').val().split('-'); var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val()); + if(startDateTime.getTime() > endDateTime.getTime()){ + endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000)); + } + + var endDateFormat = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2); + var endTimeFormat = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2); + + $('#add_show_end_date_no_repeat').val(endDateFormat); + $('#add_show_end_time').val(endTimeFormat); + + // calculate duration + calculateDuration(endDateTime, startDateTime); + }); + + // when end date/time changes, check if the changed date is in past of start date/time + $('#add_show_end_date_no_repeat, #add_show_end_time').change(function(){ + var startDate = $('#add_show_start_date').val().split('-'); + var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val()); + + var endDate = $('#add_show_end_date_no_repeat').val().split('-'); + var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val()); + + if(startDateTime.getTime() > endDateTime.getTime()){ + $('#add_show_end_date_no_repeat').css('background', '#F49C9C'); + $('#add_show_end_time').css('background', '#F49C9C'); + }else{ + $('#add_show_end_date_no_repeat').css('background', ''); + $('#add_show_end_time').css('background', ''); + } + + // calculate duration + calculateDuration(endDateTime, startDateTime); + }); + // auto puplate end date and time + /*$('#add_show_start_date, #add_show_end_time_no_repeat').change(function(){ + var startDate = $('#add_show_start_date').val().split('-'); + var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]); + + var endDate = $('#add_show_end_date_no_repeat').val().split('-'); + var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]); + + if(startDateTime.getTime() > endDateTime.getTime()){ + if($(this) == $('#add_show_start_date')){ + var endDateTemp = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2); + $('#add_show_end_date_no_repeat').val(endDateTemp); + }else{ + var startDateTemp = startDateTime.getFullYear() + '-' + pad(startDateTime.getMonth()+1,2) + '-' + pad(startDateTime.getDate(),2); + $('#add_show_end_date_no_repeat').val(startDateTemp); + } + } + + var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val()); + + var endDate = $('#add_show_end_date_no_repeat').val().split('-'); + var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val()); + // if changed start time is greater than end, set end time to start time + 1 hour if(startDateTime.getTime() > endDateTime.getTime()){ endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000)); @@ -339,7 +395,42 @@ function setAddShowEvents() { // calculate duration calculateDuration(endDateTime, startDateTime) + }) + $('#add_show_start_time, #add_show_end_time').change(function(){ + var startDate = $('#add_show_start_date').val().split('-'); + var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val()); + + var endDate = $('#add_show_end_date_no_repeat').val().split('-'); + var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val()); + + if($(this) == $('#add_show_start_time')){ + // if changed start time is greater than end, set end time to start time + 1 hour + if(startDateTime.getTime() > endDateTime.getTime()){ + endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000)); + } + + var endDate = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2); + var endTime = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2); + + $('#add_show_end_date_no_repeat').val(endDate); + $('#add_show_end_time').val(endTime); + }else{ + // if changed start time is greater than end, set end time to start time + 1 hour + if(startDateTime.getTime() > endDateTime.getTime()){ + endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000)); + } + + var endDate = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2); + var endTime = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2); + + $('#add_show_end_date_no_repeat').val(endDate); + $('#add_show_end_time').val(endTime); + } + + // calculate duration + calculateDuration(endDateTime, startDateTime) + })*/ function calculateDuration(endDateTime, startDateTime){ var duration;