Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scheduler support #27

Open
wants to merge 3 commits into
base: gh-8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fullcalendar_scheduler/fullcalendar_scheduler.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: FullCalendar Scheduler
type: module
description: Adds Scheduler support to Fullcalendar views.
core: 8.x
package: FullCalendar
dependencies:
- fullcalendar
22 changes: 22 additions & 0 deletions fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
fullcalendar_scheduler:
remote: https://fullcalendar.io/scheduler/
version: 1.9.1
license:
name: proprietary
url: https://github.com/fullcalendar/fullcalendar-scheduler/blob/master/LICENSE.md
gpl-compatible: true
js:
/libraries/fullcalendar-scheduler/scheduler.js: {}
css:
theme:
/libraries/fullcalendar-scheduler/scheduler.css: {}
dependencies:
- fullcalendar/fullcalendar

drupal.fullcalendar_scheduler.js:
version: VERSION
js:
js/fullcalendar_scheduler.fullcalendar_scheduler.js: { }
dependencies:
- fullcalendar_scheduler/fullcalendar_scheduler
- fullcalendar/drupal.fullcalendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file
* Processes the FullCalendar options and passes them to the integration.
*/

(function ($, Drupal, drupalSettings) {

"use strict";

Drupal.fullcalendar.plugins.fullcalendar_scheduler = {
options: function (fullcalendar, settings) {

fullcalendar.parseEvents = function (callback) {
var events = [];
var details = this.$calendar.find('.fullcalendar-event-details');
for (var i = 0; i < details.length; i++) {
var event = $(details[i]);
var eid = event.data('eid');
events.push({
field: event.data('field'),
index: event.data('index'),
eid: eid,
entity_type: event.data('entity-type'),
title: event.attr('title'),
start: event.data('start'),
end: event.data('end'),
url: event.attr('href'),
allDay: (event.data('all-day') === 1),
className: event.data('cn'),
editable: (event.data('editable') === 1),
color: event.data('color'),
dom_id: this.dom_id,
resourceId: settings.events[eid].resourceId
});
}
callback(events);
};

var options = Drupal.fullcalendar.plugins.fullcalendar.options(fullcalendar, settings);

// Merge in our settings.
$.extend(options, settings.fullcalendar_scheduler);

options.resourceRender = function (resourceObj, labelTds, bodyTds) {
labelTds.find('.fc-cell-text').html(resourceObj.html);
};

return options;
}

};

})(jQuery, Drupal, drupalSettings);
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

namespace Drupal\fullcalendar_scheduler\Plugin\fullcalendar\type;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\fullcalendar\Plugin\FullcalendarBase;

/**
* Provides the Fullcalendar Scheduler integration.
*
* @FullcalendarOption(
* id = "fullcalendar_scheduler",
* module = "fullcalendar_scheduler",
* js = TRUE,
* weight = "10",
* )
*/
class FullcalendarScheduler extends FullcalendarBase {

/**
* {@inheritdoc}
*/
public function defineOptions() {
$options = [];
$options['fullcalendar_scheduler'] = [
'contains' => [
'enabled' => ['default' => FALSE],
'resource_field' => ['default' => NULL],
'defaultView' => ['default' => 'timelineDay'],
'views' => ['default' => [
'timelineDay' => [
'slotLabelFormat' => '',
],
'agendaDay' => [
'slotLabelFormat' => '',
],
'timelineWeek' => [
'slotLabelFormat' => '',
],
'agendaWeek' => [
'slotLabelFormat' => '',
],
'timelineMonth' => [
'slotLabelFormat' => '',
],
'timelineYear' => [
'slotLabelFormat' => '',
],
]],
'schedulerLicenseKey' => ['default' => ''],
],
];
return $options;
}

/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['fullcalendar_scheduler'] = [
'#type' => 'details',
'#title' => $this->t('Scheduler'),
'#open' => TRUE,
];
$form['fullcalendar_scheduler']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use the <em>Scheduler</em> display'),
'#default_value' => $this->style->options['fullcalendar_scheduler']['enabled'],
'#fieldset' => 'fullcalendar_scheduler',
];

$field_labels = $this->style->displayHandler->getFieldLabels(TRUE);
$form['fullcalendar_scheduler']['resource_field'] = [
'#type' => 'select',
'#title' => $this->t('Resource field'),
'#options' => $field_labels,
'#default_value' => $this->style->options['fullcalendar_scheduler']['resource_field'],
'#fieldset' => 'fullcalendar_scheduler',
];
$form['fullcalendar_scheduler']['defaultView'] = [
'#type' => 'select',
'#title' => $this->t('Initial display'),
'#options' => [
'timelineDay' => $this->t('Day'),
'agendaDay' => $this->t('Day (Agenda)'),
'timelineWeek' => $this->t('Week'),
'agendaWeek' => $this->t('Week (Agenda)'),
'timelineMonth' => $this->t('Month'),
'timelineYear' => $this->t('Year'),
],
'#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/views/Available_Views', ['attributes' => ['target' => '_blank']])),
'#default_value' => $this->style->options['fullcalendar_scheduler']['defaultView'],
'#fieldset' => 'fullcalendar_scheduler',
];
$form['fullcalendar_scheduler']['views'] = [
'#type' => 'details',
'#title' => $this->t('Display configuration'),
];
foreach ($form['fullcalendar_scheduler']['defaultView']['#options'] as $option => $label) {
$form['fullcalendar_scheduler']['views'][$option] = [
'#type' => 'details',
'#title' => $label,
];
$form['fullcalendar_scheduler']['views'][$option]['slotLabelFormat'] = [
'#type' => 'textfield',
'#title' => $this->t('Header date format'),
'#default_value' => $this->style->options['fullcalendar_scheduler']['views'][$option]['slotLabelFormat'],
'#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/agenda/slotLabelFormat', array('attributes' => array('target' => '_blank')))),
];
$form['fullcalendar_scheduler']['views'][$option]['slotWidth'] = [
'#type' => 'textfield',
'#title' => $this->t('Column width'),
'#default_value' => $this->style->options['fullcalendar_scheduler']['views'][$option]['slotWidth'],
'#field_suffix' => 'px',
'#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/agenda/slotWidth', array('attributes' => array('target' => '_blank')))),
];
}

$form['fullcalendar_scheduler']['schedulerLicenseKey'] = [
'#type' => 'textfield',
'#title' => $this->t('License key'),
'#default_value' => $this->style->options['fullcalendar_scheduler']['schedulerLicenseKey'],
'#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('https://fullcalendar.io/scheduler/license/', ['attributes' => ['target' => '_blank']])),
];
}

/**
* {@inheritdoc}
*/
public function process(&$settings) {
if ($settings['fullcalendar_scheduler']['enabled']) {
$default_view = $settings['fullcalendar_scheduler']['defaultView'];
if (isset($settings['fullcalendar']['titleFormat']) && !is_array($settings['fullcalendar']['titleFormat'])) {
$type = strtolower(substr($default_view, 8));
$settings['fullcalendar']['titleFormat'] = $settings['fullcalendar']['titleFormat'][$type];
}

$resource_field = $settings['fullcalendar_scheduler']['resource_field'];

$settings['events'] = [];
$resources = [];
foreach ($this->style->view->result as $delta => $row) {
$field_value = $this->style->getFieldValue($delta, $resource_field);
$field = (string) $this->style->getField($delta, $resource_field);

$entity = $row->_entity;
$settings['events'][$entity->id()] = [
'resourceId' => $field_value,
];

$resources[$field_value] = [
'id' => $field_value,
'title' => strip_tags(htmlspecialchars_decode($field)),
'html' => $field,
];
}
$settings['fullcalendar_scheduler']['resources'] = array_values($resources);

unset(
$settings['fullcalendar_scheduler']['enabled'],
$settings['fullcalendar_scheduler']['resource_field']
);
}
else {
unset($settings['fullcalendar_scheduler']);
}
}

}