OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options.passwordsExceptions', function() { | 5 cr.define('options.passwordsExceptions', function() { |
6 | 6 |
7 const List = cr.ui.List; | 7 const List = cr.ui.List; |
8 const ListItem = cr.ui.ListItem; | 8 const ListItem = cr.ui.ListItem; |
9 const ArrayDataModel = cr.ui.ArrayDataModel; | 9 const ArrayDataModel = cr.ui.ArrayDataModel; |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 /** | 29 /** |
30 * Call when an element is decorated as a list item. | 30 * Call when an element is decorated as a list item. |
31 */ | 31 */ |
32 decorate: function() { | 32 decorate: function() { |
33 ListItem.prototype.decorate.call(this); | 33 ListItem.prototype.decorate.call(this); |
34 | 34 |
35 // Labels for display | 35 // Labels for display |
36 var urlLabel = cr.doc.createElement('span'); | 36 var urlLabel = cr.doc.createElement('span'); |
37 urlLabel.textContent = this.url; | 37 urlLabel.textContent = this.url; |
38 this.appendChild(urlLabel); | 38 this.appendChild(urlLabel); |
| 39 this.urlLabel = urlLabel; |
39 | 40 |
40 var usernameLabel = cr.doc.createElement('span'); | 41 var usernameLabel = cr.doc.createElement('span'); |
41 usernameLabel.textContent = this.username; | 42 usernameLabel.textContent = this.username; |
42 usernameLabel.className = 'passwordsUsername'; | 43 usernameLabel.className = 'passwordsUsername'; |
43 this.appendChild(usernameLabel); | 44 this.appendChild(usernameLabel); |
44 | |
45 this.urlLabel = urlLabel; | |
46 this.usernameLabel = usernameLabel; | 45 this.usernameLabel = usernameLabel; |
47 }, | 46 }, |
48 | 47 |
49 /** | 48 /** |
50 * Get the url for the entry. | 49 * Get the url for the entry. |
51 * @type {string} | 50 * @type {string} |
52 */ | 51 */ |
53 get url() { | 52 get url() { |
54 return this.dataItem[0]; | 53 return this.dataItem[0]; |
55 }, | 54 }, |
56 set url(url) { | 55 set url(url) { |
57 this.dataItem[0] = url; | 56 this.dataItem[0] = url; |
58 }, | 57 }, |
59 | 58 |
60 /** | 59 /** |
61 * Get the username for the entry. | 60 * Get the username for the entry. |
62 * @type {string} | 61 * @type {string} |
63 */ | 62 */ |
64 get username() { | 63 get username() { |
65 return this.dataItem[1]; | 64 return this.dataItem[1]; |
| 65 }, |
| 66 set username(username) { |
| 67 this.dataItem[1] = username; |
| 68 }, |
| 69 }; |
| 70 |
| 71 /** |
| 72 * Creates a new PasswordExceptions list item. |
| 73 * @param {Array} entry A pair of the form [url, username]. |
| 74 * @constructor |
| 75 * @extends {cr.ui.ListItem} |
| 76 */ |
| 77 function PasswordExceptionsListItem(entry) { |
| 78 var el = cr.doc.createElement('li'); |
| 79 el.dataItem = entry; |
| 80 el.__proto__ = PasswordExceptionsListItem.prototype; |
| 81 el.decorate(); |
| 82 |
| 83 return el; |
| 84 } |
| 85 |
| 86 PasswordExceptionsListItem.prototype = { |
| 87 __proto__: ListItem.prototype, |
| 88 |
| 89 /** |
| 90 * Call when an element is decorated as a list item. |
| 91 */ |
| 92 decorate: function() { |
| 93 ListItem.prototype.decorate.call(this); |
| 94 |
| 95 // Labels for display |
| 96 var urlLabel = cr.doc.createElement('span'); |
| 97 urlLabel.textContent = this.url; |
| 98 this.appendChild(urlLabel); |
| 99 this.urlLabel = urlLabel; |
66 }, | 100 }, |
67 set username(username) { | 101 |
68 this.dataItem[1] = username; | 102 /** |
| 103 * Get the url for the entry. |
| 104 * @type {string} |
| 105 */ |
| 106 get url() { |
| 107 return this.dataItem; |
| 108 }, |
| 109 set url(url) { |
| 110 this.dataItem = url; |
69 }, | 111 }, |
70 }; | 112 }; |
71 | 113 |
| 114 |
72 /** | 115 /** |
73 * Create a new passwords list. | 116 * Create a new passwords list. |
74 * @constructor | 117 * @constructor |
75 * @extends {cr.ui.List} | 118 * @extends {cr.ui.List} |
76 */ | 119 */ |
77 var PasswordsList = cr.ui.define('list'); | 120 var PasswordsList = cr.ui.define('list'); |
78 | 121 |
79 PasswordsList.prototype = { | 122 PasswordsList.prototype = { |
80 __proto__: List.prototype, | 123 __proto__: List.prototype, |
81 /** | 124 /** |
(...skipping 12 matching lines...) Expand all Loading... |
94 createItem: function(entry) { | 137 createItem: function(entry) { |
95 return new PasswordsListItem(entry); | 138 return new PasswordsListItem(entry); |
96 }, | 139 }, |
97 | 140 |
98 /** | 141 /** |
99 * Adds an entry to the js model. | 142 * Adds an entry to the js model. |
100 * @param {Array} entry A pair of the form [url, username]. | 143 * @param {Array} entry A pair of the form [url, username]. |
101 */ | 144 */ |
102 addEntry: function(entry) { | 145 addEntry: function(entry) { |
103 this.dataModel.push(entry); | 146 this.dataModel.push(entry); |
| 147 this.listArea.updateButtonSensitivity(); |
104 }, | 148 }, |
105 | 149 |
106 /** | 150 /** |
107 * Remove all entries from the js model. | 151 * Remove all entries from the js model. |
108 */ | 152 */ |
109 clear: function() { | 153 clear: function() { |
110 this.dataModel = new ArrayDataModel([]); | 154 this.dataModel = new ArrayDataModel([]); |
| 155 this.listArea.updateButtonSensitivity(); |
111 }, | 156 }, |
112 | 157 |
113 /** | 158 /** |
114 * Remove selected row from browser's model. | 159 * Remove selected row from browser's model. |
115 */ | 160 */ |
116 removeSelectedRow: function() { | 161 removeSelectedRow: function() { |
117 var selectedIndex = this.selectionModel.selectedIndex; | 162 var selectedIndex = this.selectionModel.selectedIndex; |
118 PasswordsExceptions.removeAutofillable(selectedIndex); | 163 PasswordsExceptions.removeSavedPassword(selectedIndex); |
119 }, | 164 }, |
120 | 165 |
121 showSelectedPassword: function() { | 166 showSelectedPassword: function() { |
122 var selectedIndex = this.selectionModel.selectedIndex; | 167 var selectedIndex = this.selectionModel.selectedIndex; |
123 PasswordsExceptions.showSelectedPassword(selectedIndex); | 168 PasswordsExceptions.showSelectedPassword(selectedIndex); |
124 }, | 169 }, |
125 | 170 |
| 171 /** |
| 172 * The length of the list. |
| 173 */ |
| 174 get length() { |
| 175 return this.dataModel.length; |
| 176 }, |
126 }; | 177 }; |
127 | 178 |
128 var ListArea = cr.ui.define('div'); | 179 /** |
| 180 * Create a new passwords list. |
| 181 * @constructor |
| 182 * @extends {cr.ui.List} |
| 183 */ |
| 184 var PasswordExceptionsList = cr.ui.define('list'); |
129 | 185 |
130 ListArea.prototype = { | 186 PasswordExceptionsList.prototype = { |
| 187 __proto__: List.prototype, |
| 188 /** |
| 189 * Called when an element is decorated as a list. |
| 190 */ |
| 191 decorate: function() { |
| 192 List.prototype.decorate.call(this); |
| 193 |
| 194 this.dataModel = new ArrayDataModel([]); |
| 195 }, |
| 196 |
| 197 /** |
| 198 * Creates an item to go in the list. |
| 199 * @param {Object} entry The element from the data model for this row. |
| 200 */ |
| 201 createItem: function(entry) { |
| 202 return new PasswordExceptionsListItem(entry); |
| 203 }, |
| 204 |
| 205 /** |
| 206 * Adds an entry to the js model. |
| 207 * @param {Array} entry A pair of the form [url, username]. |
| 208 */ |
| 209 addEntry: function(entry) { |
| 210 this.dataModel.push(entry); |
| 211 this.listArea.updateButtonSensitivity(); |
| 212 }, |
| 213 |
| 214 /** |
| 215 * Remove all entries from the js model. |
| 216 */ |
| 217 clear: function() { |
| 218 this.dataModel = new ArrayDataModel([]); |
| 219 this.listArea.updateButtonSensitivity(); |
| 220 }, |
| 221 |
| 222 /** |
| 223 * Remove selected row from browser's model. |
| 224 */ |
| 225 removeSelectedRow: function() { |
| 226 var selectedIndex = this.selectionModel.selectedIndex; |
| 227 PasswordsExceptions.removePasswordException(selectedIndex); |
| 228 }, |
| 229 |
| 230 /** |
| 231 * The length of the list. |
| 232 */ |
| 233 get length() { |
| 234 return this.dataModel.length; |
| 235 }, |
| 236 }; |
| 237 |
| 238 /** |
| 239 * Create a new passwords list area. |
| 240 * @constructor |
| 241 * @extends {cr.ui.div} |
| 242 */ |
| 243 var PasswordsListArea = cr.ui.define('div'); |
| 244 |
| 245 PasswordsListArea.prototype = { |
131 __proto__: HTMLDivElement.prototype, | 246 __proto__: HTMLDivElement.prototype, |
132 | 247 |
133 decorate: function() { | 248 decorate: function() { |
134 this.passwordsList = this.querySelector('list'); | 249 this.passwordsList = this.querySelector('list'); |
135 this.passwordsList.contentType = this.contentType; | 250 this.passwordsList.listArea = this; |
136 | 251 |
137 PasswordsList.decorate(this.passwordsList); | 252 PasswordsList.decorate(this.passwordsList); |
138 this.passwordsList.selectionModel.addEventListener( | 253 this.passwordsList.selectionModel.addEventListener( |
139 'change', cr.bind(this.handleOnSelectionChange_, this)); | 254 'change', cr.bind(this.handleOnSelectionChange_, this)); |
140 | 255 |
141 var removeRow = cr.doc.createElement('button'); | 256 var removeRow = cr.doc.createElement('button'); |
142 removeRow.textContent = templateData.passwordsRemoveButton; | 257 removeRow.textContent = templateData.passwordsRemoveButton; |
143 this.appendChild(removeRow); | 258 this.appendChild(removeRow); |
144 this.removeRow = removeRow; | 259 this.removeRow = removeRow; |
145 | 260 |
| 261 var removeAll = cr.doc.createElement('button'); |
| 262 removeAll.textContent = templateData.passwordsRemoveAllButton; |
| 263 this.appendChild(removeAll); |
| 264 this.removeAll = removeAll; |
| 265 |
146 var showHidePassword = cr.doc.createElement('button'); | 266 var showHidePassword = cr.doc.createElement('button'); |
147 showHidePassword.textContent = templateData.passwordsShowButton; | 267 showHidePassword.textContent = templateData.passwordsShowButton; |
148 this.appendChild(showHidePassword); | 268 this.appendChild(showHidePassword); |
149 this.showHidePassword = showHidePassword; | 269 this.showHidePassword = showHidePassword; |
150 this.showingPassword = false | 270 this.showingPassword = false |
151 | 271 |
152 var passwordLabel = cr.doc.createElement('span'); | 272 var passwordLabel = cr.doc.createElement('span'); |
153 this.appendChild(passwordLabel); | 273 this.appendChild(passwordLabel); |
154 this.passwordLabel = passwordLabel; | 274 this.passwordLabel = passwordLabel; |
155 | 275 |
156 var self = this; | 276 var self = this; |
157 removeRow.onclick = function(event) { | 277 removeRow.onclick = function(event) { |
158 self.passwordsList.removeSelectedRow(); | 278 self.passwordsList.removeSelectedRow(); |
159 }; | 279 }; |
160 | 280 |
| 281 removeAll.onclick = function(event) { |
| 282 OptionsPage.showOverlay('passwordsRemoveAllOverlay'); |
| 283 }; |
| 284 |
161 showHidePassword.onclick = function(event) { | 285 showHidePassword.onclick = function(event) { |
162 if(self.showingPassword) { | 286 if(self.showingPassword) { |
163 self.passwordLabel.textContent = ""; | 287 self.passwordLabel.textContent = ""; |
164 this.textContent = templateData.passwordsShowButton; | 288 this.textContent = templateData.passwordsShowButton; |
165 } else { | 289 } else { |
166 self.passwordsList.showSelectedPassword(); | 290 self.passwordsList.showSelectedPassword(); |
167 this.textContent = templateData.passwordsHideButton; | 291 this.textContent = templateData.passwordsHideButton; |
168 } | 292 } |
169 self.showingPassword = !self.showingPassword; | 293 self.showingPassword = !self.showingPassword; |
170 }; | 294 }; |
171 | 295 |
172 this.updateButtonSensitivity(); | 296 this.updateButtonSensitivity(); |
173 }, | 297 }, |
174 | 298 |
175 /** | |
176 * The content type for the exceptions area, such as 'passwords' | |
177 * @type {string} | |
178 */ | |
179 get contentType() { | |
180 return this.getAttribute('contentType'); | |
181 }, | |
182 set contentType(type) { | |
183 return this.getAttribute('contentType', type); | |
184 }, | |
185 | |
186 displayReturnedPassword: function(password) { | 299 displayReturnedPassword: function(password) { |
187 this.passwordLabel.textContent = password; | 300 this.passwordLabel.textContent = password; |
188 }, | 301 }, |
189 | 302 |
190 /** | 303 /** |
191 * Update the button's states | 304 * Update the button's states |
192 */ | 305 */ |
193 updateButtonSensitivity: function() { | 306 updateButtonSensitivity: function() { |
194 var selectionSize = autofillableLoginsList.selectedItems.length; | 307 var selectionSize = this.passwordsList.selectedItems.length; |
195 this.removeRow.disabled = selectionSize == 0; | 308 this.removeRow.disabled = selectionSize == 0; |
196 this.showHidePassword.disabled = selectionSize == 0; | 309 this.showHidePassword.disabled = selectionSize == 0; |
| 310 this.removeAll.disabled = this.passwordsList.length == 0; |
197 }, | 311 }, |
198 | 312 |
199 /** | 313 /** |
200 * Callback from selection model | 314 * Callback from selection model |
201 * @param {!cr.Event} ce Event with change info. | 315 * @param {!cr.Event} ce Event with change info. |
202 * @private | 316 * @private |
203 */ | 317 */ |
204 handleOnSelectionChange_: function(ce) { | 318 handleOnSelectionChange_: function(ce) { |
205 this.passwordLabel.textContent = ""; | 319 this.passwordLabel.textContent = ""; |
206 this.showHidePassword.textContent = templateData.passwordsShowButton; | 320 this.showHidePassword.textContent = templateData.passwordsShowButton; |
207 this.showingPassword = false; | 321 this.showingPassword = false; |
208 this.updateButtonSensitivity(); | 322 this.updateButtonSensitivity(); |
209 }, | 323 }, |
210 }; | 324 }; |
211 | 325 |
| 326 /** |
| 327 * Create a new passwords list area. |
| 328 * @constructor |
| 329 * @extends {cr.ui.div} |
| 330 */ |
| 331 var PasswordExceptionsListArea = cr.ui.define('div'); |
| 332 |
| 333 PasswordExceptionsListArea.prototype = { |
| 334 __proto__: HTMLDivElement.prototype, |
| 335 |
| 336 decorate: function() { |
| 337 this.passwordExceptionsList = this.querySelector('list'); |
| 338 this.passwordExceptionsList.listArea = this; |
| 339 |
| 340 PasswordExceptionsList.decorate(this.passwordExceptionsList); |
| 341 this.passwordExceptionsList.selectionModel.addEventListener( |
| 342 'change', cr.bind(this.handleOnSelectionChange_, this)); |
| 343 |
| 344 var removeRow = cr.doc.createElement('button'); |
| 345 removeRow.textContent = templateData.passwordsRemoveButton; |
| 346 this.appendChild(removeRow); |
| 347 this.removeRow = removeRow; |
| 348 |
| 349 var removeAll = cr.doc.createElement('button'); |
| 350 removeAll.textContent = templateData.passwordsRemoveAllButton; |
| 351 this.appendChild(removeAll); |
| 352 this.removeAll = removeAll; |
| 353 |
| 354 var self = this; |
| 355 removeRow.onclick = function(event) { |
| 356 self.passwordExceptionsList.removeSelectedRow(); |
| 357 }; |
| 358 |
| 359 removeAll.onclick = function(event) { |
| 360 PasswordsExceptions.removeAllPasswordExceptions(); |
| 361 }; |
| 362 |
| 363 this.updateButtonSensitivity(); |
| 364 }, |
| 365 |
| 366 /** |
| 367 * Update the button's states |
| 368 */ |
| 369 updateButtonSensitivity: function() { |
| 370 var selectionSize = this.passwordExceptionsList.selectedItems.length; |
| 371 this.removeRow.disabled = selectionSize == 0; |
| 372 this.removeAll.disabled = this.passwordExceptionsList.length == 0; |
| 373 }, |
| 374 |
| 375 /** |
| 376 * Callback from selection model |
| 377 * @param {!cr.Event} ce Event with change info. |
| 378 * @private |
| 379 */ |
| 380 handleOnSelectionChange_: function(ce) { |
| 381 this.updateButtonSensitivity(); |
| 382 }, |
| 383 }; |
| 384 |
| 385 |
212 return { | 386 return { |
213 PasswordsListItem: PasswordsListItem, | 387 PasswordsListItem: PasswordsListItem, |
| 388 PasswordExceptionsListItem: PasswordExceptionsListItem, |
214 PasswordsList: PasswordsList, | 389 PasswordsList: PasswordsList, |
215 ListArea: ListArea | 390 PasswordExceptionsList: PasswordExceptionsList, |
| 391 PasswordsListArea: PasswordsListArea, |
| 392 PasswordExceptionsListArea: PasswordExceptionsListArea |
216 }; | 393 }; |
217 }); | 394 }); |
OLD | NEW |