Chromium Code Reviews| 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' is the dialog for setting up | 6 * @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.
| |
| 7 * a new CUPS printer. | 7 * a new CUPS printer. |
| 8 */ | 8 */ |
| 9 | |
| 10 /** | |
| 11 * Different dialogs in add printer flow. | |
| 12 * @enum {string} | |
| 13 */ | |
| 14 var AddPrinterDialogs = { | |
| 15 DISCOVERY: 'add-printer-discovery-dialog', | |
| 16 MANUALLY: 'add-printer-maually-dialog', | |
| 17 CONFIGURING: 'add-printer-configuring-dialog', | |
| 18 }; | |
| 19 | |
| 20 Polymer({ | |
| 21 is: 'add-printer-discovery-dialog', | |
| 22 | |
| 23 properties: { | |
| 24 /** @type {!Array<!CupsPrinterInfo>} */ | |
| 25 discoveredPrinters: { | |
| 26 type: Array, | |
| 27 }, | |
| 28 | |
| 29 /** @type {!CupsPrinterInfo} */ | |
| 30 selectedPrinter: { | |
| 31 type: Object, | |
| 32 notify: true, | |
| 33 }, | |
| 34 }, | |
| 35 | |
| 36 /** @override */ | |
| 37 ready: function() { | |
| 38 // TODO(xdai): Get the discovered printer list after the api is ready. | |
| 39 }, | |
| 40 | |
| 41 switchToManualAddDialog_: function() { | |
| 42 this.$$('add-printer-dialog-template').close(); | |
| 43 this.fire('open-manually-add-printer-dialog'); | |
| 44 }, | |
| 45 | |
| 46 onCancelTap_: function() { | |
| 47 this.$$('add-printer-dialog-template').close(); | |
| 48 }, | |
| 49 | |
| 50 switchToConfiguringDialog_: function() { | |
| 51 this.$$('add-printer-dialog-template').close(); | |
| 52 this.fire('open-configuring-printer-dialog'); | |
| 53 }, | |
| 54 }); | |
| 55 | |
| 56 Polymer({ | |
| 57 is: 'add-printer-maually-dialog', | |
| 58 | |
| 59 properties: { | |
| 60 /** @type {!CupsPrinterInfo} */ | |
| 61 newPrinter: { | |
| 62 type: Object, | |
| 63 notify: true, | |
| 64 value: function() { | |
| 65 return { | |
| 66 printerAddress: '', | |
| 67 printerDescription: '', | |
| 68 printerId: '', | |
| 69 printerManufacturer: '', | |
| 70 printerModel: '', | |
| 71 printerName: '', | |
| 72 printerProtocol: 'ipp', | |
| 73 printerQueue: '', | |
| 74 printerStatus: '', | |
| 75 }; | |
| 76 }, | |
| 77 }, | |
| 78 }, | |
| 79 | |
| 80 switchToDiscoveryDialog_: function() { | |
| 81 this.$$('add-printer-dialog-template').close(); | |
| 82 this.fire('open-discovery-printers-dialog'); | |
| 83 }, | |
| 84 | |
| 85 onCancelTap_: function() { | |
| 86 this.$$('add-printer-dialog-template').close(); | |
| 87 }, | |
| 88 | |
| 89 switchToConfiguringDialog_: function() { | |
| 90 this.$$('add-printer-dialog-template').close(); | |
| 91 this.fire('open-configuring-printer-dialog'); | |
| 92 }, | |
| 93 }); | |
| 94 | |
| 95 Polymer({ | |
| 96 is: 'add-printer-configuring-dialog', | |
| 97 | |
| 98 properties: { | |
| 99 printerName: String, | |
| 100 }, | |
| 101 | |
| 102 /** @override */ | |
| 103 attached: function() { | |
| 104 this.$.configuringMessage.textContent = loadTimeData.getStringF( | |
| 105 'printerConfiguringMessage', this.printerName); | |
| 106 }, | |
| 107 | |
| 108 /** @private */ | |
| 109 onCancelConfiguringTap_: function() { | |
| 110 this.$$('add-printer-dialog-template').close(); | |
| 111 this.fire('configuring-dialog-closed'); | |
| 112 }, | |
| 113 }); | |
| 114 | |
| 9 Polymer({ | 115 Polymer({ |
| 10 is: 'settings-cups-add-printer-dialog', | 116 is: 'settings-cups-add-printer-dialog', |
| 11 | 117 |
| 12 /** Opens the Add printer dialog. */ | 118 properties: { |
| 119 /** @type {!CupsPrinterInfo} */ | |
| 120 selectedPrinter: { | |
| 121 type: Object, | |
| 122 }, | |
| 123 | |
| 124 /** @type {!CupsPrinterInfo} */ | |
| 125 newPrinter: { | |
| 126 type: Object, | |
| 127 }, | |
| 128 | |
| 129 /** @private {string} */ | |
| 130 previousDialog_: String, | |
| 131 | |
| 132 /** @private {string} */ | |
| 133 currentDialog_: String, | |
| 134 | |
| 135 /** @private {boolean} */ | |
| 136 showDiscoveryDialog_: Boolean, | |
| 137 | |
| 138 /** @private {boolean} */ | |
| 139 showManuallyAddDialog_: Boolean, | |
| 140 | |
| 141 /** @private {boolean} */ | |
| 142 showConfiguringDialog_: Boolean, | |
| 143 }, | |
| 144 | |
| 145 listeners: { | |
| 146 'configuring-dialog-closed': 'configuringDialogClosed_', | |
| 147 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', | |
| 148 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', | |
| 149 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', | |
| 150 }, | |
| 151 | |
| 152 /** Opens the Add printer discovery dialog. */ | |
| 13 open: function() { | 153 open: function() { |
| 14 this.$.dialog.showModal(); | 154 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
| 15 }, | 155 }, |
| 16 | 156 |
| 17 /** @private */ | 157 /** @private */ |
| 18 onCancelTap_: function() { | 158 openManuallyAddPrinterDialog_: function() { |
| 19 this.$.dialog.close(); | 159 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| 20 }, | 160 'showManuallyAddDialog_'); |
| 21 }); | 161 }, |
| 162 | |
| 163 /** @private */ | |
| 164 openDiscoveryPrintersDialog_: function() { | |
| 165 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | |
| 166 'showDiscoveryDialog_'); | |
| 167 }, | |
| 168 | |
| 169 /** @private */ | |
| 170 openConfiguringPrinterDialog_: function() { | |
| 171 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, | |
| 172 'showConfiguringDialog_'); | |
| 173 }, | |
| 174 | |
| 175 /** @private */ | |
| 176 configuringDialogClosed_: function() { | |
| 177 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | |
| 178 this.switchDialog_( | |
| 179 this.currentDialog_, this.previousDialog_, 'showDiscoveryDialog_'); | |
| 180 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { | |
| 181 this.switchDialog_( | |
| 182 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); | |
| 183 } | |
| 184 }, | |
| 185 | |
| 186 /** | |
| 187 * Switch dialog from |fromDialog| to |toDialog|. | |
| 188 * @param {string} fromDialog | |
| 189 * @param {string} toDialog | |
| 190 * @param {string} domIfBooleanName The name of the boolean variable | |
| 191 * corresponding to the |toDialog|. | |
| 192 * @private | |
| 193 */ | |
| 194 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { | |
| 195 this.previousDialog_ = fromDialog; | |
| 196 this.currentDialog_ = toDialog; | |
| 197 | |
| 198 this.set(domIfBooleanName, true); | |
| 199 this.async(function() { | |
| 200 var dialog = this.$$(toDialog); | |
| 201 dialog.addEventListener('close', function() { | |
| 202 this.set(domIfBooleanName, false); | |
| 203 }.bind(this)); | |
| 204 }.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.
| |
| 205 }, | |
| 206 | |
| 207 /** @private */ | |
|
michaelpg
2016/08/29 17:10:33
document @return type
xdai1
2016/08/29 18:45:45
Done.
| |
| 208 getConfiguringPrinterName_: function() { | |
| 209 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | |
| 210 return this.selectedPrinter.printerName; | |
| 211 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) | |
| 212 return this.newPrinter.printerName; | |
| 213 return null; | |
|
michaelpg
2016/08/29 17:10:32
why not ''?
xdai1
2016/08/29 18:45:45
Oh you're right. Thanks!
| |
| 214 }, | |
| 215 }); | |
| OLD | NEW |