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

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

Issue 2790603003: Make CUPS USB printing play better with the settings page. This change does several things: (Closed)
Patch Set: Address xdai@ comments Created 3 years, 8 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.
(...skipping 27 matching lines...) Expand all
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 scan, so
79 } else { 79 // 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
92 /** @private */ 91 /** @private */
93 stopDiscoveringPrinters_: function() { 92 stopDiscoveringPrinters_: function() {
94 settings.CupsPrintersBrowserProxyImpl.getInstance(). 93 settings.CupsPrintersBrowserProxyImpl.getInstance().
95 stopDiscoveringPrinters(); 94 stopDiscoveringPrinters();
96 this.discovering_ = false; 95 this.discovering_ = false;
97 }, 96 },
98 97
99 /** @private */ 98 /** @private */
100 switchToManualAddDialog_: function() { 99 switchToManualAddDialog_: function() {
101 this.stopDiscoveringPrinters_(); 100 this.stopDiscoveringPrinters_();
101 // If the user has a printer selected in the discovery list, we *don't* want
102 // to use that if we go to add a printer manually, so reset newPrinter.
103 this.newPrinter = {
104 printerAddress: '',
105 printerDescription: '',
106 printerId: '',
107 printerManufacturer: '',
108 printerModel: '',
109 printerName: '',
110 printerPPDPath: '',
111 printerProtocol: 'ipp',
112 printerQueue: 'ipp/print',
113 printerStatus: '',
114 };
102 this.$$('add-printer-dialog').close(); 115 this.$$('add-printer-dialog').close();
103 this.fire('open-manually-add-printer-dialog'); 116 this.fire('open-manually-add-printer-dialog');
104 }, 117 },
105 118
106 /** @private */ 119 /** @private */
107 onCancelTap_: function() { 120 onCancelTap_: function() {
108 this.stopDiscoveringPrinters_(); 121 this.stopDiscoveringPrinters_();
109 this.$$('add-printer-dialog').close(); 122 this.$$('add-printer-dialog').close();
110 }, 123 },
111 124
112 /** @private */ 125 /** @private */
113 switchToConfiguringDialog_: function() { 126 switchToManufacturerDialog_: function() {
114 this.stopDiscoveringPrinters_(); 127 this.stopDiscoveringPrinters_();
115 this.$$('add-printer-dialog').close(); 128 this.$$('add-printer-dialog').close();
116 this.fire('open-configuring-printer-dialog'); 129 this.fire('open-manufacturer-model-dialog');
117 }, 130 },
118 }); 131 });
119 132
120 Polymer({ 133 Polymer({
121 is: 'add-printer-manually-dialog', 134 is: 'add-printer-manually-dialog',
122 135
123 properties: { 136 properties: {
124 /** @type {!CupsPrinterInfo} */ 137 /** @type {!CupsPrinterInfo} */
125 newPrinter: { 138 newPrinter: {
126 type: Object, 139 type: Object,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 }, 323 },
311 }); 324 });
312 325
313 Polymer({ 326 Polymer({
314 is: 'settings-cups-add-printer-dialog', 327 is: 'settings-cups-add-printer-dialog',
315 328
316 behaviors: [WebUIListenerBehavior], 329 behaviors: [WebUIListenerBehavior],
317 330
318 properties: { 331 properties: {
319 /** @type {!CupsPrinterInfo} */ 332 /** @type {!CupsPrinterInfo} */
320 selectedPrinter: {
321 type: Object,
322 },
323
324 /** @type {!CupsPrinterInfo} */
325 newPrinter: { 333 newPrinter: {
326 type: Object, 334 type: Object,
327 }, 335 },
328 336
329 /** @type {boolean} whether the new printer setup is failed. */ 337 /** @type {boolean} whether the new printer setup is failed. */
330 setupFailed: { 338 setupFailed: {
331 type: Boolean, 339 type: Boolean,
332 value: false, 340 value: false,
333 }, 341 },
334 342
(...skipping 27 matching lines...) Expand all
362 }, 370 },
363 371
364 /** @override */ 372 /** @override */
365 ready: function() { 373 ready: function() {
366 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); 374 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this));
367 }, 375 },
368 376
369 /** Opens the Add printer discovery dialog. */ 377 /** Opens the Add printer discovery dialog. */
370 open: function() { 378 open: function() {
371 this.resetData_(); 379 this.resetData_();
372 this.switchDialog_( 380 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_');
373 '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_');
374 }, 381 },
375 382
376 /** 383 /**
377 * Reset all the printer data in the Add printer flow. 384 * Reset all the printer data in the Add printer flow.
378 * @private 385 * @private
379 */ 386 */
380 resetData_: function() { 387 resetData_: function() {
381 if (this.selectedPrinter)
382 this.selectedPrinter = this.getEmptyPrinter_();
383 if (this.newPrinter) 388 if (this.newPrinter)
384 this.newPrinter = this.getEmptyPrinter_(); 389 this.newPrinter = this.getEmptyPrinter_();
385 this.setupFailed = false; 390 this.setupFailed = false;
386 }, 391 },
387 392
388 /** 393 /**
389 * @return {!CupsPrinterInfo} 394 * @return {!CupsPrinterInfo}
390 * @private 395 * @private
391 */ 396 */
392 getEmptyPrinter_: function() { 397 getEmptyPrinter_: function() {
(...skipping 24 matching lines...) Expand all
417 }, 422 },
418 423
419 /** @private */ 424 /** @private */
420 openConfiguringPrinterDialog_: function() { 425 openConfiguringPrinterDialog_: function() {
421 this.switchDialog_( 426 this.switchDialog_(
422 this.currentDialog_, AddPrinterDialogs.CONFIGURING, 427 this.currentDialog_, AddPrinterDialogs.CONFIGURING,
423 'showConfiguringDialog_'); 428 'showConfiguringDialog_');
424 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { 429 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
425 this.configuringDialogTitle = 430 this.configuringDialogTitle =
426 loadTimeData.getString('addPrintersNearbyTitle'); 431 loadTimeData.getString('addPrintersNearbyTitle');
427 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
428 this.selectedPrinter);
429 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 432 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
430 this.configuringDialogTitle = 433 this.configuringDialogTitle =
431 loadTimeData.getString('addPrintersManuallyTitle'); 434 loadTimeData.getString('addPrintersManuallyTitle');
432 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
433 this.newPrinter);
434 } 435 }
436 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
437 this.newPrinter);
435 }, 438 },
436 439
437 /** @private */ 440 /** @private */
438 openManufacturerModelDialog_: function() { 441 openManufacturerModelDialog_: function() {
439 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, 442 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
440 'showManufacturerDialog_'); 443 'showManufacturerDialog_');
441 }, 444 },
442 445
443 /** @private */ 446 /** @private */
444 configuringDialogClosed_: function() { 447 configuringDialogClosed_: function() {
(...skipping 25 matching lines...) Expand all
470 this.set(domIfBooleanName, false); 473 this.set(domIfBooleanName, false);
471 }.bind(this)); 474 }.bind(this));
472 }); 475 });
473 }, 476 },
474 477
475 /** 478 /**
476 * @return {string} The name of the current printer in configuration. 479 * @return {string} The name of the current printer in configuration.
477 * @private 480 * @private
478 */ 481 */
479 getConfiguringPrinterName_: function() { 482 getConfiguringPrinterName_: function() {
480 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) 483 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY ||
481 return this.selectedPrinter.printerName; 484 this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
482 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
483 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 485 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
484 return this.newPrinter.printerName; 486 return this.newPrinter.printerName;
485 } 487 }
486 return ''; 488 return '';
487 }, 489 },
488 490
489 /** 491 /**
490 * @param {boolean} success 492 * @param {boolean} success
491 * @param {string} printerName 493 * @param {string} printerName
492 * @private 494 * @private
493 */ 495 */
494 onAddPrinter_: function(success, printerName) { 496 onAddPrinter_: function(success, printerName) {
495 this.$$('add-printer-configuring-dialog').close(); 497 this.$$('add-printer-configuring-dialog').close();
496 if (success) 498 if (success)
497 return; 499 return;
498 500
499 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 501 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
500 this.setupFailed = true; 502 this.setupFailed = true;
501 } 503 }
502 }, 504 },
503 }); 505 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698