From c58504895fc8605d2117a799fadd9e27f798c877 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 10 Nov 2009 18:09:06 +0100 Subject: [PATCH] Fill new event form (no saving yet). --- kronolith/js/kronolith.js | 134 ++++++++++++++++++++++++++++++------- kronolith/lib/Event.php | 22 +++++- kronolith/lib/Kronolith.php | 8 +++ kronolith/templates/index/edit.inc | 39 +++++------ 4 files changed, 154 insertions(+), 49 deletions(-) diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 72d351af1..0dece043f 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -830,7 +830,7 @@ KronolithCore = { $(id).update(); $H(Kronolith.conf.calendars.internal).each(function(cal) { if (cal.value.edit) { - $(id).insert(new Element('OPTION', { 'value': cal.key }) + $(id).insert(new Element('OPTION', { 'value': 'internal|' + cal.key }) .setStyle({ 'backgroundColor': cal.value.bg, 'color': cal.value.fg }) .update(cal.value.name.escapeHTML())); } @@ -1974,8 +1974,7 @@ KronolithCore = { return; case 'kronolithEventAllday': - $('kronolithEventStartTimeLabel').setStyle({ 'visibility': $('kronolithEventStartTimeLabel').getStyle('visibility') == 'visible' ? 'hidden' : 'visible' }); - $('kronolithEventEndTimeLabel').setStyle({ 'visibility': $('kronolithEventEndTimeLabel').getStyle('visibility') == 'visible' ? 'hidden' : 'visible' }); + this.toggleAllDay(); return; case 'kronolithEventLinkDescription': @@ -2007,11 +2006,7 @@ KronolithCore = { case 'kronolithEventLinkMonthly': case 'kronolithEventLinkYearly': case 'kronolithEventLinkLength': - $('kronolithEventTabRecur').select('DIV').invoke('hide'); - if (id != 'kronolithEventLinkNone') { - $(id.replace(/Link/, 'Repeat')).show(); - $('kronolithEventRepeatLength').show(); - } + this.toggleRecurrence(id.substring(18)); return; case 'kronolithEventSave': @@ -2309,7 +2304,7 @@ KronolithCore = { RedBox.onDisplay = null; }; - this.updateCalendarDropDown('kronolithEventCalendars'); + this.updateCalendarDropDown('kronolithEventCalendar'); $('kronolithEventTags').autocompleter.init(); $('kronolithEventForm').enable(); $('kronolithEventForm').reset(); @@ -2415,22 +2410,84 @@ KronolithCore = { return; } - $('kronolithEventId').value = ev.id; - $('kronolithEventCalendar').value = ev.ty + '|' + ev.c; - $('kronolithEventTitle').value = ev.t; - $('kronolithEventLocation').value = ev.l; - $('kronolithEventAllday').checked = ev.al; - $('kronolithEventStartDate').value = ev.sd - $('kronolithEventStartTime').value = ev.st; - $('kronolithEventEndDate').value = ev.ed; - $('kronolithEventEndTime').value = ev.et; - $('kronolithEventTags').autocompleter.init(ev.tg); + /* Basic information */ + $('kronolithEventId').setValue(ev.id); + $('kronolithEventCalendar').setValue(ev.ty + '|' + ev.c); + $('kronolithEventTitle').setValue(ev.t); + $('kronolithEventLocation').setValue(ev.l); + $('kronolithEventAllday').setValue(ev.al); + this.toggleAllDay(ev.al); + $('kronolithEventStartDate').setValue(ev.sd); + $('kronolithEventStartTime').setValue(ev.st); + $('kronolithEventEndDate').setValue(ev.ed); + $('kronolithEventEndTime').setValue(ev.et); + $('kronolithEventDescription').setValue(ev.d); + + /* Alarm */ + if (ev.a) { + $('kronolithEventAlarmOn').setValue(true); + [10080, 1440, 60, 1].each(function(unit) { + if (ev.a % unit == 0) { + $('kronolithEventAlarmValue').setValue(ev.a / unit); + $('kronolithEventAlarmUnit').setValue(unit); + throw $break; + } + }); + } else { + $('kronolithEventAlarmOff').setValue(true); + } + + /* Recurrence */ if (ev.r) { - // @todo: refine - $A($('kronolithEventRecurrence').options).find(function(option) { - return option.value == ev.r || option.value == -1; - }).selected = true; + var scheme = Kronolith.conf.recur[ev.r.t], + div = $('kronolithEventRepeat' + scheme); + $('kronolithEventLink' + scheme).setValue(true); + this.toggleRecurrence(scheme); + if (scheme == 'Monthly' || scheme == 'Yearly') { + div.down('input[name=recur_' + scheme.toLowerCase() + '_scheme][value=' + ev.r.t + ']').setValue(true); + } + if (scheme == 'Weekly') { + div.select('input[type=checkbox]').each(function(input) { + if (input.name == 'weekly[]' && + input.value & ev.r.d) { + input.setValue(true); + } + }); + } + if (ev.r.i == 1) { + div.down('input[name=recur_' + scheme.toLowerCase() + '][value=1]').setValue(true); + } else { + div.down('input[name=recur_' + scheme.toLowerCase() + '][value=0]').setValue(true); + div.down('input[name=recur_' + scheme.toLowerCase() + '_interval]').setValue(ev.r.i); + } + if (!Object.isUndefined(ev.r.e)) { + $('kronolithEventRepeatLength').down('input[name=recur_enddate_type][value=date]').setValue(true); + $('kronolithEventRecurDate').setValue(Date.parse(ev.r.e).toString(Kronolith.conf.date_format)); + } else if (!Object.isUndefined(ev.r.c)) { + $('kronolithEventRepeatLength').down('input[name=recur_enddate_type][value=count]').setValue(true); + $('kronolithEventRecurCount').setValue(ev.r.c); + } else { + $('kronolithEventRepeatLength').down('input[name=recur_enddate_type][value=none]').setValue(true); + } + } + + /* Attendees */ + if (!Object.isUndefined(ev.at)) { + $('kronolithEventAttendees').setValue(ev.at.pluck('l').join(', ')); + var table = $('kronolithEventTabAttendees').down('tbody'); + ev.at.each(function(attendee) { + var tr = new Element('tr'), i; + tr.insert(new Element('td').writeAttribute('title', attendee.l).insert(attendee.e.escapeHTML())); + for (i = 0; i < 24; i++) { + tr.insert(new Element('td')); + } + table.insert(tr); + }); } + + /* Tags */ + $('kronolithEventTags').autocompleter.init(ev.tg); + if (ev.pe) { $('kronolithEventSave').show(); $('kronolithEventForm').enable(); @@ -2448,6 +2505,37 @@ KronolithCore = { this.eventForm = RedBox.getWindowContents(); }, + /** + * Toggles the start and end time fields of the event edit form on and off. + * + * @param boolean on Whether the event is an all-day event, i.e. the time + * fields should be turned off. If not specified, the + * current state is toggled. + */ + toggleAllDay: function(on) + { + if (Object.isUndefined(on)) { + on = $('kronolithEventStartTimeLabel').getStyle('visibility') == 'visible'; + } + $('kronolithEventStartTimeLabel').setStyle({ 'visibility': on ? 'hidden' : 'visible' }); + $('kronolithEventEndTimeLabel').setStyle({ 'visibility': on ? 'hidden' : 'visible' }); + }, + + /** + * Toggles the recurrence fields of the event edit form. + * + * @param string recur The recurrence part of the field name, i.e. 'None', + * 'Daily', etc. + */ + toggleRecurrence: function(recur) + { + $('kronolithEventTabRecur').select('div').invoke('hide'); + if (recur != 'None') { + $('kronolithEventRepeat' + recur).show(); + $('kronolithEventRepeatLength').show(); + } + }, + _closeRedBox: function() { RedBox.close(); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index cca42cc63..554edaf4d 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -1084,6 +1084,7 @@ abstract class Kronolith_Event * * Possible properties are: * - t: title + * - d: description * - c: calendar id * - s: start date * - e: end date @@ -1095,8 +1096,9 @@ abstract class Kronolith_Event * - fg: foreground color * - pe: edit permissions? * - pd: delete permissions? - * - a: alarm text - * - r: recurrence type (Horde_Date_Recurrence::RECUR_* constant) + * - a: alarm text or minutes + * - r: recurrence type (Horde_Date_Recurrence::RECUR_* constant) or json + * representation of Horde_Date_Recurrence object. * - ic: icon * - ln: link * - aj: ajax link @@ -1107,6 +1109,7 @@ abstract class Kronolith_Event * - st: formatted start time * - ed: formatted end date * - et: formatted end time + * - at: attendees * - tg: tag list * * @param boolean $allDay If not null, overrides whether the event is @@ -1153,12 +1156,27 @@ abstract class Kronolith_Event if ($full) { $json->id = $this->getId(); $json->ty = $this->_calendarType; + $json->d = $this->getDescription(); $json->l = $this->getLocation(); $json->sd = $this->start->strftime('%x'); $json->st = $this->start->format($time_format); $json->ed = $this->end->strftime('%x'); $json->et = $this->end->format($time_format); + $json->a = $this->alarm; $json->tg = array_values($this->tags); + if ($this->recurs()) { + $json->r = $this->recurrence->toJson(); + } + if ($this->attendees) { + $attendees = array(); + foreach ($this->attendees as $email => $info) { + $attendees[] = array('e' => $email, + 'l' => empty($info['name']) ? $email : ($info['name'] . ' <' . $email . '>'), + 'a' => $info['attendance'], + 'r' => $info['response']); + } + $json->at = $attendees; + } } return $json; diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index db6fdeffe..92979ea46 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -139,6 +139,14 @@ class Kronolith 'confirmed' => self::STATUS_CONFIRMED, 'cancelled' => self::STATUS_CANCELLED, 'free' => self::STATUS_FREE), + 'recur' => array(Horde_Date_Recurrence::RECUR_NONE => 'None', + Horde_Date_Recurrence::RECUR_DAILY => 'Daily', + Horde_Date_Recurrence::RECUR_WEEKLY => 'Weekly', + Horde_Date_Recurrence::RECUR_MONTHLY_DATE => 'Monthly', + Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY => 'Monthly', + Horde_Date_Recurrence::RECUR_YEARLY_DATE => 'Yearly', + Horde_Date_Recurrence::RECUR_YEARLY_DAY => 'Yearly', + Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY => 'Yearly'), // Turn debugging on? 'debug' => !empty($conf['js']['debug']), ); diff --git a/kronolith/templates/index/edit.inc b/kronolith/templates/index/edit.inc index 7e6a22c9f..a9588c0e2 100644 --- a/kronolith/templates/index/edit.inc +++ b/kronolith/templates/index/edit.inc @@ -1,6 +1,5 @@