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

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_nameservers.js

Issue 2300783002: MD Settings: Internet: Cleanup JS (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @fileoverview Polymer element for displaying network nameserver options. 6 * @fileoverview Polymer element for displaying network nameserver options.
7 */ 7 */
8 Polymer({ 8 Polymer({
9 is: 'network-nameservers', 9 is: 'network-nameservers',
10 10
11 properties: { 11 properties: {
12 /** 12 /**
13 * The network properties dictionary containing the nameserver properties to 13 * The network properties dictionary containing the nameserver properties to
14 * display and modify. 14 * display and modify.
15 * @type {!CrOnc.NetworkProperties|undefined} 15 * @type {!CrOnc.NetworkProperties|undefined}
16 */ 16 */
17 networkProperties: { 17 networkProperties: {
18 type: Object, 18 type: Object,
19 observer: 'networkPropertiesChanged_', 19 observer: 'networkPropertiesChanged_',
20 }, 20 },
21 21
22 /** 22 /** Whether or not the nameservers can be edited. */
23 * Whether or not the nameservers can be edited.
24 */
25 editable: { 23 editable: {
26 type: Boolean, 24 type: Boolean,
27 value: false, 25 value: false,
28 }, 26 },
29 27
30 /** 28 /**
31 * Array of nameserver addresses stored as strings. 29 * Array of nameserver addresses stored as strings.
32 * @type {!Array<string>} 30 * @type {!Array<string>}
33 */ 31 */
34 nameservers: { 32 nameservers_: {
35 type: Array, 33 type: Array,
36 value: function() { 34 value: function() {
37 return []; 35 return [];
38 }, 36 },
39 }, 37 },
40 38
41 /** 39 /** The selected nameserver type. */
42 * The selected nameserver type. 40 nameserversType_: {
43 */
44 nameserversType: {
45 type: String, 41 type: String,
46 value: 'automatic', 42 value: 'automatic',
47 }, 43 },
48 44
49 /** 45 /**
50 * Array of nameserver types. 46 * Array of nameserver types.
51 */ 47 */
52 nameserverTypeNames_: { 48 nameserverTypeNames_: {
53 type: Array, 49 type: Array,
54 value: ['automatic', 'google', 'custom'], 50 value: ['automatic', 'google', 'custom'],
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 97 }
102 this.setNameservers_(type, nameservers); 98 this.setNameservers_(type, nameservers);
103 }, 99 },
104 100
105 /** 101 /**
106 * @param {string} nameserversType 102 * @param {string} nameserversType
107 * @param {!Array<string>} nameservers 103 * @param {!Array<string>} nameservers
108 * @private 104 * @private
109 */ 105 */
110 setNameservers_: function(nameserversType, nameservers) { 106 setNameservers_: function(nameserversType, nameservers) {
111 this.nameserversType = nameserversType; 107 this.nameserversType_ = nameserversType;
112 if (nameserversType == 'custom') { 108 if (nameserversType == 'custom') {
113 // Add empty entries for unset custom nameservers. 109 // Add empty entries for unset custom nameservers.
114 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i) 110 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i)
115 nameservers[i] = ''; 111 nameservers[i] = '';
116 } 112 }
117 this.nameservers = nameservers; 113 this.nameservers_ = nameservers;
118 }, 114 },
119 115
120 /** 116 /**
121 * @param {string} nameserversType The nameservers type. 117 * @param {string} type The nameservers type.
122 * @return {string} The description for |nameserversType|. 118 * @return {string} The description for |type|.
123 * @private 119 * @private
124 */ 120 */
125 nameserverTypeDesc_: function(nameserversType) { 121 nameserverTypeDesc_: function(type) {
126 // TODO(stevenjb): Translate. 122 // TODO(stevenjb): Translate.
127 if (nameserversType == 'custom') 123 if (type == 'custom')
128 return 'Custom name servers'; 124 return 'Custom name servers';
129 if (nameserversType == 'google') 125 if (type == 'google')
130 return 'Google name servers'; 126 return 'Google name servers';
131 return 'Automatic name servers'; 127 return 'Automatic name servers';
132 }, 128 },
133 129
134 /** 130 /**
135 * @param {boolean} editable The editable state.
136 * @param {string} nameserversType The nameservers type.
137 * @return {boolean} True if the nameservers are editable. 131 * @return {boolean} True if the nameservers are editable.
138 * @private 132 * @private
139 */ 133 */
140 canEdit_: function(editable, nameserversType) { 134 canEdit_: function() {
141 return editable && nameserversType == 'custom'; 135 return this.editable && this.nameserversType_ == 'custom';
142 }, 136 },
143 137
144 /** 138 /**
145 * Event triggered when the selected type changes. Updates nameservers and 139 * Event triggered when the selected type changes. Updates nameservers and
146 * sends the change value if necessary. 140 * sends the change value if necessary.
147 * @param {!{detail: !{selected: string}}} e 141 * @param {!{detail: !{selected: string}}} e
148 * @private 142 * @private
149 */ 143 */
150 onTypeChange_: function(e) { 144 onTypeChange_: function(e) {
151 if (this.nameserversType == 'custom') 145 if (this.nameserversType_ == 'custom')
152 this.savedNameservers_ = this.nameservers; 146 this.savedNameservers_ = this.nameservers_;
153 var type = e.detail.selected; 147 var type = e.detail.selected;
154 this.nameserversType = type; 148 this.nameserversType_ = type;
155 if (type == 'custom') { 149 if (type == 'custom') {
156 // Restore the saved nameservers. 150 // Restore the saved nameservers.
157 this.setNameservers_(type, this.savedNameservers_); 151 this.setNameservers_(type, this.savedNameservers_);
158 // Only send custom nameservers if they are not empty. 152 // Only send custom nameservers if they are not empty.
159 if (this.savedNameservers_.length == 0) 153 if (this.savedNameservers_.length == 0)
160 return; 154 return;
161 } 155 }
162 this.sendNameServers_(); 156 this.sendNameServers_();
163 }, 157 },
164 158
165 /** 159 /**
166 * Event triggered when a nameserver value changes. 160 * Event triggered when a nameserver value changes.
167 * @private 161 * @private
168 */ 162 */
169 onValueChange_: function() { 163 onValueChange_: function() {
170 if (this.nameserversType != 'custom') { 164 if (this.nameserversType_ != 'custom') {
171 // If a user inputs Google nameservers in the custom nameservers fields, 165 // If a user inputs Google nameservers in the custom nameservers fields,
172 // |nameserversType| will change to 'google' so don't send the values. 166 // |nameserversType| will change to 'google' so don't send the values.
173 return; 167 return;
174 } 168 }
175 this.sendNameServers_(); 169 this.sendNameServers_();
176 }, 170 },
177 171
178 /** 172 /**
179 * Sends the current nameservers type (for automatic) or value. 173 * Sends the current nameservers type (for automatic) or value.
180 * @private 174 * @private
181 */ 175 */
182 sendNameServers_: function() { 176 sendNameServers_: function() {
183 var type = this.nameserversType; 177 var type = this.nameserversType_;
184 178
185 if (type == 'custom') { 179 if (type == 'custom') {
186 let nameservers = []; 180 let nameservers = [];
187 for (let i = 0; i < this.MAX_NAMESERVERS; ++i) { 181 for (let i = 0; i < this.MAX_NAMESERVERS; ++i) {
188 let id = 'nameserver' + i; 182 let id = 'nameserver' + i;
189 let nameserverInput = this.$$('#' + id); 183 let nameserverInput = this.$$('#' + id);
190 let nameserver = ''; 184 let nameserver = '';
191 if (nameserverInput) 185 if (nameserverInput)
192 nameserver = this.$$('#' + id).value; 186 nameserver = this.$$('#' + id).value;
193 nameservers.push(nameserver); 187 nameservers.push(nameserver);
(...skipping 10 matching lines...) Expand all
204 }); 198 });
205 } else { 199 } else {
206 // automatic 200 // automatic
207 this.fire('nameservers-change', { 201 this.fire('nameservers-change', {
208 field: 'NameServersConfigType', 202 field: 'NameServersConfigType',
209 value: CrOnc.IPConfigType.DHCP, 203 value: CrOnc.IPConfigType.DHCP,
210 }); 204 });
211 } 205 }
212 }, 206 },
213 }); 207 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698