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 24e8f787ab684cb2dbfa651b46461cdeada14f50..e4441fb9a4db2fbbf78500656b59b7eb9eb58d44 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 |
| @@ -6,16 +6,210 @@ |
| * @fileoverview 'settings-cups-add-printer-dialog' is the dialog for setting up |
|
michaelpg
2016/08/29 17:10:32
update this comment to explain the multi-dialog se
xdai1
2016/08/29 18:45:45
Done.
|
| * a new CUPS printer. |
| */ |
| + |
| +/** |
| + * Different dialogs in add printer flow. |
| + * @enum {string} |
| + */ |
| +var AddPrinterDialogs = { |
| + DISCOVERY: 'add-printer-discovery-dialog', |
| + MANUALLY: 'add-printer-maually-dialog', |
| + CONFIGURING: 'add-printer-configuring-dialog', |
| +}; |
| + |
| +Polymer({ |
| + is: 'add-printer-discovery-dialog', |
| + |
| + properties: { |
| + /** @type {!Array<!CupsPrinterInfo>} */ |
| + discoveredPrinters: { |
| + type: Array, |
| + }, |
| + |
| + /** @type {!CupsPrinterInfo} */ |
| + selectedPrinter: { |
| + type: Object, |
| + notify: true, |
| + }, |
| + }, |
| + |
| + /** @override */ |
| + ready: function() { |
| + // TODO(xdai): Get the discovered printer list after the api is ready. |
| + }, |
| + |
| + switchToManualAddDialog_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + this.fire('open-manually-add-printer-dialog'); |
| + }, |
| + |
| + onCancelTap_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + }, |
| + |
| + switchToConfiguringDialog_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + this.fire('open-configuring-printer-dialog'); |
| + }, |
| +}); |
| + |
| +Polymer({ |
| + is: 'add-printer-maually-dialog', |
| + |
| + properties: { |
| + /** @type {!CupsPrinterInfo} */ |
| + newPrinter: { |
| + type: Object, |
| + notify: true, |
| + value: function() { |
| + return { |
| + printerAddress: '', |
| + printerDescription: '', |
| + printerId: '', |
| + printerManufacturer: '', |
| + printerModel: '', |
| + printerName: '', |
| + printerProtocol: 'ipp', |
| + printerQueue: '', |
| + printerStatus: '', |
| + }; |
| + }, |
| + }, |
| + }, |
| + |
| + switchToDiscoveryDialog_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + this.fire('open-discovery-printers-dialog'); |
| + }, |
| + |
| + onCancelTap_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + }, |
| + |
| + switchToConfiguringDialog_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + this.fire('open-configuring-printer-dialog'); |
| + }, |
| +}); |
| + |
| +Polymer({ |
| + is: 'add-printer-configuring-dialog', |
| + |
| + properties: { |
| + printerName: String, |
| + }, |
| + |
| + /** @override */ |
| + attached: function() { |
| + this.$.configuringMessage.textContent = loadTimeData.getStringF( |
| + 'printerConfiguringMessage', this.printerName); |
| + }, |
| + |
| + /** @private */ |
| + onCancelConfiguringTap_: function() { |
| + this.$$('add-printer-dialog-template').close(); |
| + this.fire('configuring-dialog-closed'); |
| + }, |
| +}); |
| + |
| Polymer({ |
| is: 'settings-cups-add-printer-dialog', |
| - /** Opens the Add printer dialog. */ |
| + properties: { |
| + /** @type {!CupsPrinterInfo} */ |
| + selectedPrinter: { |
| + type: Object, |
| + }, |
| + |
| + /** @type {!CupsPrinterInfo} */ |
| + newPrinter: { |
| + type: Object, |
| + }, |
| + |
| + /** @private {string} */ |
| + previousDialog_: String, |
| + |
| + /** @private {string} */ |
| + currentDialog_: String, |
| + |
| + /** @private {boolean} */ |
| + showDiscoveryDialog_: Boolean, |
| + |
| + /** @private {boolean} */ |
| + showManuallyAddDialog_: Boolean, |
| + |
| + /** @private {boolean} */ |
| + showConfiguringDialog_: Boolean, |
| + }, |
| + |
| + listeners: { |
| + 'configuring-dialog-closed': 'configuringDialogClosed_', |
| + 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', |
| + 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', |
| + 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', |
| + }, |
| + |
| + /** Opens the Add printer discovery dialog. */ |
| open: function() { |
| - this.$.dialog.showModal(); |
| + this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
| }, |
| /** @private */ |
| - onCancelTap_: function() { |
| - this.$.dialog.close(); |
| + openManuallyAddPrinterDialog_: function() { |
| + this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| + 'showManuallyAddDialog_'); |
| + }, |
| + |
| + /** @private */ |
| + openDiscoveryPrintersDialog_: function() { |
| + this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| + 'showDiscoveryDialog_'); |
| + }, |
| + |
| + /** @private */ |
| + openConfiguringPrinterDialog_: function() { |
| + this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| + 'showConfiguringDialog_'); |
| + }, |
| + |
| + /** @private */ |
| + configuringDialogClosed_: function() { |
| + if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| + this.switchDialog_( |
| + this.currentDialog_, this.previousDialog_, 'showDiscoveryDialog_'); |
| + } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| + this.switchDialog_( |
| + this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); |
| + } |
| + }, |
| + |
| + /** |
| + * Switch dialog from |fromDialog| to |toDialog|. |
| + * @param {string} fromDialog |
| + * @param {string} toDialog |
| + * @param {string} domIfBooleanName The name of the boolean variable |
| + * corresponding to the |toDialog|. |
| + * @private |
| + */ |
| + switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { |
| + this.previousDialog_ = fromDialog; |
| + this.currentDialog_ = toDialog; |
| + |
| + this.set(domIfBooleanName, true); |
| + this.async(function() { |
| + var dialog = this.$$(toDialog); |
| + dialog.addEventListener('close', function() { |
| + this.set(domIfBooleanName, false); |
| + }.bind(this)); |
| + }.bind(this)); |
|
michaelpg
2016/08/29 17:10:32
no need to .bind(this) -- this.async calls the cal
xdai1
2016/08/29 18:45:45
Done.
|
| + }, |
| + |
| + /** @private */ |
|
michaelpg
2016/08/29 17:10:33
document @return type
xdai1
2016/08/29 18:45:45
Done.
|
| + getConfiguringPrinterName_: function() { |
| + if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) |
| + return this.selectedPrinter.printerName; |
| + if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) |
| + return this.newPrinter.printerName; |
| + return null; |
|
michaelpg
2016/08/29 17:10:32
why not ''?
xdai1
2016/08/29 18:45:45
Oh you're right. Thanks!
|
| }, |
| }); |