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. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 behaviors: [WebUIListenerBehavior], | 39 behaviors: [WebUIListenerBehavior], |
| 40 | 40 |
| 41 properties: { | 41 properties: { |
| 42 /** @type {!Array<!CupsPrinterInfo>|undefined} */ | 42 /** @type {!Array<!CupsPrinterInfo>|undefined} */ |
| 43 discoveredPrinters: { | 43 discoveredPrinters: { |
| 44 type: Array, | 44 type: Array, |
| 45 }, | 45 }, |
| 46 | 46 |
| 47 /** @type {!CupsPrinterInfo} */ | 47 /** @type {!CupsPrinterInfo} */ |
| 48 selectedPrinter: { | 48 newPrinter: { |
| 49 type: Object, | 49 type: Object, |
| 50 notify: true, | 50 notify: true, |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 discovering_: { | 53 discovering_: { |
| 54 type: Boolean, | 54 type: Boolean, |
| 55 value: true, | 55 value: true, |
| 56 }, | 56 }, |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 /** @override */ | 59 /** @override */ |
| 60 ready: function() { | 60 ready: function() { |
| 61 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 61 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 62 startDiscoveringPrinters(); | 62 startDiscoveringPrinters(); |
| 63 this.addWebUIListener('on-printer-discovered', | 63 this.addWebUIListener('on-printer-discovered', |
| 64 this.onPrinterDiscovered_.bind(this)); | 64 this.onPrinterDiscovered_.bind(this)); |
| 65 this.addWebUIListener('on-printer-discovery-done', | 65 this.addWebUIListener('on-printer-discovery-done', |
| 66 this.onPrinterDiscoveryDone_.bind(this)); | 66 this.onPrinterDiscoveryDone_.bind(this)); |
| 67 this.addWebUIListener('on-printer-discovery-failed', | 67 this.addWebUIListener('on-printer-discovery-failed', |
| 68 this.onPrinterDiscoveryDone_.bind(this)); | 68 this.onPrinterDiscoveryDone_.bind(this)); |
| 69 }, | 69 }, |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {!Array<!CupsPrinterInfo>} printers | 72 * @param {!Array<!CupsPrinterInfo>} printers |
| 73 * @private | 73 * @private |
| 74 */ | 74 */ |
| 75 onPrinterDiscovered_: function(printers) { | 75 onPrinterDiscovered_: function(printers) { |
| 76 this.discovering_ = true; | 76 this.discoveredPrinters = printers; |
| 77 if (!this.discoveredPrinters) { | 77 if (!this.discovering_) { |
| 78 this.discoveredPrinters = printers; | 78 // This update happened after we already finished the initial |
|
xdai1
2017/03/31 22:08:37
nit: comment indent off: 'scan' should be in the p
Carlson
2017/03/31 22:58:41
Done.
| |
| 79 } else { | 79 // scan, so re-run the discovery done logic. |
| 80 for (var i = 0; i < printers.length; i++) | 80 this.onPrinterDiscoveryDone_(); |
| 81 this.push('discoveredPrinters', printers[i]); | |
| 82 } | 81 } |
| 83 }, | 82 }, |
| 84 | 83 |
| 85 /** @private */ | 84 /** @private */ |
| 86 onPrinterDiscoveryDone_: function() { | 85 onPrinterDiscoveryDone_: function() { |
| 87 this.discovering_ = false; | 86 this.discovering_ = false; |
| 88 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; | 87 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; |
| 89 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; | 88 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; |
| 90 }, | 89 }, |
| 91 | 90 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 103 this.fire('open-manually-add-printer-dialog'); | 102 this.fire('open-manually-add-printer-dialog'); |
| 104 }, | 103 }, |
| 105 | 104 |
| 106 /** @private */ | 105 /** @private */ |
| 107 onCancelTap_: function() { | 106 onCancelTap_: function() { |
| 108 this.stopDiscoveringPrinters_(); | 107 this.stopDiscoveringPrinters_(); |
| 109 this.$$('add-printer-dialog').close(); | 108 this.$$('add-printer-dialog').close(); |
| 110 }, | 109 }, |
| 111 | 110 |
| 112 /** @private */ | 111 /** @private */ |
| 113 switchToConfiguringDialog_: function() { | 112 switchToConfiguringDialog_: function() { |
|
xdai1
2017/03/31 22:08:38
I think you don't need this function any more?
Carlson
2017/03/31 22:58:41
Done.
| |
| 114 this.stopDiscoveringPrinters_(); | 113 this.stopDiscoveringPrinters_(); |
| 115 this.$$('add-printer-dialog').close(); | 114 this.$$('add-printer-dialog').close(); |
| 116 this.fire('open-configuring-printer-dialog'); | 115 this.fire('open-configuring-printer-dialog'); |
| 117 }, | 116 }, |
| 117 | |
| 118 /** @private */ | |
| 119 switchToManufacturerDialog_: function() { | |
| 120 this.stopDiscoveringPrinters_(); | |
| 121 this.$$('add-printer-dialog').close(); | |
| 122 this.fire('open-manufacturer-model-dialog'); | |
| 123 }, | |
| 118 }); | 124 }); |
| 119 | 125 |
| 120 Polymer({ | 126 Polymer({ |
| 121 is: 'add-printer-manually-dialog', | 127 is: 'add-printer-manually-dialog', |
| 122 | 128 |
| 123 properties: { | 129 properties: { |
| 124 /** @type {!CupsPrinterInfo} */ | 130 /** @type {!CupsPrinterInfo} */ |
| 125 newPrinter: { | 131 newPrinter: { |
| 126 type: Object, | 132 type: Object, |
| 127 notify: true, | 133 notify: true, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 }, | 316 }, |
| 311 }); | 317 }); |
| 312 | 318 |
| 313 Polymer({ | 319 Polymer({ |
| 314 is: 'settings-cups-add-printer-dialog', | 320 is: 'settings-cups-add-printer-dialog', |
| 315 | 321 |
| 316 behaviors: [WebUIListenerBehavior], | 322 behaviors: [WebUIListenerBehavior], |
| 317 | 323 |
| 318 properties: { | 324 properties: { |
| 319 /** @type {!CupsPrinterInfo} */ | 325 /** @type {!CupsPrinterInfo} */ |
| 320 selectedPrinter: { | |
|
xdai1
2017/03/31 22:08:38
Could you try to see the following scenario:
Open
Carlson
2017/03/31 22:58:41
Oh, you're good.
Yes, indeed, this is what happen
xdai1
2017/03/31 23:33:52
I would prefer to restore the 'selectedPrinter' ch
| |
| 321 type: Object, | |
| 322 }, | |
| 323 | |
| 324 /** @type {!CupsPrinterInfo} */ | |
| 325 newPrinter: { | 326 newPrinter: { |
| 326 type: Object, | 327 type: Object, |
| 327 }, | 328 }, |
| 328 | 329 |
| 329 /** @type {boolean} whether the new printer setup is failed. */ | 330 /** @type {boolean} whether the new printer setup is failed. */ |
| 330 setupFailed: { | 331 setupFailed: { |
| 331 type: Boolean, | 332 type: Boolean, |
| 332 value: false, | 333 value: false, |
| 333 }, | 334 }, |
| 334 | 335 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 362 }, | 363 }, |
| 363 | 364 |
| 364 /** @override */ | 365 /** @override */ |
| 365 ready: function() { | 366 ready: function() { |
| 366 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); | 367 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); |
| 367 }, | 368 }, |
| 368 | 369 |
| 369 /** Opens the Add printer discovery dialog. */ | 370 /** Opens the Add printer discovery dialog. */ |
| 370 open: function() { | 371 open: function() { |
| 371 this.resetData_(); | 372 this.resetData_(); |
| 372 this.switchDialog_( | 373 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
| 373 '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_'); | |
| 374 }, | 374 }, |
| 375 | 375 |
| 376 /** | 376 /** |
| 377 * Reset all the printer data in the Add printer flow. | 377 * Reset all the printer data in the Add printer flow. |
| 378 * @private | 378 * @private |
| 379 */ | 379 */ |
| 380 resetData_: function() { | 380 resetData_: function() { |
| 381 if (this.selectedPrinter) | |
| 382 this.selectedPrinter = this.getEmptyPrinter_(); | |
| 383 if (this.newPrinter) | 381 if (this.newPrinter) |
| 384 this.newPrinter = this.getEmptyPrinter_(); | 382 this.newPrinter = this.getEmptyPrinter_(); |
| 385 this.setupFailed = false; | 383 this.setupFailed = false; |
| 386 }, | 384 }, |
| 387 | 385 |
| 388 /** | 386 /** |
| 389 * @return {!CupsPrinterInfo} | 387 * @return {!CupsPrinterInfo} |
| 390 * @private | 388 * @private |
| 391 */ | 389 */ |
| 392 getEmptyPrinter_: function() { | 390 getEmptyPrinter_: function() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 417 }, | 415 }, |
| 418 | 416 |
| 419 /** @private */ | 417 /** @private */ |
| 420 openConfiguringPrinterDialog_: function() { | 418 openConfiguringPrinterDialog_: function() { |
| 421 this.switchDialog_( | 419 this.switchDialog_( |
| 422 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 420 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 423 'showConfiguringDialog_'); | 421 'showConfiguringDialog_'); |
| 424 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 422 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| 425 this.configuringDialogTitle = | 423 this.configuringDialogTitle = |
| 426 loadTimeData.getString('addPrintersNearbyTitle'); | 424 loadTimeData.getString('addPrintersNearbyTitle'); |
| 427 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | |
| 428 this.selectedPrinter); | |
| 429 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 425 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 430 this.configuringDialogTitle = | 426 this.configuringDialogTitle = |
| 431 loadTimeData.getString('addPrintersManuallyTitle'); | 427 loadTimeData.getString('addPrintersManuallyTitle'); |
| 432 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | |
| 433 this.newPrinter); | |
| 434 } | 428 } |
| 429 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | |
| 430 this.newPrinter); | |
| 435 }, | 431 }, |
| 436 | 432 |
| 437 /** @private */ | 433 /** @private */ |
| 438 openManufacturerModelDialog_: function() { | 434 openManufacturerModelDialog_: function() { |
| 439 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 435 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 440 'showManufacturerDialog_'); | 436 'showManufacturerDialog_'); |
| 441 }, | 437 }, |
| 442 | 438 |
| 443 /** @private */ | 439 /** @private */ |
| 444 configuringDialogClosed_: function() { | 440 configuringDialogClosed_: function() { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 470 this.set(domIfBooleanName, false); | 466 this.set(domIfBooleanName, false); |
| 471 }.bind(this)); | 467 }.bind(this)); |
| 472 }); | 468 }); |
| 473 }, | 469 }, |
| 474 | 470 |
| 475 /** | 471 /** |
| 476 * @return {string} The name of the current printer in configuration. | 472 * @return {string} The name of the current printer in configuration. |
| 477 * @private | 473 * @private |
| 478 */ | 474 */ |
| 479 getConfiguringPrinterName_: function() { | 475 getConfiguringPrinterName_: function() { |
| 480 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | 476 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY || |
| 481 return this.selectedPrinter.printerName; | 477 this.previousDialog_ == AddPrinterDialogs.MANUALLY || |
| 482 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | |
| 483 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 478 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 484 return this.newPrinter.printerName; | 479 return this.newPrinter.printerName; |
| 485 } | 480 } |
| 486 return ''; | 481 return ''; |
| 487 }, | 482 }, |
| 488 | 483 |
| 489 /** | 484 /** |
| 490 * @param {boolean} success | 485 * @param {boolean} success |
| 491 * @param {string} printerName | 486 * @param {string} printerName |
| 492 * @private | 487 * @private |
| 493 */ | 488 */ |
| 494 onAddPrinter_: function(success, printerName) { | 489 onAddPrinter_: function(success, printerName) { |
| 495 this.$$('add-printer-configuring-dialog').close(); | 490 this.$$('add-printer-configuring-dialog').close(); |
| 496 if (success) | 491 if (success) |
| 497 return; | 492 return; |
| 498 | 493 |
| 499 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 494 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 500 this.setupFailed = true; | 495 this.setupFailed = true; |
| 501 } | 496 } |
| 502 }, | 497 }, |
| 503 }); | 498 }); |
| OLD | NEW |