alecpl
2011-07-02 5b3ac324154b0d29e6e14db2b06fbc3636a3e708
- Added addressbook source selector in contact create form


6 files modified
61 ■■■■ changed files
program/js/app.js 6 ●●●● patch | view | raw | blame | history
program/steps/addressbook/edit.inc 36 ●●●● patch | view | raw | blame | history
program/steps/addressbook/func.inc 8 ●●●●● patch | view | raw | blame | history
program/steps/addressbook/save.inc 6 ●●●●● patch | view | raw | blame | history
skins/default/addressbook.css 2 ●●● patch | view | raw | blame | history
skins/default/templates/contactadd.html 3 ●●●●● patch | view | raw | blame | history
program/js/app.js
@@ -637,7 +637,11 @@
          }
          // 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;
program/steps/addressbook/edit.inc
@@ -55,6 +55,7 @@
$SOURCE_ID = $source;
function rcmail_get_edit_record()
{
    global $RCMAIL, $CONTACTS;
@@ -104,7 +105,6 @@
    return $form_start . $out . $form_end;
}
function rcmail_contact_editform($attrib)
{
@@ -167,7 +167,6 @@
    return $form_start . $out . $form_end;
}
function rcmail_upload_photo_form($attrib)
{
  global $OUTPUT;
@@ -204,17 +203,18 @@
  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 @@
    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'))
program/steps/addressbook/func.inc
@@ -68,20 +68,22 @@
    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);
}
program/steps/addressbook/save.inc
@@ -24,6 +24,12 @@
$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');
skins/default/addressbook.css
@@ -219,7 +219,7 @@
#contacttabs
{
    position: relative;
    padding-bottom: 22px;
    padding-bottom: 12px;
}
#contacttabs div.tabsbar {
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">