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 9a448f2379bfcb989c5db3d5adb5b3c34b6a6196..261863caa836d96e3d0a6d3943905e9b490eaacc 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 |
| @@ -85,6 +85,7 @@ Polymer({ |
| printerProtocol: 'ipp', |
| printerQueue: '', |
| printerStatus: '', |
| + printerPPDPath: '', |
|
michaelpg
2016/09/21 19:13:23
duplicate
xdai1
2016/09/21 23:16:16
Removed it.
|
| }; |
| }, |
| }, |
| @@ -102,52 +103,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. |
| }, |
| }); |
| @@ -170,6 +135,11 @@ Polymer({ |
| modelList: { |
| type: Array, |
| }, |
| + |
| + setupFailed: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| }, |
| observers: [ |
| @@ -247,11 +217,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: { |
| @@ -263,6 +239,12 @@ Polymer({ |
| type: Object, |
| }, |
| + /** @type {boolean} whether the new printer setup is failed. */ |
| + setupFailed: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| + |
| /** @private {string} */ |
| previousDialog_: String, |
| @@ -290,11 +272,46 @@ 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); |
| + 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 = ''; |
| + printer.printerPPDPath = ''; |
| + }, |
| + |
| /** @private */ |
| openManuallyAddPrinterDialog_: function() { |
| this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| @@ -311,6 +328,8 @@ Polymer({ |
| openConfiguringPrinterDialog_: function() { |
| this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 'showConfiguringDialog_'); |
| + settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| + addCupsPrinter(this.newPrinter); |
| }, |
| /** @private */ |
| @@ -367,4 +386,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) |
| + this.setupFailed = true; |
| + this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| + 'showManufacturerDialog_'); |
| + }, |
| }); |