From 0c0315cddb2d84995d4ace1ddaeb62b53dbb675b Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 20 Mar 2009 19:26:43 +0100 Subject: [PATCH] Implement event deletion. No fancy recurrence deleting yet. Disable event form on read-only events. --- kronolith/ajax.php | 48 +++++++++++++++++++++++++++++++++++-- kronolith/js/src/kronolith.js | 29 +++++++++++++++++----- kronolith/lib/Event.php | 11 ++++++++- kronolith/lib/Event/Holidays.php | 7 ++++++ kronolith/lib/Event/Horde.php | 7 ++++++ kronolith/lib/Event/Ical.php | 6 +++++ kronolith/lib/Event/Kolab.php | 6 +++++ kronolith/lib/Event/Sql.php | 7 ++++++ kronolith/templates/index/index.inc | 7 ++++-- 9 files changed, 117 insertions(+), 11 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index d72721bcf..e52979163 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -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; diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index 8bb4bcedd..5b4220a52 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -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(); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 7b2f2dc66..de71d6348 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -11,7 +11,7 @@ * @author Jan Schneider * @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'); diff --git a/kronolith/lib/Event/Holidays.php b/kronolith/lib/Event/Holidays.php index f384c8814..1cf83a7dd 100644 --- a/kronolith/lib/Event/Holidays.php +++ b/kronolith/lib/Event/Holidays.php @@ -12,6 +12,13 @@ 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 diff --git a/kronolith/lib/Event/Horde.php b/kronolith/lib/Event/Horde.php index 745af15dd..2a603e5e3 100644 --- a/kronolith/lib/Event/Horde.php +++ b/kronolith/lib/Event/Horde.php @@ -11,6 +11,13 @@ 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 diff --git a/kronolith/lib/Event/Ical.php b/kronolith/lib/Event/Ical.php index 89efe7499..2531ac4c3 100644 --- a/kronolith/lib/Event/Ical.php +++ b/kronolith/lib/Event/Ical.php @@ -11,6 +11,12 @@ */ 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) { diff --git a/kronolith/lib/Event/Kolab.php b/kronolith/lib/Event/Kolab.php index 2856cad95..60fac0d30 100644 --- a/kronolith/lib/Event/Kolab.php +++ b/kronolith/lib/Event/Kolab.php @@ -12,6 +12,12 @@ */ 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) { diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index 0c3930c40..9e9f55fc8 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -13,6 +13,13 @@ 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(); diff --git a/kronolith/templates/index/index.inc b/kronolith/templates/index/index.inc index f3e771178..bfc85ab41 100644 --- a/kronolith/templates/index/index.inc +++ b/kronolith/templates/index/index.inc @@ -111,7 +111,10 @@ -