From 1cb1669b185999ca8f4930eea725e10fa560ae44 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 22 Mar 2010 16:33:04 -0600 Subject: [PATCH] Improvements to the contacts script. --- imp/contacts.php | 60 +++++++++++++++++++++++++++++++----------------------- imp/js/contacts.js | 17 ++++++++-------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/imp/contacts.php b/imp/contacts.php index 30b91048f..2dd8cd1ec 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -2,6 +2,17 @@ /** * Standard (imp) contacts display page. * + * URL parameters: + * 'formfield' - (string) Overrides the form field to fill on closing the + * window. + * 'formname' - (string) Name of the calling form (defaults to 'compose'). + * 'sa' - TODO + * 'search' - (string) Search term (defaults to '' which should list + * everyone). + * 'searched' - TODO + * 'source' - TODO + * 'to_only' - (boolean) Are we limiting to only the 'To:' field? + * * Copyright 2002-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you @@ -13,37 +24,31 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('imp', array('authentication' => 'horde')); +$vars = Horde_Variables::getDefaultVariables(); + /* Get the lists of address books through the API. */ $source_list = $registry->call('contacts/sources'); /* If we self-submitted, use that source. Otherwise, choose a good * source. */ -$source = Horde_Util::getFormData('source'); -if (empty($source) || !isset($source_list[$source])) { - /* We don't just pass the second argument to getFormData() because - * we want to trap for invalid sources, not just no source. */ +if (!isset($vars->source) || !isset($source_list[$vars->source])) { reset($source_list); - $source = key($source_list); + $vars->source = key($source_list); } -/* Get the search as submitted (defaults to '' which should list everyone). */ -$search = Horde_Util::getFormData('search'); - -/* Get the name of the calling form (Defaults to 'compose'). */ -$formname = Horde_Util::getFormData('formname', 'compose'); - -/* Are we limiting to only the 'To:' field? */ -$to_only = Horde_Util::getFormData('to_only'); +if (!isset($vars->formname)) { + $vars->formname = 'compose'; +} $search_params = IMP_Compose::getAddressSearchParams(); $apiargs = array( - 'addresses' => array($search), - 'addressbooks' => array($source), + 'addresses' => array($vars->search), + 'addressbooks' => array($vars->source), 'fields' => $search_params['fields'] ); $addresses = array(); -if (Horde_Util::getFormData('searched') || $prefs->getValue('display_contact')) { +if ($vars->searched || $prefs->getValue('display_contact')) { $results = $registry->call('contacts/search', $apiargs); foreach ($results as $r) { /* The results list returns an array for each source searched. Make @@ -55,7 +60,7 @@ if (Horde_Util::getFormData('searched') || $prefs->getValue('display_contact')) /* If self-submitted, preserve the currently selected users encoded by * javascript to pass as value|text. */ $selected_addresses = array(); -foreach (explode('|', Horde_Util::getFormData('sa')) as $addr) { +foreach (explode('|', $vars->sa) as $addr) { if (strlen(trim($addr))) { $selected_addresses[] = @htmlspecialchars($addr, ENT_QUOTES, Horde_Nls::getCharset()); } @@ -66,14 +71,14 @@ $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); $template->set('action', Horde::applicationUrl('contacts.php')->add(array('uniq' => uniqid(mt_rand())))); -$template->set('formname', $formname); +$template->set('formname', $vars->formname); $template->set('formInput', Horde_Util::formInput()); -$template->set('search', htmlspecialchars($search)); +$template->set('search', htmlspecialchars($vars->search)); if (count($source_list) > 1) { $template->set('multiple_source', true); $s_list = array(); foreach ($source_list as $key => $select) { - $s_list[] = array('val' => $key, 'selected' => ($key == $source), 'label' => htmlspecialchars($select)); + $s_list[] = array('val' => $key, 'selected' => ($key == $vars->source), 'label' => htmlspecialchars($select)); } $template->set('source_list', $s_list); } else { @@ -94,16 +99,21 @@ foreach ($addresses as $addr) { } } $template->set('a_list', $a_list); -$template->set('cc', !$to_only); +$template->set('cc', intval(!$vars->to_only)); $template->set('sa', $selected_addresses); +$js = array( + 'ImpContacts.formname = "' . $vars->formname . '"', + 'ImpContacts.to_only = ' . intval($vars->to_only) +); +if (isset($vars->formfield)) { + $js[] = 'ImpContacts.formfield = "' . $vars->formfield . '"'; +} + /* Display the form. */ $title = _("Address Book"); Horde::addScriptFile('contacts.js', 'imp'); require IMP_TEMPLATES . '/common-header.inc'; -Horde::addInlineScript(array( - 'ImpContacts.formname = \'' . $formname . '\'', - 'ImpContacts.to_only = ' . intval($to_only), -)); +Horde::addInlineScript($js); echo $template->fetch(IMP_TEMPLATES . '/imp/contacts/contacts.html'); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/imp/js/contacts.js b/imp/js/contacts.js index f57b0ea89..5c7f8474a 100644 --- a/imp/js/contacts.js +++ b/imp/js/contacts.js @@ -7,7 +7,7 @@ var ImpContacts = { // The following variables are defined in contacts.php: - // formname, to_only + // formfield, formname, to_only _passAddresses: function() { @@ -77,15 +77,16 @@ var ImpContacts = { $('selected_addresses').childElements().each(function(s) { var address = s.value, f, field = null, pos, v; pos = address.indexOf(':'); - f = address.substring(0, pos); address = address.substring(pos + 2, address.length) - if (f == 'to') { - field = parent.opener.document[this.formname].to; - } else if (!this.to_only && f == 'cc') { - field = parent.opener.document[this.formname].cc; - } else if (!this.to_only && f == 'bcc') { - field = parent.opener.document[this.formname].bcc; + if (this.formfield) { + field = parent.opener.document[this.formname][this.formfield]; + } else { + f = address.substring(0, pos); + if (f == 'to' || + (!this.to_only && (f == 'cc' || f == 'bcc'))) { + field = parent.opener.document[this.formname][f]; + } } if (!field) { -- 2.11.0