From ff59f0385d21c31bbcb231d0769f92d8ba90e6d6 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 20 Mar 2009 18:15:20 +0100 Subject: [PATCH] More event form refinements. --- kronolith/ajax.php | 2 +- kronolith/js/src/kronolith.js | 62 +++++++++++++++++++++++++++++-------- kronolith/lib/Event.php | 20 +++++++++++- kronolith/lib/Kronolith.php | 4 +++ kronolith/templates/index/index.inc | 43 ++++++++++++------------- kronolith/themes/screen.css | 4 +-- 6 files changed, 97 insertions(+), 38 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index 7f6af041a..d72721bcf 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -126,7 +126,7 @@ case 'GetEvent': break; } $result = new stdClass; - $result->event = $event; + $result->event = $event->toJSON(true, $prefs->getValue('twentyFour') ? 'H:i' : 'h:i A'); break; case 'UpdateEvent': diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index b5d978915..bd263a406 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -871,8 +871,26 @@ KronolithCore = { editEvent: function(calendar, id) { - RedBox.loading(); - this.doAction('GetEvent', { 'cal': calendar, 'id': id }, this._editEvent.bind(this)); + RedBox.onDisplay = function() { + $('kronolithEventForm').focusFirstElement(); + RedBox.onDisplay = null; + }; + + if (id) { + RedBox.loading(); + this.doAction('GetEvent', { 'cal': calendar, 'id': id }, this._editEvent.bind(this)); + } else { + var d = new Date(); + $('kronolithEventForm').reset(); + $('kronolithEventDelete').hide(); + $('kronolithEventStartDate').value = d.toString(Kronolith.conf.date_format); + $('kronolithEventStartTime').value = d.toString(Kronolith.conf.time_format); + d.add(1).hour(); + $('kronolithEventEndDate').value = d.toString(Kronolith.conf.date_format); + $('kronolithEventEndTime').value = d.toString(Kronolith.conf.time_format); + RedBox.showHtml($('kronolithEventDialog').show()); + this.eventForm = RedBox.getWindowContents(); + } }, /** @@ -887,17 +905,35 @@ KronolithCore = { return; } - var ev = r.response.event; - $('id_ttl').value = ev.title; - $('id_local').value = ev.location; - $('id_fullday').checked = ev.allday; - $('id_from').value = ev.start._year + '-' + ev.start._month + '-' + ev.start._mday; - $('tobechanged').from_Hi.value = ev.start._hour + ':' + ev.start._min; - $('id_to').value = ev.end._year + '-' + ev.end._month + '-' + ev.end._mday; - $('tobechanged').to_Hi.value = ev.end._hour + ':' + ev.end._min; - $('id_tags').value = ev.tags.join(', '); - - RedBox.showHtml($('kronolithEventForm').show()); + try { + var ev = r.response.event; + $('kronolithEventTitle').value = ev.t; + $('kronolithEventLocation').value = ev.l; + $('kronolithEventAllday').checked = ev.a; + $('kronolithEventStartDate').value = ev.sd + $('kronolithEventStartTime').value = ev.st; + $('kronolithEventEndDate').value = ev.ed; + $('kronolithEventEndTime').value = ev.et; + $('kronolithEventTags').value = ev.tg.join(', '); + if (ev.r) { + // @todo: refine + $A($('kronolithEventRecurrence').options).find(function(option) { + return option.value == ev.r; + }).selected = true; + } + if (ev.e) { + $('kronolithEventSave').show(); + } else { + $('kronolithEventSave').hide(); + } + if (ev.d) { + $('kronolithEventDelete').show(); + } else { + $('kronolithEventDelete').hide(); + } + } catch (e) {} + + RedBox.showHtml($('kronolithEventDialog').show()); this.eventForm = RedBox.getWindowContents(); }, diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 75b1f2ea6..7b2f2dc66 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -994,9 +994,12 @@ class Kronolith_Event * Returns a simple object suitable for json transport representing this * event. * + * @param boolean $full Whether to return all event details. + * @param string $time_format The date() format to use for time formatting. + * * @return object A simple object. */ - public function toJSON() + public function toJSON($full = false, $time_format = 'H:i') { $json = new stdClass; $json->t = $this->getTitle(); @@ -1004,6 +1007,21 @@ class Kronolith_Event $json->bg = $this->_backgroundColor; $json->fg = $this->_foregroundColor; $json->e = $this->hasPermission(PERMS_EDIT); + $json->d = $this->hasPermission(PERMS_DELETE); + + if ($full) { + $json->l = $this->getLocation(); + $json->a = $this->isAllDay(); + $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->tg = array_values($this->tags); + if ($this->recurs()) { + $json->r = $this->recurrence->getRecurType(); + } + } + return $json; } diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 23fef40d9..316fc1be3 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -144,6 +144,10 @@ class Kronolith 'is_ie6' => ($browser->isBrowser('msie') && ($browser->getMajor() < 7)), 'login_view' => $prefs->getValue('defaultview'), 'week_start' => (int)$prefs->getValue('week_start_monday'), + 'date_format' => str_replace(array('%e', '%d', '%a', '%A', '%m', '%h', '%b', '%B', '%y', '%Y'), + array('d', 'dd', 'ddd', 'dddd', 'MM', 'MMM', 'MMM', 'MMMM', 'yy', 'yyyy'), + NLS::getLangInfo(D_FMT)), + 'time_format' => $prefs->getValue('twentyFour') ? 'HH:mm' : 'hh:mm tt', // Turn debugging on? 'debug' => !empty($conf['js']['debug']), ); diff --git a/kronolith/templates/index/index.inc b/kronolith/templates/index/index.inc index 84a23792d..f3e771178 100644 --- a/kronolith/templates/index/index.inc +++ b/kronolith/templates/index/index.inc @@ -111,32 +111,32 @@ -