Commit a0311110 authored by Mingsong Hu's avatar Mingsong Hu

The event in place moving feature

parent 80b54be9
......@@ -27,6 +27,8 @@
calendarOptions.dateClick = dayClickCallback;
// Bind the event click handler.
calendarOptions.eventClick = eventClick;
// Bind the drop event handler.
calendarOptions.eventDrop = eventDrop;
// Define calendar elemetns.
if (calendarEl) {
......@@ -192,6 +194,72 @@
return false;
}
// Event drop call back function.
function eventDrop(info) {
const end = info.event.end;
const start = info.event.start;
let strEnd = '';
let strStart = '';
const formatSettings = {
month: '2-digit',
year: 'numeric',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
locale: 'sv-SE'
};
// define the end date string in 'YYYY-MM-DD' format.
if (end) {
// The end day of an event is exclusive.
// For example, the end of 2018-09-03
// will appear to 2018-09-02 in the calendar.
// So we need one day subtract
// to ensure the day stored in Drupal
// is the same as when it appears in
// the calendar.
end.setDate(end.getDate() - 1);
// String of the end date.
strEnd = FullCalendar.formatDate(end, formatSettings);
}
// define the start date string in 'YYYY-MM-DD' format.
if (start) {
strStart = FullCalendar.formatDate(start, formatSettings);
}
const title = info.event.title.replace(/(<([^>]+)>)/ig,"");;
const msg = Drupal.t('@title end is now @event_end. Do you want to save this change?', {
'@title': title,
'@event_end': strEnd
});
if (!confirm(msg)) {
info.revert();
}
else {
/**
* Perform ajax call for event update in database.
*/
jQuery
.post(
drupalSettings.path.baseUrl +
"fullcalendar-view-event-update",
{
eid: info.event.id,
entity_type: drupalSettings.entityType,
start: strStart,
end: strEnd,
start_field: drupalSettings.startField,
end_field: drupalSettings.endField,
token: drupalSettings.token
}
)
.done(function(data) {
// alert("Response: " + data);
});
}
}
}
......
......@@ -93,7 +93,7 @@ class CalendarEventController extends ControllerBase {
];
}
else {
($entity->$start_field)[0] = ['value' => $start_date];
($entity->$start_field)[0] = ['value' => substr($start_date, 0, $length)];
}
}
}
......@@ -111,7 +111,7 @@ class CalendarEventController extends ControllerBase {
$entity->$start_field->value = gmdate("Y-m-d\TH:i:s", strtotime($start_date));
}
else {
$entity->$start_field->value = $start_date;
$entity->$start_field->value = substr($start_date, 0, $length);
}
}
}
......@@ -130,7 +130,7 @@ class CalendarEventController extends ControllerBase {
];
}
else {
($entity->$end_field)[0] = ['value' => $end_date];
($entity->$end_field)[0] = ['value' => substr($end_date, 0, $length)];
}
}
// Daterange field.
......@@ -142,7 +142,14 @@ class CalendarEventController extends ControllerBase {
($entity->$end_field)[0]->end_value = gmdate("Y-m-d\TH:i:s", strtotime($end_date));
}
else {
($entity->$end_field)[0]->end_value = $end_date;
if ($length == strlen($end_date))
{
($entity->$end_field)[0]->end_value = $end_date;
}
else {
($entity->$end_field)[0]->end_value = substr($end_date, 0, $length);
}
}
}
// Timestamp field.
......@@ -161,7 +168,13 @@ class CalendarEventController extends ControllerBase {
$entity->$end_field->value = gmdate("Y-m-d\TH:i:s", strtotime($end_date));
}
else {
$entity->$end_field->value = $end_date;
if ($length == strlen($end_date))
{
$entity->$end_field->value = $end_date;
}
else {
$entity->$end_field->value = substr($end_date, 0, $length);
}
}
}
// Daterange field.
......@@ -173,7 +186,13 @@ class CalendarEventController extends ControllerBase {
$entity->$end_field->end_value = gmdate("Y-m-d\TH:i:s", strtotime($end_date));
}
else {
$entity->$end_field->end_value = $end_date;
if ($length == strlen($end_date))
{
$entity->$end_field->end_value = $end_date;
}
else {
$entity->$end_field->end_value = substr($end_date, 0, $length);
}
}
}
// Timestamp field.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment