diff --git a/tailbone/static/js/tailbone.timesheet.edit.js b/tailbone/static/js/tailbone.timesheet.edit.js index 75275d52..47473671 100644 --- a/tailbone/static/js/tailbone.timesheet.edit.js +++ b/tailbone/static/js/tailbone.timesheet.edit.js @@ -146,12 +146,24 @@ function update_row_hours(row) { function cleanup_editor_input() { // TODO: is this hacky? invoking timepicker to format the time values // in all cases, to avoid "invalid format" from user input + var backward = false; $('#day-editor .shifts .shift').each(function() { var start_time = $(this).children('input[name|="edit_start_time"]'); var end_time = $(this).children('input[name|="edit_end_time"]'); $.timepicker._setTime(start_time.data('timepicker'), start_time.val() || '??'); $.timepicker._setTime(end_time.data('timepicker'), end_time.val() || '??'); + var t_start = parseTime(start_time.val()); + var t_end = parseTime(end_time.val()); + if (t_start && t_end) { + if ((t_start.hh > t_end.hh) || ((t_start.hh == t_end.hh) && (t_start.mm > t_end.mm))) { + alert("Start time falls *after* end time! Please fix..."); + start_time.focus().select(); + backward = true; + return false; + } + } }); + return !backward; } diff --git a/tailbone/templates/shifts/timesheet_edit.mako b/tailbone/templates/shifts/timesheet_edit.mako index bf3036a4..66232391 100644 --- a/tailbone/templates/shifts/timesheet_edit.mako +++ b/tailbone/templates/shifts/timesheet_edit.mako @@ -37,10 +37,11 @@ { text: "Save Changes", click: function(event) { - $(event.target).button('disable').button('option', 'label', "Saving..."); - cleanup_editor_input(); - update_timetable(); - $('#timetable-form').submit(); + if (cleanup_editor_input()) { + $(event.target).button('disable').button('option', 'label', "Saving..."); + update_timetable(); + $('#timetable-form').submit(); + } } }, {