!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Mail Code.
16 *
17 * The Initial Developer of the Original Code is
18 * Scott MacGregor.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Scott MacGregor <mscott@mozilla.org>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 var gIdentityListBox; // the root <listbox> node
40 var gAddButton;
41 var gEditButton;
42 var gDeleteButton;
43 var gMessengerBundle;
44
45 var gAccount = null; // the account we are showing the identities for
46
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
47 function onLoad()
48 {
49 gMessengerBundle = document.getElementById("bundle_messenger");
50
51 gIdentityListBox = document.getElementById("identitiesList");
52 gAddButton = document.getElementById("addButton");
53 gEditButton = document.getElementById("editButton");
54 gDeleteButton = document.getElementById("deleteButton");
55
56 // extract the account
57 gAccount = window.arguments[0].account;
58
59 var accountName = window.arguments[0].accountName;
60 document.title = document.getElementById("bundle_prefs")
61 .getFormattedString("identity-list-title", [accountName]);
62
63 // extract the account from
64 refreshIdentityList();
65
66 // try selecting the first identity
67 gIdentityListBox.selectedIndex = 0;
68 }
69
refreshIdentityList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
70 function refreshIdentityList()
71 {
72 // remove all children
73 while (gIdentityListBox.hasChildNodes())
74 gIdentityListBox.removeChild(gIdentityListBox.lastChild);
75
76 var identities = gAccount.identities;
77 var identitiesCount = identities.Count();
78 for (var j = 0; j < identitiesCount; j++)
79 {
80 var identity = identities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity);
81 if (identity.valid)
82 {
83 var listitem = document.createElement("listitem");
84 listitem.setAttribute("label", identity.identityName);
85 listitem.setAttribute("key", identity.key);
86 gIdentityListBox.appendChild(listitem);
87 }
88 }
89 }
90
91 // opens the identity editor dialog
92 // identity: pass in the identity (if any) to load in the dialog
openIdentityEditor
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
93 function openIdentityEditor(identity)
94 {
95 var result = false;
96 var args = { identity: identity, account: gAccount, result: result };
97
98 window.openDialog('am-identity-edit.xul', '', 'modal,titlebar,chrome', args);
99
100 var selectedItemIndex = gIdentityListBox.selectedIndex;
101
102 if (args.result)
103 {
104 refreshIdentityList();
105 gIdentityListBox.selectedIndex = selectedItemIndex;
106 }
107 }
108
getSelectedIdentity
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
109 function getSelectedIdentity()
110 {
111 var identityKey = gIdentityListBox.selectedItems[0].getAttribute("key");
112 var identities = gAccount.identities;
113 var identitiesCount = identities.Count();
114 for (var j = 0; j < identitiesCount; j++)
115 {
116 var identity = identities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity);
117 if (identity.valid && identity.key == identityKey)
118 return identity;
119 }
120
121 return null; // no identity found
122 }
123
onEdit
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
124 function onEdit(event)
125 {
126 var id = (event.target.localName == 'listbox') ? null : getSelectedIdentity();
127 openIdentityEditor(id);
128 }
129
updateButtons
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
130 function updateButtons()
131 {
132 if (gIdentityListBox.selectedItems.length <= 0)
133 {
134 gEditButton.setAttribute("disabled", "true");
135 gDeleteButton.setAttribute("disabled", "true");
136 }
137 else
138 {
139 gEditButton.removeAttribute("disabled");
140 if (gIdentityListBox.getRowCount() > 1)
141 gDeleteButton.removeAttribute("disabled");
142 }
143 }
144
onDelete
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
145 function onDelete(event)
146 {
147 if (gIdentityListBox.getRowCount() <= 1) // don't support deleting the last identity
148 return;
149
150 gAccount.removeIdentity(getSelectedIdentity());
151 // rebuild the list
152 refreshIdentityList();
153 }
154
onOk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
155 function onOk()
156 {
157 window.arguments[0].result = true;
158 return true;
159 }
160
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
161 function onCancel()
162 {
163 return true;
164 }
165
onSetDefault
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
166 function onSetDefault(event)
167 {
168 // not implemented yet
169 }