OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.autofillOptions', function() { | 5 cr.define('options.autofillOptions', function() { |
6 /** @const */ var DeletableItem = options.DeletableItem; | 6 /** @const */ var DeletableItem = options.DeletableItem; |
7 /** @const */ var DeletableItemList = options.DeletableItemList; | 7 /** @const */ var DeletableItemList = options.DeletableItemList; |
8 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 8 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
9 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 9 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
10 | 10 |
11 /** | 11 /** |
12 * @return {!HTMLButtonElement} | 12 * @return {!HTMLButtonElement} |
13 */ | 13 */ |
14 function AutofillEditProfileButton(guid, edit) { | 14 function AutofillEditProfileButton(edit) { |
15 var editButtonEl = /** @type {HTMLButtonElement} */( | 15 var editButtonEl = /** @type {HTMLButtonElement} */( |
16 document.createElement('button')); | 16 document.createElement('button')); |
17 editButtonEl.className = 'list-inline-button custom-appearance'; | 17 editButtonEl.className = 'list-inline-button custom-appearance'; |
18 editButtonEl.textContent = | 18 editButtonEl.textContent = |
19 loadTimeData.getString('autofillEditProfileButton'); | 19 loadTimeData.getString('autofillEditProfileButton'); |
20 editButtonEl.onclick = function(e) { edit(guid); }; | 20 editButtonEl.onclick = edit; |
21 | 21 |
22 editButtonEl.onmousedown = function(e) { | 22 editButtonEl.onmousedown = function(e) { |
23 // Don't select the row when clicking the button. | 23 // Don't select the row when clicking the button. |
24 e.stopPropagation(); | 24 e.stopPropagation(); |
25 // Don't focus on the button when clicking it. | 25 // Don't focus on the button when clicking it. |
26 e.preventDefault(); | 26 e.preventDefault(); |
27 }; | 27 }; |
28 | 28 |
29 return editButtonEl; | 29 return editButtonEl; |
30 } | 30 } |
31 | 31 |
32 /** | 32 /** |
33 * Creates a new address list item. | 33 * Creates a new address list item. |
34 * @param {Array} entry An array of the form [guid, label]. | 34 * @param {Object} entry An object with metadata about an address profile. |
35 * @constructor | 35 * @constructor |
36 * @extends {options.DeletableItem} | 36 * @extends {options.DeletableItem} |
37 */ | 37 */ |
38 function AddressListItem(entry) { | 38 function AddressListItem(entry) { |
39 var el = cr.doc.createElement('div'); | 39 var el = cr.doc.createElement('div'); |
40 el.guid = entry[0]; | 40 for (var key in entry) { |
41 el.label = entry[1]; | 41 el[key] = entry[key]; |
| 42 } |
42 el.__proto__ = AddressListItem.prototype; | 43 el.__proto__ = AddressListItem.prototype; |
43 el.decorate(); | 44 el.decorate(); |
44 | 45 |
45 return el; | 46 return el; |
46 } | 47 } |
47 | 48 |
48 AddressListItem.prototype = { | 49 AddressListItem.prototype = { |
49 __proto__: DeletableItem.prototype, | 50 __proto__: DeletableItem.prototype, |
50 | 51 |
51 /** @override */ | 52 /** @override */ |
52 decorate: function() { | 53 decorate: function() { |
53 DeletableItem.prototype.decorate.call(this); | 54 DeletableItem.prototype.decorate.call(this); |
54 | 55 |
55 // The stored label. | 56 // The stored label. |
56 var label = this.ownerDocument.createElement('div'); | 57 var label = this.ownerDocument.createElement('div'); |
57 label.className = 'autofill-list-item'; | 58 label.className = 'autofill-list-item'; |
58 label.textContent = this.label; | 59 label.textContent = this.label; |
59 this.contentElement.appendChild(label); | 60 this.contentElement.appendChild(label); |
60 | 61 |
| 62 if (!this.isLocal) |
| 63 this.deletable = false; |
| 64 |
61 // The 'Edit' button. | 65 // The 'Edit' button. |
| 66 var guid = this.guid; |
62 var editButtonEl = AutofillEditProfileButton( | 67 var editButtonEl = AutofillEditProfileButton( |
63 this.guid, | 68 function() { AutofillOptions.loadAddressEditor(guid); }); |
64 AutofillOptions.loadAddressEditor); | |
65 this.contentElement.appendChild(editButtonEl); | 69 this.contentElement.appendChild(editButtonEl); |
66 }, | 70 }, |
67 }; | 71 }; |
68 | 72 |
69 /** | 73 /** |
70 * Creates a new credit card list item. | 74 * Creates a new credit card list item. |
71 * @param {Array} entry An array of the form [guid, label, icon]. | 75 * @param {Object} entry An object with metadata about a credit card. |
72 * @constructor | 76 * @constructor |
73 * @extends {options.DeletableItem} | 77 * @extends {options.DeletableItem} |
74 */ | 78 */ |
75 function CreditCardListItem(entry) { | 79 function CreditCardListItem(entry) { |
76 var el = cr.doc.createElement('div'); | 80 var el = cr.doc.createElement('div'); |
77 el.guid = entry[0]; | 81 for (var key in entry) { |
78 el.label = entry[1]; | 82 el[key] = entry[key]; |
79 el.icon = entry[2]; | 83 } |
80 el.description = entry[3]; | |
81 el.__proto__ = CreditCardListItem.prototype; | 84 el.__proto__ = CreditCardListItem.prototype; |
82 el.decorate(); | 85 el.decorate(); |
83 | 86 |
84 return el; | 87 return el; |
85 } | 88 } |
86 | 89 |
87 CreditCardListItem.prototype = { | 90 CreditCardListItem.prototype = { |
88 __proto__: DeletableItem.prototype, | 91 __proto__: DeletableItem.prototype, |
89 | 92 |
90 /** @override */ | 93 /** @override */ |
91 decorate: function() { | 94 decorate: function() { |
92 DeletableItem.prototype.decorate.call(this); | 95 DeletableItem.prototype.decorate.call(this); |
93 | 96 |
94 // The stored label. | 97 // The stored label. |
95 var label = this.ownerDocument.createElement('div'); | 98 var label = this.ownerDocument.createElement('div'); |
96 label.className = 'autofill-list-item'; | 99 label.className = 'autofill-list-item'; |
97 label.textContent = this.label; | 100 label.textContent = this.label; |
98 this.contentElement.appendChild(label); | 101 this.contentElement.appendChild(label); |
99 | 102 |
100 // The credit card icon. | 103 if (!this.isLocal) |
101 var icon = this.ownerDocument.createElement('img'); | 104 this.deletable = false; |
102 icon.src = this.icon; | 105 |
103 icon.alt = this.description; | 106 var guid = this.guid; |
104 this.contentElement.appendChild(icon); | 107 if (this.isCached) { |
| 108 var localCopyText = this.ownerDocument.createElement('span'); |
| 109 localCopyText.textContent = |
| 110 loadTimeData.getString('autofillDescribeLocalCopy'); |
| 111 this.contentElement.appendChild(localCopyText); |
| 112 |
| 113 var clearLocalCopyButton = AutofillEditProfileButton( |
| 114 function() { chrome.send('clearLocalCardCopy', [guid]); }); |
| 115 clearLocalCopyButton.textContent = |
| 116 loadTimeData.getString('autofillClearLocalCopyButton'); |
| 117 this.contentElement.appendChild(clearLocalCopyButton); |
| 118 } |
105 | 119 |
106 // The 'Edit' button. | 120 // The 'Edit' button. |
107 var editButtonEl = AutofillEditProfileButton( | 121 var editButtonEl = AutofillEditProfileButton( |
108 this.guid, | 122 function() { AutofillOptions.loadCreditCardEditor(guid); }); |
109 AutofillOptions.loadCreditCardEditor); | |
110 this.contentElement.appendChild(editButtonEl); | 123 this.contentElement.appendChild(editButtonEl); |
111 }, | 124 }, |
112 }; | 125 }; |
113 | 126 |
114 /** | 127 /** |
115 * Creates a new value list item. | 128 * Creates a new value list item. |
116 * @param {options.autofillOptions.AutofillValuesList} list The parent list of | 129 * @param {options.autofillOptions.AutofillValuesList} list The parent list of |
117 * this item. | 130 * this item. |
118 * @param {string} entry A string value. | 131 * @param {string} entry A string value. |
119 * @constructor | 132 * @constructor |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 368 |
356 AutofillAddressList.prototype = { | 369 AutofillAddressList.prototype = { |
357 __proto__: AutofillProfileList.prototype, | 370 __proto__: AutofillProfileList.prototype, |
358 | 371 |
359 decorate: function() { | 372 decorate: function() { |
360 AutofillProfileList.prototype.decorate.call(this); | 373 AutofillProfileList.prototype.decorate.call(this); |
361 }, | 374 }, |
362 | 375 |
363 /** @override */ | 376 /** @override */ |
364 activateItemAtIndex: function(index) { | 377 activateItemAtIndex: function(index) { |
365 AutofillOptions.loadAddressEditor(this.dataModel.item(index)[0]); | 378 AutofillOptions.loadAddressEditor(this.dataModel.item(index)); |
366 }, | 379 }, |
367 | 380 |
368 /** | 381 /** |
369 * @override | 382 * @override |
370 * @param {Array} entry | 383 * @param {Array} entry |
371 */ | 384 */ |
372 createItem: function(entry) { | 385 createItem: function(entry) { |
373 return new AddressListItem(entry); | 386 return new AddressListItem(entry); |
374 }, | 387 }, |
375 | 388 |
376 /** @override */ | 389 /** @override */ |
377 deleteItemAtIndex: function(index) { | 390 deleteItemAtIndex: function(index) { |
378 AutofillOptions.removeData(this.dataModel.item(index)[0], | 391 AutofillOptions.removeData(this.dataModel.item(index).guid, |
379 'Options_AutofillAddressDeleted'); | 392 'Options_AutofillAddressDeleted'); |
380 }, | 393 }, |
381 }; | 394 }; |
382 | 395 |
383 /** | 396 /** |
384 * Create a new credit card list. | 397 * Create a new credit card list. |
385 * @constructor | 398 * @constructor |
386 * @extends {options.DeletableItemList} | 399 * @extends {options.DeletableItemList} |
387 */ | 400 */ |
388 var AutofillCreditCardList = cr.ui.define('list'); | 401 var AutofillCreditCardList = cr.ui.define('list'); |
389 | 402 |
390 AutofillCreditCardList.prototype = { | 403 AutofillCreditCardList.prototype = { |
391 __proto__: AutofillProfileList.prototype, | 404 __proto__: AutofillProfileList.prototype, |
392 | 405 |
393 decorate: function() { | 406 decorate: function() { |
394 AutofillProfileList.prototype.decorate.call(this); | 407 AutofillProfileList.prototype.decorate.call(this); |
395 }, | 408 }, |
396 | 409 |
397 /** @override */ | 410 /** @override */ |
398 activateItemAtIndex: function(index) { | 411 activateItemAtIndex: function(index) { |
399 AutofillOptions.loadCreditCardEditor(this.dataModel.item(index)[0]); | 412 AutofillOptions.loadCreditCardEditor(this.dataModel.item(index)); |
400 }, | 413 }, |
401 | 414 |
402 /** | 415 /** |
403 * @override | 416 * @override |
404 * @param {Array} entry | 417 * @param {Array} entry |
405 */ | 418 */ |
406 createItem: function(entry) { | 419 createItem: function(entry) { |
407 return new CreditCardListItem(entry); | 420 return new CreditCardListItem(entry); |
408 }, | 421 }, |
409 | 422 |
410 /** @override */ | 423 /** @override */ |
411 deleteItemAtIndex: function(index) { | 424 deleteItemAtIndex: function(index) { |
412 AutofillOptions.removeData(this.dataModel.item(index)[0], | 425 AutofillOptions.removeData(this.dataModel.item(index).guid, |
413 'Options_AutofillCreditCardDeleted'); | 426 'Options_AutofillCreditCardDeleted'); |
414 }, | 427 }, |
415 }; | 428 }; |
416 | 429 |
417 /** | 430 /** |
418 * Create a new value list. | 431 * Create a new value list. |
419 * @constructor | 432 * @constructor |
420 * @extends {options.InlineEditableItemList} | 433 * @extends {options.InlineEditableItemList} |
421 */ | 434 */ |
422 var AutofillValuesList = cr.ui.define('list'); | 435 var AutofillValuesList = cr.ui.define('list'); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 CreditCardListItem: CreditCardListItem, | 560 CreditCardListItem: CreditCardListItem, |
548 ValuesListItem: ValuesListItem, | 561 ValuesListItem: ValuesListItem, |
549 NameListItem: NameListItem, | 562 NameListItem: NameListItem, |
550 AutofillAddressList: AutofillAddressList, | 563 AutofillAddressList: AutofillAddressList, |
551 AutofillCreditCardList: AutofillCreditCardList, | 564 AutofillCreditCardList: AutofillCreditCardList, |
552 AutofillValuesList: AutofillValuesList, | 565 AutofillValuesList: AutofillValuesList, |
553 AutofillNameValuesList: AutofillNameValuesList, | 566 AutofillNameValuesList: AutofillNameValuesList, |
554 AutofillPhoneValuesList: AutofillPhoneValuesList, | 567 AutofillPhoneValuesList: AutofillPhoneValuesList, |
555 }; | 568 }; |
556 }); | 569 }); |
OLD | NEW |