From d9d3ed050dbedda7cb945c42040469518d6d4ad0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 6 Jul 2011 22:01:54 +0200 Subject: [PATCH] Render entire calendar edit form in PHP giving full control to driver class --- plugins/calendar/calendar.php | 16 ++----------- plugins/calendar/calendar_ui.js | 7 +++--- plugins/calendar/drivers/calendar_driver.php | 7 +++--- plugins/calendar/lib/calendar_ui.php | 23 +++++++++++++++++++ .../skins/default/templates/calendarform.html | 18 --------------- 5 files changed, 33 insertions(+), 38 deletions(-) delete mode 100644 plugins/calendar/skins/default/templates/calendarform.html diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 9879aadb..df6e418f 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -402,10 +402,8 @@ class calendar extends rcube_plugin switch ($action) { case "form-new": case "form-edit": - $this->rc->output->reset(); - $this->register_handler('plugin.calendarform', array($this, 'calendar_editform')); - $this->rc->output->send('calendar.calendarform'); - break; + echo $this->ui->calendar_editform($action, $cal); + exit; case "new": $success = $this->driver->create_calendar($cal); $reload = true; @@ -430,16 +428,6 @@ class calendar extends rcube_plugin $this->rc->output->redirect(''); } - /** - * Handler for calendar form template object. - * Will get additional form fields from driver class - */ - function calendar_editform($attrib = array()) - { - $cal = get_input_value('c', RCUBE_INPUT_GPC); - $attrib['action'] = get_input_value('action', RCUBE_INPUT_GPC); - return $this->driver->calendar_form($cal, $attrib['action']); - } /** * Dispatcher for event actions initiated by the client diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index 733f4c72..e71467e7 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -657,9 +657,6 @@ function rcube_calendar_ui(settings) url: rcmail.url('calendar'), data: { action:(calendar.id ? 'form-edit' : 'form-new'), calendar:{ id:calendar.id } }, success: function(data){ - // strip out body part - if (data.replace(/\n+/g, '').match(/]*>(.+)<.body>/g)) - data = RegExp.$1; $dialog.html(data); form = $('#calendarform > form'); name = $('#calendar-name').val(calendar.editname || calendar.name); @@ -672,6 +669,10 @@ function rcube_calendar_ui(settings) var buttons = {}; buttons[rcmail.gettext('save', 'calendar')] = function() { + // form is not loaded + if (!form) + return; + // TODO: do some input validation if (!name.val() || name.val().length < 2) { alert(rcmail.gettext('invalidcalendarproperties', 'calendar')); diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php index 7f8ebfda..2aa48693 100644 --- a/plugins/calendar/drivers/calendar_driver.php +++ b/plugins/calendar/drivers/calendar_driver.php @@ -283,13 +283,14 @@ abstract class calendar_driver /** * Callback function to append additional elements to the calendar create/edit form * + * @param string Request action 'form-edit|form-new' * @param array Calendar properties (e.g. id) - * @param array Object attributes from HTML and request (e.g. action: 'form-edit|form-new') + * @param string HTML code for default edit form * @return string HTML to be appended to form */ - public function calendar_form($calendar, $attrib) + public function calendar_form($action, $calendar, $html) { - return ''; + return $html; } } \ No newline at end of file diff --git a/plugins/calendar/lib/calendar_ui.php b/plugins/calendar/lib/calendar_ui.php index d6bd69e9..f21faa45 100644 --- a/plugins/calendar/lib/calendar_ui.php +++ b/plugins/calendar/lib/calendar_ui.php @@ -538,4 +538,27 @@ class calendar_ui return $table->show($attrib); } + /** + * Handler for calendar form template object. + * Will get additional form fields from driver class + */ + function calendar_editform($action, $calendar = array()) + { + // compose default calendar form + $input_name = new html_inputfield(array('name' => 'name', 'id' => 'calendar-name', 'size' => 20)); + $html = html::div('form-section', + html::label('calendar-name', $this->calendar->gettext('name')) . + $input_name->show($calendar['name'])); + + $input_color = new html_inputfield(array('name' => 'color', 'id' => 'calendar-color', 'size' => 6)); + $html .= html::div('form-section', + html::label('calendar-color', $this->calendar->gettext('color')) . + $input_color->show($calendar['color'])); + + // allow driver to extend the form + $html = $this->calendar->driver->calendar_form($action, $calendar, $html); + + return html::tag('form', array('action' => "#", 'method' => "get"), $html); + } + } diff --git a/plugins/calendar/skins/default/templates/calendarform.html b/plugins/calendar/skins/default/templates/calendarform.html deleted file mode 100644 index 1c9df7a3..00000000 --- a/plugins/calendar/skins/default/templates/calendarform.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - -
-
- - -
-
- - -
- - - - -