From 5f4e0acbe7879d6823150622c1f2d64f8fc123ca Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 23 Jun 2009 22:48:39 -0600 Subject: [PATCH] Add interface for accounts configuration. --- imp/config/prefs.php.dist | 23 +++++ imp/js/src/accountsmanagement.js | 58 +++++++++++++ imp/lib/Accounts.php | 133 +++++++++++++++++++++++++++++ imp/templates/prefs/accountsmanagement.inc | 79 +++++++++++++++++ imp/themes/screen.css | 14 ++- 5 files changed, 303 insertions(+), 4 deletions(-) create mode 100644 imp/js/src/accountsmanagement.js create mode 100644 imp/lib/Accounts.php create mode 100644 imp/templates/prefs/accountsmanagement.inc diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index cf3397f24..e620ecd52 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -54,6 +54,13 @@ if (!$is_pop3) { 'purge_spam_keep')); } +$prefGroups['accounts'] = array( + 'column' => _("General Options"), + 'label' => _("Additional Accounts"), + 'desc' => _("Configure additional mail accounts to display."), + 'members' => array('accountsmanagement') +); + $prefGroups['compose'] = array( 'column' => _("Message Options"), 'label' => _("Message Composition"), @@ -524,6 +531,22 @@ $_prefs['purge_trash_keep'] = array( // End Login Tasks preferences +// Accounts preferences + +// UI for flag management. +$_prefs['accountsmanagement'] = array( + 'type' => 'special' +); + +$_prefs['accounts'] = array( + 'value' => json_encode(array()), + 'locked' => false, + 'shared' => false, + 'type' => 'implicit'); + +// End Accounts preferences + + // Message Composition preferences // Link to the stationery preferences. diff --git a/imp/js/src/accountsmanagement.js b/imp/js/src/accountsmanagement.js new file mode 100644 index 000000000..84c77f745 --- /dev/null +++ b/imp/js/src/accountsmanagement.js @@ -0,0 +1,58 @@ +/** + * Provides the javascript for managing accounts. + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + */ + +var ImpAccountsmanagement = { + // Variables set by other code: confirm_delete + + _sendData: function(a, d) + { + $('accounts_action').setValue(a) + $('accounts_data').setValue(d); + $('prefs').submit(); + }, + + clickHandler: function(e) + { + if (e.isRightClick()) { + return; + } + + var elt = e.element(); + + while (Object.isElement(elt)) { + if (elt.hasClassName('accountsdelete')) { + if (window.confirm(this.confirm_delete)) { + this._sendData('delete', elt.up('TR').readAttribute('id').substring(11)); + } + e.stop(); + return; + } + + switch (elt.readAttribute('id')) { + case 'add_button': + this._sendData('add', ''); + break; + + case 'cancel_button': + this._sendData('', ''); + break; + + case 'new_button': + this._sendData('new', ''); + break; + } + + elt = elt.up(); + } + } + +}; + +document.observe('dom:loaded', function() { + var am = ImpAccountsmanagement; + document.observe('click', am.clickHandler.bindAsEventListener(am)); +}); diff --git a/imp/lib/Accounts.php b/imp/lib/Accounts.php new file mode 100644 index 000000000..96d5c61b2 --- /dev/null +++ b/imp/lib/Accounts.php @@ -0,0 +1,133 @@ + + * @package IMP + */ +class IMP_Accounts +{ + /** + * Singleton instance. + * + * @var IMP_Accounts + */ + static protected $_instance; + + /** + * The cached list of accounts. + * + * @var array + */ + protected $_accounts = null; + + /** + * Attempts to return a reference to a concrete object instance. + * It will only create a new instance if no instance currently exists. + * + * @return IMP_Accounts The created concrete instance. + */ + static public function singleton() + { + if (!isset(self::$_instance)) { + self::$_instance = new IMP_Accounts(); + } + + return self::$_instance; + } + + /** + * Save the accounts list to the prefs backend. + */ + protected function _save() + { + $GLOBALS['prefs']->setValue('accounts', json_encode($this->_accounts)); + } + + /** + * Return the raw list of servers. + * + * @return array An array of server information. + */ + public function getList() + { + $this->_loadList(); + return $this->_accounts; + } + + /** + * Loads the flag list from the preferences into the local cache. + */ + protected function _loadList() + { + if (is_null($this->_accounts)) { + $this->_accounts = json_decode($GLOBALS['prefs']->getValue('accounts'), true); + } + } + + /** + * Retrieve information on a single account. + * + * @param integer $label The label ID. + * + * @return array The configuration array, or false if label not found. + */ + public function getAccount($label) + { + $this->_loadList(); + + return isset($this->_accounts[$label]) + ? $this->_accounts[$label] + : false; + } + + /** + * Add an account. + * + * @param array $config The necessary config: + *
+     * 'port' - (integer) The remote port.
+     * 'secure' -(string) Either 'auto', 'no', or 'yes'.
+     * 'server' - (string) The server hostspec.
+     * 'type' - (string) Either 'imap' or 'pop3'.
+     * 'username' - (string) The username to use.
+     * 
+ * + * @return integer The label ID. + */ + public function addAccount($config) + { + $this->_loadList(); + + $this->_accounts[] = $config; + $this->_save(); + + end($this->_accounts); + return key($this->_accounts); + } + + /** + * Delete an account from the list. + * + * @param integer $label The label ID. + * + * @return boolean True on success. + */ + public function deleteAccount($label) + { + if ($this->getAccount($label)) { + unset($this->_accounts[$label]); + $this->_save(); + return true; + } + + return false; + } + +} diff --git a/imp/templates/prefs/accountsmanagement.inc b/imp/templates/prefs/accountsmanagement.inc new file mode 100644 index 000000000..dd6cba01f --- /dev/null +++ b/imp/templates/prefs/accountsmanagement.inc @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
: + + *
:*
:*
:
+ +
+ +" /> +" /> + +getList(); +$delete_img = Horde::img('delete.png'); +?> + + + + + + + + + + + + + + + + $val): ?> + + + + + + + + +
ServerType
+ +" /> + diff --git a/imp/themes/screen.css b/imp/themes/screen.css index 063484105..f4e297589 100644 --- a/imp/themes/screen.css +++ b/imp/themes/screen.css @@ -319,20 +319,26 @@ div.msgflags.flagForwarded, span.contextImg.flagForwarded { background-image: url("graphics/mail_forwarded.png"); } -/* Flag management (prefs) styles. */ -table.flagmanagement { +/* Accounts/flag management (prefs) styles. */ +table.accountsmanagement, table.flagmanagement { padding-bottom: 10px; } -table.flagmanagement td { +table.accountsmanagement td, table.flagmanagement td { padding-right: 12px; } -table.flagmanagement thead td { +table.accountsmanagement thead td, table.flagmanagement thead td { font-weight: bold; text-decoration: underline; } +table.accountsmanagement td.required { + color: red; +} table.flagmanagement tbody td.flagicon { text-align: center; } +table.accountsmanagement td.noneconfigured { + font-style: italic; +} .folderunsub { background: #bbb; -- 2.11.0