| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 'settings-cups-add-printer-dialog' includes multiple dialogs to | 6 * @fileoverview 'settings-cups-add-printer-dialog' includes multiple dialogs to |
| 7 * set up a new CUPS printer. | 7 * set up a new CUPS printer. |
| 8 * Subdialogs include: | 8 * Subdialogs include: |
| 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on | 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on |
| 10 * the network that are available for setup. | 10 * the network that are available for setup. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 }, | 101 }, |
| 102 | 102 |
| 103 /** @private */ | 103 /** @private */ |
| 104 switchToManufacturerDialog_: function() { | 104 switchToManufacturerDialog_: function() { |
| 105 this.$$('add-printer-dialog').close(); | 105 this.$$('add-printer-dialog').close(); |
| 106 this.fire('open-manufacturer-model-dialog'); | 106 this.fire('open-manufacturer-model-dialog'); |
| 107 }, | 107 }, |
| 108 | 108 |
| 109 /** @private */ | 109 /** @private */ |
| 110 onAddressChanged_: function() { | 110 onAddressChanged_: function() { |
| 111 this.$.searchInProgress.hidden = false; | |
| 112 this.$.searchFound.hidden = true; | |
| 113 this.$.searchNotFound.hidden = true; | |
| 114 | |
| 115 var value = this.$.printerAddressInput.value; | |
| 116 if (this.isValidIpAddress_(value)) { | |
| 117 // TODO(xdai): Check if the printer address exists after the API is ready. | |
| 118 this.$.searchInProgress.hidden = true; | |
| 119 this.$.searchFound.hidden = false; | |
| 120 this.$.searchNotFound.hidden = true; | |
| 121 } else { | |
| 122 this.$.searchInProgress.hidden = true; | |
| 123 this.$.searchFound.hidden = true; | |
| 124 this.$.searchNotFound.hidden = false; | |
| 125 } | |
| 126 }, | 111 }, |
| 127 | 112 |
| 128 /** | 113 /** |
| 129 * @param {string} ip | |
| 130 * @return {boolean} | |
| 131 * @private | |
| 132 */ | |
| 133 isValidIpAddress_: function(ip) { | |
| 134 var addressRegex = RegExp('^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
| 135 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
| 136 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
| 137 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'); | |
| 138 return addressRegex.test(ip); | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * @param {string} printerName | 114 * @param {string} printerName |
| 143 * @param {string} printerAddress | 115 * @param {string} printerAddress |
| 144 * @return {boolean} | 116 * @return {boolean} |
| 145 * @private | 117 * @private |
| 146 */ | 118 */ |
| 147 addPrinterNotAllowed_: function(printerName, printerAddress) { | 119 addPrinterNotAllowed_: function(printerName, printerAddress) { |
| 148 return !printerName || !printerAddress || | 120 return !printerName || !printerAddress; |
| 149 !this.isValidIpAddress_(printerAddress); | |
| 150 }, | 121 }, |
| 151 }); | 122 }); |
| 152 | 123 |
| 153 Polymer({ | 124 Polymer({ |
| 154 is: 'add-printer-manufacturer-model-dialog', | 125 is: 'add-printer-manufacturer-model-dialog', |
| 155 | 126 |
| 156 properties: { | 127 properties: { |
| 157 /** @type {!CupsPrinterInfo} */ | 128 /** @type {!CupsPrinterInfo} */ |
| 158 newPrinter: { | 129 newPrinter: { |
| 159 type: Object, | 130 type: Object, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 /** @private */ | 250 /** @private */ |
| 280 openDiscoveryPrintersDialog_: function() { | 251 openDiscoveryPrintersDialog_: function() { |
| 281 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 252 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 282 'showDiscoveryDialog_'); | 253 'showDiscoveryDialog_'); |
| 283 }, | 254 }, |
| 284 | 255 |
| 285 /** @private */ | 256 /** @private */ |
| 286 openConfiguringPrinterDialog_: function() { | 257 openConfiguringPrinterDialog_: function() { |
| 287 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 258 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 288 'showConfiguringDialog_'); | 259 'showConfiguringDialog_'); |
| 260 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 261 addCupsPrinter(this.newPrinter); |
| 289 }, | 262 }, |
| 290 | 263 |
| 291 /** @private */ | 264 /** @private */ |
| 292 openManufacturerModelDialog_: function() { | 265 openManufacturerModelDialog_: function() { |
| 293 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 266 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 294 'showManufacturerDialog_'); | 267 'showManufacturerDialog_'); |
| 295 }, | 268 }, |
| 296 | 269 |
| 297 /** @private */ | 270 /** @private */ |
| 298 configuringDialogClosed_: function() { | 271 configuringDialogClosed_: function() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 getConfiguringPrinterName_: function() { | 309 getConfiguringPrinterName_: function() { |
| 337 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | 310 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) |
| 338 return this.selectedPrinter.printerName; | 311 return this.selectedPrinter.printerName; |
| 339 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | 312 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || |
| 340 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 313 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 341 return this.newPrinter.printerName; | 314 return this.newPrinter.printerName; |
| 342 } | 315 } |
| 343 return ''; | 316 return ''; |
| 344 }, | 317 }, |
| 345 }); | 318 }); |
| OLD | NEW |