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', function() { | 5 cr.define('options', function() { |
6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 | 7 |
8 // The GUID of the loaded address. | 8 // The GUID of the loaded address. |
9 var guid; | 9 var guid; |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 AutoFillEditAddressOverlay.prototype = { | 24 AutoFillEditAddressOverlay.prototype = { |
25 __proto__: OptionsPage.prototype, | 25 __proto__: OptionsPage.prototype, |
26 | 26 |
27 /** | 27 /** |
28 * Initializes the page. | 28 * Initializes the page. |
29 */ | 29 */ |
30 initializePage: function() { | 30 initializePage: function() { |
31 OptionsPage.prototype.initializePage.call(this); | 31 OptionsPage.prototype.initializePage.call(this); |
32 | 32 |
33 var self = this; | 33 var self = this; |
34 $('autoFillEditAddressCancelButton').onclick = function(event) { | 34 $('auto-fill-edit-address-cancel-button').onclick = function(event) { |
35 self.dismissOverlay_(); | 35 self.dismissOverlay_(); |
36 } | 36 } |
37 $('autoFillEditAddressApplyButton').onclick = function(event) { | 37 $('auto-fill-edit-address-apply-button').onclick = function(event) { |
38 self.saveAddress_(); | 38 self.saveAddress_(); |
39 self.dismissOverlay_(); | 39 self.dismissOverlay_(); |
40 } | 40 } |
41 | 41 |
42 self.guid = ''; | 42 self.guid = ''; |
43 self.clearInputFields_(); | 43 self.clearInputFields_(); |
44 self.connectInputEvents_(); | 44 self.connectInputEvents_(); |
45 }, | 45 }, |
46 | 46 |
47 /** | 47 /** |
48 * Clears any uncommitted input, resets the stored GUID and dismisses the | 48 * Clears any uncommitted input, resets the stored GUID and dismisses the |
49 * overlay. | 49 * overlay. |
50 * @private | 50 * @private |
51 */ | 51 */ |
52 dismissOverlay_: function() { | 52 dismissOverlay_: function() { |
53 this.clearInputFields_(); | 53 this.clearInputFields_(); |
54 this.guid = ''; | 54 this.guid = ''; |
55 OptionsPage.closeOverlay(); | 55 OptionsPage.closeOverlay(); |
56 }, | 56 }, |
57 | 57 |
58 /** | 58 /** |
59 * Aggregates the values in the input fields into an array and sends the | 59 * Aggregates the values in the input fields into an array and sends the |
60 * array to the AutoFill handler. | 60 * array to the AutoFill handler. |
61 * @private | 61 * @private |
62 */ | 62 */ |
63 saveAddress_: function() { | 63 saveAddress_: function() { |
64 var address = new Array(); | 64 var address = new Array(); |
65 address[0] = this.guid; | 65 address[0] = this.guid; |
66 address[1] = $('fullName').value; | 66 address[1] = $('full-name').value; |
67 address[2] = $('companyName').value; | 67 address[2] = $('company-name').value; |
68 address[3] = $('addrLine1').value; | 68 address[3] = $('addr-line-1').value; |
69 address[4] = $('addrLine2').value; | 69 address[4] = $('addr-line-2').value; |
70 address[5] = $('city').value; | 70 address[5] = $('city').value; |
71 address[6] = $('state').value; | 71 address[6] = $('state').value; |
72 address[7] = $('zipCode').value; | 72 address[7] = $('zipCode').value; |
73 address[8] = $('country').value; | 73 address[8] = $('country').value; |
74 address[9] = $('phone').value; | 74 address[9] = $('phone').value; |
75 address[10] = $('fax').value; | 75 address[10] = $('fax').value; |
76 address[11] = $('email').value; | 76 address[11] = $('email').value; |
77 | 77 |
78 chrome.send('setAddress', address); | 78 chrome.send('setAddress', address); |
79 }, | 79 }, |
80 | 80 |
81 /** | 81 /** |
82 * Connects each input field to the inputFieldChanged_() method that enables | 82 * Connects each input field to the inputFieldChanged_() method that enables |
83 * or disables the 'Ok' button based on whether all the fields are empty or | 83 * or disables the 'Ok' button based on whether all the fields are empty or |
84 * not. | 84 * not. |
85 * @private | 85 * @private |
86 */ | 86 */ |
87 connectInputEvents_: function() { | 87 connectInputEvents_: function() { |
88 var self = this; | 88 var self = this; |
89 $('fullName').oninput = $('companyName').oninput = | 89 $('full-name').oninput = $('company-name').oninput = |
90 $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput = | 90 $('addr-line-1').oninput = $('addr-line-2').oninput = $('city').oninput = |
91 $('state').oninput = $('country').oninput = $('zipCode').oninput = | 91 $('state').oninput = $('country').oninput = $('zipCode').oninput = |
92 $('phone').oninput = $('fax').oninput = | 92 $('phone').oninput = $('fax').oninput = |
93 $('email').oninput = function(event) { | 93 $('email').oninput = function(event) { |
94 self.inputFieldChanged_(); | 94 self.inputFieldChanged_(); |
95 } | 95 } |
96 }, | 96 }, |
97 | 97 |
98 /** | 98 /** |
99 * Checks the values of each of the input fields and disables the 'Ok' | 99 * Checks the values of each of the input fields and disables the 'Ok' |
100 * button if all of the fields are empty. | 100 * button if all of the fields are empty. |
101 * @private | 101 * @private |
102 */ | 102 */ |
103 inputFieldChanged_: function() { | 103 inputFieldChanged_: function() { |
104 var disabled = | 104 var disabled = |
105 !$('fullName').value && !$('companyName').value && | 105 !$('full-name').value && !$('company-name').value && |
106 !$('addrLine1').value && !$('addrLine2').value && !$('city').value && | 106 !$('addr-line-1').value && !$('addr-line-2').value && |
107 !$('state').value && !$('zipCode').value && !('country').value && | 107 !$('city').value && !$('state').value && !$('zipCode').value && |
108 !$('phone').value && !$('fax').value && !$('email').value; | 108 !('country').value && !$('phone').value && !$('fax').value && |
109 $('autoFillEditAddressApplyButton').disabled = disabled; | 109 !$('email').value; |
| 110 $('auto-fill-edit-address-apply-button').disabled = disabled; |
110 }, | 111 }, |
111 | 112 |
112 /** | 113 /** |
113 * Clears the value of each input field. | 114 * Clears the value of each input field. |
114 * @private | 115 * @private |
115 */ | 116 */ |
116 clearInputFields_: function() { | 117 clearInputFields_: function() { |
117 $('fullName').value = ''; | 118 $('full-name').value = ''; |
118 $('companyName').value = ''; | 119 $('company-name').value = ''; |
119 $('addrLine1').value = ''; | 120 $('addr-line-1').value = ''; |
120 $('addrLine2').value = ''; | 121 $('addr-line-2').value = ''; |
121 $('city').value = ''; | 122 $('city').value = ''; |
122 $('state').value = ''; | 123 $('state').value = ''; |
123 $('zipCode').value = ''; | 124 $('zipCode').value = ''; |
124 $('country').value = ''; | 125 $('country').value = ''; |
125 $('phone').value = ''; | 126 $('phone').value = ''; |
126 $('fax').value = ''; | 127 $('fax').value = ''; |
127 $('email').value = ''; | 128 $('email').value = ''; |
128 }, | 129 }, |
129 | 130 |
130 /** | 131 /** |
131 * Loads the address data from |address|, sets the input fields based on | 132 * Loads the address data from |address|, sets the input fields based on |
132 * this data and stores the GUID of the address. | 133 * this data and stores the GUID of the address. |
133 * @private | 134 * @private |
134 */ | 135 */ |
135 loadAddress_: function(address) { | 136 loadAddress_: function(address) { |
136 this.setInputFields_(address); | 137 this.setInputFields_(address); |
137 this.inputFieldChanged_(); | 138 this.inputFieldChanged_(); |
138 this.guid = address['guid']; | 139 this.guid = address['guid']; |
139 }, | 140 }, |
140 | 141 |
141 /** | 142 /** |
142 * Sets the value of each input field according to |address| | 143 * Sets the value of each input field according to |address| |
143 * @private | 144 * @private |
144 */ | 145 */ |
145 setInputFields_: function(address) { | 146 setInputFields_: function(address) { |
146 $('fullName').value = address['fullName']; | 147 $('full-name').value = address['fullName']; |
147 $('companyName').value = address['companyName']; | 148 $('company-name').value = address['companyName']; |
148 $('addrLine1').value = address['addrLine1']; | 149 $('addr-line-1').value = address['addrLine1']; |
149 $('addrLine2').value = address['addrLine2']; | 150 $('addr-line-2').value = address['addrLine2']; |
150 $('city').value = address['city']; | 151 $('city').value = address['city']; |
151 $('state').value = address['state']; | 152 $('state').value = address['state']; |
152 $('zipCode').value = address['zipCode']; | 153 $('zipCode').value = address['zipCode']; |
153 $('country').value = address['country']; | 154 $('country').value = address['country']; |
154 $('phone').value = address['phone']; | 155 $('phone').value = address['phone']; |
155 $('fax').value = address['fax']; | 156 $('fax').value = address['fax']; |
156 $('email').value = address['email']; | 157 $('email').value = address['email']; |
157 }, | 158 }, |
158 }; | 159 }; |
159 | 160 |
160 AutoFillEditAddressOverlay.clearInputFields = function() { | 161 AutoFillEditAddressOverlay.clearInputFields = function() { |
161 AutoFillEditAddressOverlay.getInstance().clearInputFields_(); | 162 AutoFillEditAddressOverlay.getInstance().clearInputFields_(); |
162 }; | 163 }; |
163 | 164 |
164 AutoFillEditAddressOverlay.loadAddress = function(address) { | 165 AutoFillEditAddressOverlay.loadAddress = function(address) { |
165 AutoFillEditAddressOverlay.getInstance().loadAddress_(address); | 166 AutoFillEditAddressOverlay.getInstance().loadAddress_(address); |
166 }; | 167 }; |
167 | 168 |
168 AutoFillEditAddressOverlay.setTitle = function(title) { | 169 AutoFillEditAddressOverlay.setTitle = function(title) { |
169 $('autoFillAddressTitle').textContent = title; | 170 $('auto-fill-address-title').textContent = title; |
170 }; | 171 }; |
171 | 172 |
172 // Export | 173 // Export |
173 return { | 174 return { |
174 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay | 175 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay |
175 }; | 176 }; |
176 }); | 177 }); |
OLD | NEW |