Unified addressbook folder edit/create forms with the rest of plugins
This commit is contained in:
parent
42a1177109
commit
9f58502839
5 changed files with 90 additions and 158 deletions
|
@ -29,9 +29,6 @@
|
|||
if (window.rcmail) {
|
||||
rcmail.addEventListener('init', function() {
|
||||
rcmail.set_book_actions();
|
||||
if (rcmail.gui_objects.editform && rcmail.env.action.match(/^plugin\.book/)) {
|
||||
rcmail.enable_command('book-save', true);
|
||||
}
|
||||
|
||||
// contextmenu
|
||||
kolab_addressbook_contextmenu();
|
||||
|
@ -142,12 +139,48 @@ rcube_webmail.prototype.set_book_actions = function()
|
|||
|
||||
rcube_webmail.prototype.book_create = function()
|
||||
{
|
||||
this.book_show_contentframe('create');
|
||||
this.book_dialog('create');
|
||||
};
|
||||
|
||||
rcube_webmail.prototype.book_edit = function()
|
||||
{
|
||||
this.book_show_contentframe('edit');
|
||||
this.book_dialog('edit');
|
||||
};
|
||||
|
||||
// displays page with book edit/create form
|
||||
rcube_webmail.prototype.book_dialog = function(action)
|
||||
{
|
||||
var title = rcmail.gettext('kolab_addressbook.book' + action),
|
||||
params = {_act: action, _source: this.book_realname(), _framed: 1},
|
||||
dialog = $('<iframe>').attr('src', rcmail.url('plugin.book', params)),
|
||||
save_func = function() {
|
||||
var data,
|
||||
form = dialog.contents().find('form'),
|
||||
input = form.find("input[name='_name']");
|
||||
|
||||
// form is not loaded
|
||||
if (!form || !form.length)
|
||||
return false;
|
||||
|
||||
if (input.length && input.val() == '') {
|
||||
rcmail.alert_dialog(rcmail.get_label('kolab_addressbook.nobooknamewarning'), function() {
|
||||
input.focus();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// post data to server
|
||||
data = form.serializeJSON();
|
||||
|
||||
rcmail.http_post('plugin.book-save', data, rcmail.set_busy(true, 'kolab_addressbook.booksaving'));
|
||||
return true;
|
||||
};
|
||||
|
||||
rcmail.simple_dialog(dialog, title, save_func, {
|
||||
width: 600,
|
||||
height: 400
|
||||
});
|
||||
};
|
||||
|
||||
rcube_webmail.prototype.book_remove = function(id)
|
||||
|
@ -191,51 +224,6 @@ rcube_webmail.prototype.book_showurl = function()
|
|||
}
|
||||
};
|
||||
|
||||
// displays page with book edit/create form
|
||||
rcube_webmail.prototype.book_show_contentframe = function(action, framed)
|
||||
{
|
||||
var add_url = '', target = window;
|
||||
|
||||
// unselect contact
|
||||
this.contact_list.clear_selection();
|
||||
this.enable_command('edit', 'delete', 'compose', false);
|
||||
|
||||
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
|
||||
add_url = '&_framed=1';
|
||||
target = window.frames[this.env.contentframe];
|
||||
this.show_contentframe(true);
|
||||
}
|
||||
else if (framed)
|
||||
return false;
|
||||
|
||||
if (action) {
|
||||
this.lock_frame();
|
||||
this.location_href(this.env.comm_path+'&_action=plugin.book&_act='+action
|
||||
+'&_source='+urlencode(this.book_realname())
|
||||
+add_url, target);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// submits book create/update form
|
||||
rcube_webmail.prototype.book_save = function()
|
||||
{
|
||||
var form = this.gui_objects.editform,
|
||||
input = $("input[name='_name']", form)
|
||||
|
||||
if (input.length && input.val() == '') {
|
||||
alert(this.get_label('kolab_addressbook.nobooknamewarning'));
|
||||
input.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
input = this.display_message(this.get_label('kolab_addressbook.booksaving'), 'loading');
|
||||
$('<input type="hidden" name="_unlock" />').val(input).appendTo(form);
|
||||
|
||||
form.submit();
|
||||
};
|
||||
|
||||
// action executed after book delete
|
||||
rcube_webmail.prototype.book_delete_done = function(id, recur)
|
||||
{
|
||||
|
@ -285,8 +273,6 @@ rcube_webmail.prototype.book_update = function(data, old)
|
|||
})
|
||||
);
|
||||
|
||||
this.show_contentframe(false);
|
||||
|
||||
// set row attributes
|
||||
if (data.readonly)
|
||||
classes.push('readonly');
|
||||
|
|
|
@ -934,15 +934,16 @@ class kolab_addressbook extends rcube_plugin
|
|||
|
||||
$this->rc->output->show_message('kolab_addressbook.book'.$type.'d', 'confirmation');
|
||||
$this->rc->output->command('book_update', $props, kolab_storage::folder_id($prop['oldname'], true));
|
||||
$this->rc->output->send('iframe');
|
||||
}
|
||||
else {
|
||||
if (!$error) {
|
||||
$error = $plugin['message'] ? $plugin['message'] : 'kolab_addressbook.book'.$type.'error';
|
||||
}
|
||||
|
||||
$this->rc->output->show_message($error, 'error');
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
$error = $plugin['message'] ? $plugin['message'] : 'kolab_addressbook.book'.$type.'error';
|
||||
|
||||
$this->rc->output->show_message($error, 'error');
|
||||
// display the form again
|
||||
$this->ui->book_edit();
|
||||
$this->rc->output->send('iframe');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,6 +121,10 @@ class kolab_addressbook_ui
|
|||
'kolab_addressbook.nraddressbooksfound',
|
||||
'kolab_addressbook.noaddressbooksfound',
|
||||
'kolab_addressbook.foldersubscribe',
|
||||
'kolab_addressbook.bookedit',
|
||||
'kolab_addressbook.bookcreate',
|
||||
'kolab_addressbook.nobooknamewarning',
|
||||
'kolab_addressbook.booksaving',
|
||||
'resetsearch'
|
||||
);
|
||||
|
||||
|
@ -146,24 +150,18 @@ class kolab_addressbook_ui
|
|||
$this->plugin->include_stylesheet($this->plugin->local_skin_path().'/kolab_addressbook.css', true);
|
||||
$this->rc->output->add_label('kolab_addressbook.showhistory');
|
||||
}
|
||||
// book create/edit form
|
||||
else {
|
||||
$this->rc->output->add_label('kolab_addressbook.nobooknamewarning',
|
||||
'kolab_addressbook.booksaving');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for address book create/edit action
|
||||
*/
|
||||
public function book_edit()
|
||||
{
|
||||
$this->rc->output->add_handler('bookdetails', array($this, 'book_form'));
|
||||
$this->rc->output->send('kolab_addressbook.bookedit');
|
||||
$this->rc->output->set_env('pagetitle', $this->plugin->gettext('bookproperties'));
|
||||
$this->rc->output->add_handler('folderform', array($this, 'book_form'));
|
||||
$this->rc->output->send('libkolab.folderform');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for 'bookdetails' object returning form content for book create/edit
|
||||
*
|
||||
|
@ -182,17 +180,7 @@ class kolab_addressbook_ui
|
|||
$storage = $this->rc->get_storage();
|
||||
$delim = $storage->get_hierarchy_delimiter();
|
||||
|
||||
if ($this->rc->action == 'plugin.book-save') {
|
||||
// save error
|
||||
$name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_GPC, true)); // UTF8
|
||||
$old = trim(rcube_utils::get_input_value('_oldname', rcube_utils::INPUT_GPC, true)); // UTF7-IMAP
|
||||
$path_imap = trim(rcube_utils::get_input_value('_parent', rcube_utils::INPUT_GPC, true)); // UTF7-IMAP
|
||||
|
||||
$hidden_fields[] = array('name' => '_oldname', 'value' => $old);
|
||||
|
||||
$folder = $old;
|
||||
}
|
||||
else if ($action == 'edit') {
|
||||
if ($action == 'edit') {
|
||||
$path_imap = explode($delim, $folder);
|
||||
$name = rcube_charset::convert(array_pop($path_imap), 'UTF7-IMAP');
|
||||
$path_imap = implode($path_imap, $delim);
|
||||
|
@ -213,8 +201,9 @@ class kolab_addressbook_ui
|
|||
$form = array();
|
||||
|
||||
// General tab
|
||||
$form['props'] = array(
|
||||
'name' => $this->rc->gettext('properties'),
|
||||
$form['properties'] = array(
|
||||
'name' => $this->rc->gettext('properties'),
|
||||
'fields' => array(),
|
||||
);
|
||||
|
||||
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
||||
|
@ -225,14 +214,10 @@ class kolab_addressbook_ui
|
|||
$foldername = $foldername->show($name);
|
||||
}
|
||||
|
||||
$form['props']['fieldsets']['location'] = array(
|
||||
'name' => $this->rc->gettext('location'),
|
||||
'content' => array(
|
||||
'name' => array(
|
||||
'label' => $this->plugin->gettext('bookname'),
|
||||
'value' => $foldername,
|
||||
),
|
||||
),
|
||||
$form['properties']['fields']['name'] = array(
|
||||
'label' => $this->plugin->gettext('bookname'),
|
||||
'value' => $foldername,
|
||||
'id' => '_name',
|
||||
);
|
||||
|
||||
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
||||
|
@ -243,9 +228,10 @@ class kolab_addressbook_ui
|
|||
$prop = array('name' => '_parent', 'id' => '_parent');
|
||||
$select = kolab_storage::folder_selector('contact', $prop, $folder);
|
||||
|
||||
$form['props']['fieldsets']['location']['content']['parent'] = array(
|
||||
$form['properties']['fields']['parent'] = array(
|
||||
'label' => $this->plugin->gettext('parentbook'),
|
||||
'value' => $select->show(strlen($folder) ? $path_imap : ''),
|
||||
'id' => '_parent',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -253,44 +239,38 @@ class kolab_addressbook_ui
|
|||
$plugin = $this->rc->plugins->exec_hook('addressbook_form',
|
||||
array('form' => $form, 'options' => $options, 'name' => $folder));
|
||||
|
||||
$form = $plugin['form'];
|
||||
$form = $plugin['form'];
|
||||
$form_html = '';
|
||||
|
||||
// Set form tags and hidden fields
|
||||
list($form_start, $form_end) = $this->get_form_tags($attrib, 'plugin.book-save', null, $hidden_fields);
|
||||
|
||||
unset($attrib['form']);
|
||||
|
||||
// return the complete edit form as table
|
||||
$out = "$form_start\n";
|
||||
|
||||
// Create form output
|
||||
foreach ($form as $idx => $tab) {
|
||||
if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
|
||||
$content = '';
|
||||
foreach ($tab['fieldsets'] as $fieldset) {
|
||||
$subcontent = $this->get_form_part($fieldset);
|
||||
if ($subcontent) {
|
||||
$content .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent) ."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$content = $this->get_form_part($tab);
|
||||
}
|
||||
|
||||
if ($content) {
|
||||
if ($idx != 'props') {
|
||||
$out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
|
||||
}
|
||||
else {
|
||||
$out .= $content ."\n";
|
||||
}
|
||||
if (is_array($hidden_fields)) {
|
||||
foreach ($hidden_fields as $field) {
|
||||
$hiddenfield = new html_hiddenfield($field);
|
||||
$form_html .= $hiddenfield->show() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$out .= "\n$form_end";
|
||||
// create form output
|
||||
foreach ($form as $tab) {
|
||||
if (is_array($tab['fields']) && empty($tab['content'])) {
|
||||
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
|
||||
foreach ($tab['fields'] as $col => $colprop) {
|
||||
$label = !empty($colprop['label']) ? $colprop['label'] : $this->plugin->gettext($col);
|
||||
|
||||
return $out;
|
||||
$table->add('title', html::label($colprop['id'], rcube::Q($label)));
|
||||
$table->add(null, $colprop['value']);
|
||||
}
|
||||
$content = $table->show();
|
||||
}
|
||||
else {
|
||||
$content = $tab['content'];
|
||||
}
|
||||
|
||||
if (!empty($content)) {
|
||||
$form_html .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return html::tag('form', $attrib + array('action' => 'plugin.book-save', 'method' => 'post', 'id' => 'bookpropform'), $form_html);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<roundcube:include file="includes/layout.html" />
|
||||
|
||||
<h1 class="voice"><roundcube:label name="kolab_addressbook.bookproperties" /></h1>
|
||||
|
||||
<div class="formcontent">
|
||||
<roundcube:object name="bookdetails" class="propform" />
|
||||
</div>
|
||||
|
||||
<div class="formbuttons">
|
||||
<roundcube:button command="book-save" class="btn btn-primary submit" label="save" />
|
||||
</div>
|
||||
|
||||
<roundcube:include file="includes/footer.html" />
|
|
@ -1,22 +0,0 @@
|
|||
<roundcube:object name="doctype" value="html5" />
|
||||
<html>
|
||||
<head>
|
||||
<title><roundcube:object name="pagetitle" /></title>
|
||||
<roundcube:include file="/includes/links.html" />
|
||||
</head>
|
||||
<body class="iframe">
|
||||
|
||||
<h1 class="boxtitle"><roundcube:label name="kolab_addressbook.bookproperties" /></h1>
|
||||
|
||||
<div class="boxcontent">
|
||||
<roundcube:object name="bookdetails" class="propform tabbed" />
|
||||
</div>
|
||||
|
||||
<div class="footerleft formbuttons">
|
||||
<roundcube:button command="book-save" type="input" class="button mainaction" label="save" />
|
||||
</div>
|
||||
|
||||
<roundcube:include file="/includes/footer.html" />
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue