From 24d822349cce4f81ea50220504b3180b3b735346 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 7 Apr 2010 15:00:04 -0600 Subject: [PATCH] Identities prefs should be working again. --- framework/Core/lib/Horde/Core/Prefs/Ui.php | 257 ++++++++++++++++++++++++++--- horde/config/prefs.php.dist | 67 ++++---- horde/js/identityselect.js | 42 ++--- horde/lib/Prefs/Ui.php | 168 ------------------- horde/templates/prefs/identityselect.html | 23 ++- imp/config/prefs.php.dist | 5 +- imp/js/folderprefs.js | 79 +++++---- imp/lib/Prefs/Ui.php | 51 +++--- imp/templates/prefs/sentmail.html | 3 +- 9 files changed, 379 insertions(+), 316 deletions(-) diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui.php b/framework/Core/lib/Horde/Core/Prefs/Ui.php index 06d1a3c8e..dc0b03bc1 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui.php @@ -53,6 +53,13 @@ class Horde_Core_Prefs_Ui public $suppressGroups = array(); /** + * Suppressed preference entries to automatically update. + * + * @var array + */ + public $suppressUpdate = array(); + + /** * Current application. * * @var string @@ -150,23 +157,27 @@ class Horde_Core_Prefs_Ui /** * Handle a preferences form submission if there is one, updating * any preferences which have been changed. - * - * @return boolean Whether preferences have been updated. */ public function handleForm() { if (!$this->group || !$this->groupIsEditable($this->group)) { - return false; + return; } if (isset($this->vars->prefs_return)) { $this->group = $this->vars->actionID = ''; - return false; + return; } switch ($this->vars->actionID) { case 'update_prefs': - return $this->_handleForm($this->getChangeablePrefs($this->group)); + if (isset($this->prefGroups[$this->group]['type']) && + ($this->prefGroups[$this->group]['type'] == 'identities')) { + $this->_identitiesUpdate(); + } else { + $this->_handleForm(array_diff($this->getChangeablePrefs($this->group), $this->suppressUpdate), $prefs); + } + break; case 'update_special': $special = array(); @@ -175,10 +186,9 @@ class Horde_Core_Prefs_Ui $special[] = $pref; } } - return $this->_handleForm($special); + $this->_handleForm($special, $GLOBALS['prefs']); + break; } - - return false; } /* @@ -186,10 +196,9 @@ class Horde_Core_Prefs_Ui * any preferences which have been changed. * * @param array $preflist The list of preferences to process. - * - * @return boolean Whether preferences have been updated. + * @param mixed $save The object to save preferences values to. */ - protected function _handleForm($preflist) + protected function _handleForm($preflist, $save) { global $notification, $prefs, $registry; @@ -199,12 +208,12 @@ class Horde_Core_Prefs_Ui foreach ($preflist as $pref) { switch ($this->prefs[$pref]['type']) { case 'checkbox': - $updated |= $prefs->setValue($pref, intval(isset($this->vars->$pref))); + $updated |= $save->setValue($pref, intval(isset($this->vars->$pref))); break; case 'enum': if (isset($this->prefs[$pref]['enum'][$this->vars->$pref])) { - $updated |= $prefs->setValue($pref, $this->vars->$pref); + $updated |= $save->setValue($pref, $this->vars->$pref); } else { $notification->push(_("An illegal value was specified."), 'horde.error'); } @@ -224,7 +233,7 @@ class Horde_Core_Prefs_Ui } } - $updated |= $prefs->setValue($pref, @serialize($set)); + $updated |= $save->setValue($pref, @serialize($set)); break; case 'number': @@ -234,14 +243,14 @@ class Horde_Core_Prefs_Ui } elseif (empty($num)) { $notification->push(_("This number must be non-zero."), 'horde.error'); } else { - $updated |= $prefs->setValue($pref, $num); + $updated |= $save->setValue($pref, $num); } break; case 'password': case 'text': case 'textarea': - $updated |= $prefs->setValue($pref, $this->vars->$pref); + $updated |= $save->setValue($pref, $this->vars->$pref); break; @@ -256,6 +265,11 @@ class Horde_Core_Prefs_Ui } if ($updated) { + if ($save instanceof Horde_Prefs_Identity) { + // Throws Exception caught in _identitiesUpdate(). + $save->verify(); + } + if ($registry->hasAppMethod($this->app, 'prefsCallback')) { $registry->callAppMethod($this->app, 'prefsCallback', array('args' => array($this))); } @@ -268,8 +282,6 @@ class Horde_Core_Prefs_Ui $this->_loadPrefs($this->app); } - - return $updated; } /** @@ -304,6 +316,7 @@ class Horde_Core_Prefs_Ui global $notification, $prefs, $registry; $columns = $pref_list = array(); + $identities = false; /* Run app-specific init code. */ if ($registry->hasAppMethod($this->app, 'prefsInit')) { @@ -314,6 +327,17 @@ class Horde_Core_Prefs_Ui if ($this->group) { $pref_list = $this->getChangeablePrefs($this->group, true); + + /* Add necessary init stuff for identities pages. */ + if (isset($prefgroups[$this->group]['type']) && + ($prefgroups[$this->group]['type'] == 'identities')) { + Horde::addScriptFile('identityselect.js', 'horde'); + $identities = true; + + /* If this is an identities group, need to grab the base + * identity fields from Horde, if current app is NOT Horde. */ + $pref_list = $this->_addHordeIdentitiesPrefs($pref_list); + } } else { foreach ($prefgroups as $key => $val) { $columns[$val['column']][$key] = $val; @@ -337,6 +361,10 @@ class Horde_Core_Prefs_Ui ob_start(); if ($this->group) { + if ($identities) { + echo $this->_identityHeader($pref_list); + } + foreach ($pref_list as $pref) { if ($this->prefs[$pref]['type'] == 'special') { if ($registry->hasAppMethod($this->app, 'prefsSpecial')) { @@ -567,20 +595,27 @@ class Horde_Core_Prefs_Ui } /** - * Loads preferences configuration into the current object. + * Parses/loads preferences configuration. * - * @param string $app The application. + * @param string $app The application. + * @param boolean $data Return the data instead of loading into the + * current object? */ - protected function _loadPrefs($app, $merge = false) + protected function _loadPrefs($app, $data = false) { try { $res = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), $app); - $this->prefGroups = $res['prefGroups']; - $this->prefs = $res['_prefs']; } catch (Horde_Exception $e) { - $this->prefGroups = $this->prefs = array(); + $res = array('prefGroups' => array(), '_prefs' => array()); + } + + if ($data) { + return $res; } + $this->prefGroups = $res['prefGroups']; + $this->prefs = $res['_prefs']; + /* If there's only one prefGroup, just show it. */ if (!$this->group && (count($this->prefGroups) == 1)) { reset($this->prefGroups); @@ -607,4 +642,178 @@ class Horde_Core_Prefs_Ui return $out; } + /** + * Adds Horde base identities prefs to preference list. + * + * @param array $pref_list Preference list. + * + * @return array The preference list with the Horde preferences added, if + * needed. These prefs are also added to $this->prefs. + */ + protected function _addHordeIdentitiesPrefs($pref_list) + { + if ($this->app != 'horde') { + try { + $res = $this->_loadPrefs('horde', true); + foreach ($res['prefGroups'] as $pgroup) { + if (isset($pgroup['type']) && + ($pgroup['type'] == 'identities')) { + foreach ($pgroup['members'] as $member) { + $this->prefs[$member] = $res['_prefs'][$member]; + } + $pref_list = array_merge($pgroup['members'], $pref_list); + } + } + } catch (Horde_Exception $e) {} + } + + return $pref_list; + } + + /** + * Output the identities page header entries (default identity, + * identity selection, and identity deletion). + * + * @param array $members The list of prefs to display on this page. + * + * @return string HTML output. + */ + protected function _identityHeader($members) + { + $identity = Horde_Prefs_Identity::singleton(($this->app == 'horde') ? null : array($this->app, $this->app)); + $default_identity = $identity->getDefault(); + + $t = $GLOBALS['injector']->createInstance('Horde_Template'); + $t->setOption('gettext', true); + + if ($GLOBALS['prefs']->isLocked('default_identity')) { + $t->set('default_identity', intval($default_identity)); + $identities = array($default_identity); + } else { + $t->set('defaultid', _("Your default identity:")); + $t->set('label', Horde::label('identity', _("Select the identity you want to change:"))); + $identities = $identity->getAll('id'); + } + + $entry = $js = array(); + foreach ($identities as $key => $val) { + $entry[] = array( + 'i' => $key, + 'label' => htmlspecialchars($val), + 'sel' => ($key == $default_identity) + ); + + $tmp = array(); + foreach ($members as $member) { + $val = $identity->getValue($member, $key); + switch ($this->prefs[$member]['type']) { + case 'checkbox': + case 'number': + $val2 = intval($val); + break; + + case 'textarea': + if (is_array($val)) { + $val = implode("\n", $val); + } + // Fall-through + + default: + $val2 = Horde_String::convertCharset($val, Horde_Nls::getCharset(), 'UTF-8'); + } + + // [0] = pref name + // [1] = pref type + // [2] = pref value + $tmp[] = array( + $member, + $this->prefs[$member]['type'], + $val2 + ); + } + $js[] = $tmp; + } + $t->set('entry', $entry); + + Horde::addInlineScript(array( + 'HordeIdentitySelect.newChoice()' + ), 'dom'); + Horde::addInlineScript(array( + 'HordeIdentitySelect.identities = ' . Horde_Serialize::serialize($js, Horde_Serialize::JSON) + )); + + return $t->fetch(HORDE_TEMPLATES . '/prefs/identityselect.html'); + } + + /** + * Update identities prefs. + */ + protected function _identitiesUpdate() + { + global $conf, $notification, $prefs; + + $identity = Horde_Prefs_Identity::singleton(($this->app == 'horde') ? null : array($this->app, $this->app)); + + if ($this->vars->delete_identity) { + $id = intval($this->vars->id); + $deleted_identity = $identity->delete($id); + $this->_loadPrefs($this->app); + $notification->push(sprintf(_("The identity \"%s\" has been deleted."), $deleted_identity[0]['id']), 'horde.success'); + return; + } + + $old_default = $identity->getDefault(); + $from_addresses = $identity->getAll('from_addr'); + $current_from = $identity->getValue('from_addr'); + $id = intval($this->vars->identity); + + if (!$prefs->isLocked('default_identity')) { + $new_default = intval($this->vars->default_identity); + if ($new_default != $old_default) { + $identity->setDefault($new_default); + $old_default = $new_default; + $notification->push(_("Your default identity has been changed."), 'horde.success'); + + /* Need to immediately save, since we may short-circuit + * saving the identities below. */ + $identity->save(); + } + } + + if ($id == -2) { + return; + } + + if ($id == -1) { + $id = $identity->add(); + } + + $identity->setDefault($id); + + try { + $this->_handleForm(array_diff($this->_addHordeIdentitiesPrefs($this->getChangeablePrefs($this->group)), $this->suppressUpdate), $identity); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); + return; + } + + $new_from = $identity->getValue('from_addr'); + if (!empty($conf['user']['verify_from_addr']) && + ($current_from != $new_from) && + !in_array($new_from, $from_addresses)) { + try { + $result = $identity->verifyIdentity($id, empty($current_from) ? $new_from : $current_from); + if ($result instanceof Notification_Event) { + $notification->push($result, 'horde.message'); + } + } catch (Horde_Exception $e) { + $notification->push(_("The new from address can't be verified, try again later: ") . $e->getMessage(), 'horde.error'); + Horde::logMessage($e, 'ERR'); + } + } else { + $identity->setDefault($old_default); + $identity->save(); + } + } + } diff --git a/horde/config/prefs.php.dist b/horde/config/prefs.php.dist index 60f1b3e25..f0a4d3f82 100644 --- a/horde/config/prefs.php.dist +++ b/horde/config/prefs.php.dist @@ -20,6 +20,16 @@ * desc - (string) Description shown under label. * label - (string) Label for the group of settings. * members - (array) List of displayable preferences contained in this group. + * type - (string) The prefGroup type. + * VALUES: + * 'identities' - An identities screen. The identities screen will + * always show all the shared identities prefs from + * Horde, as well as the identity switching widget. + * Additionally, applications can define additional + * identity information in their prefs.php file that + * will be displayed after the Horde-wide settings. + * Empty - The default options screen. + * DEFAULT: The default options screen. * * $_prefs * ======= @@ -189,44 +199,14 @@ * $Id$ */ -// *** Personal Information preferences *** +// *** Personal Information (Identities) Preferences *** $prefGroups['identities'] = array( 'column' => _("Your Information"), 'label' => _("Personal Information"), 'desc' => _("Change the name and address that people see when they read and reply to your emails."), - 'members' => array( - 'default_identity', 'identityselect', 'id', 'fullname', 'from_addr' - ) -); - -// default identity -// Set locked to true if you don't want the users to have multiple identities. -$_prefs['default_identity'] = array( - 'value' => 0, - 'shared' => true, - 'type' => 'enum', - 'desc' => _("Your default identity:") -); - -// identities data -$_prefs['identities'] = array( - // value = serialize(array()) - 'value' => 'a:0:{}', - 'shared' => true -); - -// identify email confirmation -$_prefs['confirm_email'] = array( - // value = serialize(array()) - 'value' => 'a:0:{}', - 'shared' => true -); - -// identity selection widget -$_prefs['identityselect'] = array( - 'type' => 'special', - 'shared' => true + 'members' => array('id', 'fullname', 'from_addr'), + 'type' => 'identities' ); // identity name @@ -259,6 +239,27 @@ $_prefs['from_addr'] = array( 'desc' => _("Your From: address:") ); +// default identity +// Set locked to true if you don't want the users to have multiple identities. +$_prefs['default_identity'] = array( + 'value' => 0, + 'shared' => true +); + +// identities data +$_prefs['identities'] = array( + // default value = serialize(array()) + 'value' => 'a:0:{}', + 'shared' => true +); + +// identify email confirmation +$_prefs['confirm_email'] = array( + // default value = serialize(array()) + 'value' => 'a:0:{}', + 'shared' => true +); + // *** Authentication Preferences *** diff --git a/horde/js/identityselect.js b/horde/js/identityselect.js index f5cb8a92a..5975298af 100644 --- a/horde/js/identityselect.js +++ b/horde/js/identityselect.js @@ -5,23 +5,21 @@ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. */ -var IdentitySelect = { +var HordeIdentitySelect = { newChoice: function() { - var id = $('identity').down('[value=' + $F('identity') + ']').value; + var identity = $('identity'), + id = Number($F(identity)); if (id < 0) { - $('prefs').reset(); - $('identity').setValue(id); + identity.up('FORM').reset(); + identity.setValue(id); return; } this.identities[id].each(function(a) { var field = $(a[0]); - if (!field) { - return; - } switch (a[1]) { case "enum": @@ -33,11 +31,13 @@ var IdentitySelect = { } break; - case "implicit": - eval("newChoice_" + a[0] + "(" + a[2] + ")"); + case "special": + identity.fire('HordeIdentitySelect:change', { + i: id, + pref: a[0] + }); break; - case "checkbox": default: field.setValue(a[2]); break; @@ -45,29 +45,11 @@ var IdentitySelect = { }); }, - deleteIdentity: function() - { - var params, q, - id = $('identity').down('[value=' + $F('identity') + ']').value; - - if (id >= 0) { - q = this.deleteurl.indexOf('?'); - params = this.deleteurl.toQueryParams(); - params.id = id; - window.location.assign(this.deleteurl.substring(0, q) + '?' + params.toQueryString()); - } - }, - onDomLoad: function() { - if ($('identity')) { - $('identity').observe('change', this.newChoice.bind(this)); - } - if ($('deleteidentity')) { - $('deleteidentity').observe('click', this.deleteIdentity.bind(this)); - } + $('identity').observe('change', this.newChoice.bind(this)); } }; -document.observe('dom:loaded', IdentitySelect.onDomLoad.bind(IdentitySelect)); +document.observe('dom:loaded', HordeIdentitySelect.onDomLoad.bind(HordeIdentitySelect)); diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index 082c9c2de..5f4f19eea 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -119,9 +119,6 @@ class Horde_Prefs_Ui case 'categorymanagement': return $this->_categoryManagement($ui); - case 'identityselect': - return $this->_identitySelect($ui); - case 'remotemanagement': return $this->_remoteManagement($ui); @@ -146,9 +143,6 @@ class Horde_Prefs_Ui case 'categorymanagement': return $this->_updateCategoryManagement($ui); - case 'identityselect': - return false; - case 'remotemanagement': $this->_updateRemoteManagement($ui); break; @@ -297,93 +291,6 @@ class Horde_Prefs_Ui } /** - * Create code for identity selection. - * - * @param Horde_Core_Prefs_Ui $ui The UI object. - * - * @return string HTML UI code. - */ - protected function _identitySelect($ui) - { - $identity = Horde_Prefs_Identity::singleton($ui->app == 'horde' ? null : array($ui->app, $ui->app)); - $default_identity = $identity->getDefault(); - - $t = $GLOBALS['injector']->createInstance('Horde_Template'); - $t->setOption('gettext', true); - - if ($GLOBALS['prefs']->isLocked('default_identity')) { - $t->set('locked', true); - $t->set('default_identity', intval($default_identity)); - } else { - $t->set('label', Horde::label('identity', _("Select the identity you want to change:"))); - - $identities = $identity->getAll('id'); - $members = $this->getChangeablePrefs('identities'); - - $entry = $js = array(); - - for ($i = 0, $icnt = count($identities); $i < $icnt; ++$i) { - $entry[] = array( - 'i' => $i, - 'label' => htmlspecialchars($identities[$i]), - 'sel' => ($i == $default_identity) - ); - - $tmp = array(); - foreach ($members as $member) { - if (($member == 'default_identity') || - !empty($this->prefs[$member]['locked']) || - empty($this->prefs[$member]['type']) || - in_array($this->prefs[$member]['type'], array('link', 'special'))) { - continue; - } - - $val = $identity->getValue($member, $i); - switch ($this->prefs[$member]['type']) { - case 'checkbox': - $val2 = $val ? 'true' : 'false'; - break; - - case 'number': - $val2 = intval($val); - break; - - case 'textarea': - if (is_array($val)) { - $val = implode("\n", $val); - } - // Fall-through - - default: - $val2 = Horde_String::convertCharset($val, Horde_Nls::getCharset(), 'UTF-8'); - } - - $tmp[] = array( - $member, - $this->prefs[$member]['type'], - $val2 - ); - } - - $js[] = $tmp; - } - - $t->set('entry', $entry); - - Horde::addScriptFile('identityselect.js', 'horde'); - Horde::addInlineScript(array( - 'IdentitySelect.newChoice()' - ), 'dom'); - Horde::addInlineScript(array( - 'IdentitySelect.identities = ' . Horde_Serialize::serialize($js, Horde_Serialize::JSON), - 'IdentitySelect.deleteurl = ' . Horde_Serialize::serialize(strval(Horde::selfUrl(true)->setRaw(true)->add('actionID', 'delete_identity')), Horde_Serialize::JSON) - )); - } - - return $t->fetch(HORDE_TEMPLATES . '/prefs/identityselect.html'); - } - - /** * Create code for remote server management. * * @param Horde_Core_Prefs_Ui $ui The UI object. @@ -587,79 +494,4 @@ class Horde_Prefs_Ui } } -/* - try { - $this->prefGroups['identities']['members'] = array_keys(array_flip(array_merge( - $res['prefGroups']['identities']['members'], - $this->prefGroups['identities']['members'] - ))); - $this->prefs = Horde_Array::array_merge_recursive_overwrite($res['_prefs'], $this->prefs); - } catch (Horde_Exception $e) {} - case 'update_prefs': - $from_addresses = $identity->getAll('from_addr'); - $current_from = $identity->getValue('from_addr'); - if ($prefs->isLocked('default_identity')) { - $default = $identity->getDefault(); - } else { - $default = $this->vars->default_identity; - $id = $this->vars->identity; - if ($id == -1) { - $id = $identity->add(); - } elseif ($id == -2) { - $this->prefGroups['identities']['members'] = array('default_identity'); - } - $identity->setDefault($id); - } - - $this->_save = $identity; - - if (!$this->_handleForm($this->getChangeablePrefs($this->group))) { - return; - } - - $new_from = $identity->getValue('from_addr'); - if (!empty($conf['user']['verify_from_addr']) && - $current_from != $new_from && - !in_array($new_from, $from_addresses)) { - try { - $result = $identity->verifyIdentity($id, empty($current_from) ? $new_from : $current_from); - if ($result instanceof Notification_Event) { - $notification->push($result, 'horde.message'); - } - } catch (Horde_Exception $e) { - $notification->push(_("The new from address can't be verified, try again later: ") . $e->getMessage(), 'horde.error'); - Horde::logMessage($e, 'ERR'); - } - break; - } - - $identity->setDefault($default); - $identity->save(); - break; - case 'delete_identity': - $id = intval($this->vars->id); - $deleted_identity = $identity->delete($id); - unset($this->prefs['default_identity']['enum'][$id]); - $notification->push(sprintf(_("The identity \"%s\" has been deleted."), $deleted_identity[0]['id']), 'horde.success'); - break; - - case 'change_default_identity': - $default_identity = $identity->setDefault(intval($this->vars->id)); - $identity->save(); - $notification->push(_("Your default identity has been changed."), 'horde.success'); - break; - } - break; - - if (is_callable(array($this->_save, 'verify'))) { - try { - $this->_save->verify(); - } catch (Exception $e) { - $notification->push($e, 'horde.error'); - } - } - - // $ui->override['default_identity'] = $identity->getAll('id'); - // -*/ } diff --git a/horde/templates/prefs/identityselect.html b/horde/templates/prefs/identityselect.html index f6495d754..a6555b8c6 100644 --- a/horde/templates/prefs/identityselect.html +++ b/horde/templates/prefs/identityselect.html @@ -1,9 +1,20 @@ - - - + +
+ +
+ +
+ +
+
+
+

-
+ + + diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 8bbadc2a0..63883bb80 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -15,7 +15,8 @@ $prefGroups['identities'] = array( 'replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr', 'signature', 'sig_dashes', 'sig_first', 'save_sent_mail', 'sent_mail_folder', 'sentmailselect' - ) + ), + 'type' => 'identities' ); // user preferred email address for Reply-To:, if different from From: @@ -1440,7 +1441,7 @@ $_prefs['search_fields'] = array( $_prefs['add_source'] = array( // 'value' => 'localsql', 'value' => '', - 'shared' => true + 'shared' => true, 'type' => 'enum', 'desc' => _("Choose the address book to use when adding addresses.") ); diff --git a/imp/js/folderprefs.js b/imp/js/folderprefs.js index a02f1f3c2..cc5cb3f31 100644 --- a/imp/js/folderprefs.js +++ b/imp/js/folderprefs.js @@ -6,44 +6,57 @@ */ var ImpFolderPrefs = { - // Variables defined by other code: folders - newFolderName: function(f, fn, p1, p2) + // Variables defined by other code: folders, origtext, sentmail + + newFolderName: function(e) { - f = $(f); - fn = $(fn); - - if (f[f.selectedIndex].value == '') { - var folder = window.prompt(p1, fn.value ? fn.value : ''); - if (folder != '') { - fn.value = folder; - f[1].text = p2 + ' [' + fn.value + ']'; + var folder, tmp, + f = e.element(), + id = f.identify(), + txt = this.folders.get(id), + newfolder = $(id + '_new'), + sel = $(f[f.selectedIndex]); + + if (sel.value == '\0create' && !newfolder) { + folder = window.prompt(txt, ''); + if (!folder.empty()) { + if (!newfolder) { + newfolder = new Element('INPUT', { id: id + '_new', name: id + '_new', type: 'hidden' }); + f.insert({ after: newfolder }); + } + newfolder.setValue(folder); + this.origtext = sel.text; + sel.update(sel.text + ' [' + folder + ']'); } } - } - -}; - -document.observe('dom:loaded', function() { - var fp = ImpFolderPrefs; - fp.folders.each(function(f) { - $(f[0]).observe('change', fp.newFolderName.bind(fp, f[0], f[1], f[2], f[3])); - }); -}); - -// Called by Horde identity pref code. -function newChoice_sent_mail_folder(val) -{ - var field = $('sent_mail_folder'); - if (val == "") { - field.selectedIndex = 0; - return; - } + }, - for (var i = 0, l = field.options.length; i < l; i++) { - if (field.options[i].value == val) { - field.selectedIndex = i; + changeIdentity: function(e) + { + switch (e.memo.pref) { + case 'sentmailselect': + $('sent_mail_folder').setValue(this.sentmail[e.memo.i]); + if (this.origtext) { + $('sent_mail_folder_new').remove(); + $('sent_mail_folder').down('[value="\0create"]').update(this.origtext); + this.origtext = null; + } break; } + }, + + onDomLoad: function() + { + this.folders = $H(this.folders); + + this.folders.keys().each(function(f) { + $(f).observe('change', this.newFolderName.bindAsEventListener(this)); + }, this); + + document.observe('HordeIdentitySelect:change', this.changeIdentity.bindAsEventListener(this)); } -} + +}; + +document.observe('dom:loaded', ImpFolderPrefs.onDomLoad.bind(ImpFolderPrefs)); diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index d5f3fb700..350358e19 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -167,18 +167,18 @@ class IMP_Prefs_Ui if ($prefs->isLocked('drafts_folder')) { $ui->suppress[] = 'draftsselect'; } else { - $code[] = array('drafts', 'drafts_new', _("Enter the name for your new drafts folder"), _("Create a new drafts folder")); + $code['drafts'] = _("Enter the name for your new drafts folder"); } if ($prefs->isLocked('spam_folder')) { $ui->suppress[] = 'spamselect'; } else { - $code[] = array('spam', 'spam_new', _("Enter the name for your new spam folder"), _("Create a new spam folder")); + $code['spam'] = _("Enter the name for your new spam folder"); } if (!$prefs->isLocked('trash_folder') && !$prefs->isLocked('use_vtrash')) { - $code[] = array('trash', 'trash_new', _("Enter the name for your new trash folder"), _("Create a new trash folder")); + $code['trash'] = _("Enter the name for your new trash folder"); } else { $ui->suppress[] = 'trashselect'; } @@ -349,7 +349,7 @@ class IMP_Prefs_Ui return false; case 'draftsselect': - return $this->_updateSpecialFolders('drafts_folder', $ui->vars->drafts, $ui->vars->drafts_new, $ui); + return $this->_updateSpecialFolders('drafts_folder', $ui->vars->drafts, $ui->vars->drafts_folder_new, $ui); case 'encryptselect': $prefs->setValue('default_encrypt', $ui->vars->default_encrypt); @@ -1105,8 +1105,18 @@ class IMP_Prefs_Ui */ protected function _sentmail() { + $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); + + $js = array(); + foreach (array_keys($identity->getAll('id')) as $key) { + $js[$key] = $identity->getValue('sent_mail_folder', $key); + }; + Horde::addInlineScript(array( - 'ImpFolderPrefs.folders = ' . Horde_Serialize::serialize(array('sent_mail_folder', 'sent_mail_new', _("Enter the name for your new sent-mail folder"), _("Create a new sent-mail folder")), Horde_Serialize::JSON, Horde_Nls::getCharset()) + 'ImpFolderPrefs.folders = ' . Horde_Serialize::serialize(array( + 'sent_mail_folder' => _("Create a new sent-mail folder") + ), Horde_Serialize::JSON, Horde_Nls::getCharset()), + 'ImpFolderPrefs.sentmail = ' . Horde_Serialize::serialize($js, Horde_Serialize::JSON, Horde_Nls::getCharset()) )); $t = $GLOBALS['injector']->createInstance('Horde_Template'); @@ -1115,7 +1125,7 @@ class IMP_Prefs_Ui $t->set('label', Horde::label('sent_mail_folder', _("Sent mail folder:"))); $t->set('flist', IMP::flistSelect(array( 'filter' => array('INBOX'), - 'heading' => _("Create a new sent mail folder") + 'new_folder' => true ))); return $t->fetch(IMP_TEMPLATES . '/prefs/sentmail.html'); @@ -1130,26 +1140,29 @@ class IMP_Prefs_Ui */ protected function _updateSentmail($ui) { - if (!$GLOBALS['conf']['user']['allow_folders'] || - $GLOBALS['prefs']->isLocked('sent_mail_folder')) { + global $conf, $prefs; + + if (!$conf['user']['allow_folders'] || + $prefs->isLocked('sent_mail_folder')) { return false; } $sent_mail_folder = $ui->vars->sent_mail_folder; - $sent_mail_new = Horde_String::convertCharset($ui->vars->sent_mail_new, Horde_Nls::getCharset(), 'UTF7-IMAP'); - $sent_mail_default = $GLOBALS['prefs']->getValue('sent_mail_folder'); + if (empty($sent_mail_folder)) { + $sent_mail_new = $GLOBALS['imp_imap']->appendNamespace(Horde_String::convertCharset($ui->vars->sent_mail_folder_new, Horde_Nls::getCharset(), 'UTF7-IMAP')); + } elseif ($sent_mail_folder == '-1') { + if ($sent_mail_default = $prefs->getValue('sent_mail_folder')) { + $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_default); + } + } - if (empty($sent_mail_folder) && !empty($sent_mail_new)) { - $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_new); - } elseif (($sent_mail_folder == '-1') && !empty($sent_mail_default)) { - $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_default); + if (empty($sent_mail_folder)) { + return false; } - if (!empty($sent_mail_folder)) { - $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); - if (!$imp_folder->exists($sent_mail_folder)) { - $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe')); - } + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); + if (!$imp_folder->exists($sent_mail_folder)) { + $imp_folder->create($sent_mail_folder, $prefs->getValue('subscribe')); } $imp_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); diff --git a/imp/templates/prefs/sentmail.html b/imp/templates/prefs/sentmail.html index f40bca44a..9fcd88f5d 100644 --- a/imp/templates/prefs/sentmail.html +++ b/imp/templates/prefs/sentmail.html @@ -3,10 +3,9 @@
-
-- 2.11.0