Chromium Code Reviews| Index: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| diff --git a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| index b8dc24498eb27f9aa1ed0bdceab67cbd6de089fa..43c97455e3e7bde4569d5311d0de0f67e0ba4367 100644 |
| --- a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| +++ b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| @@ -101,52 +101,16 @@ Polymer({ |
| }, |
| /** @private */ |
| - switchToManufacturerDialog_: function() { |
| + switchToConfiguringDialog_: function() { |
| this.$$('add-printer-dialog').close(); |
| - this.fire('open-manufacturer-model-dialog'); |
| + this.fire('open-configuring-printer-dialog'); |
| }, |
| /** @private */ |
| onAddressChanged_: function() { |
| - this.$.searchInProgress.hidden = false; |
| - this.$.searchFound.hidden = true; |
| - this.$.searchNotFound.hidden = true; |
| - |
| - var value = this.$.printerAddressInput.value; |
| - if (this.isValidIpAddress_(value)) { |
| - // TODO(xdai): Check if the printer address exists after the API is ready. |
| - this.$.searchInProgress.hidden = true; |
| - this.$.searchFound.hidden = false; |
| - this.$.searchNotFound.hidden = true; |
| - } else { |
| - this.$.searchInProgress.hidden = true; |
| - this.$.searchFound.hidden = true; |
| - this.$.searchNotFound.hidden = false; |
| - } |
| - }, |
| - |
| - /** |
| - * @param {string} ip |
| - * @return {boolean} |
| - * @private |
| - */ |
| - isValidIpAddress_: function(ip) { |
| - var addressRegex = RegExp('^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + |
| - '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + |
| - '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + |
| - '([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'); |
| - return addressRegex.test(ip); |
| - }, |
| - |
| - /** |
| - * @param {string} printerName |
| - * @param {string} printerAddress |
| - * @return {boolean} |
| - * @private |
| - */ |
| - addPrinterNotAllowed_: function(printerName, printerAddress) { |
| - return !printerName || !printerAddress || |
| - !this.isValidIpAddress_(printerAddress); |
| + // TODO(xdai): Check if the printer address exists and then show the |
| + // corresponding message after the API is ready. |
| + // The format of address is: ip-address-or-hostname:port-number. |
| }, |
| }); |
| @@ -169,6 +133,11 @@ Polymer({ |
| modelList: { |
| type: Array, |
| }, |
| + |
| + setupFailed: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| }, |
| observers: [ |
| @@ -222,11 +191,17 @@ Polymer({ |
| this.$$('add-printer-dialog').close(); |
| this.fire('configuring-dialog-closed'); |
| }, |
| + |
| + close: function() { |
| + this.$$('add-printer-dialog').close(); |
| + }, |
| }); |
| Polymer({ |
| is: 'settings-cups-add-printer-dialog', |
| + behaviors: [WebUIListenerBehavior], |
| + |
| properties: { |
| /** @type {!CupsPrinterInfo} */ |
| selectedPrinter: { |
| @@ -238,6 +213,12 @@ Polymer({ |
| type: Object, |
| }, |
| + /** @type {boolean} whether the new printer setup is failed. */ |
| + setupFailed: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| + |
| /** @private {string} */ |
| previousDialog_: String, |
| @@ -265,11 +246,45 @@ Polymer({ |
| 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_', |
| }, |
| + /** @override */ |
| + ready: function() { |
| + this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); |
| + }, |
| + |
| /** Opens the Add printer discovery dialog. */ |
| open: function() { |
| + this.resetData_(); |
| this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
| }, |
| + /** |
| + * Reset all the printer data in the Add printer flow. |
| + * @private |
| + */ |
| + resetData_: function() { |
| + if (this.selectedPrinter) |
| + this.resetPrinterData_(this.selectedPrinter); |
|
michaelpg
2016/09/20 20:58:42
This doesn't notify Polymer of these changes. How
xdai1
2016/09/21 17:40:19
Actually it works. For example, this.resetPrinterD
michaelpg
2016/09/21 19:13:23
No: https://jsfiddle.net/jdysdxey/
See https://ww
xdai1
2016/09/21 23:16:16
Thanks! You're right. But then I'm confused why it
|
| + if (this.newPrinter) |
| + this.resetPrinterData_(this.newPrinter); |
| + this.setupFailed = false; |
| + }, |
| + |
| + /** |
| + * @param {!CupsPrinterInfo} printer |
| + * @private |
| + */ |
| + resetPrinterData_: function(printer) { |
| + printer.printerAddress = ''; |
| + printer.printerDescription = ''; |
| + printer.printerId = ''; |
| + printer.printerManufacturer = ''; |
| + printer.printerModel = ''; |
| + printer.printerName = ''; |
| + printer.printerProtocol = 'ipp'; |
| + printer.printerQueue = ''; |
| + printer.printerStatus = ''; |
| + }, |
| + |
| /** @private */ |
| openManuallyAddPrinterDialog_: function() { |
| this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| @@ -286,6 +301,8 @@ Polymer({ |
| openConfiguringPrinterDialog_: function() { |
| this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 'showConfiguringDialog_'); |
| + settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| + addCupsPrinter(this.newPrinter); |
| }, |
| /** @private */ |
| @@ -342,4 +359,20 @@ Polymer({ |
| } |
| return ''; |
| }, |
| + |
| + /** |
| + * @param {boolean} success |
| + * @param {string} printerName |
| + * @private |
| + */ |
| + onAddPrinter_: function(success, printerName) { |
| + this.$$('add-printer-configuring-dialog').close(); |
| + if (success) |
| + return; |
| + |
| + if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) |
|
michaelpg
2016/09/20 20:58:42
I'm having trouble following the flow here. When w
xdai1
2016/09/21 17:40:19
This is the flow https://folio.googleplex.com/chro
michaelpg
2016/09/21 19:13:23
Is this just because you haven't implemented the 0
xdai1
2016/09/21 23:16:16
Actually based on the discussion I had with the PM
|
| + this.setupFailed = true; |
| + this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| + 'showManufacturerDialog_'); |
| + }, |
| }); |