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 (function() { | |
11 'use strict'; | |
12 | |
13 Polymer({ | 10 Polymer({ |
14 is: 'network-ip-config', | 11 is: 'network-ip-config', |
15 | 12 |
16 properties: { | 13 properties: { |
17 /** | 14 /** |
18 * The network properties dictionary containing the IP Config properties to | 15 * The network properties dictionary containing the IP Config properties to |
19 * display and modify. | 16 * display and modify. |
20 * @type {!CrOnc.NetworkProperties|undefined} | 17 * @type {!CrOnc.NetworkProperties|undefined} |
21 */ | 18 */ |
22 networkProperties: { | 19 networkProperties: { |
23 type: Object, | 20 type: Object, |
24 observer: 'networkPropertiesChanged_' | 21 observer: 'networkPropertiesChanged_', |
25 }, | 22 }, |
26 | 23 |
27 /** | 24 /** |
28 * Whether or not the IP Address can be edited. | 25 * Whether or not the IP Address can be edited. |
29 * TODO(stevenjb): Implement editing. | 26 * TODO(stevenjb): Implement editing. |
30 */ | 27 */ |
31 editable: { | 28 editable: { |
32 type: Boolean, | 29 type: Boolean, |
33 value: false | 30 value: false, |
34 }, | 31 }, |
35 | 32 |
36 /** | 33 /** |
37 * State of 'Configure IP Addresses Automatically'. | 34 * State of 'Configure IP Addresses Automatically'. |
38 */ | 35 */ |
39 automatic: { | 36 automatic: { |
40 type: Boolean, | 37 type: Boolean, |
41 value: false, | 38 value: false, |
42 observer: 'automaticChanged_' | 39 observer: 'automaticChanged_', |
43 }, | 40 }, |
44 | 41 |
45 /** | 42 /** |
46 * The currently visible IP Config property dictionary. The 'RoutingPrefix' | 43 * The currently visible IP Config property dictionary. The 'RoutingPrefix' |
47 * property is a human-readable mask instead of a prefix length. | 44 * property is a human-readable mask instead of a prefix length. |
48 * @type {!{ | 45 * @type {!{ |
49 * ipv4: !CrOnc.IPConfigUIProperties, | 46 * ipv4: !CrOnc.IPConfigUIProperties, |
50 * ipv6: !CrOnc.IPConfigUIProperties | 47 * ipv6: !CrOnc.IPConfigUIProperties |
51 * }|undefined} | 48 * }|undefined} |
52 */ | 49 */ |
53 ipConfig: { | 50 ipConfig: {type: Object}, |
54 type: Object | |
55 }, | |
56 | 51 |
57 /** | 52 /** |
58 * Array of properties to pass to the property list. | 53 * Array of properties to pass to the property list. |
59 * @type {!Array<string>} | 54 * @type {!Array<string>} |
60 */ | 55 */ |
61 ipConfigFields_: { | 56 ipConfigFields_: { |
62 type: Array, | 57 type: Array, |
63 value: function() { | 58 value: function() { |
64 return [ | 59 return [ |
65 'ipv4.IPAddress', | 60 'ipv4.IPAddress', |
66 'ipv4.RoutingPrefix', | 61 'ipv4.RoutingPrefix', |
67 'ipv4.Gateway', | 62 'ipv4.Gateway', |
68 'ipv6.IPAddress' | 63 'ipv6.IPAddress', |
69 ]; | 64 ]; |
70 }, | 65 }, |
71 readOnly: true | 66 readOnly: true |
72 }, | 67 }, |
73 }, | 68 }, |
74 | 69 |
75 /** | 70 /** |
76 * Saved static IP configuration properties when switching to 'automatic'. | 71 * Saved static IP configuration properties when switching to 'automatic'. |
77 * @type {!CrOnc.IPConfigUIProperties|undefined} | 72 * @type {!CrOnc.IPConfigUIProperties|undefined} |
78 */ | 73 */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 automaticChanged_: function() { | 105 automaticChanged_: function() { |
111 if (!this.automatic || !this.ipConfig) | 106 if (!this.automatic || !this.ipConfig) |
112 return; | 107 return; |
113 if (this.automatic || !this.savedStaticIp_) { | 108 if (this.automatic || !this.savedStaticIp_) { |
114 // Save the static IP configuration when switching to automatic. | 109 // Save the static IP configuration when switching to automatic. |
115 this.savedStaticIp_ = this.ipConfig.ipv4; | 110 this.savedStaticIp_ = this.ipConfig.ipv4; |
116 var configType = | 111 var configType = |
117 this.automatic ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; | 112 this.automatic ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC; |
118 this.fire('ip-change', { | 113 this.fire('ip-change', { |
119 field: 'IPAddressConfigType', | 114 field: 'IPAddressConfigType', |
120 value: configType | 115 value: configType, |
121 }); | 116 }); |
122 } else { | 117 } else { |
123 // Restore the saved static IP configuration. | 118 // Restore the saved static IP configuration. |
124 var ipconfig = { | 119 var ipconfig = { |
125 Gateway: this.savedStaticIp_.Gateway, | 120 Gateway: this.savedStaticIp_.Gateway, |
126 IPAddress: this.savedStaticIp_.IPAddress, | 121 IPAddress: this.savedStaticIp_.IPAddress, |
127 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, | 122 RoutingPrefix: this.savedStaticIp_.RoutingPrefix, |
128 Type: this.savedStaticIp_.Type | 123 Type: this.savedStaticIp_.Type, |
129 }; | 124 }; |
130 this.fire('ip-change', { | 125 this.fire('ip-change', { |
131 field: 'StaticIPConfig', | 126 field: 'StaticIPConfig', |
132 value: this.getIPConfigProperties_(ipconfig) | 127 value: this.getIPConfigProperties_(ipconfig), |
133 }); | 128 }); |
134 } | 129 } |
135 }, | 130 }, |
136 | 131 |
137 /** | 132 /** |
138 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig | 133 * @param {!CrOnc.IPConfigProperties|undefined} ipconfig |
139 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object | 134 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object |
140 * with RoutingPrefix expressed as a string mask instead of a prefix | 135 * with RoutingPrefix expressed as a string mask instead of a prefix |
141 * length. Returns an empty object if |ipconfig| is undefined. | 136 * length. Returns an empty object if |ipconfig| is undefined. |
142 * @private | 137 * @private |
(...skipping 24 matching lines...) Expand all Loading... |
167 let value = ipconfig[key]; | 162 let value = ipconfig[key]; |
168 if (key == 'RoutingPrefix') | 163 if (key == 'RoutingPrefix') |
169 result.RoutingPrefix = CrOnc.getRoutingPrefixAsLength(value); | 164 result.RoutingPrefix = CrOnc.getRoutingPrefixAsLength(value); |
170 else | 165 else |
171 result[key] = value; | 166 result[key] = value; |
172 } | 167 } |
173 return result; | 168 return result; |
174 }, | 169 }, |
175 | 170 |
176 /** | 171 /** |
177 * @param {!CrOnc.IPConfigUIProperties} ipConfig The IP Config UI properties. | 172 * @return {boolean} |
178 * @param {boolean} editable The editable property. | 173 * @private |
179 * @param {boolean} automatic The automatic property. | 174 */ |
| 175 showIPEditFields_: function(editable, automatic) { |
| 176 return editable && !automatic; |
| 177 }, |
| 178 |
| 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(ipConfig, editable, automatic) { |
184 if (!editable || automatic) | 184 if (!editable || 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' |
(...skipping 12 matching lines...) Expand all Loading... |
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 }); |
212 })(); | |
OLD | NEW |