| 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({ |
| 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 /** |
| 34 * State of 'Configure IP Addresses Automatically'. | 33 * State of 'Configure IP Addresses Automatically'. |
| 34 * @private |
| 35 */ | 35 */ |
| 36 automatic: { | 36 automatic_: { |
| 37 type: Boolean, | 37 type: Boolean, |
| 38 value: false, | 38 value: false, |
| 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 * @type {!{ | 45 * @private {!{ |
| 46 * ipv4: !CrOnc.IPConfigUIProperties, | 46 * ipv4: !CrOnc.IPConfigUIProperties, |
| 47 * ipv6: !CrOnc.IPConfigUIProperties | 47 * ipv6: !CrOnc.IPConfigUIProperties |
| 48 * }|undefined} | 48 * }|undefined} |
| 49 */ | 49 */ |
| 50 ipConfig: {type: Object}, | 50 ipConfig_: Object, |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Array of properties to pass to the property list. | 53 * Array of properties to pass to the property list. |
| 54 * @type {!Array<string>} | 54 * @private {!Array<string>} |
| 55 */ | 55 */ |
| 56 ipConfigFields_: { | 56 ipConfigFields_: { |
| 57 type: Array, | 57 type: Array, |
| 58 value: function() { | 58 value: function() { |
| 59 return [ | 59 return [ |
| 60 'ipv4.IPAddress', | 60 'ipv4.IPAddress', |
| 61 'ipv4.RoutingPrefix', | 61 'ipv4.RoutingPrefix', |
| 62 'ipv4.Gateway', | 62 'ipv4.Gateway', |
| 63 'ipv6.IPAddress', | 63 'ipv6.IPAddress', |
| 64 ]; | 64 ]; |
| 65 }, | 65 }, |
| 66 readOnly: true | 66 readOnly: true |
| 67 }, | 67 }, |
| 68 }, | 68 }, |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Saved static IP configuration properties when switching to 'automatic'. | 71 * Saved static IP configuration properties when switching to 'automatic'. |
| 72 * @type {!CrOnc.IPConfigUIProperties|undefined} | 72 * @private {!CrOnc.IPConfigUIProperties|undefined} |
| 73 */ | 73 */ |
| 74 savedStaticIp_: undefined, | 74 savedStaticIp_: undefined, |
| 75 | 75 |
| 76 /** | 76 /** |
| 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 var ipConfigType = |
| 88 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType); | 88 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType); |
| 89 this.automatic = (ipConfigType != CrOnc.IPConfigType.STATIC); | 89 this.automatic_ = (ipConfigType != CrOnc.IPConfigType.STATIC); |
| 90 | 90 |
| 91 // Update the 'ipConfig' property. | 91 // Update the 'ipConfig' property. |
| 92 var ipv4 = | 92 var ipv4 = |
| 93 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); | 93 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); |
| 94 var ipv6 = | 94 var ipv6 = |
| 95 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); | 95 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV6); |
| 96 this.ipConfig = { | 96 this.ipConfig_ = { |
| 97 ipv4: this.getIPConfigUIProperties_(ipv4), | 97 ipv4: this.getIPConfigUIProperties_(ipv4), |
| 98 ipv6: this.getIPConfigUIProperties_(ipv6) | 98 ipv6: this.getIPConfigUIProperties_(ipv6) |
| 99 }; | 99 }; |
| 100 }, | 100 }, |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Polymer automatic changed method. | 103 * Polymer automatic changed method. |
| 104 */ | 104 */ |
| 105 automaticChanged_: function() { | 105 automaticChanged_: function() { |
| 106 if (!this.automatic || !this.ipConfig) | 106 if (!this.automatic_ || !this.ipConfig_) |
| 107 return; | 107 return; |
| 108 if (this.automatic || !this.savedStaticIp_) { | 108 if (this.automatic_ || !this.savedStaticIp_) { |
| 109 // Save the static IP configuration when switching to automatic. | 109 // Save the static IP configuration when switching to automatic. |
| 110 this.savedStaticIp_ = this.ipConfig.ipv4; | 110 this.savedStaticIp_ = this.ipConfig_.ipv4; |
| 111 var configType = | 111 var configType = |
| 112 this.automatic ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; | 112 this.automatic_ ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; |
| 113 this.fire('ip-change', { | 113 this.fire('ip-change', { |
| 114 field: 'IPAddressConfigType', | 114 field: 'IPAddressConfigType', |
| 115 value: configType, | 115 value: configType, |
| 116 }); | 116 }); |
| 117 } else { | 117 } else { |
| 118 // Restore the saved static IP configuration. | 118 // Restore the saved static IP configuration. |
| 119 var ipconfig = { | 119 var ipconfig = { |
| 120 Gateway: this.savedStaticIp_.Gateway, | 120 Gateway: this.savedStaticIp_.Gateway, |
| 121 IPAddress: this.savedStaticIp_.IPAddress, | 121 IPAddress: this.savedStaticIp_.IPAddress, |
| 122 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, | 122 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 else | 165 else |
| 166 result[key] = value; | 166 result[key] = value; |
| 167 } | 167 } |
| 168 return result; | 168 return result; |
| 169 }, | 169 }, |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @return {boolean} | 172 * @return {boolean} |
| 173 * @private | 173 * @private |
| 174 */ | 174 */ |
| 175 showIPEditFields_: function(editable, automatic) { | 175 showIPEditFields_: function() { |
| 176 return editable && !automatic; | 176 return this.editable && !this.automatic_; |
| 177 }, | 177 }, |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * @return {Object} An object with the edit type for each editable field. | 180 * @return {Object} An object with the edit type for each editable field. |
| 181 * @private | 181 * @private |
| 182 */ | 182 */ |
| 183 getIPEditFields_: function(ipConfig, editable, automatic) { | 183 getIPEditFields_: function() { |
| 184 if (!editable || automatic) | 184 if (!this.editable || this.automatic__) |
| 185 return {}; | 185 return {}; |
| 186 return { | 186 return { |
| 187 'ipv4.IPAddress': 'String', | 187 'ipv4.IPAddress': 'String', |
| 188 'ipv4.RoutingPrefix': 'String', | 188 'ipv4.RoutingPrefix': 'String', |
| 189 'ipv4.Gateway': 'String' | 189 'ipv4.Gateway': 'String' |
| 190 }; | 190 }; |
| 191 }, | 191 }, |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * Event triggered when the network property list changes. | 194 * Event triggered when the network property list changes. |
| 195 * @param {!{detail: { field: string, value: string}}} event The | 195 * @param {!{detail: {field: string, value: string}}} event The |
| 196 * network-property-list change event. | 196 * network-property-list change event. |
| 197 * @private | 197 * @private |
| 198 */ | 198 */ |
| 199 onIPChange_: function(event) { | 199 onIPChange_: function(event) { |
| 200 if (!this.ipConfig) | 200 if (!this.ipConfig_) |
| 201 return; | 201 return; |
| 202 var field = event.detail.field; | 202 var field = event.detail.field; |
| 203 var value = event.detail.value; | 203 var value = event.detail.value; |
| 204 // Note: |field| includes the 'ipv4.' prefix. | 204 // Note: |field| includes the 'ipv4.' prefix. |
| 205 this.set('ipConfig.' + field, value); | 205 this.set('ipConfig.' + field, value); |
| 206 this.fire('ip-change', { | 206 this.fire('ip-change', { |
| 207 field: 'StaticIPConfig', | 207 field: 'StaticIPConfig', |
| 208 value: this.getIPConfigProperties_(this.ipConfig.ipv4) | 208 value: this.getIPConfigProperties_(this.ipConfig_.ipv4) |
| 209 }); | 209 }); |
| 210 }, | 210 }, |
| 211 }); | 211 }); |
| OLD | NEW |