xref: /plugin/davcal/script.js (revision e05a9e4ce8d5eea570eeaab549bb1c7f175cf322)
1/* DOKUWIKI:include_once fullcalendar-2.4.0/moment.js */
2/* DOKUWIKI:include_once fullcalendar-2.4.0/fullcalendar.js */
3/* DOKUWIKI:include_once fullcalendar-2.4.0/lang/de.js */
4/* DOKUWIKI:include_once fullcalendar-2.4.0/lang/en.js */
5/* DOKUWIKI:include_once fullcalendar-2.4.0/lang/nl.js */
6/* DOKUWIKI:include_once datetimepicker-2.4.5/jquery.datetimepicker.js */
7/* DOKUWIKI:include_once jstz.js */
8
9/**
10 * Initialize the DAVCal script, attaching some event handlers and triggering
11 * the initial load of the fullcalendar JS
12 */
13jQuery(function() {
14    // Redefine functions for using moment.js with datetimepicker
15
16    Date.parseDate = function( input, format ){
17      return moment(input,format).toDate();
18    };
19    Date.prototype.dateFormat = function( format ){
20      return moment(this).format(format);
21    };
22
23    // Attach to event links
24    var calendarpage = jQuery('#fullCalendar').data('calendarpage');
25    if(!calendarpage) return;
26    dw_davcal__modals.page = calendarpage;
27
28    jQuery('div.fullCalendarSettings a').each(function() {
29        var $link = jQuery(this);
30        var href = $link.attr('href');
31        if (!href) return;
32
33        $link.click(
34            function(e) {
35                dw_davcal__modals.showSettingsDialog();
36                e.preventDefault();
37                return '';
38            }
39        );
40        }
41    );
42
43    // First, retrieve the current settings.
44    // Upon success, initialize fullcalendar.
45    var postArray = { };
46    jQuery.post(
47        DOKU_BASE + 'lib/exe/ajax.php',
48        {
49            call: 'plugin_davcal',
50            id: dw_davcal__modals.page,
51            page: dw_davcal__modals.page,
52            action: 'getSettings',
53            params: postArray
54        },
55        function(data)
56        {
57            var result = data['result'];
58            if(result === true)
59            {
60                dw_davcal__modals.settings = data['settings'];
61                var wknum = false;
62                var tz = false;
63                var we = true;
64                var ro = false;
65                var firstday = 0;
66                var detectedTz = jstz.determine().name();
67                dw_davcal__modals.detectedTz = detectedTz;
68                if(data['settings']['weeknumbers'] == 1)
69                    wknum = true;
70                if(data['settings']['timezone'] !== '')
71                    tz = data['settings']['timezone'];
72                if(data['settings']['workweek'] == 1)
73                    we = false;
74                if(data['settings']['monday'] == 1)
75                    firstday = 1;
76                var defaultView = data['settings']['meta']['view'];
77                // Initialize the davcal popup
78                var res = jQuery('#fullCalendar').fullCalendar({
79                    dayClick: function(date, jsEvent, view) {
80                        dw_davcal__modals.showEditEventDialog(date, false);
81                    },
82                    eventClick: function(calEvent, jsEvent, view) {
83                        dw_davcal__modals.showEditEventDialog(calEvent, true);
84                    },
85                    events: {
86                        url: DOKU_BASE + 'lib/exe/ajax.php',
87                        type: 'POST',
88                        data: {
89                            call: 'plugin_davcal',
90                            action: 'getEvents',
91                            id: dw_davcal__modals.page,
92                            page: dw_davcal__modals.page
93                        },
94                        error: function() {
95                            dw_davcal__modals.msg = LANG.plugins.davcal['error_retrieving_data'];
96                            dw_davcal__modals.showDialog(false);
97                        }
98                    },
99                    header: {
100                        left: 'title',
101                        center: 'today prev,next',
102                        right: 'month,agendaWeek,agendaDay'
103                    },
104                    lang: JSINFO.plugin.davcal['language'],
105                    weekNumbers: wknum,
106                    timezone: tz,
107                    weekends: we,
108                    firstDay: firstday,
109                    defaultView: defaultView
110                });
111            }
112        }
113    );
114});
115
116/**
117 * This holds all modal windows that DAVCal uses.
118 */
119var dw_davcal__modals = {
120    $editEventDialog: null,
121    $dialog: null,
122    $settingsDialog: null,
123    msg: null,
124    completeCb: null,
125    action: null,
126    uid: null,
127    settings: null,
128    page: null,
129    detectedTz: null,
130
131    /**
132     * Show the settings dialog
133     */
134    // FIXME: Hide URLs for multi-calendar
135    showSettingsDialog : function() {
136        if(dw_davcal__modals.$settingsDialog)
137            return;
138
139        // Dialog buttons are language-dependent and defined here.
140        // Attach event handlers for save and cancel.
141        var dialogButtons = {};
142        if(!JSINFO.plugin.davcal['disable_settings'])
143        {
144            dialogButtons[LANG.plugins.davcal['save']] = function() {
145                var postArray = { };
146                jQuery("input[class=dw_davcal__settings], select[class=dw_davcal__settings]").each(function() {
147                  if(jQuery(this).attr('type') == 'checkbox')
148                  {
149                      postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0;
150                  }
151                  else
152                  {
153                      postArray[jQuery(this).prop('name')] = jQuery(this).val();
154                  }
155                });
156                jQuery('#dw_davcal__ajaxsettings').html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />');
157                jQuery.post(
158                    DOKU_BASE + 'lib/exe/ajax.php',
159                    {
160                        call: 'plugin_davcal',
161                        id: dw_davcal__modals.page,
162                        page: dw_davcal__modals.page,
163                        action: 'saveSettings',
164                        params: postArray
165                    },
166                    function(data)
167                    {
168                        var result = data['result'];
169                        var html = data['html'];
170                        jQuery('#dw_davcal__ajaxsettings').html(html);
171                        if(result === true)
172                        {
173                            location.reload();
174                        }
175                    }
176                );
177            };
178        }
179        dialogButtons[LANG.plugins.davcal['cancel']] = function () {
180            dw_davcal__modals.hideSettingsDialog();
181        };
182
183        var settingsHtml = '<div><table>';
184
185        if(JSINFO.plugin.davcal['disable_settings'] && JSINFO.plugin.davcal['disable_sync'] && JSINFO.plugin.davcal['disable_ics'])
186        {
187            settingsHtml += LANG.plugins.davcal['nothing_to_show'];
188        }
189
190        if(!JSINFO.plugin.davcal['disable_settings'])
191        {
192            settingsHtml += '<tr><td>' + LANG.plugins.davcal['timezone'] + '</td><td><select name="timezone" id="dw_davcal__settings_timezone" class="dw_davcal__settings"></select></td></tr>' +
193            '<tr><td>' + LANG.plugins.davcal['weeknumbers'] + '</td><td><input type="checkbox" name="weeknumbers" id="dw_davcal__settings_weeknumbers" class="dw_davcal__settings"></td></tr>' +
194            '<tr><td>' + LANG.plugins.davcal['only_workweek'] + '</td><td><input type="checkbox" name="workweek" id="dw_davcal__settings_workweek" class="dw_davcal__settings"></td></tr>' +
195            '<tr><td>' + LANG.plugins.davcal['start_monday'] + '</td><td><input type="checkbox" name="monday" id="dw_davcal__settings_monday" class="dw_davcal__settings"></td></tr>';
196         }
197
198         if(!JSINFO.plugin.davcal['disable_sync'])
199         {
200             settingsHtml += '<tr id="dw_davcal__settings_syncurl"><td>' + LANG.plugins.davcal['sync_url'] + '</td><td><input type="text" name="syncurl" readonly="readonly" id="dw_davcal__settings_syncurl" class="dw_davcal__text" value="' + dw_davcal__modals.settings['syncurl'] + '"></td></tr>';
201         }
202
203         if(!JSINFO.plugin.davcal['disable_ics'])
204         {
205             settingsHtml += '<tr id="dw_davcal__settings_privateurl"><td>' + LANG.plugins.davcal['private_url'] + '</td><td><input type="text" name="privateurl" readonly="readonly" id="dw_davcal__settings_privateurl" class="dw_davcal__text" value="' + dw_davcal__modals.settings['privateurl'] + '"></td></tr>';
206         }
207
208         settingsHtml += '</table>' +
209            '</div>' +
210            '<div id="dw_davcal__ajaxsettings"></div>';
211
212        dw_davcal__modals.$settingsDialog = jQuery(document.createElement('div'))
213       .dialog({
214           autoOpen: false,
215           draggable: true,
216           title: LANG.plugins.davcal['settings'],
217           resizable: true,
218           buttons: dialogButtons,
219       })
220       .html(
221           settingsHtml
222            )
223       .parent()
224       .attr('id','dw_davcal__settings')
225       .show()
226       .appendTo('.dokuwiki:first');
227
228       jQuery('#dw_davcal__settings').position({
229           my: "center",
230           at: "center",
231           of: window
232       });
233
234       // Initialize current settings
235
236        if(!JSINFO.plugin.davcal['disable_settings'])
237        {
238            var $tzdropdown = jQuery('#dw_davcal__settings_timezone');
239            jQuery('#fullCalendarTimezoneList option').each(function() {
240                jQuery('<option />', {value: jQuery(this).val(),
241                        text: jQuery(this).text()}).appendTo($tzdropdown);
242            });
243
244            if(dw_davcal__modals.settings)
245            {
246                if(dw_davcal__modals.settings['timezone'] !== '')
247                    jQuery('#dw_davcal__settings_timezone').val(dw_davcal__modals.settings['timezone']);
248                if(dw_davcal__modals.settings['weeknumbers'] == 1)
249                    jQuery('#dw_davcal__settings_weeknumbers').prop('checked', true);
250                else
251                    jQuery('#dw_davcal__settings_weeknumbers').prop('checked', false);
252
253                if(dw_davcal__modals.settings['workweek'] == 1)
254                    jQuery('#dw_davcal__settings_workweek').prop('checked', true);
255                else
256                    jQuery('#dw_davcal__settings_workweek').prop('checked', false);
257
258                if(dw_davcal__modals.settings['monday'] == 1)
259                    jQuery('#dw_davcal__settings_monday').prop('checked', true);
260                else
261                    jQuery('#dw_davcal__settings_monday').prop('checked', false);
262            }
263        }
264
265        // attach event handlers
266        jQuery('#dw_davcal__settings .ui-dialog-titlebar-close').click(function(){
267          dw_davcal__modals.hideSettingsDialog();
268        });
269    },
270
271    /**
272     * Sanity-check our events.
273     *
274     * @return boolean false on failure, otherwise true
275     */
276    checkEvents : function() {
277        // Retrieve dates
278        var allDay = jQuery('#dw_davcal__allday_edit').prop('checked');
279        var startDate = moment(jQuery('#dw_davcal__eventfrom_edit').val(), 'YYYY-MM-DD');
280        var endDate = moment(jQuery('#dw_davcal__eventto_edit').val(), 'YYYY-MM-DD');
281
282        // Do the checking
283        if(!allDay)
284        {
285            var startTime = moment.duration(jQuery('#dw_davcal__eventfromtime_edit').val());
286            var endTime = moment.duration(jQuery('#dw_davcal__eventtotime_edit').val());
287            startDate.add(startTime);
288            endDate.add(endTime);
289        }
290        if(!startDate.isValid())
291        {
292            dw_davcal__modals.msg = LANG.plugins.davcal['start_date_invalid'];
293            dw_davcal__modals.showDialog(false);
294            return false;
295        }
296        if(!endDate.isValid())
297        {
298            dw_davcal__modals.msg = LANG.plugins.davcal['end_date_invalid'];
299            dw_davcal__modals.showDialog(false);
300            return false;
301        }
302        if(endDate.isBefore(startDate))
303        {
304            dw_davcal__modals.msg = LANG.plugins.davcal['end_date_before_start_date'];
305            dw_davcal__modals.showDialog(false);
306            return false;
307        }
308        if(!allDay && endDate.isSame(startDate))
309        {
310            dw_davcal__modals.msg = LANG.plugins.davcal['end_date_is_same_as_start_date'];
311            dw_davcal__modals.showDialog(false);
312            return false;
313        }
314        return true;
315    },
316
317    /**
318     * Show the edit event dialog, which is also used to create new events
319     * @param {Object} event The event to create, that is the date or the calEvent
320     * @param {Object} edit  Whether we edit (true) or create a new event (false)
321     */
322    showEditEventDialog : function(event, edit) {
323        if(dw_davcal__modals.$editEventDialog)
324            return;
325
326        var readonly = dw_davcal__modals.settings['readonly'];
327        var title = '';
328        var dialogButtons = {};
329        var calEvent = [];
330        var recurringWarning = '';
331        // Buttons are dependent on edit or create
332        // Several possibilities:
333        //
334        // 1) Somebody tries to edit, it is not recurring and not readonly -> show
335        // 2) Somebody tries to edit, it is recurring and not readonly -> message
336        // 3) Somebody tries to edit, it is readonly -> message
337        // 4) Somebody tries to create and it is readonly -> message
338        // 5) Somebody tries to create -> show
339        if(edit && (event.recurring != true) && (readonly === false))
340        {
341            calEvent = event;
342            title = LANG.plugins.davcal['edit_event'];
343            dialogButtons[LANG.plugins.davcal['edit']] = function() {
344                if(!dw_davcal__modals.checkEvents())
345                  return;
346                var postArray = { };
347                var pageid = dw_davcal__modals.page;
348                if(dw_davcal__modals.settings['multi'])
349                {
350                    pageid = jQuery("#dw_davcal__editevent_calendar option:selected").val();
351                }
352                jQuery("input.dw_davcal__editevent, textarea.dw_davcal__editevent").each(function() {
353                  if(jQuery(this).attr('type') == 'checkbox')
354                  {
355                      postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0;
356                  }
357                  else
358                  {
359                      postArray[jQuery(this).prop('name')] = jQuery(this).val();
360                  }
361                });
362                jQuery('#dw_davcal__ajaxedit').html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />');
363                jQuery.post(
364                    DOKU_BASE + 'lib/exe/ajax.php',
365                    {
366                        call: 'plugin_davcal',
367                        id: pageid,
368                        page: dw_davcal__modals.page,
369                        action: 'editEvent',
370                        params: postArray
371                    },
372                    function(data)
373                    {
374                        var result = data['result'];
375                        var html = data['html'];
376                        jQuery('#dw_davcal__ajaxedit').html(html);
377                        if(result === true)
378                        {
379                            jQuery('#fullCalendar').fullCalendar('refetchEvents');
380                            dw_davcal__modals.hideEditEventDialog();
381                        }
382                    }
383                );
384            };
385            dialogButtons[LANG.plugins.davcal['delete']] = function() {
386                dw_davcal__modals.action = 'deleteEvent';
387                dw_davcal__modals.msg = LANG.plugins.davcal['really_delete_this_event'];
388                dw_davcal__modals.completeCb = function(data) {
389                    var result = data['result'];
390                    var html = data['html'];
391                    jQuery('#dw_davcal__ajaxedit').html(html);
392                    if(result === true)
393                    {
394                        jQuery('#fullCalendar').fullCalendar('refetchEvents');
395                        dw_davcal__modals.hideEditEventDialog();
396                    }
397                };
398                dw_davcal__modals.showDialog(true);
399            };
400        }
401        else if(edit && (event.recurring == true) && (readonly === false))
402        {
403            calEvent = event;
404            title = LANG.plugins.davcal['edit_event'];
405            recurringWarning = LANG.plugins.davcal['recurring_cant_edit'];
406        }
407        else if(edit && (readonly === true))
408        {
409            calEvent = event;
410            title = LANG.plugins.davcal['edit_event'];
411            recurringWarning = LANG.plugins.davcal['no_permission'];
412        }
413        else if(readonly === true)
414        {
415            calEvent.start = event;
416            calEvent.end = moment(event);
417            calEvent.start.hour(12);
418            calEvent.start.minute(0);
419            calEvent.end.hour(13);
420            calEvent.end.minute(0);
421            calEvent.allDay = false;
422            calEvent.recurring = false;
423            calEvent.title = '';
424            calEvent.description = '';
425            calEvent.id = '0';
426            calEvent.page = dw_davcal__modals.page;
427            title = LANG.plugins.davcal['create_new_event'];
428            recurringWarning = LANG.plugins.davcal['no_permission'];
429        }
430        else
431        {
432            calEvent.start = event;
433            calEvent.end = moment(event);
434            calEvent.start.hour(12);
435            calEvent.start.minute(0);
436            calEvent.end.hour(13);
437            calEvent.end.minute(0);
438            calEvent.allDay = false;
439            calEvent.recurring = false;
440            calEvent.title = '';
441            calEvent.description = '';
442            calEvent.id = '0';
443            calEvent.page = dw_davcal__modals.settings['calids'][0]['page'];
444            title = LANG.plugins.davcal['create_new_event'];
445            dialogButtons[LANG.plugins.davcal['create']] = function() {
446                if(!dw_davcal__modals.checkEvents())
447                  return;
448
449                var postArray = { };
450                var pageid = dw_davcal__modals.page;
451                if(dw_davcal__modals.settings['multi'])
452                {
453                    pageid = jQuery("#dw_davcal__editevent_calendar option:selected").val();
454                }
455                jQuery("input.dw_davcal__editevent, textarea.dw_davcal__editevent").each(function() {
456                  if(jQuery(this).attr('type') == 'checkbox')
457                  {
458                      postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0;
459                  }
460                  else
461                  {
462                      postArray[jQuery(this).prop('name')] = jQuery(this).val();
463                  }
464                });
465                jQuery('#dw_davcal__ajaxedit').html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />');
466                jQuery.post(
467                    DOKU_BASE + 'lib/exe/ajax.php',
468                    {
469                        call: 'plugin_davcal',
470                        id: pageid,
471                        page: dw_davcal__modals.page,
472                        action: 'newEvent',
473                        params: postArray
474                    },
475                    function(data)
476                    {
477                        var result = data['result'];
478                        var html = data['html'];
479                        jQuery('#dw_davcal__ajaxedit').html(html);
480                        if(result === true)
481                        {
482                            jQuery('#fullCalendar').fullCalendar('refetchEvents');
483                            dw_davcal__modals.hideEditEventDialog();
484                        }
485                    }
486                );
487            };
488        }
489        dialogButtons[LANG.plugins.davcal['cancel']] = function() {
490            dw_davcal__modals.hideEditEventDialog();
491        };
492        dw_davcal__modals.uid = calEvent.id;
493        dw_davcal__modals.$editEventDialog = jQuery(document.createElement('div'))
494       .dialog({
495           autoOpen: false,
496           draggable: true,
497           title: title,
498           resizable: true,
499           buttons: dialogButtons,
500       })
501       .html(
502            '<div><table>' +
503            '<tr><td>' + LANG.plugins.davcal['calendar'] + '</td><td><select id="dw_davcal__editevent_calendar"></select></td></tr>' +
504            '<tr><td>' + LANG.plugins.davcal['title'] + '</td><td><input type="text" id="dw_davcal__eventname_edit" name="eventname" class="dw_davcal__editevent"></td></tr>' +
505            '<tr><td>' + LANG.plugins.davcal['description'] + '</td><td><textarea name="eventdescription" id="dw_davcal__eventdescription_edit" class="dw_davcal__editevent dw_davcal__text"></textarea></td></tr>' +
506            '<tr><td>' + LANG.plugins.davcal['from'] + '</td><td><input type="text" name="eventfrom" id="dw_davcal__eventfrom_edit" class="dw_davcal__editevent dw_davcal__date"><input type="text" name="eventfromtime" id="dw_davcal__eventfromtime_edit" class="dw_davcal__editevent dw_davcal__time"></td></tr>' +
507            '<tr><td>' + LANG.plugins.davcal['to'] + '</td><td><input type="text" name="eventto" id="dw_davcal__eventto_edit" class="dw_davcal__editevent dw_davcal__date"><input type="text" name="eventtotime" id="dw_davcal__eventtotime_edit" class="dw_davcal__editevent dw_davcal__time"></td></tr>' +
508            '<tr><td colspan="2"><input type="checkbox" name="allday" id="dw_davcal__allday_edit" class="dw_davcal__editevent">' + LANG.plugins.davcal['allday'] + '</td></tr>' +
509            '</table>' +
510            recurringWarning +
511            '<input type="hidden" name="uid" id="dw_davcal__uid_edit" class="dw_davcal__editevent">' +
512            '<input type="hidden" name="detectedtz" id="dw_davcal__tz_edit" class="dw_davcal__editevent">' +
513            '</div>' +
514            '<div id="dw_davcal__ajaxedit"></div>'
515            )
516       .parent()
517       .attr('id','dw_davcal__edit')
518       .show()
519       .appendTo('.dokuwiki:first');
520
521       jQuery('#dw_davcal__edit').position({
522           my: "center",
523           at: "center",
524           of: window
525       });
526
527       // Populate calendar dropdown
528       var $dropdown = jQuery("#dw_davcal__editevent_calendar");
529       for(var i=0; i<dw_davcal__modals.settings['calids'].length; i++)
530       {
531           var sel = '';
532           if(calEvent.page == dw_davcal__modals.settings['calids'][i]['page'])
533             sel = ' selected="selected"';
534           $dropdown.append('<option value="' + dw_davcal__modals.settings['calids'][i]['page'] + '"' + sel + '>' + dw_davcal__modals.settings['calids'][i]['name'] + '</option>');
535       }
536       if(edit || (dw_davcal__modals.settings['calids'].length < 1))
537       {
538           $dropdown.prop('disabled', true);
539       }
540
541       // Set up existing/predefined values
542       jQuery('#dw_davcal__tz_edit').val(dw_davcal__modals.detectedTz);
543       jQuery('#dw_davcal__uid_edit').val(calEvent.id);
544       jQuery('#dw_davcal__eventname_edit').val(calEvent.title);
545       jQuery('#dw_davcal__eventfrom_edit').val(calEvent.start.format('YYYY-MM-DD'));
546       jQuery('#dw_davcal__eventfromtime_edit').val(calEvent.start.format('HH:mm'));
547       jQuery('#dw_davcal__eventdescription_edit').val(calEvent.description);
548       if(calEvent.allDay && (calEvent.end === null))
549       {
550           jQuery('#dw_davcal__eventto_edit').val(calEvent.start.format('YYYY-MM-DD'));
551           jQuery('#dw_davcal__eventtotime_edit').val(calEvent.start.format('HH:mm'));
552       }
553       else if(calEvent.allDay)
554       {
555           endEvent = moment(calEvent.end);
556           endEvent.subtract(1, 'days');
557           jQuery('#dw_davcal__eventto_edit').val(endEvent.format('YYYY-MM-DD'));
558           jQuery('#dw_davcal__eventotime_edit').val(endEvent.format('HH:mm'));
559       }
560       else
561       {
562           jQuery('#dw_davcal__eventto_edit').val(calEvent.end.format('YYYY-MM-DD'));
563           jQuery('#dw_davcal__eventtotime_edit').val(calEvent.end.format('HH:mm'));
564       }
565       jQuery('#dw_davcal__allday_edit').prop('checked', calEvent.allDay);
566
567        // attach event handlers
568        jQuery('#dw_davcal__edit .ui-dialog-titlebar-close').click(function(){
569          dw_davcal__modals.hideEditEventDialog();
570        });
571        jQuery('#dw_davcal__eventfrom_edit').datetimepicker({format:'YYYY-MM-DD',
572                                                      formatDate:'YYYY-MM-DD',
573                                                      datepicker: true,
574                                                      timepicker: false,
575                                                      });
576        jQuery('#dw_davcal__eventfromtime_edit').datetimepicker({format:'HH:mm',
577                                                      formatTime:'HH:mm',
578                                                      datepicker: false,
579                                                      timepicker: true,
580                                                      step: 15});
581        jQuery('#dw_davcal__eventto_edit').datetimepicker({format:'YYYY-MM-DD',
582                                                      formatDate:'YYYY-MM-DD',
583                                                      datepicker: true,
584                                                      timepicker: false,
585                                                      });
586        jQuery('#dw_davcal__eventtotime_edit').datetimepicker({format:'HH:mm',
587                                                      formatTime:'HH:mm',
588                                                      datepicker: false,
589                                                      timepicker: true,
590                                                      step:15});
591        jQuery('#dw_davcal__allday_edit').change(function() {
592            if(jQuery(this).is(":checked"))
593            {
594                jQuery('#dw_davcal__eventfromtime_edit').prop('readonly', true);
595                jQuery('#dw_davcal__eventtotime_edit').prop('readonly', true);
596            }
597            else
598            {
599                jQuery('#dw_davcal__eventfromtime_edit').prop('readonly', false);
600                jQuery('#dw_davcal__eventtotime_edit').prop('readonly', false);
601            }
602        });
603        jQuery('#dw_davcal__allday_edit').change();
604    },
605
606    /**
607     * Show an info/confirmation dialog
608     * @param {Object} confirm Whether a confirmation dialog (true) or an info dialog (false) is requested
609     */
610    showDialog : function(confirm)
611    {
612        if(dw_davcal__modals.$confirmDialog)
613            return;
614        var dialogButtons = {};
615        var title = '';
616        if(confirm)
617        {
618            title = LANG.plugins.davcal['confirmation'];
619            var pageid = dw_davcal__modals.page;
620            if(dw_davcal__modals.settings['multi'])
621            {
622                pageid = jQuery("#dw_davcal__editevent_calendar option:selected").val();
623            }
624            dialogButtons[LANG.plugins.davcal['yes']] =  function() {
625                            jQuery.post(
626                                DOKU_BASE + 'lib/exe/ajax.php',
627                                {
628                                    call: 'plugin_davcal',
629                                    id: pageid,
630                                    page: dw_davcal__modals.page,
631                                    action: dw_davcal__modals.action,
632                                    params: {
633                                        uid: dw_davcal__modals.uid
634                                    }
635                                },
636                                function(data)
637                                {
638                                    dw_davcal__modals.completeCb(data);
639                                }
640                            );
641                            dw_davcal__modals.hideDialog();
642                    };
643            dialogButtons[LANG.plugins.davcal['cancel']] = function() {
644                            dw_davcal__modals.hideDialog();
645                    };
646        }
647        else
648        {
649            title = LANG.plugins.davcal['info'];
650            dialogButtons[LANG.plugins.davcal['ok']] = function() {
651                 dw_davcal__modals.hideDialog();
652            };
653        }
654        dw_davcal__modals.$dialog = jQuery(document.createElement('div'))
655            .dialog({
656                autoOpen: false,
657                draggable: true,
658                title: title,
659                resizable: true,
660                buttons: dialogButtons,
661            })
662            .html(
663                '<div>' + dw_davcal__modals.msg + '</div>'
664            )
665            .parent()
666            .attr('id','dw_davcal__confirm')
667            .show()
668            .appendTo('.dokuwiki:first');
669
670            jQuery('#dw_davcal__confirm').position({
671                my: "center",
672                at: "center",
673                of: window
674            });
675                 // attach event handlers
676            jQuery('#dw_davcal__confirm .ui-dialog-titlebar-close').click(function(){
677                dw_davcal__modals.hideDialog();
678            });
679    },
680
681    /**
682     * Hide the edit event dialog
683     */
684    hideEditEventDialog : function() {
685        dw_davcal__modals.$editEventDialog.empty();
686        dw_davcal__modals.$editEventDialog.remove();
687        dw_davcal__modals.$editEventDialog = null;
688    },
689
690    /**
691     * Hide the confirm/info dialog
692     */
693    hideDialog: function() {
694        dw_davcal__modals.$dialog.empty();
695        dw_davcal__modals.$dialog.remove();
696        dw_davcal__modals.$dialog = null;
697    },
698
699    /**
700     * Hide the settings dialog
701     */
702    hideSettingsDialog: function() {
703        dw_davcal__modals.$settingsDialog.empty();
704        dw_davcal__modals.$settingsDialog.remove();
705        dw_davcal__modals.$settingsDialog = null;
706    }
707};
708