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