| 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 network nameserver options. | 6 * @fileoverview Polymer element for displaying network nameserver options. |
| 7 */ | 7 */ |
| 8 Polymer({ | 8 Polymer({ |
| 9 is: 'network-nameservers', | 9 is: 'network-nameservers', |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 this.setNameservers_(type, nameservers); | 102 this.setNameservers_(type, nameservers); |
| 103 }, | 103 }, |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * @param {string} nameserversType | 106 * @param {string} nameserversType |
| 107 * @param {!Array<string>} nameservers | 107 * @param {!Array<string>} nameservers |
| 108 * @private | 108 * @private |
| 109 */ | 109 */ |
| 110 setNameservers_: function(nameserversType, nameservers) { | 110 setNameservers_: function(nameserversType, nameservers) { |
| 111 this.nameserversType_ = nameserversType; | |
| 112 if (nameserversType == 'custom') { | 111 if (nameserversType == 'custom') { |
| 113 // Add empty entries for unset custom nameservers. | 112 // Add empty entries for unset custom nameservers. |
| 114 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i) | 113 for (let i = nameservers.length; i < this.MAX_NAMESERVERS; ++i) |
| 115 nameservers[i] = ''; | 114 nameservers[i] = ''; |
| 116 } | 115 } |
| 117 this.nameservers_ = nameservers; | 116 this.nameservers_ = nameservers; |
| 117 // Set nameserversType_ after dom-repeat has been stamped. |
| 118 this.async(function() { |
| 119 this.nameserversType_ = nameserversType; |
| 120 }.bind(this)); |
| 118 }, | 121 }, |
| 119 | 122 |
| 120 /** | 123 /** |
| 121 * @param {string} type The nameservers type. | 124 * @param {string} type The nameservers type. |
| 122 * @return {string} The description for |type|. | 125 * @return {string} The description for |type|. |
| 123 * @private | 126 * @private |
| 124 */ | 127 */ |
| 125 nameserverTypeDesc_: function(type) { | 128 nameserverTypeDesc_: function(type) { |
| 126 // TODO(stevenjb): Translate. | 129 // TODO(stevenjb): Translate. |
| 127 if (type == 'custom') | 130 if (type == 'custom') |
| 128 return 'Custom name servers'; | 131 return 'Custom name servers'; |
| 129 if (type == 'google') | 132 if (type == 'google') |
| 130 return 'Google name servers'; | 133 return 'Google name servers'; |
| 131 return 'Automatic name servers'; | 134 return 'Automatic name servers'; |
| 132 }, | 135 }, |
| 133 | 136 |
| 134 /** | 137 /** |
| 135 * @return {boolean} True if the nameservers are editable. | 138 * @return {boolean} True if the nameservers are editable. |
| 136 * @private | 139 * @private |
| 137 */ | 140 */ |
| 138 canEdit_: function() { | 141 canEdit_: function() { |
| 139 return this.editable && this.nameserversType_ == 'custom'; | 142 return this.editable && this.nameserversType_ == 'custom'; |
| 140 }, | 143 }, |
| 141 | 144 |
| 142 /** | 145 /** |
| 143 * Event triggered when the selected type changes. Updates nameservers and | 146 * Event triggered when the selected type changes. Updates nameservers and |
| 144 * sends the change value if necessary. | 147 * sends the change value if necessary. |
| 145 * @param {!{detail: !{selected: string}}} e | 148 * @param {!Event} event |
| 146 * @private | 149 * @private |
| 147 */ | 150 */ |
| 148 onTypeChange_: function(e) { | 151 onTypeChange_: function(event) { |
| 149 if (this.nameserversType_ == 'custom') | 152 if (this.nameserversType_ == 'custom') |
| 150 this.savedNameservers_ = this.nameservers_; | 153 this.savedNameservers_ = this.nameservers_; |
| 151 var type = e.detail.selected; | 154 let target = /** @type {!HTMLSelectElement} */ (event.target); |
| 155 let type = target.value; |
| 152 this.nameserversType_ = type; | 156 this.nameserversType_ = type; |
| 153 if (type == 'custom') { | 157 if (type == 'custom') { |
| 154 // Restore the saved nameservers. | 158 // Restore the saved nameservers. |
| 155 this.setNameservers_(type, this.savedNameservers_); | 159 this.setNameservers_(type, this.savedNameservers_); |
| 156 // Only send custom nameservers if they are not empty. | 160 // Only send custom nameservers if they are not empty. |
| 157 if (this.savedNameservers_.length == 0) | 161 if (this.savedNameservers_.length == 0) |
| 158 return; | 162 return; |
| 159 } | 163 } |
| 160 this.sendNameServers_(); | 164 this.sendNameServers_(); |
| 161 }, | 165 }, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 }); | 206 }); |
| 203 } else { | 207 } else { |
| 204 // automatic | 208 // automatic |
| 205 this.fire('nameservers-change', { | 209 this.fire('nameservers-change', { |
| 206 field: 'NameServersConfigType', | 210 field: 'NameServersConfigType', |
| 207 value: CrOnc.IPConfigType.DHCP, | 211 value: CrOnc.IPConfigType.DHCP, |
| 208 }); | 212 }); |
| 209 } | 213 } |
| 210 }, | 214 }, |
| 211 }); | 215 }); |
| OLD | NEW |