| 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 22 matching lines...) Expand all Loading... |
| 33 */ | 33 */ |
| 34 var kPrinterListFullHeight = 350; | 34 var kPrinterListFullHeight = 350; |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Return a reset CupsPrinterInfo object. | 37 * Return a reset CupsPrinterInfo object. |
| 38 * @return {!CupsPrinterInfo} | 38 * @return {!CupsPrinterInfo} |
| 39 */ | 39 */ |
| 40 function getEmptyPrinter_() { | 40 function getEmptyPrinter_() { |
| 41 return { | 41 return { |
| 42 printerAddress: '', | 42 printerAddress: '', |
| 43 printerAutoconf: false, |
| 43 printerDescription: '', | 44 printerDescription: '', |
| 44 printerId: '', | 45 printerId: '', |
| 45 printerManufacturer: '', | 46 printerManufacturer: '', |
| 46 printerModel: '', | 47 printerModel: '', |
| 47 printerName: '', | 48 printerName: '', |
| 48 printerPPDPath: '', | 49 printerPPDPath: '', |
| 49 printerProtocol: 'ipp', | 50 printerProtocol: 'ipp', |
| 50 printerQueue: '', | 51 printerQueue: '', |
| 51 printerStatus: '', | 52 printerStatus: '', |
| 52 }; | 53 }; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 this.$$('add-printer-dialog').close(); | 163 this.$$('add-printer-dialog').close(); |
| 163 this.fire('open-discovery-printers-dialog'); | 164 this.fire('open-discovery-printers-dialog'); |
| 164 }, | 165 }, |
| 165 | 166 |
| 166 /** @private */ | 167 /** @private */ |
| 167 onCancelTap_: function() { | 168 onCancelTap_: function() { |
| 168 this.$$('add-printer-dialog').close(); | 169 this.$$('add-printer-dialog').close(); |
| 169 }, | 170 }, |
| 170 | 171 |
| 171 /** @private */ | 172 /** @private */ |
| 172 switchToManufacturerDialog_: function() { | 173 addPressed_: function() { |
| 173 // Set the default printer queue to be "ipp/print". | 174 // Set the default printer queue to be "ipp/print". |
| 174 if (!this.newPrinter.printerQueue) | 175 if (!this.newPrinter.printerQueue) { |
| 175 this.set('newPrinter.printerQueue', 'ipp/print'); | 176 this.set('newPrinter.printerQueue', 'ipp/print'); |
| 176 | 177 } |
| 177 this.$$('add-printer-dialog').close(); | 178 this.$$('add-printer-dialog').close(); |
| 178 this.fire('open-manufacturer-model-dialog'); | 179 this.fire('open-configuring-printer-dialog'); |
| 179 }, | 180 }, |
| 180 | 181 |
| 181 /** @private */ | 182 /** @private */ |
| 182 onAddressChanged_: function() { | 183 onAddressChanged_: function() { |
| 183 // TODO(xdai): Check if the printer address exists and then show the | 184 // TODO(xdai): Check if the printer address exists and then show the |
| 184 // corresponding message after the API is ready. | 185 // corresponding message after the API is ready. |
| 185 // The format of address is: ip-address-or-hostname:port-number. | 186 // The format of address is: ip-address-or-hostname:port-number. |
| 186 }, | 187 }, |
| 187 | 188 |
| 188 /** | 189 /** |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 'showManuallyAddDialog_'); | 410 'showManuallyAddDialog_'); |
| 410 }, | 411 }, |
| 411 | 412 |
| 412 /** @private */ | 413 /** @private */ |
| 413 openDiscoveryPrintersDialog_: function() { | 414 openDiscoveryPrintersDialog_: function() { |
| 414 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 415 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 415 'showDiscoveryDialog_'); | 416 'showDiscoveryDialog_'); |
| 416 }, | 417 }, |
| 417 | 418 |
| 418 /** @private */ | 419 /** @private */ |
| 420 addPrinter_: function() { |
| 421 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 422 addCupsPrinter(this.newPrinter); |
| 423 }, |
| 424 |
| 425 /** @private */ |
| 426 switchToManufacturerDialog_: function() { |
| 427 this.$$('add-printer-configuring-dialog').close(); |
| 428 this.fire('open-manufacturer-model-dialog'); |
| 429 }, |
| 430 |
| 431 /** |
| 432 * Handler for getPrinterInfo success. |
| 433 * @param {!PrinterMakeModel} info |
| 434 * @private |
| 435 * */ |
| 436 onPrinterFound_: function(info) { |
| 437 this.newPrinter.printerAutoconf = info.autoconf; |
| 438 this.newPrinter.printerManufacturer = info.manufacturer; |
| 439 this.newPrinter.printerModel = info.model; |
| 440 |
| 441 // Add the printer if it's configurable. Otherwise, forward to the |
| 442 // manufacturer dialog. |
| 443 if (this.newPrinter.printerAutoconf) { |
| 444 this.addPrinter_(); |
| 445 } else { |
| 446 this.switchToManufacturerDialog_(); |
| 447 } |
| 448 }, |
| 449 |
| 450 /** |
| 451 * Handler for getPrinterInfo failure. |
| 452 * @param {*} rejected |
| 453 * @private |
| 454 */ |
| 455 infoFailed_: function(rejected) { |
| 456 this.switchToManufacturerDialog_(); |
| 457 }, |
| 458 |
| 459 /** @private */ |
| 419 openConfiguringPrinterDialog_: function() { | 460 openConfiguringPrinterDialog_: function() { |
| 420 this.switchDialog_( | 461 this.switchDialog_( |
| 421 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 462 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 422 'showConfiguringDialog_'); | 463 'showConfiguringDialog_'); |
| 423 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 464 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| 424 this.configuringDialogTitle = | 465 this.configuringDialogTitle = |
| 425 loadTimeData.getString('addPrintersNearbyTitle'); | 466 loadTimeData.getString('addPrintersNearbyTitle'); |
| 426 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 467 this.addPrinter_(); |
| 427 this.newPrinter); | 468 } else if ( |
| 428 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 469 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 429 this.configuringDialogTitle = | 470 this.configuringDialogTitle = |
| 430 loadTimeData.getString('addPrintersManuallyTitle'); | 471 loadTimeData.getString('addPrintersManuallyTitle'); |
| 431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 472 this.addPrinter_(); |
| 432 this.newPrinter); | 473 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| 474 this.configuringDialogTitle = |
| 475 loadTimeData.getString('addPrintersManuallyTitle'); |
| 476 if (this.newPrinter.printerProtocol == 'ipp' || |
| 477 this.newPrinter.printerProtocol == 'ipps') { |
| 478 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 479 getPrinterInfo(this.newPrinter). |
| 480 then( |
| 481 this.onPrinterFound_.bind(this), this.infoFailed_.bind(this)); |
| 482 } else { |
| 483 // Defer the switch until all the elements are drawn. |
| 484 this.async(this.switchToManufacturerDialog_.bind(this)); |
| 485 } |
| 433 } | 486 } |
| 434 }, | 487 }, |
| 435 | 488 |
| 436 /** @private */ | 489 /** @private */ |
| 437 openManufacturerModelDialog_: function() { | 490 openManufacturerModelDialog_: function() { |
| 438 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 491 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 439 'showManufacturerDialog_'); | 492 'showManufacturerDialog_'); |
| 440 }, | 493 }, |
| 441 | 494 |
| 442 /** @private */ | 495 /** @private */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 onAddPrinter_: function(success, printerName) { | 541 onAddPrinter_: function(success, printerName) { |
| 489 this.$$('add-printer-configuring-dialog').close(); | 542 this.$$('add-printer-configuring-dialog').close(); |
| 490 if (success) | 543 if (success) |
| 491 return; | 544 return; |
| 492 | 545 |
| 493 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 546 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 494 this.setupFailed = true; | 547 this.setupFailed = true; |
| 495 } | 548 } |
| 496 }, | 549 }, |
| 497 }); | 550 }); |
| OLD | NEW |