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' includes multiple dialogs to | 6 * @fileoverview 'settings-cups-add-printer-dialog' includes multiple dialogs to |
| 7 * set up a new CUPS printer. | 7 * set up a new CUPS printer. |
| 8 * Subdialogs include: | 8 * Subdialogs include: |
| 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on | 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on |
| 10 * the network that are available for setup. | 10 * the network that are available for setup. |
| 11 * - 'add-printer-maually-dialog' is a dialog in which user can manually enter | 11 * - 'add-printer-maually-dialog' is a dialog in which user can manually enter |
| 12 * the information to set up a new printer. | 12 * the information to set up a new printer. |
| 13 * - 'add-printer-configuring-dialog' is the configuring-in-progress dialog. | 13 * - 'add-printer-configuring-dialog' is the configuring-in-progress dialog. |
| 14 * - 'add-printer-manufacturer-model-dialog' is a dialog in which the user can | 14 * - 'add-printer-manufacturer-model-dialog' is a dialog in which the user can |
| 15 * manually select the manufacture and model of the new printer. | 15 * manually select the manufacture and model of the new printer. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Different dialogs in add printer flow. | 19 * Different dialogs in add printer flow. |
| 20 * @enum {string} | 20 * @enum {string} |
| 21 */ | 21 */ |
| 22 var AddPrinterDialogs = { | 22 var AddPrinterDialogs = { |
| 23 DISCOVERY: 'add-printer-discovery-dialog', | 23 DISCOVERY: 'add-printer-discovery-dialog', |
| 24 MANUALLY: 'add-printer-maually-dialog', | 24 MANUALLY: 'add-printer-maually-dialog', |
| 25 CONFIGURING: 'add-printer-configuring-dialog', | 25 CONFIGURING: 'add-printer-configuring-dialog', |
| 26 MANUFACTURER: 'add-printer-manufacturer-model-dialog', | 26 MANUFACTURER: 'add-printer-manufacturer-model-dialog', |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 /** | |
| 30 * The maximum height of the discovered printers list when the searching spinner | |
| 31 * is not showing. | |
|
michaelpg
2016/10/04 22:31:10
@const {number}
xdai1
2016/10/04 23:36:19
Done.
| |
| 32 */ | |
| 33 var printerListFullHeight = 350; | |
|
michaelpg
2016/10/04 22:31:10
kPrinterListFullHeight or PRINTER_LIST_FULL_HEIGHT
xdai1
2016/10/04 23:36:19
Done.
| |
| 34 | |
| 29 Polymer({ | 35 Polymer({ |
| 30 is: 'add-printer-discovery-dialog', | 36 is: 'add-printer-discovery-dialog', |
| 31 | 37 |
| 38 behaviors: [WebUIListenerBehavior], | |
| 39 | |
| 32 properties: { | 40 properties: { |
| 33 /** @type {!Array<!CupsPrinterInfo>} */ | 41 /** @type {!Array<!CupsPrinterInfo>|undefined} */ |
| 34 discoveredPrinters: { | 42 discoveredPrinters: { |
| 35 type: Array, | 43 type: Array, |
| 36 }, | 44 }, |
| 37 | 45 |
| 38 /** @type {!CupsPrinterInfo} */ | 46 /** @type {!CupsPrinterInfo} */ |
| 39 selectedPrinter: { | 47 selectedPrinter: { |
| 40 type: Object, | 48 type: Object, |
| 41 notify: true, | 49 notify: true, |
| 42 }, | 50 }, |
| 51 | |
| 52 discovering_: { | |
| 53 type: Boolean, | |
| 54 value: false, | |
| 55 }, | |
| 43 }, | 56 }, |
| 44 | 57 |
| 45 /** @override */ | 58 /** @override */ |
| 46 ready: function() { | 59 ready: function() { |
| 47 // TODO(xdai): Get the discovered printer list after the API is ready. | 60 this.discovering_ = true; |
|
michaelpg
2016/10/04 22:31:10
Why not set the initial value to true, above?
xdai1
2016/10/04 23:36:19
Done.
| |
| 61 settings.CupsPrintersBrowserProxyImpl.getInstance(). | |
| 62 startDiscoveringPrinters(); | |
| 63 this.addWebUIListener('on-printer-discovered', | |
| 64 this.onPrinterDiscovered_.bind(this)); | |
| 65 this.addWebUIListener('on-printer-discovery-done', | |
| 66 this.onPrinterDiscoveryDone_.bind(this)); | |
| 67 this.addWebUIListener('on-printer-discovery-failed', | |
| 68 this.onPrinterDiscoveryDone_.bind(this)); | |
| 69 }, | |
| 70 | |
| 71 /** | |
| 72 * @param {!Array<!CupsPrinterInfo>} printers | |
| 73 * @private | |
| 74 */ | |
| 75 onPrinterDiscovered_: function(printers) { | |
| 76 this.discovering_ = true; | |
| 77 if (!this.discoveredPrinters) | |
| 78 this.discoveredPrinters = printers; | |
| 79 else | |
| 80 this.discoveredPrinters = this.discoveredPrinters.concat(printers); | |
|
michaelpg
2016/10/04 22:31:10
instead of replacing the whole array (which might
xdai1
2016/10/04 23:36:19
Seems like it could not push back a CupsPrinterInf
| |
| 81 }, | |
| 82 | |
| 83 /** @private */ | |
| 84 onPrinterDiscoveryDone_: function() { | |
| 85 this.discovering_ = false; | |
| 86 this.$$('add-printer-list').style.maxHeight = printerListFullHeight + 'px'; | |
| 87 if (!this.discoveredPrinters) | |
| 88 this.$.noPrinterMessage.hidden = false; | |
|
michaelpg
2016/10/04 22:31:10
this.$.nPM.hidden = !!this.discoveredPrinters;
xdai1
2016/10/04 23:36:19
Done.
| |
| 89 else | |
| 90 this.$.noPrinterMessage.hidden = true; | |
| 91 }, | |
| 92 | |
| 93 /** @private */ | |
| 94 stopDiscoveringPrinters_: function() { | |
| 95 settings.CupsPrintersBrowserProxyImpl.getInstance(). | |
| 96 stopDiscoveringPrinters(); | |
| 97 this.discovering_ = false; | |
| 48 }, | 98 }, |
| 49 | 99 |
| 50 /** @private */ | 100 /** @private */ |
| 51 switchToManualAddDialog_: function() { | 101 switchToManualAddDialog_: function() { |
| 102 this.stopDiscoveringPrinters_(); | |
| 52 this.$$('add-printer-dialog').close(); | 103 this.$$('add-printer-dialog').close(); |
| 53 this.fire('open-manually-add-printer-dialog'); | 104 this.fire('open-manually-add-printer-dialog'); |
| 54 }, | 105 }, |
| 55 | 106 |
| 56 /** @private */ | 107 /** @private */ |
| 57 onCancelTap_: function() { | 108 onCancelTap_: function() { |
| 109 this.stopDiscoveringPrinters_(); | |
| 58 this.$$('add-printer-dialog').close(); | 110 this.$$('add-printer-dialog').close(); |
| 59 }, | 111 }, |
| 60 | 112 |
| 61 /** @private */ | 113 /** @private */ |
| 62 switchToConfiguringDialog_: function() { | 114 switchToConfiguringDialog_: function() { |
| 115 this.stopDiscoveringPrinters_(); | |
| 63 this.$$('add-printer-dialog').close(); | 116 this.$$('add-printer-dialog').close(); |
| 64 this.fire('open-configuring-printer-dialog'); | 117 this.fire('open-configuring-printer-dialog'); |
| 65 }, | 118 }, |
| 66 }); | 119 }); |
| 67 | 120 |
| 68 Polymer({ | 121 Polymer({ |
| 69 is: 'add-printer-maually-dialog', | 122 is: 'add-printer-maually-dialog', |
| 70 | 123 |
| 71 properties: { | 124 properties: { |
| 72 /** @type {!CupsPrinterInfo} */ | 125 /** @type {!CupsPrinterInfo} */ |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 /** @private */ | 375 /** @private */ |
| 323 openDiscoveryPrintersDialog_: function() { | 376 openDiscoveryPrintersDialog_: function() { |
| 324 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 377 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 325 'showDiscoveryDialog_'); | 378 'showDiscoveryDialog_'); |
| 326 }, | 379 }, |
| 327 | 380 |
| 328 /** @private */ | 381 /** @private */ |
| 329 openConfiguringPrinterDialog_: function() { | 382 openConfiguringPrinterDialog_: function() { |
| 330 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 383 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 331 'showConfiguringDialog_'); | 384 'showConfiguringDialog_'); |
| 332 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 385 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| 333 addCupsPrinter(this.newPrinter); | 386 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 387 addCupsPrinter(this.selectedPrinter); | |
| 388 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | |
| 389 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | |
| 390 settings.CupsPrintersBrowserProxyImpl.getInstance(). | |
| 391 addCupsPrinter(this.newPrinter); | |
| 392 } | |
| 334 }, | 393 }, |
| 335 | 394 |
| 336 /** @private */ | 395 /** @private */ |
| 337 openManufacturerModelDialog_: function() { | 396 openManufacturerModelDialog_: function() { |
| 338 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 397 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 339 'showManufacturerDialog_'); | 398 'showManufacturerDialog_'); |
| 340 }, | 399 }, |
| 341 | 400 |
| 342 /** @private */ | 401 /** @private */ |
| 343 configuringDialogClosed_: function() { | 402 configuringDialogClosed_: function() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 /** | 450 /** |
| 392 * @param {boolean} success | 451 * @param {boolean} success |
| 393 * @param {string} printerName | 452 * @param {string} printerName |
| 394 * @private | 453 * @private |
| 395 */ | 454 */ |
| 396 onAddPrinter_: function(success, printerName) { | 455 onAddPrinter_: function(success, printerName) { |
| 397 this.$$('add-printer-configuring-dialog').close(); | 456 this.$$('add-printer-configuring-dialog').close(); |
| 398 if (success) | 457 if (success) |
| 399 return; | 458 return; |
| 400 | 459 |
| 401 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) | 460 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 402 this.setupFailed = true; | 461 this.setupFailed = true; |
| 403 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 462 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| 404 'showManufacturerDialog_'); | 463 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 464 'showManufacturerDialog_'); | |
| 465 } | |
| 405 }, | 466 }, |
| 406 }); | 467 }); |
| OLD | NEW |