Cleanup calendar edit form code: no duplicted code; don't load entire html page into form
This commit is contained in:
parent
2a34779a50
commit
288f7edacb
6 changed files with 60 additions and 68 deletions
|
@ -1311,7 +1311,7 @@ function rcube_calendar_ui(settings)
|
|||
success: function(data) {
|
||||
$dialog.html(data);
|
||||
// resize and reposition dialog window
|
||||
form = $('form', $('#calendarform')); // '#calendarform > form' doesn't work here
|
||||
form = $('#calendarpropform');
|
||||
me.dialog_resize('#calendarform', form.height(), form.width());
|
||||
name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name);
|
||||
color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color });
|
||||
|
@ -1467,7 +1467,7 @@ function rcube_calendar_ui(settings)
|
|||
this.dialog_resize = function(id, height, width)
|
||||
{
|
||||
var win = $(window), w = win.width(), h = win.height();
|
||||
$(id).dialog('option', { height: Math.min(h-20, height+125), width: Math.min(w-20, width+50) })
|
||||
$(id).dialog('option', { height: Math.min(h-20, height+110), width: Math.min(w-20, width+50) })
|
||||
.dialog('option', 'position', ['center', 'center']); // only works in a separate call (!?)
|
||||
};
|
||||
|
||||
|
|
|
@ -305,12 +305,19 @@ abstract class calendar_driver
|
|||
*
|
||||
* @param string Request action 'form-edit|form-new'
|
||||
* @param array Calendar properties (e.g. id, color)
|
||||
* @param string HTML code of default edit form
|
||||
* @param array Edit form fields
|
||||
*
|
||||
* @return string HTML content of the form
|
||||
*/
|
||||
public function calendar_form($action, $calendar, $html)
|
||||
public function calendar_form($action, $calendar, $formfields)
|
||||
{
|
||||
$html = '';
|
||||
foreach ($formfields as $prop => $field) {
|
||||
$html .= html::div('form-section',
|
||||
html::label($field['id'], $field['label']) .
|
||||
$field['value']);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
|
|
@ -832,21 +832,21 @@ class kolab_driver extends calendar_driver
|
|||
*
|
||||
* @param string Request action 'form-edit|form-new'
|
||||
* @param array Calendar properties (e.g. id, color)
|
||||
* @param string HTML code of default edit form
|
||||
* @param array Edit form fields
|
||||
*
|
||||
* @return string HTML content of the form
|
||||
*/
|
||||
public function calendar_form($action, $calendar, $html)
|
||||
public function calendar_form($action, $calendar, $formfields)
|
||||
{
|
||||
// Remove any scripts/css/js
|
||||
$this->rc->output->reset();
|
||||
|
||||
// Produce form content
|
||||
$content = $this->calendar_form_content($calendar);
|
||||
// Parse form template, write to output buffer
|
||||
// This way other plugins (e.g. acl) will be able to add scripts/style to the content
|
||||
ob_start();
|
||||
$this->rc->output->parse('calendar.calendarform-kolab', false, true);
|
||||
$html = ob_get_clean();
|
||||
$content = $this->calendar_form_content($calendar, $formfields);
|
||||
|
||||
// Parse form template for skin-dependent stuff
|
||||
// TODO: copy scripts and styles added by other plugins (e.g. acl) from $this->rc->output
|
||||
$html = $this->rc->output->parse('calendar.calendarform-kolab', false, false);
|
||||
|
||||
return str_replace('%FORM_CONTENT%', $content, $html);
|
||||
}
|
||||
|
@ -856,7 +856,7 @@ class kolab_driver extends calendar_driver
|
|||
*
|
||||
* @return string HTML content of the form
|
||||
*/
|
||||
private function calendar_form_content($calendar)
|
||||
private function calendar_form_content($calendar, $formfields)
|
||||
{
|
||||
if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) {
|
||||
$folder = $cal->get_realname(); // UTF7
|
||||
|
@ -874,7 +874,7 @@ class kolab_driver extends calendar_driver
|
|||
|
||||
if (strlen($folder)) {
|
||||
$path_imap = explode($delim, $folder);
|
||||
$name = rcube_charset_convert(array_pop($path_imap), 'UTF7-IMAP');
|
||||
array_pop($path_imap); // pop off name part
|
||||
$path_imap = implode($path_imap, $delim);
|
||||
|
||||
$this->rc->imap_connect();
|
||||
|
@ -882,7 +882,6 @@ class kolab_driver extends calendar_driver
|
|||
}
|
||||
else {
|
||||
$path_imap = '';
|
||||
$name = '';
|
||||
}
|
||||
|
||||
// General tab
|
||||
|
@ -890,16 +889,11 @@ class kolab_driver extends calendar_driver
|
|||
'name' => $this->rc->gettext('properties'),
|
||||
);
|
||||
|
||||
// calendar name
|
||||
$foldername = new html_inputfield(array('name' => 'name', 'id' => 'calendar-name', 'size' => 20));
|
||||
|
||||
// calendar name (default field)
|
||||
$form['props']['fieldsets']['location'] = array(
|
||||
'name' => $this->rc->gettext('location'),
|
||||
'content' => array(
|
||||
'name' => array(
|
||||
'label' => $this->cal->gettext('name'),
|
||||
'value' => $foldername->show($name),
|
||||
),
|
||||
'name' => $formfields['name']
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -909,23 +903,17 @@ class kolab_driver extends calendar_driver
|
|||
}
|
||||
else {
|
||||
$select = rcube_kolab::folder_selector('event', array('name' => 'parent'));
|
||||
|
||||
$form['props']['fieldsets']['location']['content']['path'] = array(
|
||||
'label' => $this->cal->gettext('parentcalendar'),
|
||||
'value' => $select->show($path_imap),
|
||||
);
|
||||
}
|
||||
|
||||
// calendar color
|
||||
$color = new html_inputfield(array('name' => 'color', 'id' => 'calendar-color', 'size' => 6));
|
||||
|
||||
// calendar color (default field)
|
||||
$form['props']['fieldsets']['settings'] = array(
|
||||
'name' => $this->rc->gettext('settings'),
|
||||
'content' => array(
|
||||
'color' => array(
|
||||
'label' => $this->cal->gettext('color'),
|
||||
'value' => $color->show($calendar['color']),
|
||||
),
|
||||
'color' => $formfields['color'],
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -537,23 +537,27 @@ class calendar_ui
|
|||
*/
|
||||
function calendar_editform($action, $calendar = array())
|
||||
{
|
||||
// compose default calendar form
|
||||
// compose default calendar form fields
|
||||
$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']));
|
||||
|
||||
$html = html::tag('form', array('action' => "#", 'method' => "get", 'id' => 'calendarpropform'), $html);
|
||||
$formfields = array(
|
||||
'name' => array(
|
||||
'label' => $this->calendar->gettext('name'),
|
||||
'value' => $input_name->show($name),
|
||||
'id' => 'calendar-name',
|
||||
),
|
||||
'color' => array(
|
||||
'label' => $this->calendar->gettext('color'),
|
||||
'value' => $input_color->show($calendar['color']),
|
||||
'id' => 'calendar-color',
|
||||
),
|
||||
);
|
||||
|
||||
// allow driver to extend or replace the form content
|
||||
$html = $this->calendar->driver->calendar_form($action, $calendar, $html);
|
||||
|
||||
return $html;
|
||||
return html::tag('form', array('action' => "#", 'method' => "get", 'id' => 'calendarpropform'),
|
||||
$this->calendar->driver->calendar_form($action, $calendar, $formfields)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -843,31 +843,33 @@ a.alarm-action-snooze:after {
|
|||
height: 160px;
|
||||
}
|
||||
|
||||
#calendar-details {
|
||||
left: 5px;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
#calendar-kolabform {
|
||||
position: relative;
|
||||
padding-top: 22px;
|
||||
margin: 0 -8px;
|
||||
}
|
||||
|
||||
#calendar-details div.tabsbar {
|
||||
top: 0;
|
||||
left: 2px;
|
||||
#calendar-kolabform div.tabsbar {
|
||||
top: 0;
|
||||
right: 2px;
|
||||
left: 2px;
|
||||
}
|
||||
|
||||
#calendar-details fieldset {
|
||||
background-color: #fff;
|
||||
#calendar-kolabform fieldset.tabbed {
|
||||
background-color: #fff;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#calendar-details span.tablink {
|
||||
#calendar-kolabform span.tablink {
|
||||
background: #E6E6E7;
|
||||
}
|
||||
|
||||
#calendar-details span.tablink-selected {
|
||||
#calendar-kolabform span.tablink-selected {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
#calendar-details span.tablink a,
|
||||
#calendar-details span.tablink-selected a {
|
||||
#calendar-kolabform span.tablink a,
|
||||
#calendar-kolabform span.tablink-selected a {
|
||||
background: none;
|
||||
border: 1px solid #AAAAAA;
|
||||
border-top-left-radius: 2px;
|
||||
|
@ -875,7 +877,7 @@ a.alarm-action-snooze:after {
|
|||
margin-left: 0;
|
||||
}
|
||||
|
||||
#calendar-details table td.title {
|
||||
#calendar-kolabform table td.title {
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
color: #666;
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
|
||||
<div id="calendar-details">
|
||||
<form action="#" id="calendarpropform">
|
||||
%FORM_CONTENT%
|
||||
</form>
|
||||
<div id="calendar-kolabform">
|
||||
%FORM_CONTENT%
|
||||
</div>
|
||||
<script type="text/javascript">rcube_init_tabs('calendar-details > form');</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<script type="text/javascript">rcube_init_tabs('calendar-kolabform');</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue