This is just some static backup of the original site, don't expect every link to work!

source: chrome/content/v_identity/vI_msgIdentityClone.js @ 9e9bab

Last change on this file since 9e9bab was 9e9bab, checked in by root <root@…>, 15 years ago

initial import v0.4.0

  • Property mode set to 100644
File size: 10.4 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s): Thunderbird Developers
23 * ***** END LICENSE BLOCK ***** */
24
25vI_msgIdentityClone = {
26    icon_usualId_class : "identity_clone-menulist person-icon",
27    icon_virtualId_class : "identity_clone-menulist person-icon new-icon",
28    text_usualId_class : "plain menulist_clone-textbox",
29    text_virtualId_class : "plain menulist_clone-textbox vIactiv",
30   
31    elements : {
32        Obj_MsgIdentity : null,
33        Obj_MsgIdentityPopup : null,
34        Obj_MsgIdentity_clone : null,
35        Obj_MsgIdentityPopup_clone : null,
36        Obj_MsgIdentityTextbox_clone : null
37    },
38   
39    init : function() {
40        vI_msgIdentityClone.elements.Obj_MsgIdentity = document.getElementById("msgIdentity");
41        vI_msgIdentityClone.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup");
42        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone = document.getElementById("msgIdentity_clone");
43        vI_msgIdentityClone.elements.Obj_MsgIdentityPopup_clone = document.getElementById("msgIdentityPopup_clone");
44        vI_msgIdentityClone.clone_Obj_MsgIdentity();
45    },
46   
47    // double the Identity-Select Dropdown-Menu
48    // if you 'created' a virtual Identity and you close the extension area, the Virtual Identity shows up in the
49    // Identity-Dropdown Menu.
50    // problem is that there is not yet a existent Identity stored in any account for it, and other Code might
51    // access the Dropdown-Menu to know which Identity is selected. So show and change only a clone of the real one.
52    clone_Obj_MsgIdentity : function() {
53        MenuItems = vI_msgIdentityClone.elements.Obj_MsgIdentityPopup.childNodes
54        for (index = 0; index < MenuItems.length; index++) {
55            var newMenuItem = MenuItems[index].cloneNode(true);
56            newMenuItem.setAttribute("class", "identity_clone-popup-item person-icon")
57            vI_msgIdentityClone.elements.Obj_MsgIdentityPopup_clone.appendChild(newMenuItem)
58            if (vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem == MenuItems[index])
59                vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem = newMenuItem;
60            // "accountname" property changed in Thunderbird 3.x, Seamonkey 1.5x to "description"
61            newMenuItem.setAttribute("accountname", vI.helper.getAccountname(newMenuItem))
62        }
63        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
64            .setAttribute("value", vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem.getAttribute("value"));
65        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
66            .setAttribute("label", vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem.getAttribute("label"));
67        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
68            .setAttribute("accountkey", vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem.getAttribute("accountkey"));
69        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
70            .setAttribute("accountname", vI.helper.getAccountname(vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem));
71    },
72   
73    resetMenuToDefault : function () {
74        vI_msgIdentityClone.setMenuToIdentity(gAccountManager.defaultAccount.defaultIdentity.key, false);
75    },
76
77    setMenuToIdentity : function (identitykey, startup) {
78        MenuItems = vI_msgIdentityClone.elements.Obj_MsgIdentityPopup_clone.childNodes
79        for (index = 0; index < MenuItems.length; index++) {
80            if (MenuItems[index].getAttribute("value") ==
81                identitykey) {
82                    vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem =
83                        MenuItems[index];
84                    break;
85            }
86        }
87        vI_msgIdentityClone.LoadIdentity(startup);
88    },
89   
90    copySelectedIdentity : function() {
91        // copy selected Menu-Value from clone to orig.
92        MenuItems = vI_msgIdentityClone.elements.Obj_MsgIdentity.firstChild.childNodes
93        for (index = 0; index < MenuItems.length; index++) {
94            if ( MenuItems[index].getAttribute("value")
95                == vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value") ) {
96                vI_msgIdentityClone.elements.Obj_MsgIdentity.selectedItem = MenuItems[index];
97                vI_msgIdentityClone.elements.Obj_MsgIdentity.value = MenuItems[index].getAttribute("value");
98                break;
99            }
100        }
101    },
102   
103    initMsgIdentityTextbox_clone : function() {
104        if (!vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone)
105            vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone
106                = document.getElementById("msgIdentity_clone_textbox");
107    },
108   
109    // this LoadIdentity - oncommand is used by our clone MsgIdentity Menu
110    // if VIdentity Extension is closed after the extension area was opened at least once,
111    // remove the Virtual Account if a different (usual) Account is choosen in the cloned dropdown-menu
112    LoadIdentity : function(startup)
113    {
114        if (vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem.value != "vid") {
115            vI_msgIdentityClone.copySelectedIdentity();
116            vI_smtpSelector.resetMenuToMsgIdentity(
117                vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem.value);
118            vI_notificationBar.dump("## vI_msgIdentityClone: calling LoadIdentity(" + startup +") from MsgCompose\n")
119            LoadIdentity(startup);
120        }
121        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
122        vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone.value =
123            vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem.getAttribute("label");
124        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.setAttribute("accountname",
125            vI.helper.getAccountname(vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.selectedItem));
126        vI_msgIdentityClone.markAsNewAccount(vI_msgIdentityClone.isNewIdentity());
127    },
128   
129    setIdentity : function(newName) {
130        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
131        vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone.value = newName;
132        vI_msgIdentityClone.markAsNewAccount(vI_msgIdentityClone.isNewIdentity());
133    },
134   
135    blurEvent : function() {
136        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
137        var address = vI.helper.getAddress();
138        vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone.value = address.combinedName;
139        vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone.setAttribute("value",address.combinedName)
140    },
141   
142    inputEvent :  function()
143    {
144        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
145        // compare Identity with existant ones and prepare Virtual-Identity if nonexistant found
146        vI_msgIdentityClone.markAsNewAccount(vI_msgIdentityClone.isNewIdentity());
147    },
148   
149    markAsNewAccount : function(newIdentity) {
150        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
151        if (newIdentity) {
152            if (vI.replacement_functions.replaceGenericFunction()) {
153                if (vI.elements.Obj_vILogo.getAttribute("hidden") != "false") {
154                    vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone
155                        .setAttribute("class", vI_msgIdentityClone.text_virtualId_class);
156                    vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
157                        .setAttribute("class", vI_msgIdentityClone.icon_virtualId_class);
158                    if (vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
159                        .getAttribute("value") != "vid") {
160                        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
161                            .setAttribute("value","vid")
162                        var accountname = document.getElementById("prettyName-Prefix")
163                                    .getAttribute("label")
164                                    + vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
165                                    .getAttribute("accountname")
166                        vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
167                            .setAttribute("accountname", accountname)
168                    }
169                    vI.elements.Obj_vILogo.setAttribute("hidden","false");
170                }
171            }
172        }
173        else {
174            if (vI.elements.Obj_vILogo.getAttribute("hidden") != "true") {
175                vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone
176                    .setAttribute("class", vI_msgIdentityClone.text_usualId_class);
177                vI_msgIdentityClone.elements.Obj_MsgIdentity_clone
178                    .setAttribute("class", vI_msgIdentityClone.icon_usualId_class);
179                vI.Cleanup();
180                vI.elements.Obj_vILogo.setAttribute("hidden","true");
181            }
182        }
183    },
184   
185    // checks if the Identity currently described by the extension-area fields i still available as
186    // a stored identity. If so, use the stored one.
187    isNewIdentity : function()
188    {
189        vI_msgIdentityClone.initMsgIdentityTextbox_clone();
190        var address = vI.helper.getAddress();
191        var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
192        for (var i in accounts) {
193            var server = accounts[i].incomingServer;
194                //  ignore (other) virtualIdentity Accounts
195                if (!server || server.hostName == "virtualIdentity") continue;
196           
197                var identites = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
198                for (var j in identites) {
199                    var identity = identites[j];
200                    var smtpKey = identity.smtpServerKey;
201                    if (!identity.smtpServerKey) smtpKey = accounts[i].defaultIdentity.smtpServerKey;
202                    if (!identity.smtpServerKey) smtpKey = vI_smtpSelector.smtpService.defaultServer.key;
203                    if (    identity.getUnicharAttribute("fullName") == address.name &&
204                        identity.getUnicharAttribute("useremail") == address.email &&
205                        smtpKey == vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key')) {
206                    //~ if (    identity.getUnicharAttribute("fullName") == FullName &&
207                        //~ identity.getUnicharAttribute("useremail") == Useremail) {
208                            //~ // all values are identical to an existing Identity
209                            // set Identity combobox to this value
210                            vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.setAttribute("value", identity.key);
211                            vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.setAttribute("label", address.name + " <" + address.email + ">");
212                            vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.setAttribute("accountname", " - " + accounts[i].incomingServer.prettyName);
213                            vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.setAttribute("accountkey", "");
214                            return false;
215                        }
216                    }
217            }
218        return true;
219    },
220}
Note: See TracBrowser for help on using the repository browser.