Skip to content
Snippets Groups Projects

Issue #275 Added read-only daily planning view below new appointment form.

Merged Issue #275 Added read-only daily planning view below new appointment form.
All threads resolved!
Merged Carlos Vega requested to merge feature/add_daily_planning_to_appointment_creation into master
All threads resolved!
3 files
+ 248
169
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -248,148 +248,146 @@ function remove_event(event) {
@@ -248,148 +248,146 @@ function remove_event(event) {
add_event(event, event.color, event.subject_id, event.location_id, boxBody);
add_event(event, event.color, event.subject_id, event.location_id, boxBody);
}
}
$(document).ready(function () {
function addDailyPlanningCalendar(calendar_selector, replace_all, calendar_dict_props){
$('#calendar').fullCalendar({
 
var customButtons = {
 
datePickerButton: {
 
text: 'select',
 
click: function () {
 
var $btnCustom = $('.fc-datePickerButton-button');
 
if ($(".calendar-datepicker").length > 0) {
 
$(".calendar-datepicker").remove();
 
}
 
else {
 
$btnCustom.after('<div class="calendar-datepicker"/>');
 
$(".calendar-datepicker").datepicker().on('changeDate', function (ev) {
 
$(calendar_selector).fullCalendar('gotoDate', ev.date);
 
$(".calendar-datepicker").remove();
 
});
 
}
 
}
 
},
 
save: {
 
text: 'Save',
 
click: function () {
 
calendarEvents = $(calendar_selector).fullCalendar('clientEvents');
 
eventsToPersist = [];
 
var saveButton = $(".fc-save-button");
 
var currentBorder = saveButton.css('border-color');
 
$.each(calendarEvents, function (i, calendar_event) {
 
if (calendar_event.rendering !== "background") {
 
eventsToPersist.push({
 
'link_id': calendar_event.link_id,
 
'appointment_id': calendar_event.appointment_id,
 
'link_who': parseInt(calendar_event.resourceId),
 
'start': calendar_event.start.format()
 
});
 
if (calendar_event.link_id !== undefined) {
 
var index = eventsCleared.indexOf(calendar_event.link_id);
 
if (index > -1) {
 
eventsCleared.splice(index, 1);
 
}
 
} else {
 
var index = appointmentsCleared.indexOf(calendar_event.appointment_id);
 
if (index > -1) {
 
appointmentsCleared.splice(index, 1);
 
}
 
}
 
}
 
});
 
$.post({
 
url: events_url,
 
data: {
 
events_to_persist: JSON.stringify(eventsToPersist),
 
events_to_clear: JSON.stringify(eventsCleared),
 
appointments_to_clear: JSON.stringify(appointmentsCleared)
 
},
 
dataType: "json"
 
}).done(function (data) {
 
 
saveButton.css('border-color', 'green');
 
setTimeout(function () {
 
saveButton.css('border-color', currentBorder);
 
}, 200);
 
}).error(function (data) {
 
 
console.log(data);
 
saveButton.css('border-color', 'red');
 
showErrorInfo("There was an unexpected problem with saving data. " + "Please contact administrators.");
 
setTimeout(function () {
 
saveButton.delay(200).css('border-color', currentBorder);
 
}, 200);
 
});
 
}
 
},
 
clear: {
 
text: 'Clear',
 
click: function () {
 
calendarEvents = $(calendar_selector).fullCalendar('clientEvents');
 
$.each(calendarEvents, function (i, calendar_event) {
 
remove_event(calendar_event);
 
});
 
}
 
},
 
toPdf: {
 
text: 'PDF',
 
click: function () {
 
var srcEl = document.getElementById("calendar");
 
var parent = srcEl.parentNode;
 
var container = document.createElement("div");
 
container.style.backgroundColor = "#FFFFFF";
 
container.style.width = "3840px";
 
document.body.appendChild(container);
 
container.appendChild(srcEl);
 
 
var pdf = new jsPDF('l', 'mm', [1485, 270]);
 
pdf.addHTML(container, function () {
 
pdf.save('daily-planning.pdf');
 
parent.appendChild(srcEl);
 
document.body.removeChild(container);
 
});
 
}
 
}
 
};
 
 
var default_properties = {
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
defaultView: 'agendaDay',
defaultView: 'agendaDay',
eventDurationEditable: false,
eventDurationEditable: false,
eventStartEditable: true,
eventStartEditable: true,
editable: true,
editable: true,
selectable: true,
selectable: true,
eventOverlap: function (stillEvent, movingEvent) {
droppable: true,
if (stillEvent.rendering === "background") {
return true;
}
return false;
},
weekends: false,
weekends: false,
 
selectHelper: true,
 
groupByResource: true,
 
displayEventTime: true,
scrollTime: '08:00',
scrollTime: '08:00',
slotDuration: '00:30',
slotDuration: '00:30',
snapDuration: '00:05',
snapDuration: '00:05',
displayEventTime: true,
resourceOrder: 'role',
resourceGroupField: 'role',
dragRevertDuration: 0,
minTime: "08:00:00",
minTime: "08:00:00",
maxTime: "19:00:00",
maxTime: "19:00:00",
groupByResource: true,
height: "auto",
customButtons: {
datePickerButton: {
text: 'select',
click: function () {
var $btnCustom = $('.fc-datePickerButton-button');
if ($(".calendar-datepicker").length > 0) {
$(".calendar-datepicker").remove();
}
else {
$btnCustom.after('<div class="calendar-datepicker"/>');
$(".calendar-datepicker").datepicker().on('changeDate', function (ev) {
$('#calendar').fullCalendar('gotoDate', ev.date);
$(".calendar-datepicker").remove();
});
}
}
},
save: {
text: 'Save',
click: function () {
calendarEvents = $('#calendar').fullCalendar('clientEvents');
eventsToPersist = [];
var saveButton = $(".fc-save-button");
var currentBorder = saveButton.css('border-color');
$.each(calendarEvents, function (i, calendar_event) {
if (calendar_event.rendering !== "background") {
eventsToPersist.push({
'link_id': calendar_event.link_id,
'appointment_id': calendar_event.appointment_id,
'link_who': parseInt(calendar_event.resourceId),
'start': calendar_event.start.format()
});
if (calendar_event.link_id !== undefined) {
var index = eventsCleared.indexOf(calendar_event.link_id);
if (index > -1) {
eventsCleared.splice(index, 1);
}
} else {
var index = appointmentsCleared.indexOf(calendar_event.appointment_id);
if (index > -1) {
appointmentsCleared.splice(index, 1);
}
}
}
});
$.post({
url: events_url,
data: {
events_to_persist: JSON.stringify(eventsToPersist),
events_to_clear: JSON.stringify(eventsCleared),
appointments_to_clear: JSON.stringify(appointmentsCleared)
},
dataType: "json"
}).done(function (data) {
saveButton.css('border-color', 'green');
setTimeout(function () {
saveButton.css('border-color', currentBorder);
}, 200);
}).error(function (data) {
console.log(data);
saveButton.css('border-color', 'red');
showErrorInfo("There was an unexpected problem with saving data. " +
"Please contact administrators.");
setTimeout(function () {
saveButton.delay(200).css('border-color', currentBorder);
}, 200);
});
}
},
clear: {
text: 'Clear',
click: function () {
calendarEvents = $('#calendar').fullCalendar('clientEvents');
$.each(calendarEvents, function (i, calendar_event) {
remove_event(calendar_event);
});
}
},
toPdf: {
text: 'PDF',
click: function () {
var srcEl = document.getElementById("calendar");
var parent = srcEl.parentNode;
var container = document.createElement("div");
container.style.backgroundColor = "#FFFFFF";
container.style.width = "3840px";
document.body.appendChild(container);
container.appendChild(srcEl);
var pdf = new jsPDF('l', 'mm', [1485, 270]);
pdf.addHTML(container, function () {
pdf.save('daily-planning.pdf');
parent.appendChild(srcEl);
document.body.removeChild(container);
});
}
}
},
viewRender: function (view, element) {
var date = view.start.format('YYYY-MM-DD');
$('#calendar').fullCalendar('removeEvents');
get_subjects_events(date);
},
businessHours: {
businessHours: {
start: '08:00',
start: '08:00',
end: '19:00'
end: '19:00'
},
},
 
dragRevertDuration: 0,
 
height: "auto",
 
customButtons: customButtons,
header: {
header: {
left: 'prev,next today',
left: 'prev,next today',
center: 'title, datePickerButton',
center: 'title, datePickerButton',
right: 'save, clear, toPdf'
right: 'save, clear, toPdf'
},
},
droppable: true,
// VIEW
 
viewRender: function (view, element) {
 
var date = view.start.format('YYYY-MM-DD');
 
$(calendar_selector).fullCalendar('removeEvents');
 
get_subjects_events(date);
 
},
 
// RESOURCES
 
resourceOrder: 'role',
 
resourceGroupField: 'role',
resourceAreaWidth: '15%',
resourceAreaWidth: '15%',
resourceLabelText: 'Workers',
resourceLabelText: 'Workers',
refetchResourcesOnNavigate: true,
refetchResourcesOnNavigate: true,
@@ -421,7 +419,7 @@ $(document).ready(function () {
@@ -421,7 +419,7 @@ $(document).ready(function () {
},
},
resources: function(callback){
resources: function(callback){
setTimeout(function(){
setTimeout(function(){
var view = $('#calendar').fullCalendar('getView');
var view = $(calendar_selector).fullCalendar('getView');
$.ajax({
$.ajax({
url: resources_url,
url: resources_url,
type: 'GET',
type: 'GET',
@@ -431,13 +429,14 @@ $(document).ready(function () {
@@ -431,13 +429,14 @@ $(document).ready(function () {
}
}
}).then(function(resources){
}).then(function(resources){
//Filter out roles
//Filter out roles
var checked_roles = $('.role_list_item > input:checked').map( (i,e) => e.value).toArray();
if($('.role_list_item > input').length > 0){
resources = resources.filter(resource => checked_roles.includes(resource.role));
var checked_roles = $('.role_list_item > input:checked').map( (i,e) => e.value).toArray();
callback(resources)
resources = resources.filter(resource => checked_roles.includes(resource.role));
 
}
 
callback(resources);
});
});
}, 0);
}, 0);
},
},
events: [],
eventRender: function (event, element) {
eventRender: function (event, element) {
if (event.rendering !== 'background') {
if (event.rendering !== 'background') {
var content =
var content =
@@ -457,6 +456,13 @@ $(document).ready(function () {
@@ -457,6 +456,13 @@ $(document).ready(function () {
} else {
} else {
}
}
},
},
 
// EVENTS
 
eventOverlap: function (stillEvent, movingEvent) {
 
if (stillEvent.rendering === "background") {
 
return true;
 
}
 
return false;
 
},
selectAllow: function (selectInfo) {
selectAllow: function (selectInfo) {
return false;
return false;
},
},
@@ -471,7 +477,6 @@ $(document).ready(function () {
@@ -471,7 +477,6 @@ $(document).ready(function () {
eventDragStart: function (event, jsEvent, view) {
eventDragStart: function (event, jsEvent, view) {
$('.popover').popover('hide');
$('.popover').popover('hide');
},
},
selectHelper: true,
drop: function (date, jsEvent, ui, resourceId) {
drop: function (date, jsEvent, ui, resourceId) {
$(this).remove();
$(this).remove();
},
},
@@ -482,9 +487,20 @@ $(document).ready(function () {
@@ -482,9 +487,20 @@ $(document).ready(function () {
};
};
setTimeout(function() {resizeCalendarColumns()}, 100);
setTimeout(function() {resizeCalendarColumns()}, 100);
}
}
});
};
})
;
// REPLACE DEFAULT PROPERTIES
 
if(replace_all){
 
default_properties = calendar_dict_props;
 
}else{
 
for (var key in calendar_dict_props) {
 
default_properties[key] = calendar_dict_props[key];
 
}
 
}
 
 
$(calendar_selector).fullCalendar(default_properties);
 
 
}
//RESIZE COLUMNS AND ENABLE HORIZONTAL SCROLL
//RESIZE COLUMNS AND ENABLE HORIZONTAL SCROLL
function resizeCalendarColumns(){
function resizeCalendarColumns(){
Loading