From c4e555c160fbca08457fd178f6031d5bba4a4c16 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 10 Feb 2011 07:07:40 -0500 Subject: [PATCH] - Fix subtype select labels for fields added with 'Add field' --- program/steps/addressbook/func.inc | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index be0c82d..336dd44 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -120,6 +120,7 @@ $line_templ = html::tag('li', array( 'id' => 'rcmli%s', 'class' => 'addressbook %s'), html::a(array('href' => '%s', + 'rel' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); // currently selected is the first address source in the list @@ -129,9 +130,11 @@ foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { $id = strval($source['id'] ? $source['id'] : $j); $js_id = JQ($id); - $dom_id = preg_replace('/[^a-z0-9\-_]/i', '_', $id); - $out .= sprintf($line_templ, $dom_id, ($current === $id ? 'selected' : ''), + $out .= sprintf($line_templ, + html_identifier($id), + ($current === $id ? 'selected' : ''), Q(rcmail_url(null, array('_source' => $id))), + $source['id'], $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); $groupdata = array('out' => $out, 'jsdata' => $jsdata, 'source' => $id); @@ -158,11 +161,16 @@ $line_templ = html::tag('li', array( 'id' => 'rcmliG%s', 'class' => 'contactgroup'), html::a(array('href' => '#', + 'rel' => '%s:%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); $jsdata = array(); foreach ($groups as $group) { - $args['out'] .= sprintf($line_templ, asciiwords($args['source'] . $group['ID'], true, '_'), $args['source'], $group['ID'], Q($group['name'])); + $args['out'] .= sprintf($line_templ, + html_identifier($args['source'] . $group['ID']), + $args['source'], $group['ID'], + $args['source'], $group['ID'], Q($group['name']) + ); $args['jsdata']['G'.$args['source'].$group['ID']] = array( 'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group'); @@ -281,6 +289,20 @@ } +function rcmail_get_type_label($type) +{ + $label = 'type'.$type; + if (rcube_label_exists($label)) + return rcube_label($label); + else if (preg_match('/\w+(\d+)$/', $label, $m) + && ($label = preg_replace('/(\d+)$/', '', $label)) + && rcube_label_exists($label)) + return rcube_label($label) . ' ' . $m[1]; + + return ucfirst($type); +} + + function rcmail_contact_form($form, $record, $attrib = null) { global $RCMAIL, $CONFIG; @@ -302,8 +324,9 @@ foreach ($coltypes as $col => $prop) { if ($prop['subtypes']) { + $subtype_names = array_map('rcmail_get_type_label', $prop['subtypes']); $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); - $select_subtype->add($prop['subtypes']); + $select_subtype->add($subtype_names, $prop['subtypes']); $coltypes[$col]['subtypes_select'] = $select_subtype->show(); } if ($prop['childs']) { @@ -324,6 +347,7 @@ if ($section == 'head') { $content = ''; + // TODO: use the save name composition function as in save.inc $names_arr = array($record['prefix'], $record['firstname'], $record['middlename'], $record['surname'], $record['suffix']); if ($record['name'] == join(' ', array_filter($names_arr))) unset($record['name']); @@ -384,8 +408,9 @@ // prepare subtype selector in edit mode if ($edit_mode && is_array($colprop['subtypes'])) { + $subtype_names = array_map('rcmail_get_type_label', $colprop['subtypes']); $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); - $select_subtype->add($colprop['subtypes']); + $select_subtype->add($subtype_names, $colprop['subtypes']); } else $select_subtype = null; @@ -474,7 +499,7 @@ // use subtype as label if ($colprop['subtypes']) - $label = $subtype; + $label = rcmail_get_type_label($subtype); // add delete button/link if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1)) -- Gitblit v1.9.1