| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 }, | 71 }, |
| 72 | 72 |
| 73 discovering_: { | 73 discovering_: { |
| 74 type: Boolean, | 74 type: Boolean, |
| 75 value: true, | 75 value: true, |
| 76 }, | 76 }, |
| 77 }, | 77 }, |
| 78 | 78 |
| 79 /** @override */ | 79 /** @override */ |
| 80 ready: function() { | 80 ready: function() { |
| 81 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 81 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 82 startDiscoveringPrinters(); | 82 .startDiscoveringPrinters(); |
| 83 this.addWebUIListener('on-printer-discovered', | 83 this.addWebUIListener( |
| 84 this.onPrinterDiscovered_.bind(this)); | 84 'on-printer-discovered', this.onPrinterDiscovered_.bind(this)); |
| 85 this.addWebUIListener('on-printer-discovery-done', | 85 this.addWebUIListener( |
| 86 this.onPrinterDiscoveryDone_.bind(this)); | 86 'on-printer-discovery-done', this.onPrinterDiscoveryDone_.bind(this)); |
| 87 this.addWebUIListener('on-printer-discovery-failed', | 87 this.addWebUIListener( |
| 88 this.onPrinterDiscoveryDone_.bind(this)); | 88 'on-printer-discovery-failed', this.onPrinterDiscoveryDone_.bind(this)); |
| 89 }, | 89 }, |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @param {!Array<!CupsPrinterInfo>} printers | 92 * @param {!Array<!CupsPrinterInfo>} printers |
| 93 * @private | 93 * @private |
| 94 */ | 94 */ |
| 95 onPrinterDiscovered_: function(printers) { | 95 onPrinterDiscovered_: function(printers) { |
| 96 this.discovering_ = true; | 96 this.discovering_ = true; |
| 97 if (!this.discoveredPrinters) { | 97 if (!this.discoveredPrinters) { |
| 98 this.discoveredPrinters = printers; | 98 this.discoveredPrinters = printers; |
| 99 } else { | 99 } else { |
| 100 for (var i = 0; i < printers.length; i++) | 100 for (var i = 0; i < printers.length; i++) |
| 101 this.push('discoveredPrinters', printers[i]); | 101 this.push('discoveredPrinters', printers[i]); |
| 102 } | 102 } |
| 103 }, | 103 }, |
| 104 | 104 |
| 105 /** @private */ | 105 /** @private */ |
| 106 onPrinterDiscoveryDone_: function() { | 106 onPrinterDiscoveryDone_: function() { |
| 107 this.discovering_ = false; | 107 this.discovering_ = false; |
| 108 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; | 108 this.$$('add-printer-list').style.maxHeight = kPrinterListFullHeight + 'px'; |
| 109 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; | 109 this.$.noPrinterMessage.hidden = !!this.discoveredPrinters; |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 /** @private */ | 112 /** @private */ |
| 113 stopDiscoveringPrinters_: function() { | 113 stopDiscoveringPrinters_: function() { |
| 114 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 114 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 115 stopDiscoveringPrinters(); | 115 .stopDiscoveringPrinters(); |
| 116 this.discovering_ = false; | 116 this.discovering_ = false; |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 /** @private */ | 119 /** @private */ |
| 120 switchToManualAddDialog_: function() { | 120 switchToManualAddDialog_: function() { |
| 121 this.stopDiscoveringPrinters_(); | 121 this.stopDiscoveringPrinters_(); |
| 122 // We're abandoning discovery in favor of manual specification, so | 122 // We're abandoning discovery in favor of manual specification, so |
| 123 // drop the selection if one exists. | 123 // drop the selection if one exists. |
| 124 this.selectedPrinter = getEmptyPrinter_(); | 124 this.selectedPrinter = getEmptyPrinter_(); |
| 125 this.$$('add-printer-dialog').close(); | 125 this.$$('add-printer-dialog').close(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 144 this.$$('add-printer-dialog').close(); | 144 this.$$('add-printer-dialog').close(); |
| 145 this.fire('open-manufacturer-model-dialog'); | 145 this.fire('open-manufacturer-model-dialog'); |
| 146 }, | 146 }, |
| 147 }); | 147 }); |
| 148 | 148 |
| 149 Polymer({ | 149 Polymer({ |
| 150 is: 'add-printer-manually-dialog', | 150 is: 'add-printer-manually-dialog', |
| 151 | 151 |
| 152 properties: { | 152 properties: { |
| 153 /** @type {!CupsPrinterInfo} */ | 153 /** @type {!CupsPrinterInfo} */ |
| 154 newPrinter: { | 154 newPrinter: {type: Object, notify: true, value: getEmptyPrinter_}, |
| 155 type: Object, | |
| 156 notify: true, | |
| 157 value: getEmptyPrinter_ | |
| 158 }, | |
| 159 }, | 155 }, |
| 160 | 156 |
| 161 /** @private */ | 157 /** @private */ |
| 162 switchToDiscoveryDialog_: function() { | 158 switchToDiscoveryDialog_: function() { |
| 163 this.$$('add-printer-dialog').close(); | 159 this.$$('add-printer-dialog').close(); |
| 164 this.fire('open-discovery-printers-dialog'); | 160 this.fire('open-discovery-printers-dialog'); |
| 165 }, | 161 }, |
| 166 | 162 |
| 167 /** @private */ | 163 /** @private */ |
| 168 onCancelTap_: function() { | 164 onCancelTap_: function() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 value: false, | 216 value: false, |
| 221 }, | 217 }, |
| 222 }, | 218 }, |
| 223 | 219 |
| 224 observers: [ | 220 observers: [ |
| 225 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 221 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', |
| 226 ], | 222 ], |
| 227 | 223 |
| 228 /** @override */ | 224 /** @override */ |
| 229 ready: function() { | 225 ready: function() { |
| 230 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 226 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 231 getCupsPrinterManufacturersList().then( | 227 .getCupsPrinterManufacturersList() |
| 232 this.manufacturerListChanged_.bind(this)); | 228 .then(this.manufacturerListChanged_.bind(this)); |
| 233 }, | 229 }, |
| 234 | 230 |
| 235 /** | 231 /** |
| 236 * @param {string} manufacturer The manufacturer for which we are retrieving | 232 * @param {string} manufacturer The manufacturer for which we are retrieving |
| 237 * models. | 233 * models. |
| 238 * @private | 234 * @private |
| 239 */ | 235 */ |
| 240 selectedManufacturerChanged_: function(manufacturer) { | 236 selectedManufacturerChanged_: function(manufacturer) { |
| 241 // Reset model if manufacturer is changed. | 237 // Reset model if manufacturer is changed. |
| 242 this.set('newPrinter.printerModel', ''); | 238 this.set('newPrinter.printerModel', ''); |
| 243 if (manufacturer) { | 239 if (manufacturer) { |
| 244 settings.CupsPrintersBrowserProxyImpl.getInstance() | 240 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 245 .getCupsPrinterModelsList(manufacturer) | 241 .getCupsPrinterModelsList(manufacturer) |
| 246 .then(this.modelListChanged_.bind(this)); | 242 .then(this.modelListChanged_.bind(this)); |
| 247 } | 243 } |
| 248 }, | 244 }, |
| 249 | 245 |
| 250 /** @private */ | 246 /** @private */ |
| 251 onBrowseFile_: function() { | 247 onBrowseFile_: function() { |
| 252 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 248 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 253 getCupsPrinterPPDPath().then(this.printerPPDPathChanged_.bind(this)); | 249 .getCupsPrinterPPDPath() |
| 250 .then(this.printerPPDPathChanged_.bind(this)); |
| 254 }, | 251 }, |
| 255 | 252 |
| 256 /** | 253 /** |
| 257 * @param {string} path | 254 * @param {string} path |
| 258 * @private | 255 * @private |
| 259 */ | 256 */ |
| 260 printerPPDPathChanged_: function(path) { | 257 printerPPDPathChanged_: function(path) { |
| 261 this.set('newPrinter.printerPPDPath', path); | 258 this.set('newPrinter.printerPPDPath', path); |
| 262 this.$$('paper-input').value = this.getBaseName_(path); | 259 this.$$('paper-input').value = this.getBaseName_(path); |
| 263 }, | 260 }, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return path.substring(path.lastIndexOf('/') + 1); | 297 return path.substring(path.lastIndexOf('/') + 1); |
| 301 }, | 298 }, |
| 302 | 299 |
| 303 /** | 300 /** |
| 304 * @param {string} printerManufacturer | 301 * @param {string} printerManufacturer |
| 305 * @param {string} printerModel | 302 * @param {string} printerModel |
| 306 * @param {string} printerPPDPath | 303 * @param {string} printerPPDPath |
| 307 * @return {boolean} Whether we have enough information to set up the printer | 304 * @return {boolean} Whether we have enough information to set up the printer |
| 308 * @private | 305 * @private |
| 309 */ | 306 */ |
| 310 canAddPrinter_: function(printerManufacturer, printerModel, printerPPDPath) { | 307 canAddPrinter_: function(printerManufacturer, printerModel, printerPPDPath) { |
| 311 return !!((printerManufacturer && printerModel) || printerPPDPath); | 308 return !!((printerManufacturer && printerModel) || printerPPDPath); |
| 312 }, | 309 }, |
| 313 }); | 310 }); |
| 314 | 311 |
| 315 Polymer({ | 312 Polymer({ |
| 316 is: 'add-printer-configuring-dialog', | 313 is: 'add-printer-configuring-dialog', |
| 317 | 314 |
| 318 properties: { | 315 properties: { |
| 319 printerName: String, | 316 printerName: String, |
| 320 dialogTitle: String, | 317 dialogTitle: String, |
| 321 }, | 318 }, |
| 322 | 319 |
| 323 /** @override */ | 320 /** @override */ |
| 324 attached: function() { | 321 attached: function() { |
| 325 this.$.configuringMessage.textContent = loadTimeData.getStringF( | 322 this.$.configuringMessage.textContent = |
| 326 'printerConfiguringMessage', this.printerName); | 323 loadTimeData.getStringF('printerConfiguringMessage', this.printerName); |
| 327 }, | 324 }, |
| 328 | 325 |
| 329 /** @private */ | 326 /** @private */ |
| 330 onCancelConfiguringTap_: function() { | 327 onCancelConfiguringTap_: function() { |
| 331 this.$$('add-printer-dialog').close(); | 328 this.$$('add-printer-dialog').close(); |
| 332 this.fire('configuring-dialog-closed'); | 329 this.fire('configuring-dialog-closed'); |
| 333 }, | 330 }, |
| 334 | 331 |
| 335 close: function() { | 332 close: function() { |
| 336 this.$$('add-printer-dialog').close(); | 333 this.$$('add-printer-dialog').close(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 * @private | 396 * @private |
| 400 */ | 397 */ |
| 401 resetData_: function() { | 398 resetData_: function() { |
| 402 if (this.newPrinter) | 399 if (this.newPrinter) |
| 403 this.newPrinter = getEmptyPrinter_(); | 400 this.newPrinter = getEmptyPrinter_(); |
| 404 this.setupFailed = false; | 401 this.setupFailed = false; |
| 405 }, | 402 }, |
| 406 | 403 |
| 407 /** @private */ | 404 /** @private */ |
| 408 openManuallyAddPrinterDialog_: function() { | 405 openManuallyAddPrinterDialog_: function() { |
| 409 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, | 406 this.switchDialog_( |
| 410 'showManuallyAddDialog_'); | 407 this.currentDialog_, AddPrinterDialogs.MANUALLY, |
| 408 'showManuallyAddDialog_'); |
| 411 }, | 409 }, |
| 412 | 410 |
| 413 /** @private */ | 411 /** @private */ |
| 414 openDiscoveryPrintersDialog_: function() { | 412 openDiscoveryPrintersDialog_: function() { |
| 415 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 413 this.switchDialog_( |
| 416 'showDiscoveryDialog_'); | 414 this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 415 'showDiscoveryDialog_'); |
| 417 }, | 416 }, |
| 418 | 417 |
| 419 /** @private */ | 418 /** @private */ |
| 420 addPrinter_: function() { | 419 addPrinter_: function() { |
| 421 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 420 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| 422 addCupsPrinter(this.newPrinter); | 421 this.newPrinter); |
| 423 }, | 422 }, |
| 424 | 423 |
| 425 /** @private */ | 424 /** @private */ |
| 426 switchToManufacturerDialog_: function() { | 425 switchToManufacturerDialog_: function() { |
| 427 this.$$('add-printer-configuring-dialog').close(); | 426 this.$$('add-printer-configuring-dialog').close(); |
| 428 this.fire('open-manufacturer-model-dialog'); | 427 this.fire('open-manufacturer-model-dialog'); |
| 429 }, | 428 }, |
| 430 | 429 |
| 431 /** | 430 /** |
| 432 * Handler for getPrinterInfo success. | 431 * Handler for getPrinterInfo success. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 458 | 457 |
| 459 /** @private */ | 458 /** @private */ |
| 460 openConfiguringPrinterDialog_: function() { | 459 openConfiguringPrinterDialog_: function() { |
| 461 this.switchDialog_( | 460 this.switchDialog_( |
| 462 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 461 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 463 'showConfiguringDialog_'); | 462 'showConfiguringDialog_'); |
| 464 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 463 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| 465 this.configuringDialogTitle = | 464 this.configuringDialogTitle = |
| 466 loadTimeData.getString('addPrintersNearbyTitle'); | 465 loadTimeData.getString('addPrintersNearbyTitle'); |
| 467 this.addPrinter_(); | 466 this.addPrinter_(); |
| 468 } else if ( | 467 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 469 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | |
| 470 this.configuringDialogTitle = | 468 this.configuringDialogTitle = |
| 471 loadTimeData.getString('addPrintersManuallyTitle'); | 469 loadTimeData.getString('addPrintersManuallyTitle'); |
| 472 this.addPrinter_(); | 470 this.addPrinter_(); |
| 473 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { | 471 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| 474 this.configuringDialogTitle = | 472 this.configuringDialogTitle = |
| 475 loadTimeData.getString('addPrintersManuallyTitle'); | 473 loadTimeData.getString('addPrintersManuallyTitle'); |
| 476 if (this.newPrinter.printerProtocol == 'ipp' || | 474 if (this.newPrinter.printerProtocol == 'ipp' || |
| 477 this.newPrinter.printerProtocol == 'ipps') { | 475 this.newPrinter.printerProtocol == 'ipps') { |
| 478 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 476 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 479 getPrinterInfo(this.newPrinter). | 477 .getPrinterInfo(this.newPrinter) |
| 480 then( | 478 .then(this.onPrinterFound_.bind(this), this.infoFailed_.bind(this)); |
| 481 this.onPrinterFound_.bind(this), this.infoFailed_.bind(this)); | |
| 482 } else { | 479 } else { |
| 483 // Defer the switch until all the elements are drawn. | 480 // Defer the switch until all the elements are drawn. |
| 484 this.async(this.switchToManufacturerDialog_.bind(this)); | 481 this.async(this.switchToManufacturerDialog_.bind(this)); |
| 485 } | 482 } |
| 486 } | 483 } |
| 487 }, | 484 }, |
| 488 | 485 |
| 489 /** @private */ | 486 /** @private */ |
| 490 openManufacturerModelDialog_: function() { | 487 openManufacturerModelDialog_: function() { |
| 491 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 488 this.switchDialog_( |
| 492 'showManufacturerDialog_'); | 489 this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 490 'showManufacturerDialog_'); |
| 493 }, | 491 }, |
| 494 | 492 |
| 495 /** @private */ | 493 /** @private */ |
| 496 configuringDialogClosed_: function() { | 494 configuringDialogClosed_: function() { |
| 497 // If the configuring dialog is closed, we want to return whence we came. | 495 // If the configuring dialog is closed, we want to return whence we came. |
| 498 // | 496 // |
| 499 // TODO(justincarlson) - This shouldn't need to be a conditional; | 497 // TODO(justincarlson) - This shouldn't need to be a conditional; |
| 500 // clean up the way we switch dialogs so we don't have to supply | 498 // clean up the way we switch dialogs so we don't have to supply |
| 501 // redundant information and can just return to the previous | 499 // redundant information and can just return to the previous |
| 502 // dialog. | 500 // dialog. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 onAddPrinter_: function(success, printerName) { | 539 onAddPrinter_: function(success, printerName) { |
| 542 this.$$('add-printer-configuring-dialog').close(); | 540 this.$$('add-printer-configuring-dialog').close(); |
| 543 if (success) | 541 if (success) |
| 544 return; | 542 return; |
| 545 | 543 |
| 546 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 544 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 547 this.setupFailed = true; | 545 this.setupFailed = true; |
| 548 } | 546 } |
| 549 }, | 547 }, |
| 550 }); | 548 }); |
| OLD | NEW |