2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2015-10-05 01:31:06 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2015-07-20 22:41:24 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Working plan utility.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of working plans.
|
|
|
|
*/
|
2022-01-11 12:52:58 +03:00
|
|
|
App.Utils.WorkingPlan = (function () {
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
2016-05-14 13:28:42 +03:00
|
|
|
* Class WorkingPlan
|
|
|
|
*
|
2016-04-24 20:28:33 +03:00
|
|
|
* Contains the working plan functionality. The working plan DOM elements must be same
|
|
|
|
* in every page this class is used.
|
2015-10-05 01:31:06 +03:00
|
|
|
*
|
2016-04-24 20:28:33 +03:00
|
|
|
* @class WorkingPlan
|
2013-09-25 18:43:17 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
class WorkingPlan {
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
|
|
|
* This flag is used when trying to cancel row editing. It is
|
|
|
|
* true only whenever the user presses the cancel button.
|
|
|
|
*
|
2016-05-14 13:28:42 +03:00
|
|
|
* @type {Boolean}
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
enableCancel = false;
|
2016-04-24 20:28:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This flag determines whether the jeditables are allowed to submit. It is
|
|
|
|
* true only whenever the user presses the save button.
|
|
|
|
*
|
2016-05-14 13:28:42 +03:00
|
|
|
* @type {Boolean}
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
enableSubmit = false;
|
2015-10-05 01:31:06 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Setup the dom elements of a given working plan.
|
|
|
|
*
|
|
|
|
* @param {Object} workingPlan Contains the working hours and breaks for each day of the week.
|
|
|
|
*/
|
|
|
|
setup(workingPlan) {
|
2022-01-18 10:18:22 +03:00
|
|
|
const weekDayId = App.Utils.Date.getWeekdayId(vars('first_weekday'));
|
2022-01-17 17:31:04 +03:00
|
|
|
const workingPlanSorted = App.Utils.Date.sortWeekDictionary(workingPlan, weekDayId);
|
|
|
|
|
|
|
|
$('.working-plan tbody').empty();
|
|
|
|
$('.breaks tbody').empty();
|
|
|
|
|
|
|
|
// Build working plan day list starting with the first weekday as set in the General settings
|
2022-01-18 10:18:22 +03:00
|
|
|
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
|
2022-01-17 17:31:04 +03:00
|
|
|
|
|
|
|
$.each(
|
|
|
|
workingPlanSorted,
|
|
|
|
function (index, workingDay) {
|
|
|
|
const day = this.convertValueToDay(index);
|
|
|
|
|
|
|
|
const dayDisplayName = App.Utils.String.upperCaseFirstLetter(day);
|
|
|
|
|
|
|
|
$('<tr/>', {
|
|
|
|
'html': [
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<div/>', {
|
|
|
|
'class': 'checkbox form-check',
|
|
|
|
'html': [
|
|
|
|
$('<input/>', {
|
|
|
|
'class': 'form-check-input',
|
|
|
|
'type': 'checkbox',
|
|
|
|
'id': index
|
|
|
|
}),
|
|
|
|
$('<label/>', {
|
|
|
|
'class': 'form-check-label',
|
|
|
|
'text': dayDisplayName,
|
|
|
|
'for': index
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<input/>', {
|
|
|
|
'id': index + '-start',
|
|
|
|
'class': 'work-start form-control form-control-sm'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<input/>', {
|
|
|
|
'id': index + '-end',
|
|
|
|
'class': 'work-start form-control form-control-sm'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}).appendTo('.working-plan tbody');
|
|
|
|
|
|
|
|
if (workingDay) {
|
|
|
|
$('#' + index).prop('checked', true);
|
|
|
|
$('#' + index + '-start').val(
|
|
|
|
moment(workingDay.start, 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
);
|
|
|
|
$('#' + index + '-end').val(moment(workingDay.end, 'HH:mm').format(timeFormat).toLowerCase());
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
workingDay.breaks.forEach(function (workingDayBreak) {
|
|
|
|
$('<tr/>', {
|
|
|
|
'html': [
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-day editable',
|
|
|
|
'text': dayDisplayName
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-start editable',
|
|
|
|
'text': moment(workingDayBreak.start, 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-end editable',
|
|
|
|
'text': moment(workingDayBreak.end, 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm edit-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('edit'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-edit'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm delete-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('delete'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-trash-alt'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm save-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('save'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-check-circle'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm cancel-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('cancel'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-ban'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}).appendTo('.breaks tbody');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('#' + index).prop('checked', false);
|
|
|
|
$('#' + index + '-start').prop('disabled', true);
|
|
|
|
$('#' + index + '-end').prop('disabled', true);
|
2021-11-06 19:38:37 +03:00
|
|
|
}
|
|
|
|
}.bind(this)
|
2022-01-17 17:31:04 +03:00
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
// Make break cells editable.
|
|
|
|
this.editableDayCell($('.breaks .break-day'));
|
|
|
|
this.editableTimeCell($('.breaks').find('.break-start, .break-end'));
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Setup the dom elements of a given working plan exception.
|
2016-04-24 20:28:33 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @param {Object} workingPlanExceptions Contains the working plan exception.
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
setupWorkingPlanExceptions(workingPlanExceptions) {
|
|
|
|
for (const date in workingPlanExceptions) {
|
|
|
|
const workingPlanException = workingPlanExceptions[date];
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
this.renderWorkingPlanExceptionRow(date, workingPlanException).appendTo(
|
|
|
|
'.working-plan-exceptions tbody'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Enable editable break day.
|
2016-04-24 20:28:33 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* This method makes editable the break day cells.
|
2016-04-24 20:28:33 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @param {Object} $selector The jquery selector ready for use.
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
editableDayCell($selector) {
|
|
|
|
const weekDays = {};
|
2022-01-18 10:22:25 +03:00
|
|
|
weekDays[lang('sunday')] = lang('sunday'); //'Sunday';
|
|
|
|
weekDays[lang('monday')] = lang('monday'); //'Monday';
|
|
|
|
weekDays[lang('tuesday')] = lang('tuesday'); //'Tuesday';
|
|
|
|
weekDays[lang('wednesday')] = lang('wednesday'); //'Wednesday';
|
|
|
|
weekDays[lang('thursday')] = lang('thursday'); //'Thursday';
|
|
|
|
weekDays[lang('friday')] = lang('friday'); //'Friday';
|
|
|
|
weekDays[lang('saturday')] = lang('saturday'); //'Saturday';
|
2022-01-17 17:31:04 +03:00
|
|
|
|
|
|
|
$selector.editable(
|
|
|
|
function (value) {
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'select',
|
|
|
|
data: weekDays,
|
|
|
|
event: 'edit',
|
|
|
|
height: '30px',
|
|
|
|
submit: '<button type="button" class="d-none submit-editable">Submit</button>',
|
|
|
|
cancel: '<button type="button" class="d-none cancel-editable">Cancel</button>',
|
|
|
|
onblur: 'ignore',
|
|
|
|
onreset: function () {
|
|
|
|
if (!this.enableCancel) {
|
|
|
|
return false; // disable ESC button
|
|
|
|
}
|
|
|
|
}.bind(this),
|
|
|
|
onsubmit: function () {
|
|
|
|
if (!this.enableSubmit) {
|
|
|
|
return false; // disable Enter button
|
|
|
|
}
|
|
|
|
}.bind(this)
|
2016-04-24 20:28:33 +03:00
|
|
|
}
|
2022-01-17 17:31:04 +03:00
|
|
|
);
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Enable editable break time.
|
|
|
|
*
|
|
|
|
* This method makes editable the break time cells.
|
2016-04-24 20:28:33 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @param {Object} $selector The jquery selector ready for use.
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
editableTimeCell($selector) {
|
|
|
|
$selector.editable(
|
|
|
|
function (value) {
|
|
|
|
// Do not return the value because the user needs to press the "Save" button.
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
event: 'edit',
|
|
|
|
height: '30px',
|
|
|
|
submit: $('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'd-none submit-editable',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('save')
|
2022-01-17 17:31:04 +03:00
|
|
|
}).get(0).outerHTML,
|
|
|
|
cancel: $('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'd-none cancel-editable',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('cancel')
|
2022-01-17 17:31:04 +03:00
|
|
|
}).get(0).outerHTML,
|
|
|
|
onblur: 'ignore',
|
|
|
|
onreset: function () {
|
|
|
|
if (!this.enableCancel) {
|
|
|
|
return false; // disable ESC button
|
|
|
|
}
|
|
|
|
}.bind(this),
|
|
|
|
onsubmit: function () {
|
|
|
|
if (!this.enableSubmit) {
|
|
|
|
return false; // disable Enter button
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
2022-10-16 18:05:23 +03:00
|
|
|
* Render a working plan exception row.
|
2016-04-24 20:28:33 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* This method makes editable the break time cells.
|
2016-05-14 13:28:42 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @param {String} date In "Y-m-d" format.
|
|
|
|
* @param {Object} workingPlanException Contains exception information.
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
renderWorkingPlanExceptionRow(date, workingPlanException) {
|
2022-01-18 10:18:22 +03:00
|
|
|
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
|
2022-01-17 17:31:04 +03:00
|
|
|
|
|
|
|
return $('<tr/>', {
|
|
|
|
'data': {
|
|
|
|
'date': date,
|
|
|
|
'workingPlanException': workingPlanException
|
|
|
|
},
|
|
|
|
'html': [
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'working-plan-exception-date',
|
2022-01-18 10:18:22 +03:00
|
|
|
'text': App.Utils.Date.format(date, vars('date_format'), vars('time_format'), false)
|
2022-01-17 17:31:04 +03:00
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'working-plan-exception--start',
|
|
|
|
'text': moment(workingPlanException.start, 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'working-plan-exception--end',
|
|
|
|
'text': moment(workingPlanException.end, 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm edit-working-plan-exception',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('edit'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-edit'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm delete-working-plan-exception',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('delete'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-trash-alt'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
/**
|
2022-01-18 10:47:16 +03:00
|
|
|
* Add the utility event listeners.
|
2016-04-24 20:28:33 +03:00
|
|
|
*/
|
2022-01-18 10:47:16 +03:00
|
|
|
addEventListeners() {
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Event: Day Checkbox "Click"
|
|
|
|
*
|
|
|
|
* Enable or disable the time selection for each day.
|
|
|
|
*/
|
|
|
|
$('.working-plan tbody').on('click', 'input:checkbox', function () {
|
|
|
|
const id = $(this).attr('id');
|
|
|
|
|
|
|
|
if ($(this).prop('checked') === true) {
|
|
|
|
$('#' + id + '-start')
|
|
|
|
.prop('disabled', false)
|
|
|
|
.val('9:00 AM');
|
|
|
|
$('#' + id + '-end')
|
|
|
|
.prop('disabled', false)
|
|
|
|
.val('6:00 PM');
|
|
|
|
} else {
|
|
|
|
$('#' + id + '-start')
|
|
|
|
.prop('disabled', true)
|
|
|
|
.val('');
|
|
|
|
$('#' + id + '-end')
|
|
|
|
.prop('disabled', true)
|
|
|
|
.val('');
|
|
|
|
}
|
|
|
|
});
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Event: Add Break Button "Click"
|
|
|
|
*
|
|
|
|
* A new row is added on the table and the user can enter the new break
|
|
|
|
* data. After that he can either press the save or cancel button.
|
|
|
|
*/
|
|
|
|
$('.add-break').on(
|
|
|
|
'click',
|
|
|
|
function () {
|
2022-01-18 10:18:22 +03:00
|
|
|
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
|
2022-01-17 17:31:04 +03:00
|
|
|
|
|
|
|
const $newBreak = $('<tr/>', {
|
|
|
|
'html': [
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-day editable',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('sunday')
|
2022-01-17 17:31:04 +03:00
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-start editable',
|
|
|
|
'text': moment('12:00', 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'break-end editable',
|
|
|
|
'text': moment('14:00', 'HH:mm').format(timeFormat).toLowerCase()
|
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm edit-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('edit'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-edit'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm delete-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('delete'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-trash-alt'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm save-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('save'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-check-circle'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm cancel-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('cancel'),
|
2022-01-17 17:31:04 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-ban'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}).appendTo('.breaks tbody');
|
|
|
|
|
|
|
|
// Bind editable and event handlers.
|
|
|
|
this.editableDayCell($newBreak.find('.break-day'));
|
|
|
|
this.editableTimeCell($newBreak.find('.break-start, .break-end'));
|
|
|
|
$newBreak.find('.edit-break').trigger('click');
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Break Button "Click"
|
|
|
|
*
|
|
|
|
* Enables the row editing for the "Breaks" table rows.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.edit-break', function () {
|
|
|
|
// Reset previous editable table cells.
|
|
|
|
const $previousEdits = $(this).closest('table').find('.editable');
|
|
|
|
|
|
|
|
$previousEdits.each(function (index, editable) {
|
|
|
|
if (editable.reset) {
|
|
|
|
editable.reset();
|
|
|
|
}
|
|
|
|
});
|
2021-11-06 19:38:37 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
// Make all cells in current row editable.
|
|
|
|
$(this).parent().parent().children().trigger('edit');
|
|
|
|
$(this)
|
|
|
|
.parent()
|
|
|
|
.parent()
|
|
|
|
.find('.break-start input, .break-end input')
|
|
|
|
.timepicker({
|
2022-01-18 10:18:22 +03:00
|
|
|
timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm',
|
2022-01-18 10:22:25 +03:00
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
|
|
|
timeOnlyTitle: lang('select_time'),
|
|
|
|
timeText: lang('time'),
|
|
|
|
hourText: lang('hour'),
|
|
|
|
minuteText: lang('minutes')
|
2022-01-17 17:31:04 +03:00
|
|
|
});
|
|
|
|
$(this).parent().parent().find('.break-day select').focus();
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
// Show save - cancel buttons.
|
|
|
|
const $tr = $(this).closest('tr');
|
|
|
|
$tr.find('.edit-break, .delete-break').addClass('d-none');
|
|
|
|
$tr.find('.save-break, .cancel-break').removeClass('d-none');
|
|
|
|
$tr.find('select,input:text').addClass('form-control form-control-sm');
|
|
|
|
});
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Event: Delete Break Button "Click"
|
|
|
|
*
|
|
|
|
* Removes the current line from the "Breaks" table.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.delete-break', function () {
|
|
|
|
$(this).parent().parent().remove();
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Event: Cancel Break Button "Click"
|
|
|
|
*
|
|
|
|
* Bring the ".breaks" table back to its initial state.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
|
|
|
*/
|
|
|
|
$(document).on(
|
|
|
|
'click',
|
|
|
|
'.cancel-break',
|
|
|
|
function (event) {
|
|
|
|
const element = event.target;
|
|
|
|
const $modifiedRow = $(element).closest('tr');
|
|
|
|
this.enableCancel = true;
|
|
|
|
$modifiedRow.find('.cancel-editable').trigger('click');
|
|
|
|
this.enableCancel = false;
|
|
|
|
|
|
|
|
$modifiedRow.find('.edit-break, .delete-break').removeClass('d-none');
|
|
|
|
$modifiedRow.find('.save-break, .cancel-break').addClass('d-none');
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Break Button "Click"
|
|
|
|
*
|
|
|
|
* Save the editable values and restore the table to its initial state.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
|
|
|
*/
|
|
|
|
$(document).on(
|
|
|
|
'click',
|
|
|
|
'.save-break',
|
|
|
|
function (event) {
|
|
|
|
// Break's start time must always be prior to break's end.
|
|
|
|
const element = event.target;
|
|
|
|
|
|
|
|
const $modifiedRow = $(element).closest('tr');
|
|
|
|
|
|
|
|
const startMoment = moment($modifiedRow.find('.break-start input').val(), 'HH:mm');
|
|
|
|
|
|
|
|
const endMoment = moment($modifiedRow.find('.break-end input').val(), 'HH:mm');
|
|
|
|
|
|
|
|
if (startMoment.isAfter(endMoment)) {
|
|
|
|
$modifiedRow.find('.break-end input').val(
|
|
|
|
startMoment
|
|
|
|
.add(1, 'hour')
|
2022-01-18 10:18:22 +03:00
|
|
|
.format(vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm')
|
2022-01-17 17:31:04 +03:00
|
|
|
.toLowerCase()
|
|
|
|
);
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
this.enableSubmit = true;
|
|
|
|
$modifiedRow.find('.editable .submit-editable').trigger('click');
|
|
|
|
this.enableSubmit = false;
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
$modifiedRow.find('.save-break, .cancel-break').addClass('d-none');
|
|
|
|
$modifiedRow.find('.edit-break, .delete-break').removeClass('d-none');
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add Working Plan Exception Button "Click"
|
|
|
|
*
|
|
|
|
* A new row is added on the table and the user can enter the new working plan exception.
|
|
|
|
*/
|
|
|
|
$(document).on(
|
|
|
|
'click',
|
|
|
|
'.add-working-plan-exception',
|
|
|
|
function () {
|
|
|
|
App.Components.WorkingPlanExceptionsModal.add().done(
|
|
|
|
function (date, workingPlanException) {
|
|
|
|
let $tr = null;
|
|
|
|
|
|
|
|
$('.working-plan-exceptions tbody tr').each(function (index, tr) {
|
|
|
|
if (date === $(tr).data('date')) {
|
|
|
|
$tr = $(tr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let $newTr = this.renderWorkingPlanExceptionRow(date, workingPlanException);
|
|
|
|
|
|
|
|
if ($tr) {
|
|
|
|
$tr.replaceWith($newTr);
|
|
|
|
} else {
|
|
|
|
$newTr.appendTo('.working-plan-exceptions tbody');
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit working plan exception Button "Click"
|
|
|
|
*
|
|
|
|
* Enables the row editing for the "working plan exception" table rows.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
|
|
|
*/
|
|
|
|
$(document).on(
|
|
|
|
'click',
|
|
|
|
'.edit-working-plan-exception',
|
|
|
|
function (event) {
|
|
|
|
const $tr = $(event.target).closest('tr');
|
|
|
|
const date = $tr.data('date');
|
|
|
|
const workingPlanException = $tr.data('workingPlanException');
|
|
|
|
|
|
|
|
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
|
|
|
|
function (date, workingPlanException) {
|
|
|
|
$tr.replaceWith(this.renderWorkingPlanExceptionRow(date, workingPlanException));
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete working plan exception Button "Click"
|
|
|
|
*
|
|
|
|
* Removes the current line from the "working plan exceptions" table.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.delete-working-plan-exception', function () {
|
|
|
|
$(this).closest('tr').remove();
|
|
|
|
});
|
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Get the working plan settings.
|
2018-04-12 16:03:46 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @return {Object} Returns the working plan settings object.
|
2018-04-12 16:03:46 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
get() {
|
|
|
|
const workingPlan = {};
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
|
2022-01-17 23:32:44 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
$('.working-plan input:checkbox').each(
|
|
|
|
function (index, checkbox) {
|
|
|
|
const id = $(checkbox).attr('id');
|
|
|
|
if ($(checkbox).prop('checked') === true) {
|
|
|
|
workingPlan[id] = {
|
2022-01-17 23:32:44 +03:00
|
|
|
start: moment($('#' + id + '-start').val(), timeFormat).format('HH:mm'),
|
|
|
|
end: moment($('#' + id + '-end').val(), timeFormat).format('HH:mm'),
|
2022-01-17 17:31:04 +03:00
|
|
|
breaks: []
|
|
|
|
};
|
|
|
|
|
|
|
|
$('.breaks tr').each(
|
|
|
|
function (index, tr) {
|
|
|
|
const day = this.convertDayToValue($(tr).find('.break-day').text());
|
|
|
|
|
|
|
|
if (day === id) {
|
|
|
|
const start = $(tr).find('.break-start').text();
|
|
|
|
const end = $(tr).find('.break-end').text();
|
|
|
|
|
|
|
|
workingPlan[id].breaks.push({
|
|
|
|
start: moment(
|
|
|
|
start,
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'
|
2022-01-17 17:31:04 +03:00
|
|
|
).format('HH:mm'),
|
2022-01-18 10:18:22 +03:00
|
|
|
end: moment(end, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format(
|
|
|
|
'HH:mm'
|
|
|
|
)
|
2022-01-17 17:31:04 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sort breaks increasingly by hour within day
|
|
|
|
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.localeCompare(break2.start);
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2022-01-17 17:31:04 +03:00
|
|
|
} else {
|
|
|
|
workingPlan[id] = null;
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
return workingPlan;
|
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Get the working plan exceptions settings.
|
2018-04-12 16:03:46 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @return {Object} Returns the working plan exceptions settings object.
|
2018-04-12 16:03:46 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
getWorkingPlanExceptions() {
|
|
|
|
const workingPlanExceptions = {};
|
2021-11-06 19:38:37 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
$('.working-plan-exceptions tbody tr').each(function (index, tr) {
|
|
|
|
const $tr = $(tr);
|
|
|
|
const date = $tr.data('date');
|
|
|
|
workingPlanExceptions[date] = $tr.data('workingPlanException');
|
|
|
|
});
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
return workingPlanExceptions;
|
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2022-01-17 17:31:04 +03:00
|
|
|
* Enables or disables the timepicker functionality from the working plan input text fields.
|
2018-04-12 16:03:46 +03:00
|
|
|
*
|
2022-01-17 17:31:04 +03:00
|
|
|
* @param {Boolean} [disabled] If true then the timepickers will be disabled.
|
2018-04-12 16:03:46 +03:00
|
|
|
*/
|
2022-01-17 17:31:04 +03:00
|
|
|
timepickers(disabled) {
|
|
|
|
disabled = disabled || false;
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2022-01-17 17:31:04 +03:00
|
|
|
if (disabled === false) {
|
|
|
|
// Set timepickers where needed.
|
|
|
|
$('.working-plan input:text').timepicker({
|
2022-01-18 10:18:22 +03:00
|
|
|
timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm',
|
2022-01-18 10:22:25 +03:00
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
|
|
|
timeOnlyTitle: lang('select_time'),
|
|
|
|
timeText: lang('time'),
|
|
|
|
hourText: lang('hour'),
|
|
|
|
minuteText: lang('minutes'),
|
2022-01-17 17:31:04 +03:00
|
|
|
|
|
|
|
onSelect: function () {
|
|
|
|
// Start time must be earlier than end time.
|
|
|
|
const startMoment = moment($(this).parent().parent().find('.work-start').val(), 'HH:mm');
|
|
|
|
|
|
|
|
const endMoment = moment($(this).parent().parent().find('.work-end').val(), 'HH:mm');
|
|
|
|
|
|
|
|
if (startMoment > endMoment) {
|
|
|
|
$(this)
|
|
|
|
.parent()
|
|
|
|
.parent()
|
|
|
|
.find('.work-end')
|
|
|
|
.val(
|
|
|
|
startMoment
|
|
|
|
.add(1, 'hour')
|
2022-01-18 10:18:22 +03:00
|
|
|
.format(vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm')
|
2022-01-17 17:31:04 +03:00
|
|
|
.toLowerCase()
|
|
|
|
);
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
}
|
2022-01-17 17:31:04 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('.working-plan input').timepicker('destroy');
|
|
|
|
}
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* Reset the current plan back to the company's default working plan.
|
|
|
|
*/
|
|
|
|
reset() {}
|
|
|
|
/**
|
|
|
|
* This is necessary for translated days.
|
|
|
|
*
|
|
|
|
* @param {String} value Day value could be like "monday", "tuesday" etc.
|
|
|
|
*/
|
|
|
|
convertValueToDay(value) {
|
|
|
|
switch (value) {
|
|
|
|
case 'sunday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('sunday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'monday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('monday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'tuesday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('tuesday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'wednesday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('wednesday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'thursday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('thursday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'friday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('friday');
|
2022-01-17 17:31:04 +03:00
|
|
|
case 'saturday':
|
2022-01-18 10:22:25 +03:00
|
|
|
return lang('saturday');
|
2022-01-17 17:31:04 +03:00
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
}
|
2022-01-17 17:31:04 +03:00
|
|
|
/**
|
|
|
|
* This is necessary for translated days.
|
|
|
|
*
|
|
|
|
* @param {String} day Day value could be like "Monday", "Tuesday" etc.
|
|
|
|
*/
|
|
|
|
convertDayToValue(day) {
|
|
|
|
switch (day) {
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('sunday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'sunday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('monday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'monday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('tuesday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'tuesday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('wednesday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'wednesday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('thursday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'thursday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('friday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'friday';
|
2022-01-18 10:22:25 +03:00
|
|
|
case lang('saturday'):
|
2022-01-17 17:31:04 +03:00
|
|
|
return 'saturday';
|
|
|
|
}
|
2016-04-24 20:28:33 +03:00
|
|
|
}
|
2022-01-17 17:31:04 +03:00
|
|
|
}
|
2013-12-20 13:12:36 +02:00
|
|
|
|
2022-01-11 12:52:58 +03:00
|
|
|
return WorkingPlan;
|
2016-10-23 22:52:36 +03:00
|
|
|
})();
|