mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-29 10:02:27 +03:00
Make sure that editing a working plan exception and changing the date will not keep the previous entry in place (#1515)
This commit is contained in:
parent
af2e3a065f
commit
07bc7b3812
4 changed files with 30 additions and 5 deletions
|
@ -468,6 +468,8 @@ class Calendar extends EA_Controller
|
|||
|
||||
$date = request('date');
|
||||
|
||||
$original_date = request('original_date');
|
||||
|
||||
$working_plan_exception = request('working_plan_exception');
|
||||
|
||||
if (!$working_plan_exception) {
|
||||
|
@ -478,6 +480,10 @@ class Calendar extends EA_Controller
|
|||
|
||||
$this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception);
|
||||
|
||||
if ($date !== $original_date) {
|
||||
$this->providers_model->delete_working_plan_exception($provider_id, $original_date);
|
||||
}
|
||||
|
||||
json_response([
|
||||
'success' => true,
|
||||
]);
|
||||
|
|
|
@ -131,10 +131,18 @@ App.Http.Calendar = (function () {
|
|||
* @param {Number} providerId Contains the working plan exceptions data.
|
||||
* @param {Function} successCallback The ajax success callback function.
|
||||
* @param {Function} errorCallback The ajax failure callback function.
|
||||
* @param {Date} [originalDate] On edit, provide the original date.
|
||||
*
|
||||
* @return {*|jQuery}
|
||||
*/
|
||||
function saveWorkingPlanException(date, workingPlanException, providerId, successCallback, errorCallback) {
|
||||
function saveWorkingPlanException(
|
||||
date,
|
||||
workingPlanException,
|
||||
providerId,
|
||||
successCallback,
|
||||
errorCallback,
|
||||
originalDate,
|
||||
) {
|
||||
const url = App.Utils.Url.siteUrl('calendar/save_working_plan_exception');
|
||||
|
||||
const data = {
|
||||
|
@ -142,6 +150,7 @@ App.Http.Calendar = (function () {
|
|||
date: date,
|
||||
working_plan_exception: workingPlanException,
|
||||
provider_id: providerId,
|
||||
original_date: originalDate,
|
||||
};
|
||||
|
||||
return $.post(url, data)
|
||||
|
|
|
@ -90,11 +90,11 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
const data = lastFocusedEventData.extendedProps.data;
|
||||
|
||||
if (data.hasOwnProperty('workingPlanException')) {
|
||||
const date = lastFocusedEventData.extendedProps.data.date;
|
||||
const originalDate = lastFocusedEventData.extendedProps.data.date;
|
||||
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
|
||||
const provider = lastFocusedEventData.extendedProps.data.provider;
|
||||
|
||||
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
|
||||
App.Components.WorkingPlanExceptionsModal.edit(originalDate, workingPlanException).done(
|
||||
(date, workingPlanException) => {
|
||||
const successCallback = () => {
|
||||
App.Layouts.Backend.displayNotification(lang('working_plan_exception_saved'));
|
||||
|
@ -103,6 +103,10 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
|
||||
workingPlanExceptions[date] = workingPlanException;
|
||||
|
||||
if (date !== originalDate) {
|
||||
delete workingPlanExceptions[originalDate];
|
||||
}
|
||||
|
||||
for (const index in vars('available_providers')) {
|
||||
const availableProvider = vars('available_providers')[index];
|
||||
|
||||
|
@ -122,6 +126,7 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
provider.id,
|
||||
successCallback,
|
||||
null,
|
||||
originalDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -165,11 +165,11 @@ App.Utils.CalendarTableView = (function () {
|
|||
let endMoment;
|
||||
|
||||
if (lastFocusedEventData.extendedProps.data.workingPlanException) {
|
||||
const date = lastFocusedEventData.extendedProps.data.date;
|
||||
const originalDate = lastFocusedEventData.extendedProps.data.date;
|
||||
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
|
||||
const provider = lastFocusedEventData.extendedProps.data.provider;
|
||||
|
||||
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
|
||||
App.Components.WorkingPlanExceptionsModal.edit(originalDate, workingPlanException).done(
|
||||
(date, workingPlanException) => {
|
||||
const successCallback = () => {
|
||||
App.Layouts.Backend.displayNotification(lang('working_plan_exception_saved'));
|
||||
|
@ -178,6 +178,10 @@ App.Utils.CalendarTableView = (function () {
|
|||
|
||||
workingPlanExceptions[date] = workingPlanException;
|
||||
|
||||
if (date !== originalDate) {
|
||||
delete workingPlanExceptions[originalDate];
|
||||
}
|
||||
|
||||
for (const index in vars('available_providers')) {
|
||||
const availableProvider = vars('available_providers')[index];
|
||||
|
||||
|
@ -197,6 +201,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
provider.id,
|
||||
successCallback,
|
||||
null,
|
||||
originalDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue