From a3644638aaf0418598196a870204e0b632a4c8ad Mon Sep 17 00:00:00 2001 From: Thomas Bruederli <thomas@roundcube.net> Date: Fri, 17 Apr 2015 06:28:40 -0400 Subject: [PATCH] Allow preference sections to define CSS class names --- program/steps/addressbook/func.inc | 205 +++++++++++++++++++++++++++++++------------------- 1 files changed, 127 insertions(+), 78 deletions(-) diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 8be721c..594c2a6 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -81,7 +81,6 @@ $OUTPUT->set_env('search_mods', $search_mods); $OUTPUT->set_env('address_sources', $js_list); $OUTPUT->set_env('writable_source', $writeable); - $OUTPUT->set_env('compose_extwin', $RCMAIL->config->get('compose_extwin',false)); $OUTPUT->set_pagetitle($RCMAIL->gettext('addressbook')); $_SESSION['addressbooks_count'] = $count; @@ -109,6 +108,31 @@ $RCMAIL->session->remove('contact_undo'); } +// register UI objects +$OUTPUT->add_handlers(array( + 'directorylist' => 'rcmail_directory_list', + 'savedsearchlist' => 'rcmail_savedsearch_list', + 'addresslist' => 'rcmail_contacts_list', + 'addresslisttitle' => 'rcmail_contacts_list_title', + 'addressframe' => 'rcmail_contact_frame', + 'recordscountdisplay' => 'rcmail_rowcount_display', + 'searchform' => array($OUTPUT, 'search_form') +)); + +// register action aliases +$RCMAIL->register_action_map(array( + 'add' => 'edit.inc', + 'group-create' => 'groups.inc', + 'group-rename' => 'groups.inc', + 'group-delete' => 'groups.inc', + 'group-addmembers' => 'groups.inc', + 'group-delmembers' => 'groups.inc', + 'search-create' => 'search.inc', + 'search-delete' => 'search.inc', +)); + + + // instantiate a contacts object according to the given source function rcmail_contact_source($source=null, $init_env=false, $writable=false) { @@ -135,7 +159,7 @@ return $CONTACTS; $OUTPUT->set_env('readonly', $CONTACTS->readonly); - $OUTPUT->set_env('source', $source); + $OUTPUT->set_env('source', (string) $source); // reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object if (is_array($CONTACTS->coltypes)) { @@ -226,6 +250,28 @@ $out .= '</li>'; } + $OUTPUT->set_env('contactgroups', $jsdata); + $OUTPUT->set_env('collapsed_abooks', (string)$RCMAIL->config->get('collapsed_abooks','')); + $OUTPUT->add_gui_object('folderlist', $attrib['id']); + $OUTPUT->include_script('treelist.js'); + + // add some labels to client + $OUTPUT->add_label('deletegroupconfirm', 'groupdeleting', 'addingmember', 'removingmember', + 'newgroup', 'grouprename', 'searchsave', 'namex', 'save' + ); + + return html::tag('ul', $attrib, $out, html::$common_attrib); +} + + +function rcmail_savedsearch_list($attrib) +{ + global $RCMAIL, $OUTPUT; + + if (!$attrib['id']) + $attrib['id'] = 'rcmsavedsearchlist'; + + $out = ''; $line_templ = html::tag('li', array( 'id' => 'rcmli%s', 'class' => '%s'), html::a(array('href' => '#', 'rel' => 'S%s', @@ -233,31 +279,24 @@ // Saved searches $sources = $RCMAIL->user->list_searches(rcube_user::SEARCH_ADDRESSBOOK); - foreach ($sources as $j => $source) { - $id = $source['id']; + foreach ($sources as $source) { + $id = $source['id']; $js_id = rcube::JQ($id); // set class name(s) - $class_name = 'contactsearch'; - if ($current === $id) - $class_name .= ' selected'; - if ($source['class_name']) - $class_name .= ' ' . $source['class_name']; + $classes = array('contactsearch'); + if (!empty($source['class_name'])) + $classes[] = $source['class_name']; $out .= sprintf($line_templ, rcube_utils::html_identifier('S'.$id, true), - $class_name, + join(' ', $classes), $id, - $js_id, (!empty($source['name']) ? rcube::Q($source['name']) : rcube::Q($id))); + $js_id, (!empty($source['name']) ? rcube::Q($source['name']) : rcube::Q($id)) + ); } - $OUTPUT->set_env('contactgroups', $jsdata); - $OUTPUT->set_env('collapsed_abooks', (string)$RCMAIL->config->get('collapsed_abooks','')); - $OUTPUT->add_gui_object('folderlist', $attrib['id']); - $OUTPUT->include_script('treelist.js'); - - // add some labels to client - $OUTPUT->add_label('deletegroupconfirm', 'groupdeleting', 'addingmember', 'removingmember'); + $OUTPUT->add_gui_object('savedsearchlist', $attrib['id']); return html::tag('ul', $attrib, $out, html::$common_attrib); } @@ -370,7 +409,7 @@ ), '»'); } else - $val = ' '; + $val = ''; break; default: @@ -397,7 +436,7 @@ unset($attrib['name']); $OUTPUT->add_gui_object('addresslist_title', $attrib['id']); - $OUTPUT->add_label('contacts'); + $OUTPUT->add_label('contacts','uponelevel'); return html::tag($attrib['tag'], $attrib, $RCMAIL->gettext($attrib['label']), html::$common_attrib); } @@ -479,12 +518,13 @@ $plugin = $RCMAIL->plugins->exec_hook('contact_form', array( 'form' => $form, 'record' => $record)); - $form = $plugin['form']; - $record = $plugin['record']; - $edit_mode = $RCMAIL->action != 'show'; + $form = $plugin['form']; + $record = $plugin['record']; + $edit_mode = $RCMAIL->action != 'show' && $RCMAIL->action != 'print'; $del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete'))) : $RCMAIL->gettext('delete'); + $out = ''; + unset($attrib['deleteicon']); - $out = ''; // get default coltypes $coltypes = $GLOBALS['CONTACT_COLTYPES']; @@ -493,7 +533,7 @@ 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 = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype', 'title' => $prop['label'] . ' ' . $RCMAIL->gettext('type'))); $select_subtype->add($subtype_names, $prop['subtypes']); $coltypes[$col]['subtypes_select'] = $select_subtype->show(); } @@ -505,8 +545,9 @@ foreach ($form as $section => $fieldset) { // skip empty sections - if (empty($fieldset['content'])) + if (empty($fieldset['content'])) { continue; + } $select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section)); $select_add->add($RCMAIL->gettext('addfield'), ''); @@ -516,18 +557,20 @@ $content = ''; // unset display name if it is composed from name parts - if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record)) - unset($record['name']); + if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record)) { + unset($record['name']); + } // group fields $field_blocks = array( - 'names' => array('prefix','firstname','middlename','surname','suffix'), - 'displayname' => array('name'), - 'nickname' => array('nickname'), + 'names' => array('prefix','firstname','middlename','surname','suffix'), + 'displayname' => array('name'), + 'nickname' => array('nickname'), 'organization' => array('organization'), - 'department' => array('department'), - 'jobtitle' => array('jobtitle'), + 'department' => array('department'), + 'jobtitle' => array('jobtitle'), ); + foreach ($field_blocks as $blockname => $colnames) { $fields = ''; foreach ($colnames as $col) { @@ -535,11 +578,16 @@ if (!$coltypes[$col]) continue; + // skip cols not listed in the form definition + if (is_array($fieldset['content']) && !in_array($col, array_keys($fieldset['content']))) { + continue; + } + // only string values are expected here if (is_array($record[$col])) $record[$col] = join(' ', $record[$col]); - if ($RCMAIL->action == 'show') { + if (!$edit_mode) { if (!empty($record[$col])) $fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . " "; } @@ -572,21 +620,26 @@ $fullkey = $col.':'.$subtype; // skip cols unknown to the backend - if (!$coltypes[$field]) + if (!$coltypes[$field] && empty($colprop['value'])) { continue; + } // merge colprop with global coltype configuration - $colprop += $coltypes[$field]; + if ($coltypes[$field]) { + $colprop += $coltypes[$field]; + } + $label = isset($colprop['label']) ? $colprop['label'] : $RCMAIL->gettext($col); // 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 = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype', 'title' => $colprop['label'] . ' ' . $RCMAIL->gettext('type'))); $select_subtype->add($subtype_names, $colprop['subtypes']); } - else + else { $select_subtype = null; + } if (!empty($colprop['value'])) { $values = (array)$colprop['value']; @@ -623,6 +676,8 @@ foreach ($values as $i => $val) { if ($subtypes[$i]) $subtype = $subtypes[$i]; + + $colprop['id'] = 'ff_' . $col . intval($coltypes[$field]['count']); // render composite field if ($colprop['type'] == 'composite') { @@ -688,12 +743,21 @@ // display row with label if ($label) { + if ($RCMAIL->action == 'print') { + $_label = rcube::Q($colprop['label'] . ($label != $colprop['label'] ? ' (' . $label . ')' : '')); + } + else { + $_label = $select_subtype ? $select_subtype->show($subtype) : html::label($colprop['id'], rcube::Q($label)); + } + $rows .= html::div('row', - html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : rcube::Q($label)) . + html::div('contactfieldlabel label', $_label) . html::div('contactfieldcontent '.$colprop['type'], $val)); } - else // row without label + // row without label + else { $rows .= html::div('row', html::div('contactfield', $val)); + } } // add option to the add-field menu @@ -704,9 +768,13 @@ // wrap rows in fieldgroup container if ($rows) { - $content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')), - ($colprop['subtypes'] ? html::tag('legend', null, rcube::Q($colprop['label'])) : ' ') . - $rows); + $c_class = 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col; + $with_label = $colprop['subtypes'] && $RCMAIL->action != 'print'; + $content .= html::tag( + 'fieldset', + array('class' => $c_class, 'style' => ($rows ? null : 'display:none')), + ($with_label ? html::tag('legend', null, rcube::Q($colprop['label'])) : ' ') . $rows + ); } } @@ -728,9 +796,9 @@ } if ($edit_mode) { - $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels); - $RCMAIL->output->set_env('delbutton', $del_button); - $RCMAIL->output->add_label('delete'); + $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels); + $RCMAIL->output->set_env('delbutton', $del_button); + $RCMAIL->output->add_label('delete'); } return $out; @@ -744,11 +812,12 @@ if ($result = $CONTACTS->get_result()) $record = $result->first(); - $photo_img = $attrib['placeholder'] ? $RCMAIL->output->get_skin_file($attrib['placeholder']) : 'program/resources/blank.gif'; + $photo_img = $attrib['placeholder'] ? $RCMAIL->output->abs_url($attrib['placeholder'], true) : 'program/resources/blank.gif'; if ($record['_type'] == 'group' && $attrib['placeholdergroup']) - $photo_img = $RCMAIL->output->get_skin_file($attrib['placeholdergroup']); + $photo_img = $RCMAIL->output->abs_url($attrib['placeholdergroup'], true); - $RCMAIL->output->set_env('photo_placeholder', $photo_img); + $RCMAIL->output->set_env('photo_placeholder', $RCMAIL->output->asset_url($photo_img)); + unset($attrib['placeholder']); $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'data' => $record['photo'])); @@ -775,11 +844,15 @@ } $photo_img = $RCMAIL->url($url); } - else + else { $ff_value = '-del-'; // will disable delete-photo action + } - $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => '')); - $content = html::div($attrib, $img); + $content = html::div($attrib, html::img(array( + 'src' => $photo_img, + 'alt' => $RCMAIL->gettext('contactphoto'), + 'onerror' => 'this.src = rcmail.env.photo_placeholder', + ))); if ($CONTACT_COLTYPES['photo'] && ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add')) { $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']); @@ -851,13 +924,13 @@ * * @return array List of contact IDs per-source */ -function rcmail_get_cids($filter = null) +function rcmail_get_cids($filter = null, $request_type = rcube_utils::INPUT_GPC) { // contact ID (or comma-separated list of IDs) is provided in two // forms. If _source is an empty string then the ID is a string // containing contact ID and source name in form: <ID>-<SOURCE> - $cid = rcube_utils::get_input_value('_cid', rcube_utils::INPUT_GPC); + $cid = rcube_utils::get_input_value('_cid', $request_type); $source = (string) rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC); if (is_array($cid)) { @@ -895,27 +968,3 @@ return $filter !== null ? $result[$filter] : $result; } - - -// register UI objects -$OUTPUT->add_handlers(array( - 'directorylist' => 'rcmail_directory_list', -// 'groupslist' => 'rcmail_contact_groups', - 'addresslist' => 'rcmail_contacts_list', - 'addresslisttitle' => 'rcmail_contacts_list_title', - 'addressframe' => 'rcmail_contact_frame', - 'recordscountdisplay' => 'rcmail_rowcount_display', - 'searchform' => array($OUTPUT, 'search_form') -)); - -// register action aliases -$RCMAIL->register_action_map(array( - 'add' => 'edit.inc', - 'group-create' => 'groups.inc', - 'group-rename' => 'groups.inc', - 'group-delete' => 'groups.inc', - 'group-addmembers' => 'groups.inc', - 'group-delmembers' => 'groups.inc', - 'search-create' => 'search.inc', - 'search-delete' => 'search.inc', -)); -- Gitblit v1.9.1