diff --git a/src/application/controllers/Backend.php b/src/application/controllers/Backend.php index 51c13750..9b9d15e1 100755 --- a/src/application/controllers/Backend.php +++ b/src/application/controllers/Backend.php @@ -250,6 +250,7 @@ class Backend extends CI_Controller { $view['active_menu'] = PRIV_SYSTEM_SETTINGS; $view['company_name'] = $this->settings_model->get_setting('company_name'); $view['date_format'] = $this->settings_model->get_setting('date_format'); + $view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['time_format'] = $this->settings_model->get_setting('time_format'); $view['role_slug'] = $this->session->userdata('role_slug'); $view['system_settings'] = $this->settings_model->get_settings(); diff --git a/src/application/views/backend/settings.php b/src/application/views/backend/settings.php index 2170c23c..1c2a1a59 100755 --- a/src/application/views/backend/settings.php +++ b/src/application/views/backend/settings.php @@ -9,6 +9,7 @@ 'csrfToken' : security->get_csrf_hash()) ?>, 'baseUrl' : , 'dateFormat' : , + 'firstWeekday' : , 'timeFormat' : , 'userSlug' : , 'settings' : { @@ -214,92 +215,7 @@ - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - +
diff --git a/src/application/views/backend/users.php b/src/application/views/backend/users.php index 7e420ba1..ed062a53 100755 --- a/src/application/views/backend/users.php +++ b/src/application/views/backend/users.php @@ -10,6 +10,7 @@ csrfToken : security->get_csrf_hash()) ?>, baseUrl : , dateFormat : , + firstWeekday : , timeFormat : , admins : , providers : , @@ -216,92 +217,7 @@ - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - +
diff --git a/src/assets/js/backend_settings_system.js b/src/assets/js/backend_settings_system.js index e2c4fe4b..6a96e881 100644 --- a/src/assets/js/backend_settings_system.js +++ b/src/assets/js/backend_settings_system.js @@ -46,9 +46,12 @@ // Update the logo title on the header. $('#header-logo span').text($('#company-name').val()); + // Update variables also used in other setting tabs + GlobalVariables.timeFormat = $('#time-format').val(); + GlobalVariables.firstWeekday = $('#first-weekday').val(); + // We need to refresh the working plan. var workingPlan = BackendSettings.wp.get(); - $('.breaks tbody').empty(); BackendSettings.wp.setup(workingPlan); BackendSettings.wp.timepickers(false); }, 'json').fail(GeneralFunctions.ajaxFailureHandler); diff --git a/src/assets/js/backend_users_providers.js b/src/assets/js/backend_users_providers.js index f0a6785c..4f0b0e82 100644 --- a/src/assets/js/backend_users_providers.js +++ b/src/assets/js/backend_users_providers.js @@ -94,7 +94,6 @@ $('#provider-notifications').prop('disabled', false); $('#providers').find('.add-break, .edit-break, .delete-break, #reset-working-plan').prop('disabled', false); $('#provider-services input:checkbox').prop('disabled', false); - $('#providers input:checkbox').prop('disabled', false); // Apply default working plan BackendUsers.wp.setup(GlobalVariables.workingPlan); @@ -232,8 +231,6 @@ * Event: Reset Working Plan Button "Click". */ $('#providers').on('click', '#reset-working-plan', function () { - $('.breaks tbody').empty(); - $('.work-start, .work-end').val(''); BackendUsers.wp.setup(GlobalVariables.workingPlan); BackendUsers.wp.timepickers(false); }); @@ -358,16 +355,12 @@ $('#provider-notifications').prop('disabled', true); $('#provider-services input:checkbox').prop('disabled', true); $('#providers .add-break, #reset-working-plan').prop('disabled', true); - BackendUsers.wp.timepickers(true); - $('#providers .working-plan input:text').timepicker('destroy'); - $('#providers .working-plan input:checkbox').prop('disabled', true); - $('.breaks').find('.edit-break, .delete-break').prop('disabled', true); $('#edit-provider, #delete-provider').prop('disabled', true); $('#providers .record-details').find('input, textarea').val(''); - $('#providers input:checkbox').prop('checked', false); $('#provider-services input:checkbox').prop('checked', false); $('#provider-services a').remove(); + $('#providers .working-plan tbody').empty(); $('#providers .breaks tbody').empty(); }; @@ -422,10 +415,10 @@ }); // Display working plan - $('#providers .breaks tbody').empty(); var workingPlan = $.parseJSON(provider.settings.working_plan); BackendUsers.wp.setup(workingPlan); $('.breaks').find('.edit-break, .delete-break').prop('disabled', true); + $('#providers .working-plan input:checkbox').prop('disabled', true); }; /** diff --git a/src/assets/js/working_plan.js b/src/assets/js/working_plan.js index 725e391b..a130d283 100755 --- a/src/assets/js/working_plan.js +++ b/src/assets/js/working_plan.js @@ -45,22 +45,48 @@ * @param {Object} workingPlan Contains the working hours and breaks for each day of the week. */ WorkingPlan.prototype.setup = function (workingPlan) { - // Always displaying breaks with Sunday as the first day to be consistent with what is done in the the working plan view. - var workingPlanSorted = GeneralFunctions.sortWeekDict(workingPlan,0); // 0 is the ID for Sunday + var fDaynum = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday); + var workingPlanSorted = GeneralFunctions.sortWeekDict(workingPlan,fDaynum); + + $('.working-plan tbody').empty(); + $('.breaks tbody').empty(); + // Build working plan day list starting with the first weekday as set in the General settings $.each(workingPlanSorted, function (index, workingDay) { + + var day = this.convertValueToDay(index); + var dayTranslatedname = GeneralFunctions.ucaseFirstLetter(day) + + var tr = + '' + + '' + + '
' + + '' + + '
' + + '' + + '' + + '' + + ''; + + $('.working-plan tbody').append(tr); + if (workingDay != null) { $('#' + index).prop('checked', true); $('#' + index + '-start').val(Date.parse(workingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase()); $('#' + index + '-end').val(Date.parse(workingDay.end).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase()); + // Sort day's breaks according to the starting hour + workingDay.breaks.sort(function (break1, break2) { + // We can do a direct string comparison since we have time based on 24 hours clock. + return (break1.start).localeCompare(break2.start); + }); + // Add the day's breaks on the breaks table. $.each(workingDay.breaks, function (i, brk) { - var day = this.convertValueToDay(index); - var tr = + tr = '' + - '' + GeneralFunctions.ucaseFirstLetter(day) + '' + + '' + dayTranslatedname + '' + '' + Date.parse(brk.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase() + '' + '' + Date.parse(brk.end).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase() + '' + '' + @@ -171,7 +197,7 @@ * * Enable or disable the time selection for each day. */ - $('.working-plan input:checkbox').click(function () { + $('.working-plan tbody').on( "click", "input:checkbox", function (event) { var id = $(this).attr('id'); if ($(this).prop('checked') == true) { @@ -308,6 +334,12 @@ $modifiedRow.find('.save-break, .cancel-break').addClass('hidden'); $(element).closest('table').find('.edit-break, .delete-break').removeClass('hidden'); $('.add-break').prop('disabled', false); + + // Refresh working plan to have the new break sorted in the break list. + var workingPlan = this.get(); + this.setup(workingPlan); + this.timepickers(false); + }.bind(this)); }; @@ -342,7 +374,7 @@ 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; + return (break1.start).localeCompare(break2.start); }); }.bind(this)); } else {