forked from pdrakeweb/Drupal-FullCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullcalendar-ajax-endpoint-971034-20.patch
275 lines (273 loc) · 9.78 KB
/
fullcalendar-ajax-endpoint-971034-20.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
diff --git fullcalendar.info fullcalendar.info
index 296f6d0..2627d53 100644
--- fullcalendar.info
+++ fullcalendar.info
@@ -7,3 +7,4 @@ dependencies[] = views
dependencies[] = date
dependencies[] = jquery_ui
dependencies[] = jquery_update
+dependencies[] = views_ajax_endpoint
diff --git fullcalendar.install fullcalendar.install
index a3e0e81..184c2d6 100644
--- fullcalendar.install
+++ fullcalendar.install
@@ -55,9 +55,28 @@ function fullcalendar_requirements($phase) {
}
/**
+ * Implementation of hook_install()
+ */
+function fullcalendar_install() {
+ fullcalendar_update_6001();
+}
+
+/**
* Implementation of hook_uninstall().
*/
function fullcalendar_uninstall() {
variable_del('fullcalendar_path');
variable_del('fullcalendar_compression_type');
}
+
+
+/**
+ * Install new date formats
+ */
+function fullcalendar_update_6001() {
+ include_once(drupal_get_path('module', 'date') .'/date.install');
+ date_install_create_format(NULL, t('Fullcalendar (Date Format)'), 'fullcalendar_date_format', 'c');
+
+ $ret = array(array('success' => TRUE, 'query' => $module . " additional date format installation successful."));
+ return $ret;
+}
diff --git fullcalendar.module fullcalendar.module
index e092fa2..af12aa0 100644
--- fullcalendar.module
+++ fullcalendar.module
@@ -181,6 +181,9 @@ function template_preprocess_views_view_fullcalendar(&$vars) {
'monthString' => t('Month'),
'todayString' => t('Today'),
);
+ if (!empty($vars['options']['modules']['ajax_callback'])) {
+ $settings['ajax_callback'] = url($vars['options']['modules']['ajax_callback']);
+ }
drupal_add_js(array('fullcalendar' => $settings), 'setting');
drupal_add_js(drupal_get_path('module', 'fullcalendar') . '/fullcalendar.views.js', 'module');
}
diff --git fullcalendar.views.inc fullcalendar.views.inc
index c1b0ad5..8d6cc37 100644
--- fullcalendar.views.inc
+++ fullcalendar.views.inc
@@ -46,6 +46,18 @@ function fullcalendar_views_plugins() {
'uses grouping' => TRUE,
'type' => 'normal',
'parent' => 'default',
+ 'even empty' => TRUE,
+ ),
+ 'fullcalendar_ajax_json' => array(
+ 'title' => t('Fullcalendar AJAJ Endpoint'),
+ 'theme' => 'views_view_ajax_json',
+ 'help' => t('Displays nodes in the JSON data format'),
+ 'handler' => 'views_plugin_style_fullcalendar_ajax_json',
+ 'uses row plugin' => TRUE,
+ 'uses options' => TRUE,
+ 'uses fields' => TRUE,
+ 'uses grouping' => FALSE,
+ 'type' => 'ajax',
),
),
'row' => array(
diff --git fullcalendar.views.js fullcalendar.views.js
index c305e9f..bd5ae24 100644
--- fullcalendar.views.js
+++ fullcalendar.views.js
@@ -46,6 +46,24 @@ Drupal.behaviors.fullCalendar = function(context) {
month: Drupal.settings.fullcalendar.monthString
},
events: function(start, end, callback) {
+ // Load events from AJAX callback, if set.
+ if (Drupal.settings.fullcalendar.ajax_callback) {
+ // TODO: refactor to use "data:" block to pass arg attributes from filters
+ var argattr = "";
+ if (window.location.href.indexOf('?') != -1) {
+ argattr = window.location.href.slice(window.location.href.indexOf('?'));
+ }
+ var argdate = new Date((start.getTime()+end.getTime())/2);
+ var argdateStr = argdate.getFullYear() + "-" + (argdate.getMonth()+1)
+ $.ajax({
+ url: Drupal.settings.fullcalendar.ajax_callback + '/' + argdateStr + argattr,
+ dataType: 'json',
+ success: function(events) {
+ callback(events);
+ }
+ });
+ return; // Don't load events from page.
+ }
var events = [];
$('.fullcalendar_event').each(function() {
diff --git views_plugin_style_fullcalendar.inc views_plugin_style_fullcalendar.inc
index 1672753..b7870fb 100644
--- views_plugin_style_fullcalendar.inc
+++ views_plugin_style_fullcalendar.inc
@@ -201,5 +201,19 @@ class views_plugin_style_fullcalendar extends views_plugin_style {
'#default_value' => $this->options['modules']['fc_url_colorbox'],
'#description' => t('If checked, each event will open in colorbox (if it is installed).'),
);
+ $ajax_callback_options = array();
+ foreach ($this->view->display as $display) {
+ if ($display->display_options['style_plugin'] == "fullcalendar_ajax_json") {
+ $ajax_callback_options[$display->display_options['path']] = $display->display_options['path'];
+ }
+ }
+ array_unshift($ajax_callback_options, '<None>');
+ $form['modules']['ajax_callback'] = array(
+ '#type' => 'select',
+ '#title' => t('AJAX callback'),
+ '#options' => $ajax_callback_options,
+ '#default_value' => $this->options['modules']['ajax_callback'],
+ '#description' => t("(Advanced) When selected the fullcalendar plugin will use this callback to pull in JSON data to the calendar. Note: You will need to enable the AJAX Fullcalendar Endpoint to configure the fields for display."),
+ );
}
}
diff --git views_plugin_style_fullcalendar_ajax_json.inc views_plugin_style_fullcalendar_ajax_json.inc
new file mode 100644
index 0000000..ad11e23
--- /dev/null
+++ views_plugin_style_fullcalendar_ajax_json.inc
@@ -0,0 +1,137 @@
+<?php
+
+// require_once(drupal_get_path('module', 'views_ajax_endpoint') . '/views_plugin_style_ajax.inc');
+
+class views_plugin_style_fullcalendar_ajax_json extends views_plugin_style {
+ /**
+ * Set default options.
+ */
+ function option_definition() {
+ $options = parent::option_definition();
+
+ return $options;
+ }
+
+ /**
+ * Extend the options form.
+ */
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+ // Style types
+ $fields = array(0 => '<'. t('None') .'>');
+ foreach ($this->view->display_handler->get_option('fields') as $field => $definition) {
+ $fields[$field] = !empty($definition['label']) ? $definition['label'] : $field;
+ }
+ $form['field'] = array(
+ '#title' => t('Field'),
+ '#description' => t('Choose a field to be used for field updates.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['field'],
+ );
+ $form['index'] = array(
+ '#title' => t('index'),
+ '#description' => t('Choose a field to be used for index (delta) items.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['index'],
+ );
+ $form['nid'] = array(
+ '#title' => t('nid'),
+ '#description' => t('Choose a field to be used for the nid.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['nid'],
+ );
+ $form['title'] = array(
+ '#title' => t('title'),
+ '#description' => t('Choose a field to be used for the title.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['title'],
+ );
+ $form['start'] = array(
+ '#title' => t('start'),
+ '#description' => t('Choose a field to be used for start date.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['start'],
+ );
+ $form['end'] = array(
+ '#title' => t('end'),
+ '#description' => t('Choose a field to be used for end date.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['end'],
+ );
+ $form['url'] = array(
+ '#title' => t('url'),
+ '#description' => t('Choose a field to be used for the URL.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['url'],
+ );
+ $form['allDay'] = array(
+ '#title' => t('allDay'),
+ '#description' => t('Choose a field to be used for the allDay status.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['allDay'],
+ );
+ $form['className'] = array(
+ '#title' => t('className'),
+ '#description' => t('Choose a field to be used for the className.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['className'],
+ );
+ $form['editable'] = array(
+ '#title' => t('editable'),
+ '#description' => t('Choose a field to be used for edit status of the item.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['editable'],
+ );
+ $form['description'] = array(
+ '#title' => t('description'),
+ '#description' => t('Choose a field to be used for the description of the item.'),
+ '#type' => 'select',
+ '#options' => $fields,
+ '#default_value' => $this->options['description'],
+ );
+ }
+
+ function render() {
+ $output = parent::render();
+ drupal_set_header('Content-type: text/javascript; charset=utf-8');
+ $jsonoutput = array();
+ foreach ($this->rendered_fields as $field) {
+ $structure = array();
+ foreach ($this->options as $key => $value) {
+ if (!is_null($value) && $value && ($value != "0")) {
+ $structure[$key] = $field[$value];
+ }
+ if ($key == 'recurring') {
+ $structure[$key] = FALSE;
+ }
+ if ($key == 'allDay') {
+ $structure[$key] = FALSE;
+ }
+ if ($key == 'className') {
+ $structure[$key] = 'crayon crayon-' . theme('seed_crayon', $field[$value]);
+ }
+ if ($key == 'field') {
+ $structure[$key] = "field_date";
+ }
+ if ($key == 'start') {
+ $structure[$key] = array_pop(explode(' ', strip_tags($field[$value])));
+ }
+ if ($key == 'end') {
+ $structure[$key] = array_pop(explode(' ', strip_tags($field[$value])));
+ }
+ }
+ $jsonoutput[] = $structure;
+ }
+ return drupal_to_js($jsonoutput);
+ }
+}