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