| 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 26 matching lines...) Expand all Loading... |
| 37 type: Boolean, | 37 type: Boolean, |
| 38 value: true, | 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|undefined) |
| 48 * }} | 48 * }} |
| 49 */ | 49 */ |
| 50 ipConfig_: { | 50 ipConfig_: { |
| 51 type: Object, | 51 type: Object, |
| 52 value: null, | 52 value: null, |
| 53 }, | 53 }, |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Array of properties to pass to the property list. | 56 * Array of properties to pass to the property list. |
| 57 * @private {!Array<string>} | 57 * @private {!Array<string>} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); | 101 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); |
| 102 this.ipConfig_ = { | 102 this.ipConfig_ = { |
| 103 ipv4: this.getIPConfigUIProperties_(ipv4), | 103 ipv4: this.getIPConfigUIProperties_(ipv4), |
| 104 ipv6: this.getIPConfigUIProperties_(ipv6) | 104 ipv6: this.getIPConfigUIProperties_(ipv6) |
| 105 }; | 105 }; |
| 106 } | 106 } |
| 107 }, | 107 }, |
| 108 | 108 |
| 109 /** @private */ | 109 /** @private */ |
| 110 automaticChanged_: function() { | 110 automaticChanged_: function() { |
| 111 if (!this.automatic_ || !this.ipConfig_) { | 111 if (!this.automatic_) { |
| 112 // When switching from automatic, don't send any changes, ip-change will | 112 // Ensure that there is a valid IPConfig object. |
| 113 // be fired in onIPChange when a field is changed. | 113 this.ipConfig_ = this.ipConfig_ || { |
| 114 ipv4: { |
| 115 Gateway: '192.168.1.1', |
| 116 IPAddress: '192.168.1.1', |
| 117 RoutingPrefix: '255.255.255.0', |
| 118 Type: CrOnc.IPType.IPV4, |
| 119 }, |
| 120 }; |
| 121 this.sendStaticIpConfig_(); |
| 114 return; | 122 return; |
| 115 } | 123 } |
| 124 |
| 116 // Save the static IP configuration when switching to automatic. | 125 // Save the static IP configuration when switching to automatic. |
| 117 this.savedStaticIp_ = this.ipConfig_.ipv4; | 126 if (this.ipConfig_) |
| 127 this.savedStaticIp_ = this.ipConfig_.ipv4; |
| 118 // Send the change. | 128 // Send the change. |
| 119 this.fire('ip-change', { | 129 this.fire('ip-change', { |
| 120 field: 'IPAddressConfigType', | 130 field: 'IPAddressConfigType', |
| 121 value: CrOnc.IPConfigType.DHCP, | 131 value: CrOnc.IPConfigType.DHCP, |
| 122 }); | 132 }); |
| 123 }, | 133 }, |
| 124 | 134 |
| 125 /** | 135 /** |
| 126 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig | 136 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig |
| 127 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object | 137 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 * network-property-list change event. | 191 * network-property-list change event. |
| 182 * @private | 192 * @private |
| 183 */ | 193 */ |
| 184 onIPChange_: function(event) { | 194 onIPChange_: function(event) { |
| 185 if (!this.ipConfig_) | 195 if (!this.ipConfig_) |
| 186 return; | 196 return; |
| 187 var field = event.detail.field; | 197 var field = event.detail.field; |
| 188 var value = event.detail.value; | 198 var value = event.detail.value; |
| 189 // Note: |field| includes the 'ipv4.' prefix. | 199 // Note: |field| includes the 'ipv4.' prefix. |
| 190 this.set('ipConfig_.' + field, value); | 200 this.set('ipConfig_.' + field, value); |
| 201 this.sendStaticIpConfig_(); |
| 202 }, |
| 203 |
| 204 /** @private */ |
| 205 sendStaticIpConfig_: function() { |
| 191 // This will also set IPAddressConfigType to STATIC. | 206 // This will also set IPAddressConfigType to STATIC. |
| 192 this.fire('ip-change', { | 207 this.fire('ip-change', { |
| 193 field: 'StaticIPConfig', | 208 field: 'StaticIPConfig', |
| 194 value: this.getIPConfigProperties_(this.ipConfig_.ipv4) | 209 value: this.getIPConfigProperties_(this.ipConfig_.ipv4) |
| 195 }); | 210 }); |
| 196 }, | 211 }, |
| 197 }); | 212 }); |
| OLD | NEW |