Better naming of the prefs javascript code
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 Aug 2009 08:35:09 +0000 (02:35 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 Aug 2009 16:29:05 +0000 (10:29 -0600)
imp/js/accountsmanagement.js [deleted file]
imp/js/accountsprefs.js [new file with mode: 0644]
imp/js/addressbooksmanagement.js [deleted file]
imp/js/addressbooksprefs.js [new file with mode: 0644]
imp/js/flagmanagement.js [deleted file]
imp/js/flagprefs.js [new file with mode: 0644]
imp/js/foldermanagement.js [deleted file]
imp/js/folderprefs.js [new file with mode: 0644]
imp/lib/Application.php

diff --git a/imp/js/accountsmanagement.js b/imp/js/accountsmanagement.js
deleted file mode 100644 (file)
index 84c77f7..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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/js/accountsprefs.js b/imp/js/accountsprefs.js
new file mode 100644 (file)
index 0000000..ffdb542
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * 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 ImpAccountsPrefs = {
+    // 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() {
+    document.observe('click', ImpAccountsPrefs.clickHandler.bindAsEventListener(ImpAccountsPrefs));
+});
diff --git a/imp/js/addressbooksmanagement.js b/imp/js/addressbooksmanagement.js
deleted file mode 100644 (file)
index e3237f1..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * Provides the javascript for managing addressbooks.
- *
- * 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 ImpAddressbooksmanagement = {
-    // Variables set by other code: fields
-
-    deselectHeaders: function()
-    {
-        $F('unselected_search_sources').selectedIndex = $F('selected_search_sources').selectedIndex = -1;
-    },
-
-    resetHidden: function()
-    {
-        $('search_sources').setValue($F('selected_search_sources').join("\t"));
-    },
-
-    addSource: function()
-    {
-        this._sourceAction($('unselected_search_sources'), $('selected_search_sources'));
-    },
-
-    removeSource: function()
-    {
-        this._sourceAction($('selected_search_sources'), $('unselected_search_sources'));
-    },
-
-    _sourceAction: function(from, to)
-    {
-        var i = 1;
-
-        $A(from.options).slice(1).each(function(s) {
-            if (s.selected) {
-                to[i] = s.cloneNode(false);
-                s.remove();
-            }
-            ++i;
-        });
-
-        this.resetHidden();
-    },
-
-    moveSourceUp: function()
-    {
-        var sss = $('selected_search_sources'),
-            sel = sss.selectedIndex;
-
-        if (sel == -1 || sss.length <= 2) {
-            return;
-        }
-
-        // Deselect everything but the first selected item
-        sss.selectedIndex = sel;
-
-        sss.options[sel].previous().insert({ before: sss.options[sel].cloneNode(false) });
-        sss.options[sel].remove();
-
-        this.resetHidden();
-    },
-
-    moveSourceDown: function()
-    {
-        var i,
-            sss = $('selected_search_sources'),
-            sel = sss.selectedIndex,
-            l = sss.length,
-            tmp = [];
-
-        if (sel == -1 || l <= 2) {
-            return;
-        }
-
-        // deselect everything but the first selected item
-        sss.selectedIndex = sel;
-
-        sss.options[sel].next().insert({ after: sss.options[sel].cloneNode(false) });
-        sss.options[sel].remove();
-
-        this.resetHidden();
-    },
-
-    updateSearchFields: function()
-    {
-        var sv = this._getSelectedValue(false),
-            sf = $('search_fields');
-
-        sf.update('');
-
-        this.fields.each(function(f) {
-            if (f[0] == sv) {
-                f.slice(1).each(function(o) {
-                    var tmp = new Option(o[1], o[0]);
-                    if (o[2]) {
-                        tmp.selected = true;
-                    }
-                    sf.insert(tmp);
-                });
-            }
-        });
-
-        this.changeSearchFields();
-    },
-
-    _getSelectedValue: function(index)
-    {
-        var sss = $('selected_search_sources');
-
-        if (sss) {
-            return index ? sss.selectedIndex : sss.options[sss.selectedIndex].value;
-        } else {
-            return index ? 0 : this.fields[0][0];
-        }
-    },
-
-    changeSearchFields: function()
-    {
-        var data = [],
-            i = 0,
-            sf = $('search_fields'),
-            sv = this._getSelectedValue(true);
-
-        $A(sf.options).each(function(o) {
-            this.fields[sv][i + 1][2] = o.selected;
-            ++i;
-        }.bind(this));
-
-        this.fields.each(function(f) {
-            var tmp = [ f[0] ];
-            f.slice(1).each(function(o) {
-                if (o[2]) {
-                    tmp.push(o[0]);
-                }
-            });
-            data.push(tmp.join("\t"));
-        });
-
-        $('search_fields_string').setValue(data.join("\n"));
-    },
-
-    onDomLoad: function()
-    {
-        this.updateSearchFields();
-
-        if ($('search_fields')) {
-            $('search_fields').observe('change', this.changeSearchFields.bind(this));
-        }
-
-        if ($('unselected_search_sources')) {
-            $('unselected_search_sources').observe('change', this.deselectHeaders.bind(this));
-            $('selected_search_sources').observe('change', function() {
-                this.deselectHeaders();
-                this.updateSearchFields();
-            }.bind(this));
-            $('addsource').observe('click', this.addSource.bind(this));
-            $('removesource').observe('click', this.removeSource.bind(this));
-            $('moveup').observe('click', this.moveSourceUp.bind(this));
-            $('movedown').observe('click', this.moveSourceDown.bind(this));
-        }
-    }
-
-};
-
-document.observe('dom:loaded', ImpAddressbooksmanagement.onDomLoad.bind(ImpAddressbooksmanagement));
diff --git a/imp/js/addressbooksprefs.js b/imp/js/addressbooksprefs.js
new file mode 100644 (file)
index 0000000..53238ad
--- /dev/null
@@ -0,0 +1,166 @@
+/**
+ * Provides the javascript for managing addressbooks.
+ *
+ * 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 ImpAddressbooksPrefs = {
+    // Variables set by other code: fields
+
+    deselectHeaders: function()
+    {
+        $F('unselected_search_sources').selectedIndex = $F('selected_search_sources').selectedIndex = -1;
+    },
+
+    resetHidden: function()
+    {
+        $('search_sources').setValue($F('selected_search_sources').join("\t"));
+    },
+
+    addSource: function()
+    {
+        this._sourceAction($('unselected_search_sources'), $('selected_search_sources'));
+    },
+
+    removeSource: function()
+    {
+        this._sourceAction($('selected_search_sources'), $('unselected_search_sources'));
+    },
+
+    _sourceAction: function(from, to)
+    {
+        var i = 1;
+
+        $A(from.options).slice(1).each(function(s) {
+            if (s.selected) {
+                to[i] = s.cloneNode(false);
+                s.remove();
+            }
+            ++i;
+        });
+
+        this.resetHidden();
+    },
+
+    moveSourceUp: function()
+    {
+        var sss = $('selected_search_sources'),
+            sel = sss.selectedIndex;
+
+        if (sel == -1 || sss.length <= 2) {
+            return;
+        }
+
+        // Deselect everything but the first selected item
+        sss.selectedIndex = sel;
+
+        sss.options[sel].previous().insert({ before: sss.options[sel].cloneNode(false) });
+        sss.options[sel].remove();
+
+        this.resetHidden();
+    },
+
+    moveSourceDown: function()
+    {
+        var i,
+            sss = $('selected_search_sources'),
+            sel = sss.selectedIndex,
+            l = sss.length,
+            tmp = [];
+
+        if (sel == -1 || l <= 2) {
+            return;
+        }
+
+        // deselect everything but the first selected item
+        sss.selectedIndex = sel;
+
+        sss.options[sel].next().insert({ after: sss.options[sel].cloneNode(false) });
+        sss.options[sel].remove();
+
+        this.resetHidden();
+    },
+
+    updateSearchFields: function()
+    {
+        var sv = this._getSelectedValue(false),
+            sf = $('search_fields');
+
+        sf.update('');
+
+        this.fields.each(function(f) {
+            if (f[0] == sv) {
+                f.slice(1).each(function(o) {
+                    var tmp = new Option(o[1], o[0]);
+                    if (o[2]) {
+                        tmp.selected = true;
+                    }
+                    sf.insert(tmp);
+                });
+            }
+        });
+
+        this.changeSearchFields();
+    },
+
+    _getSelectedValue: function(index)
+    {
+        var sss = $('selected_search_sources');
+
+        if (sss) {
+            return index ? sss.selectedIndex : sss.options[sss.selectedIndex].value;
+        } else {
+            return index ? 0 : this.fields[0][0];
+        }
+    },
+
+    changeSearchFields: function()
+    {
+        var data = [],
+            i = 0,
+            sf = $('search_fields'),
+            sv = this._getSelectedValue(true);
+
+        $A(sf.options).each(function(o) {
+            this.fields[sv][i + 1][2] = o.selected;
+            ++i;
+        }.bind(this));
+
+        this.fields.each(function(f) {
+            var tmp = [ f[0] ];
+            f.slice(1).each(function(o) {
+                if (o[2]) {
+                    tmp.push(o[0]);
+                }
+            });
+            data.push(tmp.join("\t"));
+        });
+
+        $('search_fields_string').setValue(data.join("\n"));
+    },
+
+    onDomLoad: function()
+    {
+        this.updateSearchFields();
+
+        if ($('search_fields')) {
+            $('search_fields').observe('change', this.changeSearchFields.bind(this));
+        }
+
+        if ($('unselected_search_sources')) {
+            $('unselected_search_sources').observe('change', this.deselectHeaders.bind(this));
+            $('selected_search_sources').observe('change', function() {
+                this.deselectHeaders();
+                this.updateSearchFields();
+            }.bind(this));
+            $('addsource').observe('click', this.addSource.bind(this));
+            $('removesource').observe('click', this.removeSource.bind(this));
+            $('moveup').observe('click', this.moveSourceUp.bind(this));
+            $('movedown').observe('click', this.moveSourceDown.bind(this));
+        }
+    }
+
+};
+
+document.observe('dom:loaded', ImpAddressbooksPrefs.onDomLoad.bind(ImpAddressbooksPrefs));
diff --git a/imp/js/flagmanagement.js b/imp/js/flagmanagement.js
deleted file mode 100644 (file)
index 4acce0b..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Provides the javascript for managing message flags.
- *
- * 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 ImpFlagmanagement = {
-    // Variables set by other code: confirm_delete, new_prompt
-
-    addFlag: function()
-    {
-        var category = window.prompt(this.new_prompt, '');
-        if (category) {
-            this._sendData('add', category);
-        }
-    },
-
-    _sendData: function(a, d)
-    {
-        $('flag_action').setValue(a)
-        $('flag_data').setValue(d);
-        $('prefs').submit();
-    },
-
-    clickHandler: function(e)
-    {
-        if (e.isRightClick()) {
-            return;
-        }
-
-        var elt = e.element(), elt2, id;
-
-        while (Object.isElement(elt)) {
-            if (elt.hasClassName('flagcolorpicker')) {
-                elt2 = elt.previous('INPUT');
-                id = elt2.readAttribute('id');
-                new ColorPicker({
-                    color: $F(elt2),
-                    offsetParent: elt,
-                    update: [[ id, 'value' ], [ id, 'background' ]]
-                });
-                e.stop();
-                return;
-            }
-
-            if (elt.hasClassName('flagdelete')) {
-                if (window.confirm(this.confirm_delete)) {
-                    this._sendData('delete', elt.previous('INPUT').readAttribute('id'));
-                }
-                e.stop();
-                return;
-            }
-
-            switch (elt.readAttribute('id')) {
-            case 'new_button':
-                this.addFlag();
-                break;
-            }
-
-            elt = elt.up();
-        }
-    },
-
-    resetHandler: function()
-    {
-        $('prefs').getInputs('text').each(function(i) {
-            if (i.readAttribute('id').startsWith('color_')) {
-                i.setStyle({ backgroundColor: $F(i) });
-            }
-        });
-    }
-
-};
-
-document.observe('dom:loaded', function() {
-    var fm = ImpFlagmanagement;
-    document.observe('click', fm.clickHandler.bindAsEventListener(fm));
-    $('prefs').observe('reset', function() { fm.resetHandler.defer(); });
-});
diff --git a/imp/js/flagprefs.js b/imp/js/flagprefs.js
new file mode 100644 (file)
index 0000000..466d32a
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * Provides the javascript for managing message flags.
+ *
+ * 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 ImpFlagPrefs = {
+    // Variables set by other code: confirm_delete, new_prompt
+
+    addFlag: function()
+    {
+        var category = window.prompt(this.new_prompt, '');
+        if (category) {
+            this._sendData('add', category);
+        }
+    },
+
+    _sendData: function(a, d)
+    {
+        $('flag_action').setValue(a)
+        $('flag_data').setValue(d);
+        $('prefs').submit();
+    },
+
+    clickHandler: function(e)
+    {
+        if (e.isRightClick()) {
+            return;
+        }
+
+        var elt = e.element(), elt2, id;
+
+        while (Object.isElement(elt)) {
+            if (elt.hasClassName('flagcolorpicker')) {
+                elt2 = elt.previous('INPUT');
+                id = elt2.readAttribute('id');
+                new ColorPicker({
+                    color: $F(elt2),
+                    offsetParent: elt,
+                    update: [[ id, 'value' ], [ id, 'background' ]]
+                });
+                e.stop();
+                return;
+            }
+
+            if (elt.hasClassName('flagdelete')) {
+                if (window.confirm(this.confirm_delete)) {
+                    this._sendData('delete', elt.previous('INPUT').readAttribute('id'));
+                }
+                e.stop();
+                return;
+            }
+
+            switch (elt.readAttribute('id')) {
+            case 'new_button':
+                this.addFlag();
+                break;
+            }
+
+            elt = elt.up();
+        }
+    },
+
+    resetHandler: function()
+    {
+        $('prefs').getInputs('text').each(function(i) {
+            if (i.readAttribute('id').startsWith('color_')) {
+                i.setStyle({ backgroundColor: $F(i) });
+            }
+        });
+    }
+
+};
+
+document.observe('dom:loaded', function() {
+    var fp = ImpFlagPrefs;
+    document.observe('click', fp.clickHandler.bindAsEventListener(fp));
+    $('prefs').observe('reset', function() { fp.resetHandler.defer(); });
+});
diff --git a/imp/js/foldermanagement.js b/imp/js/foldermanagement.js
deleted file mode 100644 (file)
index 0c59a86..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Provides the javascript for managing folders.
- *
- * 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 ImpFoldermanagement = {
-    // Variables defined by other code: folders
-
-    newFolderName: function(f, fn, p1, p2)
-    {
-        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 + ']';
-            }
-        }
-    }
-
-};
-
-document.observe('dom:loaded', function() {
-    var fm = ImpFoldermanagement;
-    fm.folders.each(function(f) {
-        $(f[0]).observe('change', fm.newFolderName.bind(fm, 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;
-            break;
-        }
-    }
-}
diff --git a/imp/js/folderprefs.js b/imp/js/folderprefs.js
new file mode 100644 (file)
index 0000000..a02f1f3
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * Provides the javascript for managing folders.
+ *
+ * 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 ImpFolderPrefs = {
+    // Variables defined by other code: folders
+
+    newFolderName: function(f, fn, p1, p2)
+    {
+        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 + ']';
+            }
+        }
+    }
+
+};
+
+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;
+            break;
+        }
+    }
+}
index 3491d38..94c93fe 100644 (file)
@@ -418,7 +418,7 @@ class IMP_Application extends Horde_Registry_Application
          * document HEAD). */
         switch ($group) {
         case 'accounts':
-            Horde::addScriptFile('accountsmanagement.js', 'imp', true);
+            Horde::addScriptFile('accountsprefs.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())
@@ -431,7 +431,7 @@ class IMP_Application extends Horde_Registry_Application
 
         case 'flags':
             Horde::addScriptFile('colorpicker.js', 'horde', true);
-            Horde::addScriptFile('flagmanagement.js', 'imp', true);
+            Horde::addScriptFile('flagprefs.js', 'imp', true);
 
             Horde::addInlineScript(array(
                 'ImpFlagmanagement.new_prompt = ' . Horde_Serialize::serialize(_("Please enter the label for the new flag:"), Horde_Serialize::JSON, Horde_Nls::getCharset()),
@@ -441,7 +441,7 @@ class IMP_Application extends Horde_Registry_Application
 
         case 'identities':
             if (!$GLOBALS['prefs']->isLocked('sent_mail_folder')) {
-                Horde::addScriptFile('foldermanagement.js', 'imp', true);
+                Horde::addScriptFile('folderprefs.js', 'imp', true);
                 Horde::addInlineScript(array(
                     'ImpFoldermanagement.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())
                 ));
@@ -465,7 +465,7 @@ class IMP_Application extends Horde_Registry_Application
             }
 
             if (!empty($code)) {
-                Horde::addScriptFile('foldermanagement.js', 'imp', true);
+                Horde::addScriptFile('folderprefs.js', 'imp', true);
                 Horde::addInlineScript(array(
                     'ImpFoldermanagement.folders = ' . Horde_Serialize::serialize($code, Horde_Serialize::JSON, Horde_Nls::getCharset())
                 ));
@@ -891,7 +891,7 @@ class IMP_Application extends Horde_Registry_Application
             ++$source_count;
         }
 
-        Horde::addScriptFile('addressbooksmanagement.js', 'imp', true);
+        Horde::addScriptFile('addressbooksprefs.js', 'imp', true);
         Horde::addInlineScript(array(
             'ImpAddressbooksmanagement.fields = ' . Horde_Serialize::serialize($search_fields, Horde_Serialize::JSON, Horde_Nls::getCharset())
         ));