| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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( |
| 64 this.onPrinterDiscovered_.bind(this)); | 64 'on-printer-discovered', this.onPrinterDiscovered_.bind(this)); |
| 65 this.addWebUIListener('on-printer-discovery-done', | 65 this.addWebUIListener( |
| 66 this.onPrinterDiscoveryDone_.bind(this)); | 66 'on-printer-discovery-done', this.onPrinterDiscoveryDone_.bind(this)); |
| 67 this.addWebUIListener('on-printer-discovery-failed', | 67 this.addWebUIListener( |
| 68 this.onPrinterDiscoveryDone_.bind(this)); | 68 'on-printer-discovery-failed', 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.discovering_ = true; |
| 77 if (!this.discoveredPrinters) { | 77 if (!this.discoveredPrinters) { |
| 78 this.discoveredPrinters = printers; | 78 this.discoveredPrinters = printers; |
| 79 } else { | 79 } else { |
| 80 for (var i = 0; i < printers.length; i++) | 80 for (var i = 0; i < printers.length; i++) |
| 81 this.push('discoveredPrinters', printers[i]); | 81 this.push('discoveredPrinters', printers[i]); |
| 82 } | 82 } |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 /** @private */ | 85 /** @private */ |
| 86 onPrinterDiscoveryDone_: function() { | 86 onPrinterDiscoveryDone_: function() { |
| 87 this.discovering_ = false; | 87 this.discovering_ = false; |
| 88 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; | 88 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; |
| 89 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; | 89 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; |
| 90 }, | 90 }, |
| 91 | 91 |
| 92 /** @private */ | 92 /** @private */ |
| 93 stopDiscoveringPrinters_: function() { | 93 stopDiscoveringPrinters_: function() { |
| 94 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 94 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 95 stopDiscoveringPrinters(); | 95 .stopDiscoveringPrinters(); |
| 96 this.discovering_ = false; | 96 this.discovering_ = false; |
| 97 }, | 97 }, |
| 98 | 98 |
| 99 /** @private */ | 99 /** @private */ |
| 100 switchToManualAddDialog_: function() { | 100 switchToManualAddDialog_: function() { |
| 101 this.stopDiscoveringPrinters_(); | 101 this.stopDiscoveringPrinters_(); |
| 102 this.$$('add-printer-dialog').close(); | 102 this.$$('add-printer-dialog').close(); |
| 103 this.fire('open-manually-add-printer-dialog'); | 103 this.fire('open-manually-add-printer-dialog'); |
| 104 }, | 104 }, |
| 105 | 105 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 value: false, | 200 value: false, |
| 201 }, | 201 }, |
| 202 }, | 202 }, |
| 203 | 203 |
| 204 observers: [ | 204 observers: [ |
| 205 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 205 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', |
| 206 ], | 206 ], |
| 207 | 207 |
| 208 /** @override */ | 208 /** @override */ |
| 209 ready: function() { | 209 ready: function() { |
| 210 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 210 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 211 getCupsPrinterManufacturersList().then( | 211 .getCupsPrinterManufacturersList() |
| 212 this.manufacturerListChanged_.bind(this)); | 212 .then(this.manufacturerListChanged_.bind(this)); |
| 213 }, | 213 }, |
| 214 | 214 |
| 215 /** | 215 /** |
| 216 * @param {string} manufacturer The manufacturer for which we are retrieving | 216 * @param {string} manufacturer The manufacturer for which we are retrieving |
| 217 * models. | 217 * models. |
| 218 * @private | 218 * @private |
| 219 */ | 219 */ |
| 220 selectedManufacturerChanged_: function(manufacturer) { | 220 selectedManufacturerChanged_: function(manufacturer) { |
| 221 if (manufacturer) { | 221 if (manufacturer) { |
| 222 settings.CupsPrintersBrowserProxyImpl.getInstance() | 222 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 223 .getCupsPrinterModelsList(manufacturer) | 223 .getCupsPrinterModelsList(manufacturer) |
| 224 .then(this.modelListChanged_.bind(this)); | 224 .then(this.modelListChanged_.bind(this)); |
| 225 } | 225 } |
| 226 }, | 226 }, |
| 227 | 227 |
| 228 /** @private */ | 228 /** @private */ |
| 229 onBrowseFile_: function() { | 229 onBrowseFile_: function() { |
| 230 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 230 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 231 getCupsPrinterPPDPath().then(this.printerPPDPathChanged_.bind(this)); | 231 .getCupsPrinterPPDPath() |
| 232 .then(this.printerPPDPathChanged_.bind(this)); |
| 232 }, | 233 }, |
| 233 | 234 |
| 234 /** | 235 /** |
| 235 * @param {string} path | 236 * @param {string} path |
| 236 * @private | 237 * @private |
| 237 */ | 238 */ |
| 238 printerPPDPathChanged_: function(path) { | 239 printerPPDPathChanged_: function(path) { |
| 239 this.newPrinter.printerPPDPath = path; | 240 this.newPrinter.printerPPDPath = path; |
| 240 this.$$('paper-input').value = this.getBaseName_(path); | 241 this.$$('paper-input').value = this.getBaseName_(path); |
| 241 }, | 242 }, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 Polymer({ | 289 Polymer({ |
| 289 is: 'add-printer-configuring-dialog', | 290 is: 'add-printer-configuring-dialog', |
| 290 | 291 |
| 291 properties: { | 292 properties: { |
| 292 printerName: String, | 293 printerName: String, |
| 293 dialogTitle: String, | 294 dialogTitle: String, |
| 294 }, | 295 }, |
| 295 | 296 |
| 296 /** @override */ | 297 /** @override */ |
| 297 attached: function() { | 298 attached: function() { |
| 298 this.$.configuringMessage.textContent = loadTimeData.getStringF( | 299 this.$.configuringMessage.textContent = |
| 299 'printerConfiguringMessage', this.printerName); | 300 loadTimeData.getStringF('printerConfiguringMessage', this.printerName); |
| 300 }, | 301 }, |
| 301 | 302 |
| 302 /** @private */ | 303 /** @private */ |
| 303 onCancelConfiguringTap_: function() { | 304 onCancelConfiguringTap_: function() { |
| 304 this.$$('add-printer-dialog').close(); | 305 this.$$('add-printer-dialog').close(); |
| 305 this.fire('configuring-dialog-closed'); | 306 this.fire('configuring-dialog-closed'); |
| 306 }, | 307 }, |
| 307 | 308 |
| 308 close: function() { | 309 close: function() { |
| 309 this.$$('add-printer-dialog').close(); | 310 this.$$('add-printer-dialog').close(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 printerName: '', | 400 printerName: '', |
| 400 printerPPDPath: '', | 401 printerPPDPath: '', |
| 401 printerProtocol: 'ipp', | 402 printerProtocol: 'ipp', |
| 402 printerQueue: '', | 403 printerQueue: '', |
| 403 printerStatus: '', | 404 printerStatus: '', |
| 404 }; | 405 }; |
| 405 }, | 406 }, |
| 406 | 407 |
| 407 /** @private */ | 408 /** @private */ |
| 408 openManuallyAddPrinterDialog_: function() { | 409 openManuallyAddPrinterDialog_: function() { |
| 409 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, | 410 this.switchDialog_( |
| 410 'showManuallyAddDialog_'); | 411 this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| 412 'showManuallyAddDialog_'); |
| 411 }, | 413 }, |
| 412 | 414 |
| 413 /** @private */ | 415 /** @private */ |
| 414 openDiscoveryPrintersDialog_: function() { | 416 openDiscoveryPrintersDialog_: function() { |
| 415 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 417 this.switchDialog_( |
| 416 'showDiscoveryDialog_'); | 418 this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 419 'showDiscoveryDialog_'); |
| 417 }, | 420 }, |
| 418 | 421 |
| 419 /** @private */ | 422 /** @private */ |
| 420 openConfiguringPrinterDialog_: function() { | 423 openConfiguringPrinterDialog_: function() { |
| 421 this.switchDialog_( | 424 this.switchDialog_( |
| 422 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 425 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 423 'showConfiguringDialog_'); | 426 'showConfiguringDialog_'); |
| 424 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 427 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| 425 this.configuringDialogTitle = | 428 this.configuringDialogTitle = |
| 426 loadTimeData.getString('addPrintersNearbyTitle'); | 429 loadTimeData.getString('addPrintersNearbyTitle'); |
| 427 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 430 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| 428 this.selectedPrinter); | 431 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( | 435 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| 433 this.newPrinter); | 436 this.newPrinter); |
| 434 } | 437 } |
| 435 }, | 438 }, |
| 436 | 439 |
| 437 /** @private */ | 440 /** @private */ |
| 438 openManufacturerModelDialog_: function() { | 441 openManufacturerModelDialog_: function() { |
| 439 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 442 this.switchDialog_( |
| 440 'showManufacturerDialog_'); | 443 this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 444 'showManufacturerDialog_'); |
| 441 }, | 445 }, |
| 442 | 446 |
| 443 /** @private */ | 447 /** @private */ |
| 444 configuringDialogClosed_: function() { | 448 configuringDialogClosed_: function() { |
| 445 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { | 449 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| 446 this.switchDialog_( | 450 this.switchDialog_( |
| 447 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); | 451 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); |
| 448 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 452 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 449 this.switchDialog_( | 453 this.switchDialog_( |
| 450 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_'); | 454 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_'); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 onAddPrinter_: function(success, printerName) { | 498 onAddPrinter_: function(success, printerName) { |
| 495 this.$$('add-printer-configuring-dialog').close(); | 499 this.$$('add-printer-configuring-dialog').close(); |
| 496 if (success) | 500 if (success) |
| 497 return; | 501 return; |
| 498 | 502 |
| 499 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 503 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 500 this.setupFailed = true; | 504 this.setupFailed = true; |
| 501 } | 505 } |
| 502 }, | 506 }, |
| 503 }); | 507 }); |
| OLD | NEW |