calendar not editable pandora_enterprise#3943

This commit is contained in:
Daniel Barbero Martin 2022-02-07 13:07:48 +01:00
parent dca70fa8ec
commit 0e0e737283
4 changed files with 395 additions and 267 deletions

View File

@ -700,6 +700,7 @@ if ($step == 2) {
[ [
'message' => __('No alert has been scheduled yet'), 'message' => __('No alert has been scheduled yet'),
'force_style' => 'display:none;', 'force_style' => 'display:none;',
'force_class' => 'alert_schedule',
], ],
'', '',
true true
@ -1509,6 +1510,8 @@ if ($step == 2) {
} }
}); });
var is_management_allowed = parseInt('<?php echo (int) $is_management_allowed; ?>');
var eventsBBDD = $("#hidden-schedule").val(); var eventsBBDD = $("#hidden-schedule").val();
if(eventsBBDD === '') { if(eventsBBDD === '') {
eventsBBDD = '<?php echo json_encode($default_events_calendar); ?>'; eventsBBDD = '<?php echo json_encode($default_events_calendar); ?>';
@ -1516,6 +1519,58 @@ if ($step == 2) {
var events = loadEventBBDD(eventsBBDD); var events = loadEventBBDD(eventsBBDD);
var calendarEl = document.getElementById('calendar_map'); var calendarEl = document.getElementById('calendar_map');
var options = {
contentHeight: "auto",
headerToolbar: {
left: "",
center: "",
right: is_management_allowed === 0 ? '' : "timeGridWeek,dayGridWeek"
},
buttonText: {
dayGridWeek: '<?php echo __('Simple'); ?>',
timeGridWeek: '<?php echo __('Detailed'); ?>'
},
dayHeaderFormat: { weekday: "short" },
initialView: "dayGridWeek",
navLinks: false,
selectable: true,
selectMirror: true,
slotDuration: "01:00:00",
slotLabelInterval: "02:00:00",
snapDuration: "01:00:00",
slotMinTime: "00:00:00",
slotMaxTime: "24:00:00",
scrollTime: "01:00:00",
locale: "en-GB",
firstDay: 1,
eventTimeFormat: {
hour: "numeric",
minute: "2-digit",
hour12: false
},
eventColor: "#82b92e",
editable: is_management_allowed === 0 ? false : true,
dayMaxEvents: 3,
dayPopoverFormat: { weekday: "long" },
defaultAllDay: false,
displayEventTime: true,
displayEventEnd: true,
selectOverlap: false,
eventOverlap: false,
allDaySlot: true,
droppable: false,
select: is_management_allowed === 0 ? false : select_alert_template,
selectAllow: is_management_allowed === 0 ? false : selectAllow_alert_template,
eventAllow: is_management_allowed === 0 ? false : eventAllow_alert_template,
eventDrop: is_management_allowed === 0 ? false : eventDrop_alert_template,
eventDragStop: is_management_allowed === 0 ? false : eventDragStop_alert_template,
eventResize: is_management_allowed === 0 ? false : eventResize_alert_template,
eventMouseEnter: is_management_allowed === 0 ? false : eventMouseEnter_alert_template,
eventMouseLeave: is_management_allowed === 0 ? false : eventMouseLeave_alert_template,
eventClick: is_management_allowed === 0 ? false : eventClick_alert_template,
};
var settings = { var settings = {
timeFormat: '<?php echo TIME_FORMAT_JS; ?>', timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
timeOnlyTitle: '<?php echo __('Choose time'); ?>', timeOnlyTitle: '<?php echo __('Choose time'); ?>',
@ -1530,12 +1585,10 @@ if ($step == 2) {
userLanguage: '<?php echo get_user_language(); ?>', userLanguage: '<?php echo get_user_language(); ?>',
loadingText: '<?php echo __('Loading, this operation might take several minutes...'); ?>', loadingText: '<?php echo __('Loading, this operation might take several minutes...'); ?>',
tooltipText: '<?php echo __('Drag out to remove'); ?>', tooltipText: '<?php echo __('Drag out to remove'); ?>',
simple: '<?php echo __('Simple'); ?>',
detailed: '<?php echo __('Detailed'); ?>',
alert: '<?php echo __('Alert'); ?>' alert: '<?php echo __('Alert'); ?>'
} }
var calendar = fullCalendarPandora(calendarEl, settings, events); var calendar = fullCalendarPandora(calendarEl, options, settings, events);
calendar.render(); calendar.render();
<?php <?php
} else if ($step == 3) { } else if ($step == 3) {

View File

@ -251,6 +251,7 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t
$icon_image = ''; $icon_image = '';
$no_close_bool = false; $no_close_bool = false;
$force_style = ''; $force_style = '';
$force_class = '';
if (is_array($message)) { if (is_array($message)) {
if (!empty($message['title'])) { if (!empty($message['title'])) {
$text_title = $message['title']; $text_title = $message['title'];
@ -271,6 +272,10 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t
if (!empty($message['force_style'])) { if (!empty($message['force_style'])) {
$force_style = $message['force_style']; $force_style = $message['force_style'];
} }
if (empty($message['force_class']) === false) {
$force_class = $message['force_class'];
}
} else { } else {
$text_message = $message; $text_message = $message;
} }
@ -319,6 +324,10 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t
$id = 'info_box_'.uniqid(); $id = 'info_box_'.uniqid();
if (empty($force_class) === false) {
$class = $class.' '.$force_class;
}
// Use the no_meta parameter because this image is only in the base console. // Use the no_meta parameter because this image is only in the base console.
$output = '<table cellspacing="0" cellpadding="0" id="'.$id.'" '.$attributes.' $output = '<table cellspacing="0" cellpadding="0" id="'.$id.'" '.$attributes.'
class="info_box '.$id.' '.$class.' textodialogo" style="'.$force_style.'"> class="info_box '.$id.' '.$class.' textodialogo" style="'.$force_style.'">

View File

@ -1,275 +1,334 @@
/* globals $, FullCalendar, uniqId, confirmDialog*/ /* globals $, FullCalendar, uniqId, confirmDialog*/
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function fullCalendarPandora(calendarEl, settings, initialEvents) { function fullCalendarPandora(calendarEl, options, settings, initialEvents) {
var calendar = new FullCalendar.Calendar(calendarEl, { var calendar = new FullCalendar.Calendar(calendarEl, {
//height: 200, contentHeight: options.contentHeight,
contentHeight: "auto", headerToolbar: options.headerToolbar,
headerToolbar: { buttonText: options.buttonText,
left: "", dayHeaderFormat: options.dayHeaderFormat,
center: "", initialView: options.initialView,
right: "timeGridWeek,dayGridWeek" navLinks: options.navLinks,
}, selectable: options.selectable,
buttonText: { selectMirror: options.selectMirror,
dayGridWeek: settings.simple, slotDuration: options.slotDuration,
timeGridWeek: settings.detailed slotLabelInterval: options.slotLabelInterval,
}, snapDuration: options.snapDuration,
dayHeaderFormat: { weekday: "short" }, slotMinTime: options.slotMinTime,
initialView: "dayGridWeek", slotMaxTime: options.slotMaxTime,
navLinks: false, scrollTime: options.scrollTime,
selectable: true, locale: options.locale,
selectMirror: true, firstDay: options.firstDay,
slotDuration: "01:00:00", eventTimeFormat: options.eventTimeFormat,
slotLabelInterval: "02:00:00", eventColor: options.eventColor,
snapDuration: "01:00:00", editable: options.editable,
//slotLabelFormat: { dayMaxEvents: options.dayMaxEvents,
// hour: "numeric", dayPopoverFormat: options.dayPopoverFormat,
// minute: "2-digit", defaultAllDay: options.defaultAllDay,
// hour12: false displayEventTime: options.displayEventTime,
//}, displayEventEnd: options.displayEventEnd,
slotMinTime: "00:00:00", selectOverlap: options.selectOverlap,
slotMaxTime: "24:00:00", eventOverlap: options.eventOverlap,
scrollTime: "01:00:00", allDaySlot: options.allDaySlot,
locale: "en-GB", droppable: options.droppable,
//timeZone: "local",
firstDay: 1,
eventTimeFormat: {
hour: "numeric",
minute: "2-digit",
hour12: false
},
eventColor: "#82b92e",
editable: true,
dayMaxEvents: 3,
dayPopoverFormat: { weekday: "long" },
events: initialEvents, events: initialEvents,
defaultAllDay: false, select:
displayEventTime: true, options.select != undefined && typeof options.select === "function"
displayEventEnd: true, ? function(info) {
select: function(info) { options.select(info, calendar);
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1; }
if ( : false,
info.start.getDay() == info.end.getDay() || selectAllow:
(nextDay == info.end.getDay() && time_format(info.end) == "00:00:00") options.selectAllow != undefined &&
) { typeof options.selectAllow === "function"
recalculate_events(calendar, {}, info.start, info.end, true); ? function(info) {
return options.selectAllow(info);
}
: false,
eventAllow:
options.eventAllow != undefined &&
typeof options.eventAllow === "function"
? function(dropInfo, draggedEvent) {
return options.eventAllow(dropInfo, draggedEvent);
}
: false,
eventDrop:
options.eventDrop != undefined && typeof options.eventDrop === "function"
? function(info) {
options.eventDrop(info, calendar);
}
: false,
eventDragStop:
options.eventDragStop != undefined &&
typeof options.eventDragStop === "function"
? function(info) {
options.eventDragStop(info, calendar);
}
: false,
eventResize:
options.eventResize != undefined &&
typeof options.eventResize === "function"
? function(info) {
options.eventResize(info, calendar);
}
: false,
eventMouseEnter:
options.eventMouseEnter != undefined &&
typeof options.eventMouseEnter === "function"
? function(info) {
options.eventMouseEnter(info, settings.tooltipText);
}
: false,
eventMouseLeave:
options.eventMouseLeave != undefined &&
typeof options.eventMouseLeave === "function"
? function(info) {
options.eventMouseLeave(info);
}
: false,
eventClick:
options.eventClick != undefined &&
typeof options.eventClick === "function"
? function(info) {
options.eventClick(info, calendar, settings);
}
: false
});
return calendar;
}
// Specific functions Alerts templates && Correlated events.
// eslint-disable-next-line no-unused-vars
function select_alert_template(info, calendar) {
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
if (
info.start.getDay() == info.end.getDay() ||
(nextDay == info.end.getDay() && time_format(info.end) == "00:00:00")
) {
recalculate_events(calendar, {}, info.start, info.end, true);
}
calendar.unselect();
save_data_input(calendar);
}
// eslint-disable-next-line no-unused-vars
function selectAllow_alert_template(info) {
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1;
if (
info.start.getDay() == info.end.getDay() ||
(nextDay == info.end.getDay() && time_format(info.end) == "00:00:00")
) {
return true;
}
return false;
}
// eslint-disable-next-line no-unused-vars
function eventAllow_alert_template(dropInfo, draggedEvent) {
if (dropInfo.allDay != true) {
var nextDay =
draggedEvent.start.getDay() === 6 ? 0 : draggedEvent.start.getDay() + 1;
if (
(draggedEvent.start.getDay() == dropInfo.start.getDay() &&
dropInfo.start.getDay() == dropInfo.end.getDay()) ||
(nextDay == dropInfo.end.getDay() &&
time_format(dropInfo.end) == "00:00:00")
) {
return true;
}
}
return false;
}
// eslint-disable-next-line no-unused-vars
function eventDrop_alert_template(info, calendar) {
if (info.event.allDay != true) {
var nextDay =
info.event.start.getDay() === 6 ? 0 : info.event.start.getDay() + 1;
if (
info.event.start.getDay() == info.event.end.getDay() ||
(nextDay == info.event.end.getDay() &&
time_format(info.event.end) == "00:00:00")
) {
recalculate_events(
calendar,
info.event,
info.event.start,
info.event.end,
false
);
save_data_input(calendar);
}
}
}
// eslint-disable-next-line no-unused-vars
function eventDragStop_alert_template(info, calendar) {
var trashEl = $("#calendar_map");
var ofs = trashEl.offset();
var x1 = ofs.left;
var x2 = ofs.left + trashEl.outerWidth(true);
var y1 = ofs.top;
var y2 = ofs.top + trashEl.outerHeight(true);
if (
x1 >= info.jsEvent.pageX ||
x2 <= info.jsEvent.pageX ||
y1 >= info.jsEvent.pageY ||
y2 <= info.jsEvent.pageY
) {
// Remove event.
info.event.remove();
save_data_input(calendar);
}
}
// eslint-disable-next-line no-unused-vars
function eventResize_alert_template(info, calendar) {
var nextDay =
info.event.start.getDay() === 6 ? 0 : info.event.start.getDay() + 1;
if (
info.event.start.getDay() == info.event.end.getDay() ||
(nextDay == info.event.end.getDay() &&
time_format(info.event.end) == "00:00:00")
) {
recalculate_events(
calendar,
info.event,
info.event.start,
info.event.end,
false
);
save_data_input(calendar);
}
}
// eslint-disable-next-line no-unused-vars
function eventMouseEnter_alert_template(info, tooltipText) {
var tooltip = '<div class="tooltipevent">';
tooltip += tooltipText;
tooltip += "</div>";
$(tooltip).appendTo(info.el);
}
// eslint-disable-next-line no-unused-vars
function eventMouseLeave_alert_template(info) {
$(".tooltipevent").remove();
}
// eslint-disable-next-line no-unused-vars
function eventClick_alert_template(info, calendar, settings) {
var calendar_date_from = new Date(calendar.view.activeStart);
var calendar_days = [];
var acum = 1;
var i = 0;
// Week date.
for (var index = 1; index <= 7; index++) {
// Sunday key 0.
if (acum === 7) {
acum = 0;
}
var date_acum = new Date(calendar_date_from);
calendar_days[acum] = date_acum.setDate(calendar_date_from.getDate() + i);
acum++;
i++;
}
confirmDialog({
title: settings.alert,
message: function() {
var id = "div-" + uniqId();
var loading = settings.loadingText;
$.ajax({
method: "post",
url: settings.url,
data: {
page: "include/ajax/alert_list.ajax",
resize_event_week: true,
day_from: info.event.start.getDay(),
day_to: info.event.end.getDay(),
time_from: time_format(info.event.start),
time_to: time_format(info.event.end)
},
dataType: "html",
success: function(data) {
$("#" + id)
.empty()
.append(data);
$("#text-time_from_event, #text-time_to_event").timepicker({
timeFormat: settings.timeFormat,
timeOnlyTitle: settings.timeOnlyTitle,
timeText: settings.timeText,
hourText: settings.hourText,
minuteText: settings.minuteText,
secondText: settings.secondText,
currentText: settings.currentText,
closeText: settings.closeText
});
$.datepicker.setDefaults(
$.datepicker.regional[settings.userLanguage]
);
},
error: function(error) {
console.error(error);
}
});
return "<div id ='" + id + "'>" + loading + "</div>";
},
onAccept: function() {
var replace_day_from = $("#hidden-day_from").val();
var replace_time_from = $("#text-time_from_event").val();
var array_time_from = replace_time_from.split(":");
var new_date_from = new Date(calendar_days[replace_day_from]);
new_date_from.setHours(
array_time_from[0],
array_time_from[1],
array_time_from[2]
);
var replace_day_to = $("#hidden-day_to").val();
var replace_time_to = $("#text-time_to_event").val();
if (replace_time_to === "23:59:59") {
replace_day_to++;
replace_time_to = "00:00:00";
}
var array_time_to = replace_time_to.split(":");
var new_date_to = new Date(calendar_days[replace_day_to]);
new_date_to.setHours(
array_time_to[0],
array_time_to[1],
array_time_to[2]
);
if (new_date_from < new_date_to) {
recalculate_events(
calendar,
info.event,
new_date_from,
new_date_to,
false
);
} else {
console.error("You cannot add smaller events");
} }
calendar.unselect();
save_data_input(calendar); save_data_input(calendar);
}, },
selectAllow: function(info) { newButton: {
var nextDay = info.start.getDay() === 6 ? 0 : info.start.getDay() + 1; text: settings.removeText,
if ( class: "",
info.start.getDay() == info.end.getDay() || onFunction: function() {
(nextDay == info.end.getDay() && time_format(info.end) == "00:00:00")
) {
return true;
}
return false;
},
eventAllow: function(dropInfo, draggedEvent) {
if (dropInfo.allDay != true) {
var nextDay =
draggedEvent.start.getDay() === 6
? 0
: draggedEvent.start.getDay() + 1;
if (
(draggedEvent.start.getDay() == dropInfo.start.getDay() &&
dropInfo.start.getDay() == dropInfo.end.getDay()) ||
(nextDay == dropInfo.end.getDay() &&
time_format(dropInfo.end) == "00:00:00")
) {
return true;
}
}
return false;
},
eventDrop: function(info) {
if (info.event.allDay != true) {
var nextDay =
info.event.start.getDay() === 6 ? 0 : info.event.start.getDay() + 1;
if (
info.event.start.getDay() == info.event.end.getDay() ||
(nextDay == info.event.end.getDay() &&
time_format(info.event.end) == "00:00:00")
) {
recalculate_events(
calendar,
info.event,
info.event.start,
info.event.end,
false
);
save_data_input(calendar);
}
}
},
eventDragStop: function(info) {
var trashEl = $("#calendar_map");
var ofs = trashEl.offset();
var x1 = ofs.left;
var x2 = ofs.left + trashEl.outerWidth(true);
var y1 = ofs.top;
var y2 = ofs.top + trashEl.outerHeight(true);
if (
x1 >= info.jsEvent.pageX ||
x2 <= info.jsEvent.pageX ||
y1 >= info.jsEvent.pageY ||
y2 <= info.jsEvent.pageY
) {
// Remove event. // Remove event.
info.event.remove(); info.event.remove();
save_data_input(calendar); save_data_input(calendar);
} }
}, }
eventResize: function(info) {
var nextDay =
info.event.start.getDay() === 6 ? 0 : info.event.start.getDay() + 1;
if (
info.event.start.getDay() == info.event.end.getDay() ||
(nextDay == info.event.end.getDay() &&
time_format(info.event.end) == "00:00:00")
) {
recalculate_events(
calendar,
info.event,
info.event.start,
info.event.end,
false
);
save_data_input(calendar);
}
},
eventMouseEnter: function(info) {
var tooltip = '<div class="tooltipevent">';
tooltip += settings.tooltipText;
tooltip += "</div>";
$(tooltip).appendTo(info.el);
},
eventMouseLeave: function() {
$(".tooltipevent").remove();
},
eventClick: function(info) {
var calendar_date_from = new Date(calendar.view.activeStart);
var calendar_days = [];
var acum = 1;
var i = 0;
// Week date.
for (var index = 1; index <= 7; index++) {
// Sunday key 0.
if (acum === 7) {
acum = 0;
}
var date_acum = new Date(calendar_date_from);
calendar_days[acum] = date_acum.setDate(
calendar_date_from.getDate() + i
);
acum++;
i++;
}
confirmDialog({
title: settings.alert,
message: function() {
var id = "div-" + uniqId();
var loading = settings.loadingText;
$.ajax({
method: "post",
url: settings.url,
data: {
page: "include/ajax/alert_list.ajax",
resize_event_week: true,
day_from: info.event.start.getDay(),
day_to: info.event.end.getDay(),
time_from: time_format(info.event.start),
time_to: time_format(info.event.end)
},
dataType: "html",
success: function(data) {
$("#" + id)
.empty()
.append(data);
$("#text-time_from_event, #text-time_to_event").timepicker({
timeFormat: settings.timeFormat,
timeOnlyTitle: settings.timeOnlyTitle,
timeText: settings.timeText,
hourText: settings.hourText,
minuteText: settings.minuteText,
secondText: settings.secondText,
currentText: settings.currentText,
closeText: settings.closeText
});
$.datepicker.setDefaults(
$.datepicker.regional[settings.userLanguage]
);
},
error: function(error) {
console.error(error);
}
});
return "<div id ='" + id + "'>" + loading + "</div>";
},
onAccept: function() {
var replace_day_from = $("#hidden-day_from").val();
var replace_time_from = $("#text-time_from_event").val();
var array_time_from = replace_time_from.split(":");
var new_date_from = new Date(calendar_days[replace_day_from]);
new_date_from.setHours(
array_time_from[0],
array_time_from[1],
array_time_from[2]
);
var replace_day_to = $("#hidden-day_to").val();
var replace_time_to = $("#text-time_to_event").val();
if (replace_time_to === "23:59:59") {
replace_day_to++;
replace_time_to = "00:00:00";
}
var array_time_to = replace_time_to.split(":");
var new_date_to = new Date(calendar_days[replace_day_to]);
new_date_to.setHours(
array_time_to[0],
array_time_to[1],
array_time_to[2]
);
if (new_date_from < new_date_to) {
recalculate_events(
calendar,
info.event,
new_date_from,
new_date_to,
false
);
} else {
console.error("You cannot add smaller events");
}
save_data_input(calendar);
},
newButton: {
text: settings.removeText,
class: "",
onFunction: function() {
// Remove event.
info.event.remove();
save_data_input(calendar);
}
}
});
},
selectOverlap: false,
eventOverlap: false,
allDaySlot: true
}); });
return calendar;
} }
function time_format(date) { function time_format(date) {
@ -367,9 +426,9 @@ function save_data_input(calendar) {
}); });
if (data && Object.keys(data).length === 0) { if (data && Object.keys(data).length === 0) {
$(".warning.textodialogo").show(); $(".alert_schedule.textodialogo").show();
} else { } else {
$(".warning").hide(); $(".alert_schedule").hide();
} }
$("#hidden-schedule").val(JSON.stringify(data)); $("#hidden-schedule").val(JSON.stringify(data));
@ -378,11 +437,11 @@ function save_data_input(calendar) {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function loadEventBBDD(events) { function loadEventBBDD(events) {
if (events == undefined || events === null || events === "") { if (events == undefined || events === null || events === "") {
$(".warning").show(); $(".alert_schedule").show();
return {}; return {};
} }
$(".warning").hide(); $(".alert_schedule").hide();
var current_day = new Date(); var current_day = new Date();

View File

@ -8486,6 +8486,8 @@ div#err_msg_centralised {
width: 70px; width: 70px;
overflow-wrap: break-word; overflow-wrap: break-word;
white-space: pre-wrap; white-space: pre-wrap;
font-size: 10px;
line-height: 12px;
} }
#select_multiple_modules_filtered > div { #select_multiple_modules_filtered > div {
@ -8524,3 +8526,8 @@ div#err_msg_centralised {
width: 95%; width: 95%;
height: 95%; height: 95%;
} }
.resume_calendar_map {
width: 90%;
margin: 0 auto;
}