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

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

Issue 2300783002: MD Settings: Internet: Cleanup JS (Closed)
Patch Set: Feedback 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 * @private {!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 /**
42 * The selected nameserver type. 40 * The selected nameserver type.
41 * @private
43 */ 42 */
44 nameserversType: { 43 nameserversType_: {
45 type: String, 44 type: String,
46 value: 'automatic', 45 value: 'automatic',
47 }, 46 },
48 47
49 /** 48 /**
50 * Array of nameserver types. 49 * Array of nameserver types.
50 * @private
51 */ 51 */
52 nameserverTypeNames_: { 52 nameserverTypeNames_: {
53 type: Array, 53 type: Array,
54 value: ['automatic', 'google', 'custom'], 54 value: ['automatic', 'google', 'custom'],
55 readOnly: true, 55 readOnly: true,
56 }, 56 },
57 }, 57 },
58 58
59 /** @const */ 59 /** @const */
60 GOOGLE_NAMESERVERS: [ 60 GOOGLE_NAMESERVERS: [
61 '8.8.4.4', 61 '8.8.4.4',
62 '8.8.8.8', 62 '8.8.8.8',
63 ], 63 ],
64 64
65 /** @const */ 65 /** @const */
66 MAX_NAMESERVERS: 4, 66 MAX_NAMESERVERS: 4,
67 67
68 /** 68 /**
69 * Saved nameservers when switching to 'automatic'. 69 * Saved nameservers when switching to 'automatic'.
70 * @type {!Array<string>} 70 * @private {!Array<string>}
71 */ 71 */
72 savedNameservers_: [], 72 savedNameservers_: [],
73 73
74 /** @private */ 74 /** @private */
75 networkPropertiesChanged_: function(newValue, oldValue) { 75 networkPropertiesChanged_: function(newValue, oldValue) {
76 if (!this.networkProperties) 76 if (!this.networkProperties)
77 return; 77 return;
78 78
79 if (!oldValue || newValue.GUID != oldValue.GUID) 79 if (!oldValue || newValue.GUID != oldValue.GUID)
80 this.savedNameservers_ = []; 80 this.savedNameservers_ = [];
(...skipping 20 matching lines...) Expand all
101 } 101 }
102 this.setNameservers_(type, nameservers); 102 this.setNameservers_(type, nameservers);
103 }, 103 },
104 104
105 /** 105 /**
106 * @param {string} nameserversType 106 * @param {string} nameserversType
107 * @param {!Array<string>} nameservers 107 * @param {!Array<string>} nameservers
108 * @private 108 * @private
109 */ 109 */
110 setNameservers_: function(nameserversType, nameservers) { 110 setNameservers_: function(nameserversType, nameservers) {
111 this.nameserversType = nameserversType; 111 this.nameserversType_ = nameserversType;
112 if (nameserversType == 'custom') { 112 if (nameserversType == 'custom') {
113 // Add empty entries for unset custom nameservers. 113 // Add empty entries for unset custom nameservers.
114 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i) 114 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i)
115 nameservers[i] = ''; 115 nameservers[i] = '';
116 } 116 }
117 this.nameservers = nameservers; 117 this.nameservers_ = nameservers;
118 }, 118 },
119 119
120 /** 120 /**
121 * @param {string} nameserversType The nameservers type. 121 * @param {string} type The nameservers type.
122 * @return {string} The description for |nameserversType|. 122 * @return {string} The description for |type|.
123 * @private 123 * @private
124 */ 124 */
125 nameserverTypeDesc_: function(nameserversType) { 125 nameserverTypeDesc_: function(type) {
126 // TODO(stevenjb): Translate. 126 // TODO(stevenjb): Translate.
127 if (nameserversType == 'custom') 127 if (type == 'custom')
128 return 'Custom name servers'; 128 return 'Custom name servers';
129 if (nameserversType == 'google') 129 if (type == 'google')
130 return 'Google name servers'; 130 return 'Google name servers';
131 return 'Automatic name servers'; 131 return 'Automatic name servers';
132 }, 132 },
133 133
134 /** 134 /**
135 * @param {boolean} editable The editable state.
136 * @param {string} nameserversType The nameservers type.
137 * @return {boolean} True if the nameservers are editable. 135 * @return {boolean} True if the nameservers are editable.
138 * @private 136 * @private
139 */ 137 */
140 canEdit_: function(editable, nameserversType) { 138 canEdit_: function() {
141 return editable && nameserversType == 'custom'; 139 return this.editable && this.nameserversType_ == 'custom';
142 }, 140 },
143 141
144 /** 142 /**
145 * Event triggered when the selected type changes. Updates nameservers and 143 * Event triggered when the selected type changes. Updates nameservers and
146 * sends the change value if necessary. 144 * sends the change value if necessary.
147 * @param {!{detail: !{selected: string}}} e 145 * @param {!{detail: !{selected: string}}} e
148 * @private 146 * @private
149 */ 147 */
150 onTypeChange_: function(e) { 148 onTypeChange_: function(e) {
151 if (this.nameserversType == 'custom') 149 if (this.nameserversType_ == 'custom')
152 this.savedNameservers_ = this.nameservers; 150 this.savedNameservers_ = this.nameservers_;
153 var type = e.detail.selected; 151 var type = e.detail.selected;
154 this.nameserversType = type; 152 this.nameserversType_ = type;
155 if (type == 'custom') { 153 if (type == 'custom') {
156 // Restore the saved nameservers. 154 // Restore the saved nameservers.
157 this.setNameservers_(type, this.savedNameservers_); 155 this.setNameservers_(type, this.savedNameservers_);
158 // Only send custom nameservers if they are not empty. 156 // Only send custom nameservers if they are not empty.
159 if (this.savedNameservers_.length == 0) 157 if (this.savedNameservers_.length == 0)
160 return; 158 return;
161 } 159 }
162 this.sendNameServers_(); 160 this.sendNameServers_();
163 }, 161 },
164 162
165 /** 163 /**
166 * Event triggered when a nameserver value changes. 164 * Event triggered when a nameserver value changes.
167 * @private 165 * @private
168 */ 166 */
169 onValueChange_: function() { 167 onValueChange_: function() {
170 if (this.nameserversType != 'custom') { 168 if (this.nameserversType_ != 'custom') {
171 // If a user inputs Google nameservers in the custom nameservers fields, 169 // If a user inputs Google nameservers in the custom nameservers fields,
172 // |nameserversType| will change to 'google' so don't send the values. 170 // |nameserversType| will change to 'google' so don't send the values.
173 return; 171 return;
174 } 172 }
175 this.sendNameServers_(); 173 this.sendNameServers_();
176 }, 174 },
177 175
178 /** 176 /**
179 * Sends the current nameservers type (for automatic) or value. 177 * Sends the current nameservers type (for automatic) or value.
180 * @private 178 * @private
181 */ 179 */
182 sendNameServers_: function() { 180 sendNameServers_: function() {
183 var type = this.nameserversType; 181 var type = this.nameserversType_;
184 182
185 if (type == 'custom') { 183 if (type == 'custom') {
186 let nameservers = []; 184 let nameservers = [];
187 for (let i = 0; i < this.MAX_NAMESERVERS; ++i) { 185 for (let i = 0; i < this.MAX_NAMESERVERS; ++i) {
188 let id = 'nameserver' + i; 186 let id = 'nameserver' + i;
189 let nameserverInput = this.$$('#' + id); 187 let nameserverInput = this.$$('#' + id);
190 let nameserver = ''; 188 let nameserver = '';
191 if (nameserverInput) 189 if (nameserverInput)
192 nameserver = this.$$('#' + id).value; 190 nameserver = this.$$('#' + id).value;
193 nameservers.push(nameserver); 191 nameservers.push(nameserver);
(...skipping 10 matching lines...) Expand all
204 }); 202 });
205 } else { 203 } else {
206 // automatic 204 // automatic
207 this.fire('nameservers-change', { 205 this.fire('nameservers-change', {
208 field: 'NameServersConfigType', 206 field: 'NameServersConfigType',
209 value: CrOnc.IPConfigType.DHCP, 207 value: CrOnc.IPConfigType.DHCP,
210 }); 208 });
211 } 209 }
212 }, 210 },
213 }); 211 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698