diff options
Diffstat (limited to 'program')
-rw-r--r-- | program/js/app.js | 6 | ||||
-rw-r--r-- | program/steps/addressbook/edit.inc | 36 | ||||
-rw-r--r-- | program/steps/addressbook/func.inc | 8 | ||||
-rw-r--r-- | program/steps/addressbook/save.inc | 6 |
4 files changed, 46 insertions, 10 deletions
diff --git a/program/js/app.js b/program/js/app.js index c96c3ebee..53ae463b2 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -637,7 +637,11 @@ function rcube_webmail() } // contacts/identities else { - if ((input = $("input[name='_name']", form)) &&input.length && input.val() == '') { + // + if (props == 'reload') { + form.action += '?_reload=1'; + } + else if ((input = $("input[name='_name']", form)) &&input.length && input.val() == '') { alert(this.get_label('nonamewarning')); input.focus(); break; diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc index 39161127c..f9d74e4fb 100644 --- a/program/steps/addressbook/edit.inc +++ b/program/steps/addressbook/edit.inc @@ -55,6 +55,7 @@ else { $SOURCE_ID = $source; + function rcmail_get_edit_record() { global $RCMAIL, $CONTACTS; @@ -105,7 +106,6 @@ function rcmail_contact_edithead($attrib) return $form_start . $out . $form_end; } - function rcmail_contact_editform($attrib) { global $RCMAIL, $CONTACT_COLTYPES; @@ -167,7 +167,6 @@ function rcmail_contact_editform($attrib) return $form_start . $out . $form_end; } - function rcmail_upload_photo_form($attrib) { global $OUTPUT; @@ -204,17 +203,18 @@ function rcmail_upload_photo_form($attrib) return $out; } - // similar function as in /steps/settings/edit_identity.inc function get_form_tags($attrib) { - global $CONTACTS, $EDIT_FORM, $RCMAIL; + global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID; $form_start = $form_end = ''; if (empty($EDIT_FORM)) { - $hiddenfields = new html_hiddenfield(array( - 'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); + $hiddenfields = new html_hiddenfield(); + + if ($RCMAIL->action == 'edit') + $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID)); $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); if (($result = $CONTACTS->get_result()) && ($record = $result->first())) @@ -234,12 +234,36 @@ function get_form_tags($attrib) return array($form_start, $form_end); } +function rcmail_source_selector($attrib) +{ + global $RCMAIL, $SOURCE_ID; + + $sources_list = $RCMAIL->get_address_sources(true); + + if (count($sources_list) < 2) { + $source = $sources_list[$SOURCE_ID]; + $hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID)); + return html::span($attrib, Q($source['name']) . $hiddenfield->show()); + } + + $attrib['name'] = '_source'; + $attrib['onchange'] = JS_OBJECT_NAME . ".command('save', 'reload', this.form)"; + + $select = new html_select($attrib); + + foreach ($sources_list as $source) + $select->add($source['name'], $source['id']); + + return $select->show($SOURCE_ID); +} + $OUTPUT->add_handlers(array( 'contactedithead' => 'rcmail_contact_edithead', 'contacteditform' => 'rcmail_contact_editform', 'contactphoto' => 'rcmail_contact_photo', 'photouploadform' => 'rcmail_upload_photo_form', + 'sourceselector' => 'rcmail_source_selector', )); if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd')) diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index d0be00dbb..4c930c80b 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -68,20 +68,22 @@ if (!$RCMAIL->action && !$OUTPUT->ajax_call) { if (!strlen($source) || !isset($js_list[$source])) $source = $js_list[key($js_list)]['id']; - // find writeable source + // count writeable sources + $writeable = 0; foreach ($js_list as $s) { if (!$s['readonly']) { - $OUTPUT->set_env('writable_source', $s['id']); - break; + $writeable++; } } $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT); $OUTPUT->set_env('search_mods', $search_mods); $OUTPUT->set_env('address_sources', $js_list); + $OUTPUT->set_env('writable_source', $writeable); $OUTPUT->set_pagetitle(rcube_label('addressbook')); $_SESSION['addressbooks_count'] = count($js_list); + $_SESSION['addressbooks_count_writeable'] = $writeable; $CONTACTS = rcmail_contact_source($source, true); } diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc index 19d8f8c7d..e1986efeb 100644 --- a/program/steps/addressbook/save.inc +++ b/program/steps/addressbook/save.inc @@ -24,6 +24,12 @@ $cid = get_input_value('_cid', RCUBE_INPUT_POST); $return_action = empty($cid) ? 'add' : 'edit'; +// Source changed, display the form again +if (!empty($_GET['_reload'])) { + rcmail_overwrite_action($return_action); + return; +} + // cannot edit record if ($CONTACTS->readonly) { $OUTPUT->show_message('contactreadonly', 'error'); |