| OLD | NEW |
| 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({ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 type: Boolean, | 28 type: Boolean, |
| 29 value: false, | 29 value: false, |
| 30 }, | 30 }, |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * State of 'Configure IP Addresses Automatically'. | 33 * State of 'Configure IP Addresses Automatically'. |
| 34 * @private | 34 * @private |
| 35 */ | 35 */ |
| 36 automatic_: { | 36 automatic_: { |
| 37 type: Boolean, | 37 type: Boolean, |
| 38 value: false, | 38 value: true, |
| 39 observer: 'automaticChanged_', | 39 observer: 'automaticChanged_', |
| 40 }, | 40 }, |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * The currently visible IP Config property dictionary. The 'RoutingPrefix' | 43 * The currently visible IP Config property dictionary. The 'RoutingPrefix' |
| 44 * property is a human-readable mask instead of a prefix length. | 44 * property is a human-readable mask instead of a prefix length. |
| 45 * @private {!{ | 45 * @private {!{ |
| 46 * ipv4: !CrOnc.IPConfigUIProperties, | 46 * ipv4: !CrOnc.IPConfigUIProperties, |
| 47 * ipv6: !CrOnc.IPConfigUIProperties | 47 * ipv6: !CrOnc.IPConfigUIProperties |
| 48 * }|undefined} | 48 * }|undefined} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 77 * Polymer networkProperties changed method. | 77 * Polymer networkProperties changed method. |
| 78 */ | 78 */ |
| 79 networkPropertiesChanged_: function(newValue, oldValue) { | 79 networkPropertiesChanged_: function(newValue, oldValue) { |
| 80 if (!this.networkProperties) | 80 if (!this.networkProperties) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 if (newValue.GUID != (oldValue && oldValue.GUID)) | 83 if (newValue.GUID != (oldValue && oldValue.GUID)) |
| 84 this.savedStaticIp_ = undefined; | 84 this.savedStaticIp_ = undefined; |
| 85 | 85 |
| 86 // Update the 'automatic' property. | 86 // Update the 'automatic' property. |
| 87 var ipConfigType = | 87 if (this.networkProperties.IPAddressConfigType ) { |
| 88 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType); | 88 var ipConfigType = |
| 89 this.automatic_ = (ipConfigType != CrOnc.IPConfigType.STATIC); | 89 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType); |
| 90 this.automatic_ = (ipConfigType != CrOnc.IPConfigType.STATIC); |
| 91 } |
| 90 | 92 |
| 91 // Update the 'ipConfig' property. | 93 if (this.networkProperties.IPConfigs) { |
| 92 var ipv4 = | 94 // Update the 'ipConfig' property. |
| 93 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); | 95 var ipv4 = |
| 94 var ipv6 = | 96 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); |
| 95 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); | 97 var ipv6 = |
| 96 this.ipConfig_ = { | 98 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); |
| 97 ipv4: this.getIPConfigUIProperties_(ipv4), | 99 this.ipConfig_ = { |
| 98 ipv6: this.getIPConfigUIProperties_(ipv6) | 100 ipv4: this.getIPConfigUIProperties_(ipv4), |
| 99 }; | 101 ipv6: this.getIPConfigUIProperties_(ipv6) |
| 102 }; |
| 103 } |
| 104 }, |
| 105 |
| 106 /** @private */ |
| 107 automaticChanged_: function() { |
| 108 if (!this.automatic_ || !this.ipConfig_) { |
| 109 // When switching from automatic, don't send any changes, ip-change will |
| 110 // be fired in onIPChange when a field is changed. |
| 111 return; |
| 112 } |
| 113 // Save the static IP configuration when switching to automatic. |
| 114 this.savedStaticIp_ = this.ipConfig_.ipv4; |
| 115 // Send the change. |
| 116 this.fire('ip-change', { |
| 117 field: 'IPAddressConfigType', |
| 118 value: CrOnc.IPConfigType.DHCP, |
| 119 }); |
| 100 }, | 120 }, |
| 101 | 121 |
| 102 /** | 122 /** |
| 103 * Polymer automatic changed method. | |
| 104 */ | |
| 105 automaticChanged_: function() { | |
| 106 if (!this.automatic_ || !this.ipConfig_) | |
| 107 return; | |
| 108 if (this.automatic_ || !this.savedStaticIp_) { | |
| 109 // Save the static IP configuration when switching to automatic. | |
| 110 this.savedStaticIp_ = this.ipConfig_.ipv4; | |
| 111 var configType = | |
| 112 this.automatic_ ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; | |
| 113 this.fire('ip-change', { | |
| 114 field: 'IPAddressConfigType', | |
| 115 value: configType, | |
| 116 }); | |
| 117 } else { | |
| 118 // Restore the saved static IP configuration. | |
| 119 var ipconfig = { | |
| 120 Gateway: this.savedStaticIp_.Gateway, | |
| 121 IPAddress: this.savedStaticIp_.IPAddress, | |
| 122 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, | |
| 123 Type: this.savedStaticIp_.Type, | |
| 124 }; | |
| 125 this.fire('ip-change', { | |
| 126 field: 'StaticIPConfig', | |
| 127 value: this.getIPConfigProperties_(ipconfig), | |
| 128 }); | |
| 129 } | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig | 123 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig |
| 134 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object | 124 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object |
| 135 * with RoutingPrefix expressed as a string mask instead of a prefix | 125 * with RoutingPrefix expressed as a string mask instead of a prefix |
| 136 * length. Returns an empty object if |ipconfig| is undefined. | 126 * length. Returns an empty object if |ipconfig| is undefined. |
| 137 * @private | 127 * @private |
| 138 */ | 128 */ |
| 139 getIPConfigUIProperties_: function(ipconfig) { | 129 getIPConfigUIProperties_: function(ipconfig) { |
| 140 var result = {}; | 130 var result = {}; |
| 141 if (!ipconfig) | 131 if (!ipconfig) |
| 142 return result; | 132 return result; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 * network-property-list change event. | 186 * network-property-list change event. |
| 197 * @private | 187 * @private |
| 198 */ | 188 */ |
| 199 onIPChange_: function(event) { | 189 onIPChange_: function(event) { |
| 200 if (!this.ipConfig_) | 190 if (!this.ipConfig_) |
| 201 return; | 191 return; |
| 202 var field = event.detail.field; | 192 var field = event.detail.field; |
| 203 var value = event.detail.value; | 193 var value = event.detail.value; |
| 204 // Note: |field| includes the 'ipv4.' prefix. | 194 // Note: |field| includes the 'ipv4.' prefix. |
| 205 this.set('ipConfig_.' + field, value); | 195 this.set('ipConfig_.' + field, value); |
| 196 // This will also set IPAddressConfigType to STATIC. |
| 206 this.fire('ip-change', { | 197 this.fire('ip-change', { |
| 207 field: 'StaticIPConfig', | 198 field: 'StaticIPConfig', |
| 208 value: this.getIPConfigProperties_(this.ipConfig_.ipv4) | 199 value: this.getIPConfigProperties_(this.ipConfig_.ipv4) |
| 209 }); | 200 }); |
| 210 }, | 201 }, |
| 211 }); | 202 }); |
| OLD | NEW |