Render entire calendar edit form in PHP giving full control to driver class
This commit is contained in:
parent
552cf212c4
commit
d9d3ed050d
5 changed files with 33 additions and 38 deletions
|
@ -402,10 +402,8 @@ class calendar extends rcube_plugin
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case "form-new":
|
case "form-new":
|
||||||
case "form-edit":
|
case "form-edit":
|
||||||
$this->rc->output->reset();
|
echo $this->ui->calendar_editform($action, $cal);
|
||||||
$this->register_handler('plugin.calendarform', array($this, 'calendar_editform'));
|
exit;
|
||||||
$this->rc->output->send('calendar.calendarform');
|
|
||||||
break;
|
|
||||||
case "new":
|
case "new":
|
||||||
$success = $this->driver->create_calendar($cal);
|
$success = $this->driver->create_calendar($cal);
|
||||||
$reload = true;
|
$reload = true;
|
||||||
|
@ -430,16 +428,6 @@ class calendar extends rcube_plugin
|
||||||
$this->rc->output->redirect('');
|
$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
|
* Dispatcher for event actions initiated by the client
|
||||||
|
|
|
@ -657,9 +657,6 @@ function rcube_calendar_ui(settings)
|
||||||
url: rcmail.url('calendar'),
|
url: rcmail.url('calendar'),
|
||||||
data: { action:(calendar.id ? 'form-edit' : 'form-new'), calendar:{ id:calendar.id } },
|
data: { action:(calendar.id ? 'form-edit' : 'form-new'), calendar:{ id:calendar.id } },
|
||||||
success: function(data){
|
success: function(data){
|
||||||
// strip out body part
|
|
||||||
if (data.replace(/\n+/g, '').match(/<body[^>]*>(.+)<.body>/g))
|
|
||||||
data = RegExp.$1;
|
|
||||||
$dialog.html(data);
|
$dialog.html(data);
|
||||||
form = $('#calendarform > form');
|
form = $('#calendarform > form');
|
||||||
name = $('#calendar-name').val(calendar.editname || calendar.name);
|
name = $('#calendar-name').val(calendar.editname || calendar.name);
|
||||||
|
@ -672,6 +669,10 @@ function rcube_calendar_ui(settings)
|
||||||
var buttons = {};
|
var buttons = {};
|
||||||
|
|
||||||
buttons[rcmail.gettext('save', 'calendar')] = function() {
|
buttons[rcmail.gettext('save', 'calendar')] = function() {
|
||||||
|
// form is not loaded
|
||||||
|
if (!form)
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: do some input validation
|
// TODO: do some input validation
|
||||||
if (!name.val() || name.val().length < 2) {
|
if (!name.val() || name.val().length < 2) {
|
||||||
alert(rcmail.gettext('invalidcalendarproperties', 'calendar'));
|
alert(rcmail.gettext('invalidcalendarproperties', 'calendar'));
|
||||||
|
|
|
@ -283,13 +283,14 @@ abstract class calendar_driver
|
||||||
/**
|
/**
|
||||||
* Callback function to append additional elements to the calendar create/edit form
|
* 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 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
|
* @return string HTML to be appended to form
|
||||||
*/
|
*/
|
||||||
public function calendar_form($calendar, $attrib)
|
public function calendar_form($action, $calendar, $html)
|
||||||
{
|
{
|
||||||
return '';
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -538,4 +538,27 @@ class calendar_ui
|
||||||
return $table->show($attrib);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
<body class="iframe">
|
|
||||||
|
|
||||||
<form action="#" id="calendarpropform">
|
|
||||||
<div class="form-section">
|
|
||||||
<label for="calendar-name"><roundcube:label name="calendar.name" /></label>
|
|
||||||
<input type="text" name="name" size="20" id="calendar-name" />
|
|
||||||
</div>
|
|
||||||
<div class="form-section">
|
|
||||||
<label for="calendar-color"><roundcube:label name="calendar.color" /></label>
|
|
||||||
<input type="text" name="color" size="6" id="calendar-color" />
|
|
||||||
</div>
|
|
||||||
<roundcube:object name="plugin.calendarform" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Add table
Reference in a new issue