Detect "backwards" shift when time sheet is edited, alert user

This commit is contained in:
Lance Edgar 2017-03-27 23:25:17 -05:00
parent 27903b5984
commit 04e9752ee1
2 changed files with 17 additions and 4 deletions

View file

@ -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;
}

View file

@ -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();
}
}
},
{