Fixed default calendar edit form handling

This commit is contained in:
Aleksander Machniak (Kolab Systems) 2011-07-27 11:20:27 +02:00
parent 479819d4bb
commit a13fec7a21
4 changed files with 27 additions and 13 deletions

View file

@ -1310,8 +1310,8 @@ function rcube_calendar_ui(settings)
success: function(data) { success: function(data) {
$dialog.html(data); $dialog.html(data);
// resize and reposition dialog window // resize and reposition dialog window
me.dialog_resize('#calendarform', $('#calendar-details').height(), $('#calendar-details').width());
form = $('form', $('#calendarform')); // '#calendarform > form' doesn't work here form = $('form', $('#calendarform')); // '#calendarform > form' doesn't work here
me.dialog_resize('#calendarform', form.height(), form.width());
name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name); name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name);
color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color }); color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color });
name.select(); name.select();
@ -1465,17 +1465,18 @@ function rcube_calendar_ui(settings)
// resize and reposition (center) the dialog window // resize and reposition (center) the dialog window
this.dialog_resize = function(id, height, width) this.dialog_resize = function(id, height, width)
{ {
height = Math.min(400, height+90);
width = Math.min(500, width+50);
var win = $(window), w = win.width(), h = win.height(); var win = $(window), w = win.width(), h = win.height();
height = Math.min(h-20, height+125);
width = Math.min(w-20, width+50);
w = w - width < 0 ? 0 : (w - width) / 2; w = w - width < 0 ? 0 : (w - width) / 2;
h = h - height < 0 ? 0 : (h - height) / 2; h = h - height < 0 ? 0 : (h - height) / 2;
$(id).dialog('option', { height: height, width: width, position: [w, h] }); $(id).dialog('option', { height: height, width: width, position: [w, h] });
}; };
/*** startup code ***/ /*** startup code ***/
// create list of event sources AKA calendars // create list of event sources AKA calendars

View file

@ -305,10 +305,11 @@ abstract class calendar_driver
* *
* @param string Request action 'form-edit|form-new' * @param string Request action 'form-edit|form-new'
* @param array Calendar properties (e.g. id, color) * @param array Calendar properties (e.g. id, color)
* @param string HTML code of default edit form
* *
* @return string HTML content of the form * @return string HTML content of the form
*/ */
public function calendar_form($action, $calendar) public function calendar_form($action, $calendar, $html)
{ {
return null; return null;
} }

View file

@ -827,10 +827,11 @@ class kolab_driver extends calendar_driver
* *
* @param string Request action 'form-edit|form-new' * @param string Request action 'form-edit|form-new'
* @param array Calendar properties (e.g. id, color) * @param array Calendar properties (e.g. id, color)
* @param string HTML code of default edit form
* *
* @return string HTML content of the form * @return string HTML content of the form
*/ */
public function calendar_form($action, $calendar) public function calendar_form($action, $calendar, $html)
{ {
// Remove any scripts/css/js // Remove any scripts/css/js
$this->rc->output->reset(); $this->rc->output->reset();

View file

@ -537,10 +537,21 @@ class calendar_ui
*/ */
function calendar_editform($action, $calendar = array()) function calendar_editform($action, $calendar = array())
{ {
$html = $this->calendar->driver->calendar_form($action, $calendar); // 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']));
if (!$html) $input_color = new html_inputfield(array('name' => 'color', 'id' => 'calendar-color', 'size' => 6));
$html = $this->rc->output->parse('calendar.calendarform', false, false); $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);
// allow driver to extend or replace the form content
$html = $this->calendar->driver->calendar_form($action, $calendar, $html);
return $html; return $html;
} }