diff --git a/src/assets/js/working_plan.js b/src/assets/js/working_plan.js index a1ed8f96..2de1f9fc 100644 --- a/src/assets/js/working_plan.js +++ b/src/assets/js/working_plan.js @@ -268,12 +268,13 @@ */ $(document).on('click', '.cancel-break', function(e) { var element = e.target; + var $modifiedRow = $(element).closest('tr'); this.enableCancel = true; - $(element).parent().parent().find('.cancel-editable').trigger('click'); + $modifiedRow.find('.cancel-editable').trigger('click'); this.enableCancel = false; $(element).closest('table').find('.edit-break, .delete-break').removeClass('hidden'); - $(element).parent().find('.save-break, .cancel-break').addClass('hidden'); + $modifiedRow.find('.save-break, .cancel-break').addClass('hidden'); $('.add-break').prop('disabled', false); }.bind(this)); @@ -287,17 +288,19 @@ $(document).on('click', '.save-break', function(e) { // Break's start time must always be prior to break's end. var element = e.target, - start = Date.parse($(element).parent().parent().find('.break-start input').val()), - end = Date.parse($(element).parent().parent().find('.break-end input').val()); + $modifiedRow = $(element).closest('tr'), + start = Date.parse($modifiedRow.find('.break-start input').val()), + end = Date.parse($modifiedRow.find('.break-end input').val()); + if (start > end) { - $(element).parent().parent().find('.break-end input').val(start.addHours(1).toString('HH:mm')); + $modifiedRow.find('.break-end input').val(start.addHours(1).toString('HH:mm')); } this.enableSubmit = true; - $(element).parent().parent().find('.editable .submit-editable').trigger('click'); + $modifiedRow.find('.editable .submit-editable').trigger('click'); this.enableSubmit = false; - $(element).parent().find('.save-break, .cancel-break').addClass('hidden'); + $modifiedRow.find('.save-break, .cancel-break').addClass('hidden'); $(element).closest('table').find('.edit-break, .delete-break').removeClass('hidden'); $('.add-break').prop('disabled', false); }.bind(this)); @@ -329,6 +332,11 @@ 'end': end }); } + + workingPlan[id].breaks.sort(function(break1, break2) { + // We can do a direct string comparison since we have time based on 24 hours clock + return break1.start - break2.start; + }); }.bind(this)); } else { workingPlan[id] = null;