Commit 0fdf5ac3 authored by Mingsong Hu's avatar Mingsong Hu

Double click to add a new event

parent 1cf1aaab
......@@ -39,7 +39,7 @@ function fullcalendar_view_form_node_form_alter(&$form, FormStateInterface $form
// Only handle datetime field.
if ($form[$start_field]['widget'][0]['value']['#type'] === 'datetime') {
// Prepopulate the start date field as the event date.
$form[$start_field]['widget'][0]['value']['#default_value'] = new DrupalDateTime($start);
$form[$start_field]['widget'][0]['value']['#default_value'] = new DrupalDateTime($start, 'UTC');
}
}
}
......
......@@ -9,6 +9,8 @@
var calendarObjs = [];
var initialLocaleCode = 'en';
var localeSelectorEl = document.getElementById('locale-selector');
// Date entry clicked.
var slotDate;
// Create all calendars.
$('.js-drupal-fullcalendar', context)
......@@ -17,8 +19,6 @@
var calendarEl = document.getElementsByClassName("js-drupal-fullcalendar");
let calendarOptions = JSON.parse(drupalSettings.calendar_options);
// Date entry clicked.
var slotDate;
// Bind the render event handler.
calendarOptions.eventRender = eventRender;
// Bind the resize event handler.
......@@ -36,6 +36,7 @@
var calendar = new FullCalendar.Calendar(calendarEl[i], calendarOptions);
// Render the calendar.
calendar.render();
// Language dropdown box.
if (drupalSettings.languageSelector) {
// build the locale selector's options
calendar.getAvailableLocaleCodes().forEach(function(localeCode) {
......@@ -57,7 +58,30 @@
}
// Put into the calendar array.
calendarObjs[i] = calendar;
}
}
// Double click event.
$(".js-drupal-fullcalendar").dblclick(function() {
console.log(slotDate);
if (
slotDate &&
drupalSettings.eventBundleType &&
drupalSettings.dblClickToCreate &&
drupalSettings.addForm !== ""
) {
// Open a new window to create a new event (content).
window.open(
drupalSettings.path.baseUrl +
drupalSettings.addForm +
"?start=" +
slotDate +
"&start_field=" +
drupalSettings.startField,
"_blank"
);
}
});
}
});
......@@ -222,7 +246,9 @@
// to ensure the day stored in Drupal
// is the same as when it appears in
// the calendar.
end.setDate(end.getDate() - 1);
if (end.getHours() == 0 && end.getMinutes() == 0 && end.getSeconds() == 0) {
end.setDate(end.getDate() - 1);
}
// String of the end date.
strEnd = FullCalendar.formatDate(end, formatSettings);
}
......
......@@ -147,7 +147,7 @@ class CalendarEventController extends ControllerBase {
($entity->$end_field)[0]->end_value = $end_date;
}
else {
($entity->$end_field)[0]->end_value = substr($end_date, 0, $length);
($entity->$end_field)[0]->end_value = substr($end_date, 0, $length ? : strlen($end_date));
}
}
......@@ -173,7 +173,7 @@ class CalendarEventController extends ControllerBase {
$entity->$end_field->value = $end_date;
}
else {
$entity->$end_field->value = substr($end_date, 0, $length);
$entity->$end_field->value = substr($end_date, 0, $length ? : strlen($end_date));
}
}
}
......@@ -191,7 +191,7 @@ class CalendarEventController extends ControllerBase {
$entity->$end_field->end_value = $end_date;
}
else {
$entity->$end_field->end_value = substr($end_date, 0, $length);
$entity->$end_field->end_value = substr($end_date, 0, $length ? : strlen($end_date));
}
}
}
......
......@@ -5,12 +5,10 @@ namespace Drupal\fullcalendar_view\Plugin\views\style;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\fullcalendar_view\TaxonomyColor;
use Drupal\core\form\FormStateInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Datetime\DrupalDateTime;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
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