summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-07-02 15:27:46 +0000
committeralecpl <alec@alec.pl>2011-07-02 15:27:46 +0000
commit5b3ac324154b0d29e6e14db2b06fbc3636a3e708 (patch)
tree94fdc54541279065b01dd7f61c061d3e0764bd2e
parent4b1d5d6e384fc5bddff8ee1c7cb35b8ea9c84bf3 (diff)
- Added addressbook source selector in contact create form
-rw-r--r--program/js/app.js6
-rw-r--r--program/steps/addressbook/edit.inc36
-rw-r--r--program/steps/addressbook/func.inc8
-rw-r--r--program/steps/addressbook/save.inc6
-rw-r--r--skins/default/addressbook.css2
-rw-r--r--skins/default/templates/contactadd.html3
6 files changed, 50 insertions, 11 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');
diff --git a/skins/default/addressbook.css b/skins/default/addressbook.css
index 7c156a66b..4fbed89e5 100644
--- a/skins/default/addressbook.css
+++ b/skins/default/addressbook.css
@@ -219,7 +219,7 @@ body.iframe,
#contacttabs
{
position: relative;
- padding-bottom: 22px;
+ padding-bottom: 12px;
}
#contacttabs div.tabsbar {
diff --git a/skins/default/templates/contactadd.html b/skins/default/templates/contactadd.html
index 6e0737020..305940afd 100644
--- a/skins/default/templates/contactadd.html
+++ b/skins/default/templates/contactadd.html
@@ -10,6 +10,9 @@
<div id="contact-title" class="boxtitle"><roundcube:label name="addcontact" /></div>
<div id="contact-details" class="boxcontent">
<form name="editform" method="post" action="./">
+ <div id="sourcename" style="height: 20px">
+ <roundcube:label name="addressbook" />: <roundcube:object name="sourceselector" class="hint" id="sourceselect" />
+ </div>
<div id="contactphoto">
<roundcube:object name="contactphoto" id="contactpic" placeholder="/images/contactpic.png" />
<div class="formlinks">