mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 08:45:12 +02:00
alert template schedule pandora_enterprise#3943
This commit is contained in:
parent
b8a3dccc8d
commit
a4f092f0a0
@ -1282,7 +1282,7 @@ ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript
|
|||||||
ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/');
|
ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/');
|
||||||
ui_require_css_file('main.min', 'include/javascript/fullcalendar/');
|
ui_require_css_file('main.min', 'include/javascript/fullcalendar/');
|
||||||
ui_require_javascript_file('main.min', 'include/javascript/fullcalendar/');
|
ui_require_javascript_file('main.min', 'include/javascript/fullcalendar/');
|
||||||
|
ui_require_javascript_file('pandora_fullcalendar');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -1305,18 +1305,18 @@ var not_normal = <?php echo "'".__('The alert would fire when the module is in n
|
|||||||
|
|
||||||
function check_fields_step2() {
|
function check_fields_step2() {
|
||||||
var correct = true;
|
var correct = true;
|
||||||
|
|
||||||
type = $("select[name='type']").val();
|
type = $("select[name='type']").val();
|
||||||
min_v = $("input[name='min']").val();
|
min_v = $("input[name='min']").val();
|
||||||
max_v = $("input[name='max']").val();
|
max_v = $("input[name='max']").val();
|
||||||
|
|
||||||
if (type == 'max_min') {
|
if (type == 'max_min') {
|
||||||
if ((min_v == 0) && (max_v == 0)) {
|
if ((min_v == 0) && (max_v == 0)) {
|
||||||
alert(error_message_min_max_zero);
|
alert(error_message_min_max_zero);
|
||||||
correct = false;
|
correct = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return correct;
|
return correct;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1391,7 +1391,7 @@ if ($step == 2) {
|
|||||||
$("input#text-value").keyup (render_example);
|
$("input#text-value").keyup (render_example);
|
||||||
$("input#text-max").keyup (render_example);
|
$("input#text-max").keyup (render_example);
|
||||||
$("input#text-min").keyup (render_example);
|
$("input#text-min").keyup (render_example);
|
||||||
|
|
||||||
$("#type").change (function () {
|
$("#type").change (function () {
|
||||||
switch (this.value) {
|
switch (this.value) {
|
||||||
case "equal":
|
case "equal":
|
||||||
@ -1399,76 +1399,74 @@ if ($step == 2) {
|
|||||||
$("img#regex_good, img#regex_bad, span#matches_value").hide ();
|
$("img#regex_good, img#regex_bad, span#matches_value").hide ();
|
||||||
$("#template-max, #template-min").hide ();
|
$("#template-max, #template-min").hide ();
|
||||||
$("#template-value, #template-example").show ();
|
$("#template-value, #template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
if (this.value == "equal")
|
if (this.value == "equal")
|
||||||
$("span#example").empty ().append (is);
|
$("span#example").empty ().append (is);
|
||||||
else
|
else
|
||||||
$("span#example").empty ().append (is_not);
|
$("span#example").empty ().append (is_not);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "regex":
|
case "regex":
|
||||||
$("#template-max, #template-min").hide ();
|
$("#template-max, #template-min").hide ();
|
||||||
$("#template-value, #template-example, span#matches_value").show ();
|
$("#template-value, #template-example, span#matches_value").show ();
|
||||||
check_regex ();
|
check_regex ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
if ($("#checkbox-matches_value")[0].checked)
|
if ($("#checkbox-matches_value")[0].checked)
|
||||||
$("span#example").empty ().append (matches);
|
$("span#example").empty ().append (matches);
|
||||||
else
|
else
|
||||||
$("span#example").empty ().append (matches_not);
|
$("span#example").empty ().append (matches_not);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "max_min":
|
case "max_min":
|
||||||
$("#template-value").hide ();
|
$("#template-value").hide ();
|
||||||
$("#template-max, #template-min, #template-example, span#matches_value").show ();
|
$("#template-max, #template-min, #template-example, span#matches_value").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
if ($("#checkbox-matches_value")[0].checked)
|
if ($("#checkbox-matches_value")[0].checked)
|
||||||
$("span#example").empty ().append (between);
|
$("span#example").empty ().append (between);
|
||||||
else
|
else
|
||||||
$("span#example").empty ().append (between_not);
|
$("span#example").empty ().append (between_not);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "max":
|
case "max":
|
||||||
$("#template-value, #template-min, span#matches_value").hide ();
|
$("#template-value, #template-min, span#matches_value").hide ();
|
||||||
$("#template-max, #template-example").show ();
|
$("#template-max, #template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
$("span#example").empty ().append (over);
|
$("span#example").empty ().append (over);
|
||||||
break;
|
break;
|
||||||
case "min":
|
case "min":
|
||||||
$("#template-value, #template-max, span#matches_value").hide ();
|
$("#template-value, #template-max, span#matches_value").hide ();
|
||||||
$("#template-min, #template-example").show ();
|
$("#template-min, #template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
$("span#example").empty ().append (under);
|
$("span#example").empty ().append (under);
|
||||||
break;
|
break;
|
||||||
case "warning":
|
case "warning":
|
||||||
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
||||||
$("#template-example").show ();
|
$("#template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
$("span#example").empty ().append (warning);
|
$("span#example").empty ().append (warning);
|
||||||
break;
|
break;
|
||||||
case "critical":
|
case "critical":
|
||||||
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
||||||
$("#template-example").show ();
|
$("#template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
$("span#example").empty ().append (critical);
|
$("span#example").empty ().append (critical);
|
||||||
break;
|
break;
|
||||||
case "not_normal":
|
case "not_normal":
|
||||||
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
$("#template-value, #template-max, span#matches_value, #template-min").hide ();
|
||||||
$("#template-example").show ();
|
$("#template-example").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
$("span#example").empty ().append (not_normal);
|
$("span#example").empty ().append (not_normal);
|
||||||
break;
|
break;
|
||||||
case "onchange":
|
case "onchange":
|
||||||
$("#template-value, #template-max, #template-min").hide ();
|
$("#template-value, #template-max, #template-min").hide ();
|
||||||
$("#template-example, span#matches_value").show ();
|
$("#template-example, span#matches_value").show ();
|
||||||
|
|
||||||
/* Show example */
|
/* Show example */
|
||||||
if ($("#checkbox-matches_value")[0].checked)
|
if ($("#checkbox-matches_value")[0].checked)
|
||||||
$("span#example").empty ().append (onchange_msg);
|
$("span#example").empty ().append (onchange_msg);
|
||||||
@ -1490,10 +1488,10 @@ if ($step == 2) {
|
|||||||
$("#template-value, #template-max, #template-min, #template-example, span#matches_value").hide ();
|
$("#template-value, #template-max, #template-min, #template-example, span#matches_value").hide ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_example ();
|
render_example ();
|
||||||
}).change ();
|
}).change ();
|
||||||
|
|
||||||
$("#checkbox-matches_value").click (function () {
|
$("#checkbox-matches_value").click (function () {
|
||||||
enabled = this.checked;
|
enabled = this.checked;
|
||||||
type = $("#type").val();
|
type = $("#type").val();
|
||||||
@ -1520,12 +1518,12 @@ if ($step == 2) {
|
|||||||
else {
|
else {
|
||||||
$("span#example").empty ().append (onchange_not);
|
$("span#example").empty ().append (onchange_not);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render_example ();
|
render_example ();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#text-value").keyup (check_regex);
|
$("#text-value").keyup (check_regex);
|
||||||
|
|
||||||
$('#text-time_from, #text-time_to').timepicker({
|
$('#text-time_from, #text-time_to').timepicker({
|
||||||
showSecond: true,
|
showSecond: true,
|
||||||
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
||||||
@ -1535,8 +1533,9 @@ if ($step == 2) {
|
|||||||
minuteText: '<?php echo __('Minute'); ?>',
|
minuteText: '<?php echo __('Minute'); ?>',
|
||||||
secondText: '<?php echo __('Second'); ?>',
|
secondText: '<?php echo __('Second'); ?>',
|
||||||
currentText: '<?php echo __('Now'); ?>',
|
currentText: '<?php echo __('Now'); ?>',
|
||||||
closeText: '<?php echo __('Close'); ?>'});
|
closeText: '<?php echo __('Close'); ?>'}
|
||||||
|
);
|
||||||
|
|
||||||
$("#threshold").change (function () {
|
$("#threshold").change (function () {
|
||||||
if (this.value == -1) {
|
if (this.value == -1) {
|
||||||
$("#text-other_threshold").val("");
|
$("#text-other_threshold").val("");
|
||||||
@ -1549,186 +1548,21 @@ if ($step == 2) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
function formatDate(date) {
|
|
||||||
var d = new Date(date),
|
|
||||||
month = '' + (d.getMonth() + 1),
|
|
||||||
day = '' + d.getDate(),
|
|
||||||
year = d.getFullYear();
|
|
||||||
|
|
||||||
if (month.length < 2)
|
|
||||||
month = '0' + month;
|
|
||||||
if (day.length < 2)
|
|
||||||
day = '0' + day;
|
|
||||||
|
|
||||||
return [year, month, day].join('/');
|
|
||||||
}*/
|
|
||||||
|
|
||||||
function time_format(date) {
|
|
||||||
var d = new Date(date)
|
|
||||||
hours = format_two_digits(d.getHours());
|
|
||||||
minutes = format_two_digits(d.getMinutes());
|
|
||||||
seconds = format_two_digits(d.getSeconds());
|
|
||||||
return hours + ":" + minutes + ":" + seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
function format_two_digits(n) {
|
|
||||||
return n < 10 ? '0' + n : n;
|
|
||||||
}
|
|
||||||
|
|
||||||
var calendarEl = document.getElementById('calendar');
|
var calendarEl = document.getElementById('calendar');
|
||||||
var calendar = new FullCalendar.Calendar(calendarEl, {
|
var settings = {
|
||||||
height: 625,
|
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
||||||
headerToolbar: {
|
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
|
||||||
left: '',
|
timeText: '<?php echo __('Time'); ?>',
|
||||||
center: '',
|
hourText: '<?php echo __('Hour'); ?>',
|
||||||
right: ''
|
minuteText: '<?php echo __('Minute'); ?>',
|
||||||
},
|
secondText: '<?php echo __('Second'); ?>',
|
||||||
dayHeaderFormat: { weekday: 'short' },
|
currentText: '<?php echo __('Now'); ?>',
|
||||||
initialView: 'timeGridWeek',
|
closeText: '<?php echo __('Close'); ?>',
|
||||||
navLinks: false,
|
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>'
|
||||||
selectable: true,
|
}
|
||||||
selectMirror: true,
|
|
||||||
slotDuration: '01:00:00',
|
|
||||||
slotLabelInterval: '02:00:00',
|
|
||||||
snapDuration: '01:00:00',
|
|
||||||
slotLabelFormat: {
|
|
||||||
hour: 'numeric',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12:false
|
|
||||||
},
|
|
||||||
slotMinTime: '00:00:00',
|
|
||||||
slotMaxTime: '24:00:00',
|
|
||||||
scrollTime: '01:00:00',
|
|
||||||
timeFormat: 'H:mm',
|
|
||||||
locale: 'en-GB',
|
|
||||||
//timeZone: "local",
|
|
||||||
firstDay: 1,
|
|
||||||
eventOverlap: false,
|
|
||||||
select: function(arg) {
|
|
||||||
calendar.addEvent({
|
|
||||||
title: '',
|
|
||||||
start: arg.start,
|
|
||||||
end: arg.end,
|
|
||||||
});
|
|
||||||
calendar.unselect();
|
|
||||||
},
|
|
||||||
eventDrop: function(event) {
|
|
||||||
event.revert();
|
|
||||||
},
|
|
||||||
eventClick: function(info) {
|
|
||||||
var calendar_date_from = new Date(calendar.view.activeStart);
|
|
||||||
var calendar_date_to = new Date(calendar.view.activeEnd);
|
|
||||||
var calendar_day_from = calendar_date_from.getDate();
|
|
||||||
var calendar_day_to = calendar_date_to.getDate();
|
|
||||||
|
|
||||||
var calendar_days = [];
|
|
||||||
var acum = 1;
|
|
||||||
var i = 0;
|
|
||||||
for (var index = calendar_day_from; index < calendar_day_to; index++) {
|
|
||||||
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: 'Event',
|
|
||||||
message: function () {
|
|
||||||
var id = "div-" + uniqId();
|
|
||||||
var loading = "<?php echo __('Loading, this operation might take several minutes...'); ?>";
|
|
||||||
$.ajax({
|
|
||||||
method: "post",
|
|
||||||
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
|
||||||
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: '<?php echo TIME_FORMAT_JS; ?>',
|
|
||||||
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
|
|
||||||
timeText: '<?php echo __('Time'); ?>',
|
|
||||||
hourText: '<?php echo __('Hour'); ?>',
|
|
||||||
minuteText: '<?php echo __('Minute'); ?>',
|
|
||||||
secondText: '<?php echo __('Second'); ?>',
|
|
||||||
currentText: '<?php echo __('Now'); ?>',
|
|
||||||
closeText: '<?php echo __('Close'); ?>'
|
|
||||||
});
|
|
||||||
|
|
||||||
$.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]);
|
|
||||||
},
|
|
||||||
error: function(error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return "<div id ='" + id + "'>" + loading + "</div>";
|
|
||||||
},
|
|
||||||
onAccept: function() {
|
|
||||||
var remove_event = $('#checkbox-remove_event').is(':checked');
|
|
||||||
if(remove_event === false) {
|
|
||||||
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]
|
|
||||||
);
|
|
||||||
|
|
||||||
info.event.setDates(new_date_from,new_date_to);
|
|
||||||
} else {
|
|
||||||
info.event.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
eventOverlap: function(stillEvent, movingEvent) {
|
|
||||||
return stillEvent.allDay && movingEvent.allDay;
|
|
||||||
},
|
|
||||||
selectOverlap: function(event) {
|
|
||||||
return event.rendering === 'background';
|
|
||||||
},
|
|
||||||
eventTimeFormat: {
|
|
||||||
hour: 'numeric',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12:false
|
|
||||||
},
|
|
||||||
eventColor: '#82b92e',
|
|
||||||
editable: true,
|
|
||||||
dayMaxEvents: false, // allow "more" link when too many events
|
|
||||||
events: []
|
|
||||||
});
|
|
||||||
|
|
||||||
|
var calendar = fullCalendarPandora(calendarEl, settings);
|
||||||
calendar.render();
|
calendar.render();
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
} else if ($step == 3) {
|
} else if ($step == 3) {
|
||||||
?>
|
?>
|
||||||
|
@ -575,13 +575,22 @@ if ($resize_event_week === true) {
|
|||||||
$table->class = 'databox filters';
|
$table->class = 'databox filters';
|
||||||
$table->width = '100%';
|
$table->width = '100%';
|
||||||
$table->data = [];
|
$table->data = [];
|
||||||
$table->data[0][0] = __('From:');
|
|
||||||
$table->data[0][1] = html_print_input_hidden(
|
$table->data[0][0] = __('Remove');
|
||||||
|
$table->data[0][1] = html_print_checkbox_switch(
|
||||||
|
'remove_event',
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$table->data[1][0] = __('From:');
|
||||||
|
$table->data[1][1] = html_print_input_hidden(
|
||||||
'day_from',
|
'day_from',
|
||||||
$day_from,
|
$day_from,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$table->data[0][1] .= html_print_input_text(
|
$table->data[1][1] .= html_print_input_text(
|
||||||
'time_from_event',
|
'time_from_event',
|
||||||
$time_from,
|
$time_from,
|
||||||
'',
|
'',
|
||||||
@ -589,13 +598,13 @@ if ($resize_event_week === true) {
|
|||||||
9,
|
9,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$table->data[1][0] = __('To:');
|
$table->data[2][0] = __('To:');
|
||||||
$table->data[1][1] = html_print_input_hidden(
|
$table->data[2][1] = html_print_input_hidden(
|
||||||
'day_to',
|
'day_to',
|
||||||
$day_from,
|
$day_from,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$table->data[1][1] .= html_print_input_text(
|
$table->data[2][1] .= html_print_input_text(
|
||||||
'time_to_event',
|
'time_to_event',
|
||||||
($time_to === '00:00:00') ? '23:59:59' : $time_to,
|
($time_to === '00:00:00') ? '23:59:59' : $time_to,
|
||||||
'',
|
'',
|
||||||
@ -604,14 +613,6 @@ if ($resize_event_week === true) {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
echo __('Remove');
|
|
||||||
echo html_print_checkbox_switch(
|
|
||||||
'remove_event',
|
|
||||||
1,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
echo html_print_table($table, true);
|
echo html_print_table($table, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
311
pandora_console/include/javascript/pandora_fullcalendar.js
Normal file
311
pandora_console/include/javascript/pandora_fullcalendar.js
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
/* globals $, FullCalendar, uniqId, confirmDialog*/
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function fullCalendarPandora(calendarEl, settings) {
|
||||||
|
var calendar = new FullCalendar.Calendar(calendarEl, {
|
||||||
|
height: 625,
|
||||||
|
headerToolbar: {
|
||||||
|
left: "",
|
||||||
|
center: "",
|
||||||
|
right: ""
|
||||||
|
},
|
||||||
|
dayHeaderFormat: { weekday: "short" },
|
||||||
|
initialView: "timeGridWeek",
|
||||||
|
navLinks: false,
|
||||||
|
selectable: true,
|
||||||
|
selectMirror: true,
|
||||||
|
slotDuration: "01:00:00",
|
||||||
|
slotLabelInterval: "02:00:00",
|
||||||
|
snapDuration: "01:00:00",
|
||||||
|
slotLabelFormat: {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false
|
||||||
|
},
|
||||||
|
slotMinTime: "00:00:00",
|
||||||
|
slotMaxTime: "24:00:00",
|
||||||
|
scrollTime: "01:00:00",
|
||||||
|
timeFormat: "H:mm",
|
||||||
|
locale: "en-GB",
|
||||||
|
//timeZone: "local",
|
||||||
|
firstDay: 1,
|
||||||
|
eventTimeFormat: {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false
|
||||||
|
},
|
||||||
|
eventColor: "#82b92e",
|
||||||
|
editable: true,
|
||||||
|
dayMaxEvents: false,
|
||||||
|
events: [],
|
||||||
|
select: function(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")
|
||||||
|
) {
|
||||||
|
recalculate_events(calendar, {}, info.start, info.end, true);
|
||||||
|
}
|
||||||
|
calendar.unselect();
|
||||||
|
},
|
||||||
|
selectAllow: function(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;
|
||||||
|
},
|
||||||
|
eventAllow: function(dropInfo, draggedEvent) {
|
||||||
|
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) {
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
eventDragStop: function(info) {
|
||||||
|
var trashEl = $("#calendar");
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
eventClick: function(info) {
|
||||||
|
var calendar_date_from = new Date(calendar.view.activeStart);
|
||||||
|
var calendar_date_to = new Date(calendar.view.activeEnd);
|
||||||
|
var calendar_day_from = calendar_date_from.getDate();
|
||||||
|
var calendar_day_to = calendar_date_to.getDate();
|
||||||
|
|
||||||
|
var calendar_days = [];
|
||||||
|
var acum = 1;
|
||||||
|
var i = 0;
|
||||||
|
// Week date.
|
||||||
|
for (var index = calendar_day_from; index < calendar_day_to; 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: "Event",
|
||||||
|
message: function() {
|
||||||
|
var id = "div-" + uniqId();
|
||||||
|
var loading =
|
||||||
|
"<?php echo __('Loading, this operation might take several minutes...'); ?>";
|
||||||
|
$.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["<?php echo get_user_language(); ?>"]
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return "<div id ='" + id + "'>" + loading + "</div>";
|
||||||
|
},
|
||||||
|
onAccept: function() {
|
||||||
|
var remove_event = $("#checkbox-remove_event").is(":checked");
|
||||||
|
if (remove_event === false) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Remove event.
|
||||||
|
info.event.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
eventOverlap: false,
|
||||||
|
selectOverlap: false
|
||||||
|
});
|
||||||
|
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
function time_format(date) {
|
||||||
|
var d = new Date(date);
|
||||||
|
var hours = format_two_digits(d.getHours());
|
||||||
|
var minutes = format_two_digits(d.getMinutes());
|
||||||
|
var seconds = format_two_digits(d.getSeconds());
|
||||||
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_two_digits(n) {
|
||||||
|
return n < 10 ? "0" + n : n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function recalculate_events(calendar, newEvent, from, to, create) {
|
||||||
|
var allEvents = calendar.getEvents();
|
||||||
|
allEvents.forEach(function(oldEvent) {
|
||||||
|
if (create === false) {
|
||||||
|
// Avoid the same event.
|
||||||
|
if (newEvent.id === oldEvent.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// New event inside complete in old event.
|
||||||
|
if (oldEvent.start < from && oldEvent.end > to) {
|
||||||
|
// Remove new event.
|
||||||
|
newEvent.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// New event inside complete in old event.
|
||||||
|
if (oldEvent.start > from && oldEvent.end < to) {
|
||||||
|
// Remove new event.
|
||||||
|
oldEvent.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inside From.
|
||||||
|
if (oldEvent.start > from && oldEvent.start <= to) {
|
||||||
|
if (time_format(oldEvent.start) !== "00:00:00") {
|
||||||
|
to = oldEvent.end;
|
||||||
|
oldEvent.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inside To.
|
||||||
|
if (oldEvent.end >= from && oldEvent.end < to) {
|
||||||
|
if (time_format(oldEvent.end) !== "00:00:00") {
|
||||||
|
from = oldEvent.start;
|
||||||
|
oldEvent.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (create === true) {
|
||||||
|
calendar.addEvent({
|
||||||
|
title: "",
|
||||||
|
start: from,
|
||||||
|
end: to,
|
||||||
|
id: uniqId()
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Update event.
|
||||||
|
newEvent.setDates(from, to);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user