Implement event deletion. No fancy recurrence deleting yet.
authorJan Schneider <jan@horde.org>
Fri, 20 Mar 2009 18:26:43 +0000 (19:26 +0100)
committerJan Schneider <jan@horde.org>
Fri, 20 Mar 2009 18:27:56 +0000 (19:27 +0100)
Disable event form on read-only events.

kronolith/ajax.php
kronolith/js/src/kronolith.js
kronolith/lib/Event.php
kronolith/lib/Event/Holidays.php
kronolith/lib/Event/Horde.php
kronolith/lib/Event/Ical.php
kronolith/lib/Event/Kolab.php
kronolith/lib/Event/Sql.php
kronolith/templates/index/index.inc

index d72721b..e529791 100644 (file)
@@ -114,7 +114,11 @@ case 'GetEvent':
         $result = true;
         break;
     }
-    $event = $kronolith_driver->getEvent(Util::getFormData('id'));
+    if (is_null($id = Util::getFormData('id'))) {
+        $result = true;
+        break;
+    }
+    $event = $kronolith_driver->getEvent($id);
     if (is_a($event, 'PEAR_Error')) {
         $notification->push($event, 'horde.error');
         $result = true;
@@ -133,7 +137,11 @@ case 'UpdateEvent':
     if (!($kronolith_driver = getDriver($cal = Util::getFormData('cal')))) {
         break;
     }
-    $event = $kronolith_driver->getEvent(Util::getFormData('id'));
+    if (is_null($id = Util::getFormData('id'))) {
+        $result = true;
+        break;
+    }
+    $event = $kronolith_driver->getEvent($id);
     if (is_a($event, 'PEAR_Error')) {
         $notification->push($event, 'horde.error');
         break;
@@ -160,6 +168,42 @@ case 'UpdateEvent':
     }
     break;
 
+case 'DeleteEvent':
+    if (!($kronolith_driver = getDriver($cal = Util::getFormData('cal')))) {
+        $result = true;
+        break;
+    }
+    if (is_null($id = Util::getFormData('id'))) {
+        $result = true;
+        break;
+    }
+    $event = $kronolith_driver->getEvent($id);
+    if (is_a($event, 'PEAR_Error')) {
+        $notification->push($event, 'horde.error');
+        $result = true;
+        break;
+    }
+    if (!$event) {
+        $notification->push(_("The requested event was not found."), 'horde.error');
+        $result = true;
+        break;
+    }
+    $share = &$kronolith_shares->getShare($event->getCalendar());
+    if (!$share->hasPermission(Auth::getAuth(), PERMS_DELETE, $event->getCreatorID())) {
+        $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
+        $result = true;
+        break;
+    }
+    $deleted = $kronolith_driver->deleteEvent($event->getId());
+    if (is_a($deleted, 'PEAR_Error')) {
+        $notification->push($deleted, 'horde.error');
+        $result = true;
+        break;
+    }
+    $result = new stdClass;
+    $result->deleted = true;
+    break;
+
 case 'SaveCalPref':
     $result = true;
     break;
index 8bb4bce..5b4220a 100644 (file)
@@ -754,10 +754,20 @@ KronolithCore = {
                 e.stop();
                 return;
 
-            case 'kronolithEventActions':
-                if (orig.match('input.button')) {
-                   this._closeRedBox();
-                }
+            case 'kronolithEventDelete':
+                var cal = $F('kronolithEventCalendar'),
+                    eventid = $F('kronolithEventId'),
+                    elm = $('kronolithEvent' + this.view + cal + eventid);
+                this.doAction('DeleteEvent',
+                              { 'cal': cal, 'id': eventid },
+                              function(r) { if (r.response.deleted) elm.remove(); else elm.toggle() });
+                elm.hide();
+                this._closeRedBox();
+                e.stop();
+                return;
+
+            case 'kronolithEventCancel':
+                this._closeRedBox();
                 e.stop();
                 return;
 
@@ -872,7 +882,9 @@ KronolithCore = {
     editEvent: function(calendar, id)
     {
         RedBox.onDisplay = function() {
-            $('kronolithEventForm').focusFirstElement();
+            try {
+                $('kronolithEventForm').focusFirstElement();
+            } catch(e) {}
             RedBox.onDisplay = null;
         };
 
@@ -881,7 +893,7 @@ KronolithCore = {
             this.doAction('GetEvent', { 'cal': calendar, 'id': id }, this._editEvent.bind(this));
         } else {
             var d = new Date();
-            $('kronolithEventForm').reset();
+            $('kronolithEventForm').enable().reset();
             $('kronolithEventDelete').hide();
             $('kronolithEventStartDate').value = d.toString(Kronolith.conf.date_format);
             $('kronolithEventStartTime').value = d.toString(Kronolith.conf.time_format);
@@ -907,6 +919,8 @@ KronolithCore = {
 
         try {
             var ev = r.response.event;
+            $('kronolithEventId').value = ev.i;
+            $('kronolithEventCalendar').value = ev.ty + '|' + ev.c;
             $('kronolithEventTitle').value = ev.t;
             $('kronolithEventLocation').value = ev.l;
             $('kronolithEventAllday').checked = ev.a;
@@ -923,8 +937,11 @@ KronolithCore = {
             }
             if (ev.e) {
                 $('kronolithEventSave').show();
+                $('kronolithEventForm').enable();
             } else {
                 $('kronolithEventSave').hide();
+                $('kronolithEventForm').disable();
+                $('kronolithEventCancel').enable();
             }
             if (ev.d) {
                 $('kronolithEventDelete').show();
index 7b2f2dc..de71d63 100644 (file)
@@ -11,7 +11,7 @@
  * @author  Jan Schneider <jan@horde.org>
  * @package Kronolith
  */
-class Kronolith_Event
+abstract class Kronolith_Event
 {
     /**
      * Flag that is set to true if this event has data from either a storage
@@ -174,6 +174,13 @@ class Kronolith_Event
     protected $_calendar;
 
     /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType;
+
+    /**
      * The HTML background color to be used for this event.
      *
      * @var string
@@ -1010,6 +1017,8 @@ class Kronolith_Event
         $json->d = $this->hasPermission(PERMS_DELETE);
 
         if ($full) {
+            $json->i = $this->getId();
+            $json->ty = $this->_calendarType;
             $json->l = $this->getLocation();
             $json->a = $this->isAllDay();
             $json->sd = $this->start->strftime('%x');
index f384c88..1cf83a7 100644 (file)
 class Kronolith_Event_Holidays extends Kronolith_Event
 {
     /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType = 'holiday';
+
+    /**
      * The status of this event.
      *
      * @var integer
index 745af15..2a603e5 100644 (file)
 class Kronolith_Event_Horde extends Kronolith_Event
 {
     /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType = 'external';
+
+    /**
      * The API (application) of this event.
      *
      * @var string
index 89efe74..2531ac4 100644 (file)
  */
 class Kronolith_Event_Ical extends Kronolith_Event
 {
+    /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType = 'remote';
 
     public function fromDriver($vEvent)
     {
index 2856cad..60fac0d 100644 (file)
  */
 class Kronolith_Event_Kolab extends Kronolith_Event
 {
+    /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType = 'internal';
 
     public function fromDriver($event)
     {
index 0c3930c..9e9f55f 100644 (file)
 class Kronolith_Event_Sql extends Kronolith_Event
 {
     /**
+     * The type of the calender this event exists on.
+     *
+     * @var string
+     */
+    protected $_calendarType = 'internal';
+
+    /**
      * @var array
      */
     private $_properties = array();
index f3e7711..bfc85ab 100644 (file)
 <!-- end menu -->
 
 <!-- ini edit -->
-<div id="kronolithEventDialog" style="display:none"><form id="kronolithEventForm">
+<div id="kronolithEventDialog" style="display:none">
+<form id="kronolithEventForm">
+<input id="kronolithEventCalendar" type="hidden" name="calendar" />
+<input id="kronolithEventId" type="hidden" name="eventid" />
 <div>
   <label for="kronolithEventTitle"><?php echo _("Title") ?></label><br />
   <input type="text" name="title" id="kronolithEventTitle" class="kronolithLongField" />
 <div id="kronolithEventActions">
   <input id="kronolithEventSave" type="button" value="<?php echo _("Save") ?>" class="button ok" />
   <input id="kronolithEventDelete" type="button" value="<?php echo _("Delete") ?>" class="button ko" />
-  <input type="button" value="<?php echo _("Cancel") ?>" class="button cancel" />
+  <input id="kronolithEventCancel" type="button" value="<?php echo _("Cancel") ?>" class="button cancel" />
   <span id="kronolithEventAdvancedLink">| <a href="#"><?php echo _("Advanced") ?></a></span><br />
 </div>