Re-add some accounts management code that went missing on merge.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 17 Aug 2009 21:22:09 +0000 (15:22 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 Aug 2009 01:02:13 +0000 (19:02 -0600)
Also, provide some more information on the accounts pref page.

imp/js/accountsmanagement.js [new file with mode: 0644]
imp/lib/Application.php
imp/templates/prefs/accountsmanagement.inc
imp/themes/screen.css

diff --git a/imp/js/accountsmanagement.js b/imp/js/accountsmanagement.js
new file mode 100644 (file)
index 0000000..84c77f7
--- /dev/null
@@ -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));
+});
index 1cc52bb..ca69960 100644 (file)
@@ -406,6 +406,14 @@ class IMP_Application extends Horde_Registry_Application
         /* Add necessary javascript files here (so they are added to the
          * document HEAD). */
         switch ($group) {
+        case 'accounts':
+            Horde::addScriptFile('accountsmanagement.js', 'imp', true);
+
+            Horde::addInlineScript(array(
+                'ImpAccountsmanagement.confirm_delete = ' . Horde_Serialize::serialize(_("Are you sure you want to delete this account?"), Horde_Serialize::JSON, Horde_Nls::getCharset())
+            ));
+            break;
+
         case 'flags':
             Horde::addScriptFile('colorpicker.js', 'horde', true);
             Horde::addScriptFile('flagmanagement.js', 'imp', true);
@@ -462,6 +470,10 @@ class IMP_Application extends Horde_Registry_Application
         case 'flagmanagement':
             $this->_prefsFlagManagement();
             return false;
+
+        case 'accountsmanagement':
+            $this->_prefsAccountsManagement();
+            return false;
         }
     }
 
@@ -726,6 +738,47 @@ class IMP_Application extends Horde_Registry_Application
         }
     }
 
+    /**
+     * TODO
+     */
+    protected function _prefsAccountsManagement()
+    {
+        $vars = Horde_Variables::getDefaultVariables();
+
+        switch ($vars->accounts_action) {
+        case 'add':
+            if (!$vars->accounts_server ||
+                !$vars->accounts_username) {
+                    $GLOBALS['notification']->push(_("Missing required values."), 'horde.error');
+                } else {
+                    /* Port is not required. */
+                    $port = $vars->accounts_port;
+                    if (!$port) {
+                        $port = ($vars->accounts_type == 'imap') ? 143 : 110;
+                    }
+
+                    $imp_accounts = IMP_Accounts::singleton();
+                    $imp_accounts->addAccount(array(
+                        'port' => $port,
+                        'secure' => $vars->accounts_secure,
+                        'server' => $vars->accounts_server,
+                        'type' => $vars->accounts_type,
+                        'username' => $vars->accounts_username
+                    ));
+                    $GLOBALS['notification']->push(sprintf(_("Account \"%s\" added."), $vars->accounts_server), 'horde.success');
+                }
+            break;
+
+        case 'delete':
+            $imp_accounts = IMP_Accounts::singleton();
+            $tmp = $imp_accounts->getAccount($vars->accounts_data);
+            if ($imp_accounts->deleteAccount($vars->accounts_data)) {
+                $GLOBALS['notification']->push(sprintf(_("Account \"%s\" deleted."), $tmp['server']), 'horde.success');
+            }
+            break;
+        }
+    }
+
     /* horde/services/cache.php methods. */
 
     /**
index dd6cba0..89b55b0 100644 (file)
@@ -53,8 +53,10 @@ $delete_img = Horde::img('delete.png');
 <table class="accountsmanagement">
  <thead>
   <tr>
-   <td>Server</td>
-   <td>Type</td>
+   <td><?php echo _("Server") ?></td>
+   <td><?php echo _("Type") ?></td>
+   <td><?php echo _("Port") ?></td>
+   <td><?php echo _("Secure") ?>?</td>
    <td></td>
   </tr>
  </thead>
@@ -68,6 +70,14 @@ $delete_img = Horde::img('delete.png');
   <tr id="accountsid_<?php echo $key ?>">
    <td><?php echo htmlspecialchars($val['server']) ?></td>
    <td><?php echo htmlspecialchars($val['type']) ?></td>
+   <td><?php echo htmlspecialchars($val['port']) ?></td>
+<?php if ($val['secure'] == 'auto'): ?>
+   <td><?php echo _("Auto") ?></td>
+<?php elseif ($val['secure'] == 'yes'): ?>
+   <td class="accountsSecure"><?php echo _("Yes") ?></td>
+<?php else: ?>
+   <td class="accountsNotSecure"><?php echo _("No") ?></td>
+<?php endif; ?>
    <td><a class="accountsdelete" href="#"><?php echo $delete_img ?></a></td>
   </tr>
 <?php endforeach; ?>
index fe84d47..0744474 100644 (file)
@@ -330,9 +330,12 @@ table.accountsmanagement thead td, table.flagmanagement thead td {
     font-weight: bold;
     text-decoration: underline;
 }
-table.accountsmanagement td.required {
+table.accountsmanagement td.required, .accountsNotSecure {
     color: red;
 }
+.accountsSecure {
+    color: green;
+}
 table.flagmanagement tbody td.flagicon {
     text-align: center;
 }