From 78bd5e67fdaacc798ea767801bb5a6fff6d6f12c Mon Sep 17 00:00:00 2001 From: oxteam Date: Mon, 25 Jun 2018 23:53:12 +0200 Subject: [PATCH 1/6] Fix display of breaks in the backend for working plans stored in database with Monday as the first weekday (EA! Issue #506). Prior commit 00372f2f1af96df0d4545053ae6f27834e109ea6, the first weekday was Monday. After this commit, it is set to Sunday and the display of breaks in the backend calendar is broken for former working plans. The fix consists in reordering the working plan elements with Sunday as the first day prior displaying the backend calendar. In addition, the working plan elements are also reordered when displaying 'Settings/Business Logic' and 'Users/Providers' tabs. This is to ensure that breaks are always displayed with Sunday first, like done for the Working Plan in those tabs, for consistency purpose.. --- .../js/backend_calendar_default_view.js | 6 +- src/assets/js/general_functions.js | 67 +++++++++++++++++++ src/assets/js/working_plan.js | 5 +- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/assets/js/backend_calendar_default_view.js b/src/assets/js/backend_calendar_default_view.js index 2dc4d9a3..40b8e8a0 100755 --- a/src/assets/js/backend_calendar_default_view.js +++ b/src/assets/js/backend_calendar_default_view.js @@ -801,9 +801,13 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') { $.each(GlobalVariables.availableProviders, function (index, provider) { if (provider.id == recordId) { - var workingPlan = jQuery.parseJSON(provider.settings.working_plan); + var workingPlan={}; + var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan); var unavailablePeriod; + // Sort the working plan starting with the first day as set in General settings to correctly align breaks in the calendar display + workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,0); // 0 is the ID for Sunday + switch (calendarView) { case 'agendaDay': var selectedDayName = weekDays[$calendar.fullCalendar('getView').start.format('d')]; diff --git a/src/assets/js/general_functions.js b/src/assets/js/general_functions.js index 21287f0e..52e76034 100755 --- a/src/assets/js/general_functions.js +++ b/src/assets/js/general_functions.js @@ -431,4 +431,71 @@ window.GeneralFunctions = window.GeneralFunctions || {}; return result; }; + /** + * Get the name in lowercase of a Weekday using its Id. + * + * @param {Integer} weekDayId The Id (From 0 for sunday to 6 for saturday). + + * @return {String} Returns the name of the weekday. + */ + exports.getWeekDayName = function (weekDayId) { + var result; + + switch (weekDayId) { + + case 0: + result = 'sunday'; + break; + + case 1: + result = 'monday'; + break; + + case 2: + result = 'tuesday'; + break; + + case 3: + result = 'wednesday'; + break; + + case 4: + result = 'thursday'; + break; + + case 5: + result = 'friday'; + break; + + case 6: + result = 'saturday'; + break; + + default: + throw new Error('Invalid weekday Id provided!', weekDayId); + } + + return result; + }; + + /** + * Sort a dictionary where keys are weekdays + * + * @param {Object} weekDict A dictionnary with weekdays as keys. + * @param {Integer} startDayId Id of the first day to start sorting (From 0 for sunday to 6 for saturday). + + * @return {Object} Returns a sorted dictionary + */ + exports.sortWeekDict = function (weekDict, startDayId) { + var sortedWeekDict={}; + + for (var i = startDayId; i < startDayId+7; i++) + { + var weekDayname = GeneralFunctions.getWeekDayName(i%7); + sortedWeekDict[weekDayname] = weekDict[weekDayname]; + } + + return sortedWeekDict; + }; + })(window.GeneralFunctions); diff --git a/src/assets/js/working_plan.js b/src/assets/js/working_plan.js index 7dfca90f..725e391b 100755 --- a/src/assets/js/working_plan.js +++ b/src/assets/js/working_plan.js @@ -45,7 +45,10 @@ * @param {Object} workingPlan Contains the working hours and breaks for each day of the week. */ WorkingPlan.prototype.setup = function (workingPlan) { - $.each(workingPlan, function (index, workingDay) { + // 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 + + $.each(workingPlanSorted, function (index, workingDay) { if (workingDay != null) { $('#' + index).prop('checked', true); $('#' + index + '-start').val(Date.parse(workingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase()); From 502027e894211c86f774589e76b6c5d7b8f62b0a Mon Sep 17 00:00:00 2001 From: oxteam Date: Tue, 26 Jun 2018 10:38:51 +0200 Subject: [PATCH 2/6] Minor change in a comment to be more relevant. --- src/assets/js/backend_calendar_default_view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets/js/backend_calendar_default_view.js b/src/assets/js/backend_calendar_default_view.js index 40b8e8a0..840eacc0 100755 --- a/src/assets/js/backend_calendar_default_view.js +++ b/src/assets/js/backend_calendar_default_view.js @@ -805,7 +805,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan); var unavailablePeriod; - // Sort the working plan starting with the first day as set in General settings to correctly align breaks in the calendar display + // Sort the working plan starting with Sunday as the first weekday to correctly align breaks in the calendar display workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,0); // 0 is the ID for Sunday switch (calendarView) { From 734be961262f6ec41d26cf58a58796a06889321e Mon Sep 17 00:00:00 2001 From: oxteam Date: Fri, 29 Jun 2018 00:41:17 +0200 Subject: [PATCH 3/6] Add new system-wide setting that enable users to choose the first day of the week. (#471) The setting change the display of weeks shown in backend and booking page calendars. Work plans and break lists in the 'settings' page are still displayed starting on Sunday. --- src/application/config/config.php | 2 +- src/application/config/migration.php | 2 +- src/application/controllers/Appointments.php | 2 + src/application/controllers/Backend.php | 9 ++-- .../language/arabic/translations_lang.php | 2 + .../language/bulgarian/translations_lang.php | 2 + .../language/chinese/translations_lang.php | 2 + .../language/danish/translations_lang.php | 2 + .../language/dutch/translations_lang.php | 2 + .../language/english/translations_lang.php | 2 + .../language/finnish/translations_lang.php | 2 + .../language/french/translations_lang.php | 2 + .../language/german/translations_lang.php | 2 + .../language/greek/translations_lang.php | 2 + .../language/hindi/translations_lang.php | 2 + .../language/hungarian/translations_lang.php | 2 + .../language/italian/translations_lang.php | 2 + .../language/japanese/translations_lang.php | 2 + .../luxembourgish/translations_lang.php | 2 + .../language/polish/translations_lang.php | 2 + .../portuguese-br/translations_lang.php | 2 + .../language/portuguese/translations_lang.php | 2 + .../language/romanian/translations_lang.php | 2 + .../language/russian/translations_lang.php | 2 + .../language/slovak/translations_lang.php | 2 + .../language/spanish/translations_lang.php | 2 + .../language/turkish/translations_lang.php | 2 + .../013_add_weekday_start_setting.php | 35 ++++++++++++ src/application/views/appointments/book.php | 1 + src/application/views/backend/calendar.php | 1 + src/application/views/backend/settings.php | 17 ++++++ .../js/backend_calendar_appointments_modal.js | 7 ++- .../js/backend_calendar_default_view.js | 22 +++----- ...backend_calendar_unavailabilities_modal.js | 6 ++- src/assets/js/frontend_book.js | 5 +- src/assets/js/general_functions.js | 54 +++++++++++++++++++ src/assets/sql/data.sql | 5 +- 37 files changed, 188 insertions(+), 26 deletions(-) create mode 100644 src/application/migrations/013_add_weekday_start_setting.php diff --git a/src/application/config/config.php b/src/application/config/config.php index 61ffc8b4..8ab10e56 100644 --- a/src/application/config/config.php +++ b/src/application/config/config.php @@ -273,7 +273,7 @@ $config['cache_path'] = __DIR__ . '/../../storage/cache/'; | new release. | */ -$config['cache_busting_token'] = '93GT3'; +$config['cache_busting_token'] = '93GX4'; /* |-------------------------------------------------------------------------- diff --git a/src/application/config/migration.php b/src/application/config/migration.php index 9f9804dd..5f8c03eb 100644 --- a/src/application/config/migration.php +++ b/src/application/config/migration.php @@ -37,7 +37,7 @@ $config['migration_table'] = 'ea_migrations'; | be upgraded / downgraded to. | */ -$config['migration_version'] = 12; // current +$config['migration_version'] = 13; // current /* diff --git a/src/application/controllers/Appointments.php b/src/application/controllers/Appointments.php index a13bdbbe..56a0f57f 100755 --- a/src/application/controllers/Appointments.php +++ b/src/application/controllers/Appointments.php @@ -76,6 +76,7 @@ class Appointments extends CI_Controller { $company_name = $this->settings_model->get_setting('company_name'); $date_format = $this->settings_model->get_setting('date_format'); $time_format = $this->settings_model->get_setting('time_format'); + $first_weekday = $this->settings_model->get_setting('first_weekday'); $display_cookie_notice = $this->settings_model->get_setting('display_cookie_notice'); $cookie_notice_content = $this->settings_model->get_setting('cookie_notice_content'); $display_terms_and_conditions = $this->settings_model->get_setting('display_terms_and_conditions'); @@ -147,6 +148,7 @@ class Appointments extends CI_Controller { 'customer_token' => $customer_token, 'date_format' => $date_format, 'time_format' => $time_format, + 'first_weekday' => $first_weekday, 'appointment_data' => $appointment, 'provider_data' => $provider, 'customer_data' => $customer, diff --git a/src/application/controllers/Backend.php b/src/application/controllers/Backend.php index fc0c33a2..62aa423c 100755 --- a/src/application/controllers/Backend.php +++ b/src/application/controllers/Backend.php @@ -70,6 +70,7 @@ class Backend extends CI_Controller { $view['book_advance_timeout'] = $this->settings_model->get_setting('book_advance_timeout'); $view['date_format'] = $this->settings_model->get_setting('date_format'); $view['time_format'] = $this->settings_model->get_setting('time_format'); + $view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['company_name'] = $this->settings_model->get_setting('company_name'); $view['available_providers'] = $this->providers_model->get_available_providers(); $view['available_services'] = $this->services_model->get_available_services(); @@ -132,6 +133,7 @@ class Backend extends CI_Controller { $view['company_name'] = $this->settings_model->get_setting('company_name'); $view['date_format'] = $this->settings_model->get_setting('date_format'); $view['time_format'] = $this->settings_model->get_setting('time_format'); + $view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['customers'] = $this->customers_model->get_batch(); $view['available_providers'] = $this->providers_model->get_available_providers(); $view['available_services'] = $this->services_model->get_available_services(); @@ -170,6 +172,7 @@ class Backend extends CI_Controller { $view['company_name'] = $this->settings_model->get_setting('company_name'); $view['date_format'] = $this->settings_model->get_setting('date_format'); $view['time_format'] = $this->settings_model->get_setting('time_format'); + $view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['services'] = $this->services_model->get_batch(); $view['categories'] = $this->services_model->get_all_categories(); $this->set_user_data($view); @@ -207,6 +210,7 @@ class Backend extends CI_Controller { $view['company_name'] = $this->settings_model->get_setting('company_name'); $view['date_format'] = $this->settings_model->get_setting('date_format'); $view['time_format'] = $this->settings_model->get_setting('time_format'); + $view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['admins'] = $this->admins_model->get_batch(); $view['providers'] = $this->providers_model->get_batch(); $view['secretaries'] = $this->secretaries_model->get_batch(); @@ -320,14 +324,13 @@ class Backend extends CI_Controller { { throw new Exception('You do not have the required privileges for this task!'); } - $this->load->library('migration'); - + if ( ! $this->migration->current()) { throw new Exception($this->migration->error_string()); } - + $view = ['success' => TRUE]; } catch (Exception $exc) diff --git a/src/application/language/arabic/translations_lang.php b/src/application/language/arabic/translations_lang.php index 19fdd8f0..f83238e0 100755 --- a/src/application/language/arabic/translations_lang.php +++ b/src/application/language/arabic/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'صيغة التاريخ'; $lang['date_format_hint'] = 'تغيير صيغة وعرض التاريخ (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'ليتم تضمينه في صفحة الحجز Google Analytics ID أضف معرّف'; $lang['availabilities_type'] = 'نوع التوفر أو الإتاحة'; $lang['flexible'] = 'مرن'; diff --git a/src/application/language/bulgarian/translations_lang.php b/src/application/language/bulgarian/translations_lang.php index ddc7dd70..35064573 100755 --- a/src/application/language/bulgarian/translations_lang.php +++ b/src/application/language/bulgarian/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Формат на Дата'; $lang['date_format_hint'] = 'Промяна на дормат за показ на дата (D - дата, M - месец, Y - година).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Добавете Google Analytics ID за да бъде включена статистика в страницата за запазване на час.'; $lang['availabilities_type'] = 'Типове на работен период.'; $lang['flexible'] = 'Гъвкав'; diff --git a/src/application/language/chinese/translations_lang.php b/src/application/language/chinese/translations_lang.php index edc0951a..846ddaf1 100755 --- a/src/application/language/chinese/translations_lang.php +++ b/src/application/language/chinese/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/danish/translations_lang.php b/src/application/language/danish/translations_lang.php index 5e4ac1ac..9803c15e 100755 --- a/src/application/language/danish/translations_lang.php +++ b/src/application/language/danish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/dutch/translations_lang.php b/src/application/language/dutch/translations_lang.php index a1dbd5e8..088e19e0 100755 --- a/src/application/language/dutch/translations_lang.php +++ b/src/application/language/dutch/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Datum formaat'; $lang['date_format_hint'] = 'Verander het datum formaat (D - dag, M - maand, Y - jaar).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Voeg je Google Analytics ID toe om deze te gebruiken op je boekings pagina.'; $lang['availabilities_type'] = 'Beschikbaarheidstype'; $lang['flexible'] = 'Flexibel'; diff --git a/src/application/language/english/translations_lang.php b/src/application/language/english/translations_lang.php index fcb7c6e5..18ee9fed 100755 --- a/src/application/language/english/translations_lang.php +++ b/src/application/language/english/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/finnish/translations_lang.php b/src/application/language/finnish/translations_lang.php index 3112c095..dabb8b6d 100755 --- a/src/application/language/finnish/translations_lang.php +++ b/src/application/language/finnish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Päiväyksen muoto'; $lang['date_format_hint'] = 'Vaihda päiväyksen esitysmuoto (D - Päivä, M - Kuukausi, Y - Vuosi).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Lisää Google Analytics ID varaussivulle.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/french/translations_lang.php b/src/application/language/french/translations_lang.php index 355ae447..384be3d3 100755 --- a/src/application/language/french/translations_lang.php +++ b/src/application/language/french/translations_lang.php @@ -274,6 +274,8 @@ $lang['date_format'] = 'Format des Dates'; $lang['date_format_hint'] = 'Change le format d\'affichage des dates (D - Jour, M - Mois, Y - Année).'; $lang['time_format'] = 'Format de l\'Heure'; $lang['time_format_hint'] = 'Change le format d\'affichage de l\'Heure (H - Heures, M - Minutes).'; +$lang['first_weekday'] = 'Premier jour de la semaine'; +$lang['first_weekday_hint'] = 'Définit le premier jour de la semaine calendaire.'; $lang['google_analytics_code_hint'] = 'Renseignez l\'ID Google Analytics à utiliser dans la page des réservations.'; $lang['availabilities_type'] = 'Type de disponibilités'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/german/translations_lang.php b/src/application/language/german/translations_lang.php index c6e469ed..03799539 100755 --- a/src/application/language/german/translations_lang.php +++ b/src/application/language/german/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Datumsformat'; $lang['date_format_hint'] = 'Ändern Sie das Datumsanzeigeformat (D - Datum, M - Monat, Y - Jahr).'; $lang['time_format'] = 'Zeitformat'; $lang['time_format_hint'] = 'Ändern Sie das Zeitanzeigeformat (H - Stunden, M - Minuten).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Fügen Sie Ihre Google Analytics-ID hinzu, das auf der Buchungsseite enthalten wird.'; $lang['availabilities_type'] = 'Verfügungstyp'; $lang['flexible'] = 'Flexibel'; diff --git a/src/application/language/greek/translations_lang.php b/src/application/language/greek/translations_lang.php index f09c8115..dddba1d9 100755 --- a/src/application/language/greek/translations_lang.php +++ b/src/application/language/greek/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Μορφή Ημερομηνίας'; $lang['date_format_hint'] = 'Αλλάξτε την μορφή ημερομηνίας (D - Ημέρα, M - Μήνας, Y - Χρόνος).'; $lang['time_format'] = 'Μορφή Ώρας'; $lang['time_format_hint'] = 'Αλλάξτε την μορφή ώρας (H - Ώρα, M - Λεπτά).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Προσθέστε τον Google Analytics ID σας το οποίο θα συμπεριληφθεί στην σελίδα κράτησης.'; $lang['availabilities_type'] = 'Τύπος Διαθεσιμοτήτων'; $lang['flexible'] = 'Ευέλικτος'; diff --git a/src/application/language/hindi/translations_lang.php b/src/application/language/hindi/translations_lang.php index 0f0906b7..d429b81c 100755 --- a/src/application/language/hindi/translations_lang.php +++ b/src/application/language/hindi/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/hungarian/translations_lang.php b/src/application/language/hungarian/translations_lang.php index 7acf24a7..10447d44 100755 --- a/src/application/language/hungarian/translations_lang.php +++ b/src/application/language/hungarian/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/italian/translations_lang.php b/src/application/language/italian/translations_lang.php index 1de9ad9c..3f5000e5 100755 --- a/src/application/language/italian/translations_lang.php +++ b/src/application/language/italian/translations_lang.php @@ -282,6 +282,8 @@ $lang['date_format'] = 'Formato data'; $lang['date_format_hint'] = 'Cambia il formato di visualizzazione della data (D - Giorno, M - Mese, Y - Anno).'; $lang['time_format'] = 'Formato orario'; $lang['time_format_hint'] = 'Cambia il formato di visualizzazione dell\'orario. (H - Ore, M - Minuti)'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Aggiunti il tuo ID di Google Analytics per includerlo nella pagina di prenotazione.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/japanese/translations_lang.php b/src/application/language/japanese/translations_lang.php index 71100c88..8bdcc991 100755 --- a/src/application/language/japanese/translations_lang.php +++ b/src/application/language/japanese/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/luxembourgish/translations_lang.php b/src/application/language/luxembourgish/translations_lang.php index c6404b37..18cdcba6 100755 --- a/src/application/language/luxembourgish/translations_lang.php +++ b/src/application/language/luxembourgish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/polish/translations_lang.php b/src/application/language/polish/translations_lang.php index 5d3e3f78..454fb447 100755 --- a/src/application/language/polish/translations_lang.php +++ b/src/application/language/polish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/portuguese-br/translations_lang.php b/src/application/language/portuguese-br/translations_lang.php index f106171b..c7427796 100755 --- a/src/application/language/portuguese-br/translations_lang.php +++ b/src/application/language/portuguese-br/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Formato da Data'; $lang['date_format_hint'] = 'Altera o formato de visualização da Data (D - Data, M - Mes, Y - Ano).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Adicione o seu ID do Google Analytics para ser incluido na pagina de agendamentos.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/portuguese/translations_lang.php b/src/application/language/portuguese/translations_lang.php index 39550c76..459c89e7 100755 --- a/src/application/language/portuguese/translations_lang.php +++ b/src/application/language/portuguese/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = 'Time Format'; $lang['time_format_hint'] = 'Change the time display format (H - Hours, M - Minutes).'; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/romanian/translations_lang.php b/src/application/language/romanian/translations_lang.php index 43ea9d19..cfb52fe0 100755 --- a/src/application/language/romanian/translations_lang.php +++ b/src/application/language/romanian/translations_lang.php @@ -282,6 +282,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = ''; $lang['time_format_hint'] = ''; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/russian/translations_lang.php b/src/application/language/russian/translations_lang.php index 3d267e23..7a3daf5b 100755 --- a/src/application/language/russian/translations_lang.php +++ b/src/application/language/russian/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = ''; $lang['time_format_hint'] = ''; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/slovak/translations_lang.php b/src/application/language/slovak/translations_lang.php index 17e0b90b..27a1f898 100755 --- a/src/application/language/slovak/translations_lang.php +++ b/src/application/language/slovak/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Formát dátumu'; $lang['date_format_hint'] = 'Zmeňte formát zobrazenia dátumu (D - Dátum, M - Mesiac, Y - Rok).'; $lang['time_format'] = ''; $lang['time_format_hint'] = ''; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Pridajte svoje ID služby Google Analytics, aby ste bola zahrnutá do stránky rezervácie.'; $lang['availabilities_type'] = 'Typ dostupnosti'; $lang['flexible'] = 'Flexibilný'; diff --git a/src/application/language/spanish/translations_lang.php b/src/application/language/spanish/translations_lang.php index c8659ff6..d4202e8d 100755 --- a/src/application/language/spanish/translations_lang.php +++ b/src/application/language/spanish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Formato de Fecha'; $lang['date_format_hint'] = 'Cambia el formato de fecha para mostrar (D - Día, M - Mes, Y - Año).'; $lang['time_format'] = ''; $lang['time_format_hint'] = ''; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Agrega tu ID de Google Analytics para ser incluido en la página de reservas.'; $lang['availabilities_type'] = 'Tipos disponibles'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/language/turkish/translations_lang.php b/src/application/language/turkish/translations_lang.php index 48bb8e0c..b88cba4a 100755 --- a/src/application/language/turkish/translations_lang.php +++ b/src/application/language/turkish/translations_lang.php @@ -276,6 +276,8 @@ $lang['date_format'] = 'Date Format'; $lang['date_format_hint'] = 'Change the date display format (D - Date, M - Month, Y - Year).'; $lang['time_format'] = ''; $lang['time_format_hint'] = ''; +$lang['first_weekday'] = 'First day of week'; +$lang['first_weekday_hint'] = 'Set the first day of the calendar week.'; $lang['google_analytics_code_hint'] = 'Add your Google Analytics ID to be included in the booking page.'; $lang['availabilities_type'] = 'Availabilities Type'; $lang['flexible'] = 'Flexible'; diff --git a/src/application/migrations/013_add_weekday_start_setting.php b/src/application/migrations/013_add_weekday_start_setting.php new file mode 100644 index 00000000..9314b2d1 --- /dev/null +++ b/src/application/migrations/013_add_weekday_start_setting.php @@ -0,0 +1,35 @@ + + * @copyright Copyright (c) 2013 - 2018, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.3.2 + * ---------------------------------------------------------------------------- */ + +class Migration_Add_weekday_start_setting extends CI_Migration { + public function up() + { + $this->load->model('settings_model'); + + try + { + $this->settings_model->get_setting('first_weekday'); + } + catch (Exception $exception) + { + $this->settings_model->set_setting('first_weekday', 'sunday'); + } + } + + public function down() + { + $this->load->model('settings_model'); + + $this->settings_model->remove_setting('first_weekday'); + } +} diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php index 20b99982..04daa75f 100755 --- a/src/application/views/appointments/book.php +++ b/src/application/views/appointments/book.php @@ -370,6 +370,7 @@ customerToken : , dateFormat : , timeFormat : , + firstWeekday : , displayCookieNotice : , appointmentData : , providerData : , diff --git a/src/application/views/backend/calendar.php b/src/application/views/backend/calendar.php index b0e0afe6..d347e549 100755 --- a/src/application/views/backend/calendar.php +++ b/src/application/views/backend/calendar.php @@ -20,6 +20,7 @@ 'bookAdvanceTimeout' : , 'dateFormat' : , 'timeFormat' : , + 'firstWeekday' : , 'editAppointment' : , 'customers' : , 'secretaryProviders' : , diff --git a/src/application/views/backend/settings.php b/src/application/views/backend/settings.php index 65d9232b..2170c23c 100755 --- a/src/application/views/backend/settings.php +++ b/src/application/views/backend/settings.php @@ -135,6 +135,23 @@ +
+ + + + + +

diff --git a/src/assets/js/backend_calendar_appointments_modal.js b/src/assets/js/backend_calendar_appointments_modal.js index d3021b7c..a4464698 100755 --- a/src/assets/js/backend_calendar_appointments_modal.js +++ b/src/assets/js/backend_calendar_appointments_modal.js @@ -389,6 +389,9 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa throw new Error('Invalid GlobalVariables.dateFormat value.'); } + var fDay = GlobalVariables.firstWeekday; + var fDaynum = GeneralFunctions.getWeekDayId(fDay); + $dialog.find('#start-datetime').datetimepicker({ dateFormat: dateFormat, timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm TT' : 'HH:mm', @@ -415,7 +418,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa timeText: EALang.time, hourText: EALang.hour, minuteText: EALang.minutes, - firstDay: 0 + firstDay: fDaynum }); $dialog.find('#start-datetime').datetimepicker('setDate', startDatetime); @@ -445,7 +448,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa timeText: EALang.time, hourText: EALang.hour, minuteText: EALang.minutes, - firstDay: 0 + firstDay: fDaynum }); $dialog.find('#end-datetime').datetimepicker('setDate', endDatetime); }; diff --git a/src/assets/js/backend_calendar_default_view.js b/src/assets/js/backend_calendar_default_view.js index 840eacc0..fa680901 100755 --- a/src/assets/js/backend_calendar_default_view.js +++ b/src/assets/js/backend_calendar_default_view.js @@ -785,16 +785,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; $calendar.fullCalendar('removeEvents'); $calendar.fullCalendar('addEventSource', calendarEvents); - var weekDays = [ - 'sunday', - 'monday', - 'tuesday', - 'wednesday', - 'thursday', - 'friday', - 'saturday' - ]; - // :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS var calendarView = $calendar.fullCalendar('getView').name; @@ -805,12 +795,13 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan); var unavailablePeriod; - // Sort the working plan starting with Sunday as the first weekday to correctly align breaks in the calendar display - workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,0); // 0 is the ID for Sunday + // Sort the working plan starting with the first day as set in General settings to correctly align breaks in the calendar display + var fDaynum = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday); + workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,fDaynum); switch (calendarView) { case 'agendaDay': - var selectedDayName = weekDays[$calendar.fullCalendar('getView').start.format('d')]; + var selectedDayName = GeneralFunctions.getWeekDayName(parseInt($calendar.fullCalendar('getView').start.format('d'))); // Add custom unavailable periods. $.each(response.unavailables, function (index, unavailable) { @@ -1091,12 +1082,15 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; var defaultView = window.innerWidth < 468 ? 'agendaDay' : 'agendaWeek'; + var fDay = GlobalVariables.firstWeekday; + var fDaynum = GeneralFunctions.getWeekDayId(fDay); + // Initialize page calendar $('#calendar').fullCalendar({ defaultView: defaultView, height: _getCalendarHeight(), editable: true, - firstDay: 0, + firstDay: fDaynum, snapDuration: '00:30:00', timeFormat: timeFormat, slotLabelFormat: slotTimeFormat, diff --git a/src/assets/js/backend_calendar_unavailabilities_modal.js b/src/assets/js/backend_calendar_unavailabilities_modal.js index ca0aef67..5f7baa21 100755 --- a/src/assets/js/backend_calendar_unavailabilities_modal.js +++ b/src/assets/js/backend_calendar_unavailabilities_modal.js @@ -180,6 +180,8 @@ window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabili break; } + var fDay = GlobalVariables.firstWeekday; + var fDaynum = GeneralFunctions.getWeekDayId(fDay); $dialog.find('#unavailable-start').datetimepicker({ dateFormat: dateFormat, @@ -207,7 +209,7 @@ window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabili timeText: EALang.time, hourText: EALang.hour, minuteText: EALang.minutes, - firstDay: 0 + firstDay: fDaynum }); $dialog.find('#unavailable-start').val(start); @@ -237,7 +239,7 @@ window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabili timeText: EALang.time, hourText: EALang.hour, minuteText: EALang.minutes, - firstDay: 0 + firstDay: fDaynum }); $dialog.find('#unavailable-end').val(end); diff --git a/src/assets/js/frontend_book.js b/src/assets/js/frontend_book.js index 892f8a86..7d6083ba 100644 --- a/src/assets/js/frontend_book.js +++ b/src/assets/js/frontend_book.js @@ -104,9 +104,12 @@ window.FrontendBook = window.FrontendBook || {}; } }); + var fDay = GlobalVariables.firstWeekday; + var fDaynum = GeneralFunctions.getWeekDayId(fDay); + $('#select-date').datepicker({ dateFormat: 'dd-mm-yy', - firstDay: 0, + firstDay: fDaynum, minDate: 0, defaultDate: Date.today(), diff --git a/src/assets/js/general_functions.js b/src/assets/js/general_functions.js index 52e76034..8a6518a9 100755 --- a/src/assets/js/general_functions.js +++ b/src/assets/js/general_functions.js @@ -431,6 +431,60 @@ window.GeneralFunctions = window.GeneralFunctions || {}; return result; }; + /** + * Get the Id of a Weekday using the US week format and day names (Sunday=0) as used in the JS code of the appli, case insensitive, short and long names supported. + * + * @param {String} weekDayName The weekday name amongs Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. + + * @return {Integer} Returns the ID of the weekday. + */ + exports.getWeekDayId = function (weekDayName) { + var result; + + switch (weekDayName.toLowerCase()) { + + case 'sunday': + case 'sun': + result = 0; + break; + + case 'monday': + case 'mon': + result = 1; + break; + + case 'tuesday': + case 'tue': + result = 2; + break; + + case 'wednesday': + case 'wed': + result = 3; + break; + + case 'thursday': + case 'thu': + result = 4; + break; + + case 'friday': + case 'fri': + result = 5; + break; + + case 'saturday': + case 'sat': + result = 6; + break; + + default: + throw new Error('Invalid weekday name provided!', weekDayName); + } + + return result; + }; + /** * Get the name in lowercase of a Weekday using its Id. * diff --git a/src/assets/sql/data.sql b/src/assets/sql/data.sql index e6fca50c..d97512ca 100644 --- a/src/assets/sql/data.sql +++ b/src/assets/sql/data.sql @@ -22,6 +22,7 @@ VALUES ('display_terms_and_conditions', '0'), ('terms_and_conditions_content', 'Terms and conditions content.'), ('display_privacy_policy', '0'), - ('privacy_policy_content', 'Privacy policy content.'); + ('privacy_policy_content', 'Privacy policy content.'), + ('first_weekday', 'sunday'); -INSERT INTO `ea_migrations` VALUES ('12'); +INSERT INTO `ea_migrations` VALUES ('13'); From 06630e0d2dbd495f2cc8913a8124609fce5fafcc Mon Sep 17 00:00:00 2001 From: oxteam Date: Fri, 29 Jun 2018 14:31:09 +0200 Subject: [PATCH 4/6] Cosmetic changes (removing blanks) --- src/application/controllers/Backend.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/application/controllers/Backend.php b/src/application/controllers/Backend.php index 62aa423c..51c13750 100755 --- a/src/application/controllers/Backend.php +++ b/src/application/controllers/Backend.php @@ -324,13 +324,14 @@ class Backend extends CI_Controller { { throw new Exception('You do not have the required privileges for this task!'); } + $this->load->library('migration'); - + if ( ! $this->migration->current()) { throw new Exception($this->migration->error_string()); } - + $view = ['success' => TRUE]; } catch (Exception $exc) From beaa309054114c3a85173fdd389cfe48ff15c32c Mon Sep 17 00:00:00 2001 From: oxteam Date: Fri, 6 Jul 2018 01:21:24 +0200 Subject: [PATCH 5/6] Days sorted also in the Users and Setting pages in the backend. --- src/application/controllers/Backend.php | 1 + src/application/views/backend/settings.php | 88 +--------------------- src/application/views/backend/users.php | 88 +--------------------- src/assets/js/backend_settings_system.js | 5 +- src/assets/js/backend_users_providers.js | 11 +-- src/assets/js/working_plan.js | 46 +++++++++-- 6 files changed, 50 insertions(+), 189 deletions(-) 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 { From 813a9049d8249ce780a566eb7c50cac3555ff375 Mon Sep 17 00:00:00 2001 From: oxteam Date: Fri, 6 Jul 2018 02:07:34 +0200 Subject: [PATCH 6/6] Remove unnecessary call to the timepickers function. --- src/assets/js/working_plan.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/assets/js/working_plan.js b/src/assets/js/working_plan.js index a130d283..ef983043 100755 --- a/src/assets/js/working_plan.js +++ b/src/assets/js/working_plan.js @@ -338,7 +338,6 @@ // 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)); };