Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js

Issue 2380753004: [CUPS] Implement the Webui handler for the printers auto discovery. (Closed)
Patch Set: Address michaelpg@'s comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
32 * @const {number}
33 */
34 var kPrinterListFullHeight = 350;
35
29 Polymer({ 36 Polymer({
30 is: 'add-printer-discovery-dialog', 37 is: 'add-printer-discovery-dialog',
31 38
39 behaviors: [WebUIListenerBehavior],
40
32 properties: { 41 properties: {
33 /** @type {!Array<!CupsPrinterInfo>} */ 42 /** @type {!Array<!CupsPrinterInfo>|undefined} */
34 discoveredPrinters: { 43 discoveredPrinters: {
35 type: Array, 44 type: Array,
36 }, 45 },
37 46
38 /** @type {!CupsPrinterInfo} */ 47 /** @type {!CupsPrinterInfo} */
39 selectedPrinter: { 48 selectedPrinter: {
40 type: Object, 49 type: Object,
41 notify: true, 50 notify: true,
42 }, 51 },
52
53 discovering_: {
54 type: Boolean,
55 value: true,
56 },
43 }, 57 },
44 58
45 /** @override */ 59 /** @override */
46 ready: function() { 60 ready: function() {
47 // TODO(xdai): Get the discovered printer list after the API is ready. 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 for (var i = 0; i < printers.length; i++)
81 this.push('discoveredPrinters', printers[i]);
82 }
83 },
84
85 /** @private */
86 onPrinterDiscoveryDone_: function() {
87 this.discovering_ = false;
88 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px';
89 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters;
90 },
91
92 /** @private */
93 stopDiscoveringPrinters_: function() {
94 settings.CupsPrintersBrowserProxyImpl.getInstance().
95 stopDiscoveringPrinters();
96 this.discovering_ = false;
48 }, 97 },
49 98
50 /** @private */ 99 /** @private */
51 switchToManualAddDialog_: function() { 100 switchToManualAddDialog_: function() {
101 this.stopDiscoveringPrinters_();
52 this.$$('add-printer-dialog').close(); 102 this.$$('add-printer-dialog').close();
53 this.fire('open-manually-add-printer-dialog'); 103 this.fire('open-manually-add-printer-dialog');
54 }, 104 },
55 105
56 /** @private */ 106 /** @private */
57 onCancelTap_: function() { 107 onCancelTap_: function() {
108 this.stopDiscoveringPrinters_();
58 this.$$('add-printer-dialog').close(); 109 this.$$('add-printer-dialog').close();
59 }, 110 },
60 111
61 /** @private */ 112 /** @private */
62 switchToConfiguringDialog_: function() { 113 switchToConfiguringDialog_: function() {
114 this.stopDiscoveringPrinters_();
63 this.$$('add-printer-dialog').close(); 115 this.$$('add-printer-dialog').close();
64 this.fire('open-configuring-printer-dialog'); 116 this.fire('open-configuring-printer-dialog');
65 }, 117 },
66 }); 118 });
67 119
68 Polymer({ 120 Polymer({
69 is: 'add-printer-maually-dialog', 121 is: 'add-printer-maually-dialog',
70 122
71 properties: { 123 properties: {
72 /** @type {!CupsPrinterInfo} */ 124 /** @type {!CupsPrinterInfo} */
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 /** @private */ 374 /** @private */
323 openDiscoveryPrintersDialog_: function() { 375 openDiscoveryPrintersDialog_: function() {
324 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, 376 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY,
325 'showDiscoveryDialog_'); 377 'showDiscoveryDialog_');
326 }, 378 },
327 379
328 /** @private */ 380 /** @private */
329 openConfiguringPrinterDialog_: function() { 381 openConfiguringPrinterDialog_: function() {
330 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, 382 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING,
331 'showConfiguringDialog_'); 383 'showConfiguringDialog_');
332 settings.CupsPrintersBrowserProxyImpl.getInstance(). 384 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
333 addCupsPrinter(this.newPrinter); 385 settings.CupsPrintersBrowserProxyImpl.getInstance().
386 addCupsPrinter(this.selectedPrinter);
387 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
388 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
389 settings.CupsPrintersBrowserProxyImpl.getInstance().
390 addCupsPrinter(this.newPrinter);
391 }
334 }, 392 },
335 393
336 /** @private */ 394 /** @private */
337 openManufacturerModelDialog_: function() { 395 openManufacturerModelDialog_: function() {
338 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, 396 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
339 'showManufacturerDialog_'); 397 'showManufacturerDialog_');
340 }, 398 },
341 399
342 /** @private */ 400 /** @private */
343 configuringDialogClosed_: function() { 401 configuringDialogClosed_: function() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 /** 449 /**
392 * @param {boolean} success 450 * @param {boolean} success
393 * @param {string} printerName 451 * @param {string} printerName
394 * @private 452 * @private
395 */ 453 */
396 onAddPrinter_: function(success, printerName) { 454 onAddPrinter_: function(success, printerName) {
397 this.$$('add-printer-configuring-dialog').close(); 455 this.$$('add-printer-configuring-dialog').close();
398 if (success) 456 if (success)
399 return; 457 return;
400 458
401 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) 459 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
402 this.setupFailed = true; 460 this.setupFailed = true;
403 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, 461 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) {
404 'showManufacturerDialog_'); 462 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
463 'showManufacturerDialog_');
464 }
405 }, 465 },
406 }); 466 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698