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