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

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_ip_config.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 the IP Config properties for 6 * @fileoverview Polymer element for displaying the IP Config properties for
7 * a network state. TODO(stevenjb): Allow editing of static IP configurations 7 * a network state. TODO(stevenjb): Allow editing of static IP configurations
8 * when 'editable' is true. 8 * when 'editable' is true.
9 */ 9 */
10 Polymer({ 10 Polymer({
11 is: 'network-ip-config', 11 is: 'network-ip-config',
12 12
13 properties: { 13 properties: {
14 /** 14 /**
15 * The network properties dictionary containing the IP Config properties to 15 * The network properties dictionary containing the IP Config properties to
16 * display and modify. 16 * display and modify.
17 * @type {!CrOnc.NetworkProperties|undefined} 17 * @type {!CrOnc.NetworkProperties|undefined}
18 */ 18 */
19 networkProperties: { 19 networkProperties: {
20 type: Object, 20 type: Object,
21 observer: 'networkPropertiesChanged_', 21 observer: 'networkPropertiesChanged_',
22 }, 22 },
23 23
24 /** 24 /**
25 * Whether or not the IP Address can be edited. 25 * Whether or not the IP Address can be edited.
26 * TODO(stevenjb): Implement editing.
27 */ 26 */
28 editable: { 27 editable: {
29 type: Boolean, 28 type: Boolean,
30 value: false, 29 value: false,
31 }, 30 },
32 31
33 /** 32 /** State of 'Configure IP Addresses Automatically'. */
34 * State of 'Configure IP Addresses Automatically'. 33 automatic_: {
35 */
36 automatic: {
37 type: Boolean, 34 type: Boolean,
38 value: false, 35 value: false,
39 observer: 'automaticChanged_', 36 observer: 'automaticChanged_',
40 }, 37 },
41 38
42 /** 39 /**
43 * The currently visible IP Config property dictionary. The 'RoutingPrefix' 40 * The currently visible IP Config property dictionary. The 'RoutingPrefix'
44 * property is a human-readable mask instead of a prefix length. 41 * property is a human-readable mask instead of a prefix length.
45 * @type {!{ 42 * @type {!{
46 * ipv4: !CrOnc.IPConfigUIProperties, 43 * ipv4: !CrOnc.IPConfigUIProperties,
47 * ipv6: !CrOnc.IPConfigUIProperties 44 * ipv6: !CrOnc.IPConfigUIProperties
48 * }|undefined} 45 * }|undefined}
49 */ 46 */
50 ipConfig: {type: Object}, 47 ipConfig_: {type: Object},
51 48
52 /** 49 /**
53 * Array of properties to pass to the property list. 50 * Array of properties to pass to the property list.
54 * @type {!Array<string>} 51 * @type {!Array<string>}
55 */ 52 */
56 ipConfigFields_: { 53 ipConfigFields_: {
57 type: Array, 54 type: Array,
58 value: function() { 55 value: function() {
59 return [ 56 return [
60 'ipv4.IPAddress', 57 'ipv4.IPAddress',
(...skipping 18 matching lines...) Expand all
79 networkPropertiesChanged_: function(newValue, oldValue) { 76 networkPropertiesChanged_: function(newValue, oldValue) {
80 if (!this.networkProperties) 77 if (!this.networkProperties)
81 return; 78 return;
82 79
83 if (newValue.GUID != (oldValue && oldValue.GUID)) 80 if (newValue.GUID != (oldValue && oldValue.GUID))
84 this.savedStaticIp_ = undefined; 81 this.savedStaticIp_ = undefined;
85 82
86 // Update the 'automatic' property. 83 // Update the 'automatic' property.
87 var ipConfigType = 84 var ipConfigType =
88 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType); 85 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType);
89 this.automatic = (ipConfigType != CrOnc.IPConfigType.STATIC); 86 this.automatic_ = (ipConfigType != CrOnc.IPConfigType.STATIC);
90 87
91 // Update the 'ipConfig' property. 88 // Update the 'ipConfig' property.
92 var ipv4 = 89 var ipv4 =
93 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); 90 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4);
94 var ipv6 = 91 var ipv6 =
95 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); 92 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6);
96 this.ipConfig = { 93 this.ipConfig_ = {
97 ipv4: this.getIPConfigUIProperties_(ipv4), 94 ipv4: this.getIPConfigUIProperties_(ipv4),
98 ipv6: this.getIPConfigUIProperties_(ipv6) 95 ipv6: this.getIPConfigUIProperties_(ipv6)
99 }; 96 };
100 }, 97 },
101 98
102 /** 99 /**
103 * Polymer automatic changed method. 100 * Polymer automatic changed method.
104 */ 101 */
105 automaticChanged_: function() { 102 automaticChanged_: function() {
106 if (!this.automatic || !this.ipConfig) 103 if (!this.automatic_ || !this.ipConfig_)
107 return; 104 return;
108 if (this.automatic || !this.savedStaticIp_) { 105 if (this.automatic_ || !this.savedStaticIp_) {
109 // Save the static IP configuration when switching to automatic. 106 // Save the static IP configuration when switching to automatic.
110 this.savedStaticIp_ = this.ipConfig.ipv4; 107 this.savedStaticIp_ = this.ipConfig_.ipv4;
111 var configType = 108 var configType =
112 this.automatic ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; 109 this.automatic_ ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC;
113 this.fire('ip-change', { 110 this.fire('ip-change', {
114 field: 'IPAddressConfigType', 111 field: 'IPAddressConfigType',
115 value: configType, 112 value: configType,
116 }); 113 });
117 } else { 114 } else {
118 // Restore the saved static IP configuration. 115 // Restore the saved static IP configuration.
119 var ipconfig = { 116 var ipconfig = {
120 Gateway: this.savedStaticIp_.Gateway, 117 Gateway: this.savedStaticIp_.Gateway,
121 IPAddress: this.savedStaticIp_.IPAddress, 118 IPAddress: this.savedStaticIp_.IPAddress,
122 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, 119 RoutingPrefix: this.savedStaticIp_.RoutingPrefix,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 else 162 else
166 result[key] = value; 163 result[key] = value;
167 } 164 }
168 return result; 165 return result;
169 }, 166 },
170 167
171 /** 168 /**
172 * @return {boolean} 169 * @return {boolean}
173 * @private 170 * @private
174 */ 171 */
175 showIPEditFields_: function(editable, automatic) { 172 showIPEditFields_: function() {
176 return editable && !automatic; 173 return this.editable && !this.automatic_;
177 }, 174 },
178 175
179 /** 176 /**
180 * @return {Object} An object with the edit type for each editable field. 177 * @return {Object} An object with the edit type for each editable field.
181 * @private 178 * @private
182 */ 179 */
183 getIPEditFields_: function(ipConfig, editable, automatic) { 180 getIPEditFields_: function() {
184 if (!editable || automatic) 181 if (!this.editable || this.automatic__)
185 return {}; 182 return {};
186 return { 183 return {
187 'ipv4.IPAddress': 'String', 184 'ipv4.IPAddress': 'String',
188 'ipv4.RoutingPrefix': 'String', 185 'ipv4.RoutingPrefix': 'String',
189 'ipv4.Gateway': 'String' 186 'ipv4.Gateway': 'String'
190 }; 187 };
191 }, 188 },
192 189
193 /** 190 /**
194 * Event triggered when the network property list changes. 191 * Event triggered when the network property list changes.
195 * @param {!{detail: { field: string, value: string}}} event The 192 * @param {!{detail: { field: string, value: string}}} event The
Dan Beam 2016/08/31 21:59:47 nit: spurious space, \sfield
stevenjb 2016/08/31 22:10:16 Done.
196 * network-property-list change event. 193 * network-property-list change event.
197 * @private 194 * @private
198 */ 195 */
199 onIPChange_: function(event) { 196 onIPChange_: function(event) {
200 if (!this.ipConfig) 197 if (!this.ipConfig_)
201 return; 198 return;
202 var field = event.detail.field; 199 var field = event.detail.field;
203 var value = event.detail.value; 200 var value = event.detail.value;
204 // Note: |field| includes the 'ipv4.' prefix. 201 // Note: |field| includes the 'ipv4.' prefix.
205 this.set('ipConfig.' + field, value); 202 this.set('ipConfig.' + field, value);
206 this.fire('ip-change', { 203 this.fire('ip-change', {
207 field: 'StaticIPConfig', 204 field: 'StaticIPConfig',
208 value: this.getIPConfigProperties_(this.ipConfig.ipv4) 205 value: this.getIPConfigProperties_(this.ipConfig_.ipv4)
209 }); 206 });
210 }, 207 },
211 }); 208 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698