Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/resources/options/autofill_edit_address_overlay.js

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reuploading Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 var self = this; 33 var self = this;
34 $('autoFillEditAddressCancelButton').onclick = function(event) { 34 $('autoFillEditAddressCancelButton').onclick = function(event) {
35 self.dismissOverlay_(); 35 self.dismissOverlay_();
36 } 36 }
37 $('autoFillEditAddressApplyButton').onclick = function(event) { 37 $('autoFillEditAddressApplyButton').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.populateCountryList_();
43 self.clearInputFields_(); 44 self.clearInputFields_();
44 self.connectInputEvents_(); 45 self.connectInputEvents_();
45 }, 46 },
46 47
47 /** 48 /**
48 * Clears any uncommitted input, resets the stored GUID and dismisses the 49 * Clears any uncommitted input, resets the stored GUID and dismisses the
49 * overlay. 50 * overlay.
50 * @private 51 * @private
51 */ 52 */
52 dismissOverlay_: function() { 53 dismissOverlay_: function() {
53 this.clearInputFields_(); 54 this.clearInputFields_();
54 this.guid = ''; 55 this.guid = '';
55 OptionsPage.closeOverlay(); 56 OptionsPage.closeOverlay();
56 }, 57 },
57 58
58 /** 59 /**
59 * Aggregates the values in the input fields into an array and sends the 60 * Aggregates the values in the input fields into an array and sends the
60 * array to the AutoFill handler. 61 * array to the AutoFill handler.
61 * @private 62 * @private
62 */ 63 */
63 saveAddress_: function() { 64 saveAddress_: function() {
64 var address = new Array(); 65 var address = new Array();
65 address[0] = this.guid; 66 address[0] = this.guid;
66 address[1] = $('fullName').value; 67 address[1] = $('fullName').value;
67 address[2] = $('companyName').value; 68 address[2] = $('companyName').value;
68 address[3] = $('addrLine1').value; 69 address[3] = $('addrLine1').value;
69 address[4] = $('addrLine2').value; 70 address[4] = $('addrLine2').value;
70 address[5] = $('city').value; 71 address[5] = $('city').value;
71 address[6] = $('state').value; 72 address[6] = $('state').value;
72 address[7] = $('zipCode').value; 73 address[7] = $('postalCode').value;
73 address[8] = $('country').value; 74 address[8] = $('country').value;
74 address[9] = $('phone').value; 75 address[9] = $('phone').value;
75 address[10] = $('fax').value; 76 address[10] = $('fax').value;
76 address[11] = $('email').value; 77 address[11] = $('email').value;
77 78
78 chrome.send('setAddress', address); 79 chrome.send('setAddress', address);
79 }, 80 },
80 81
81 /** 82 /**
82 * Connects each input field to the inputFieldChanged_() method that enables 83 * 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 84 * or disables the 'Ok' button based on whether all the fields are empty or
84 * not. 85 * not.
85 * @private 86 * @private
86 */ 87 */
87 connectInputEvents_: function() { 88 connectInputEvents_: function() {
88 var self = this; 89 var self = this;
89 $('fullName').oninput = $('companyName').oninput = 90 $('fullName').oninput = $('companyName').oninput =
90 $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput = 91 $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput =
91 $('state').oninput = $('country').oninput = $('zipCode').oninput = 92 $('state').oninput = $('country').oninput = $('postalCode').oninput =
92 $('phone').oninput = $('fax').oninput = 93 $('phone').oninput = $('fax').oninput =
93 $('email').oninput = function(event) { 94 $('email').oninput = function(event) {
94 self.inputFieldChanged_(); 95 self.inputFieldChanged_();
95 } 96 }
97
98 $('country').onchange = function(event) {
99 self.countryChanged_(event);
100 }
96 }, 101 },
97 102
98 /** 103 /**
99 * Checks the values of each of the input fields and disables the 'Ok' 104 * Checks the values of each of the input fields and disables the 'Ok'
100 * button if all of the fields are empty. 105 * button if all of the fields are empty.
101 * @private 106 * @private
102 */ 107 */
103 inputFieldChanged_: function() { 108 inputFieldChanged_: function() {
104 var disabled = 109 var disabled =
105 !$('fullName').value && !$('companyName').value && 110 !$('fullName').value && !$('companyName').value &&
106 !$('addrLine1').value && !$('addrLine2').value && !$('city').value && 111 !$('addrLine1').value && !$('addrLine2').value && !$('city').value &&
107 !$('state').value && !$('zipCode').value && !('country').value && 112 !$('state').value && !$('postalCode').value && !('country').value &&
108 !$('phone').value && !$('fax').value && !$('email').value; 113 !$('phone').value && !$('fax').value && !$('email').value;
109 $('autoFillEditAddressApplyButton').disabled = disabled; 114 $('autoFillEditAddressApplyButton').disabled = disabled;
110 }, 115 },
111 116
112 /** 117 /**
118 * Updates the postal code and state field labels appropriately for the
119 * selected country.
120 * @private
121 */
122 countryChanged_: function(event) {
123 var country_code = $('country').value;
arv (Not doing code reviews) 2011/02/11 22:55:37 No underscores in JS
Ilya Sherman 2011/02/12 07:33:02 Done.
124 var details = templateData.autofillCountryData[country_code];
125 $('postalCodeLabel').textContent = details['postalCodeLabel'];
126 $('stateLabel').textContent = details['stateLabel'];
127 },
128
129 /**
130 * Populates the country <select> list.
131 * @private
132 */
133 populateCountryList_: function() {
134 var countryList = $('country');
135 var countries = templateData.autofillCountryData;
136 for (country_code in countries) {
arv (Not doing code reviews) 2011/02/11 22:55:37 missing var
Ilya Sherman 2011/02/12 07:33:02 Done.
137 var option = document.createElement('option');
138 option.value = country_code;
139 option.textContent = countries[country_code]['name'];
140 countryList.appendChild(option)
141 }
142 },
143
144 /**
113 * Clears the value of each input field. 145 * Clears the value of each input field.
114 * @private 146 * @private
115 */ 147 */
116 clearInputFields_: function() { 148 clearInputFields_: function() {
117 $('fullName').value = ''; 149 $('fullName').value = '';
118 $('companyName').value = ''; 150 $('companyName').value = '';
119 $('addrLine1').value = ''; 151 $('addrLine1').value = '';
120 $('addrLine2').value = ''; 152 $('addrLine2').value = '';
121 $('city').value = ''; 153 $('city').value = '';
122 $('state').value = ''; 154 $('state').value = '';
123 $('zipCode').value = ''; 155 $('postalCode').value = '';
124 $('country').value = ''; 156 $('country').value = '';
125 $('phone').value = ''; 157 $('phone').value = '';
126 $('fax').value = ''; 158 $('fax').value = '';
127 $('email').value = ''; 159 $('email').value = '';
160
161 var self = this;
162 self.countryChanged_();
arv (Not doing code reviews) 2011/02/11 22:55:37 this.countryChanged_();
Ilya Sherman 2011/02/12 07:33:02 Done. When should "self" be used? I was mirrorin
arv (Not doing code reviews) 2011/02/14 18:36:41 Only when you need to capture a reference to this
128 }, 163 },
129 164
130 /** 165 /**
131 * Loads the address data from |address|, sets the input fields based on 166 * Loads the address data from |address|, sets the input fields based on
132 * this data and stores the GUID of the address. 167 * this data and stores the GUID of the address.
133 * @private 168 * @private
134 */ 169 */
135 loadAddress_: function(address) { 170 loadAddress_: function(address) {
136 this.setInputFields_(address); 171 this.setInputFields_(address);
137 this.inputFieldChanged_(); 172 this.inputFieldChanged_();
138 this.guid = address['guid']; 173 this.guid = address['guid'];
139 }, 174 },
140 175
141 /** 176 /**
142 * Sets the value of each input field according to |address| 177 * Sets the value of each input field according to |address|
143 * @private 178 * @private
144 */ 179 */
145 setInputFields_: function(address) { 180 setInputFields_: function(address) {
146 $('fullName').value = address['fullName']; 181 $('fullName').value = address['fullName'];
147 $('companyName').value = address['companyName']; 182 $('companyName').value = address['companyName'];
148 $('addrLine1').value = address['addrLine1']; 183 $('addrLine1').value = address['addrLine1'];
149 $('addrLine2').value = address['addrLine2']; 184 $('addrLine2').value = address['addrLine2'];
150 $('city').value = address['city']; 185 $('city').value = address['city'];
151 $('state').value = address['state']; 186 $('state').value = address['state'];
152 $('zipCode').value = address['zipCode']; 187 $('postalCode').value = address['postalCode'];
153 $('country').value = address['country']; 188 $('country').value = address['country'];
154 $('phone').value = address['phone']; 189 $('phone').value = address['phone'];
155 $('fax').value = address['fax']; 190 $('fax').value = address['fax'];
156 $('email').value = address['email']; 191 $('email').value = address['email'];
192
193 var self = this;
194 self.countryChanged_();
157 }, 195 },
158 }; 196 };
159 197
160 AutoFillEditAddressOverlay.clearInputFields = function() { 198 AutoFillEditAddressOverlay.clearInputFields = function() {
161 AutoFillEditAddressOverlay.getInstance().clearInputFields_(); 199 AutoFillEditAddressOverlay.getInstance().clearInputFields_();
162 }; 200 };
163 201
164 AutoFillEditAddressOverlay.loadAddress = function(address) { 202 AutoFillEditAddressOverlay.loadAddress = function(address) {
165 AutoFillEditAddressOverlay.getInstance().loadAddress_(address); 203 AutoFillEditAddressOverlay.getInstance().loadAddress_(address);
166 }; 204 };
167 205
168 AutoFillEditAddressOverlay.setTitle = function(title) { 206 AutoFillEditAddressOverlay.setTitle = function(title) {
169 $('autoFillAddressTitle').textContent = title; 207 $('autoFillAddressTitle').textContent = title;
170 }; 208 };
171 209
172 // Export 210 // Export
173 return { 211 return {
174 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay 212 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay
175 }; 213 };
176 }); 214 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698