| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 this.fire('open-manually-add-printer-dialog'); | 103 this.fire('open-manually-add-printer-dialog'); |
| 104 }, | 104 }, |
| 105 | 105 |
| 106 /** @private */ | 106 /** @private */ |
| 107 onCancelTap_: function() { | 107 onCancelTap_: function() { |
| 108 this.stopDiscoveringPrinters_(); | 108 this.stopDiscoveringPrinters_(); |
| 109 this.$$('add-printer-dialog').close(); | 109 this.$$('add-printer-dialog').close(); |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 /** @private */ | 112 /** @private */ |
| 113 switchToConfiguringDialog_: function() { | 113 switchToManufacturerDialog_: function() { |
| 114 this.stopDiscoveringPrinters_(); | 114 this.stopDiscoveringPrinters_(); |
| 115 this.$$('add-printer-dialog').close(); | 115 this.$$('add-printer-dialog').close(); |
| 116 this.fire('open-configuring-printer-dialog'); | 116 this.fire('open-manufacturer-model-dialog'); |
| 117 }, | 117 }, |
| 118 }); | 118 }); |
| 119 | 119 |
| 120 Polymer({ | 120 Polymer({ |
| 121 is: 'add-printer-manually-dialog', | 121 is: 'add-printer-manually-dialog', |
| 122 | 122 |
| 123 properties: { | 123 properties: { |
| 124 /** @type {!CupsPrinterInfo} */ | 124 /** @type {!CupsPrinterInfo} */ |
| 125 newPrinter: { | 125 newPrinter: { |
| 126 type: Object, | 126 type: Object, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 */ | 176 */ |
| 177 onProtocolChange_: function(event) { | 177 onProtocolChange_: function(event) { |
| 178 this.set('newPrinter.printerProtocol', event.target.value); | 178 this.set('newPrinter.printerProtocol', event.target.value); |
| 179 }, | 179 }, |
| 180 }); | 180 }); |
| 181 | 181 |
| 182 Polymer({ | 182 Polymer({ |
| 183 is: 'add-printer-manufacturer-model-dialog', | 183 is: 'add-printer-manufacturer-model-dialog', |
| 184 | 184 |
| 185 properties: { | 185 properties: { |
| 186 /** @type {!CupsPrinterInfo} */ | 186 /** |
| 187 * The printer object from 'add-printer-manually-dialog'. |
| 188 * @type {!CupsPrinterInfo} |
| 189 */ |
| 187 newPrinter: { | 190 newPrinter: { |
| 188 type: Object, | 191 type: Object, |
| 189 notify: true, | 192 notify: true, |
| 190 }, | 193 }, |
| 191 | 194 |
| 195 /** |
| 196 * The printer object from 'add-printer-discovery-dialog'. |
| 197 * @type {!CupsPrinterInfo} |
| 198 */ |
| 199 selectedPrinter: { |
| 200 type: Object, |
| 201 notify: true, |
| 202 }, |
| 203 |
| 192 /** @type {?Array<string>} */ | 204 /** @type {?Array<string>} */ |
| 193 manufacturerList: { | 205 manufacturerList: { |
| 194 type: Array, | 206 type: Array, |
| 195 }, | 207 }, |
| 196 | 208 |
| 197 /** @type {?Array<string>} */ | 209 /** @type {?Array<string>} */ |
| 198 modelList: { | 210 modelList: { |
| 199 type: Array, | 211 type: Array, |
| 200 }, | 212 }, |
| 201 | 213 |
| 202 setupFailed: { | 214 setupFailed: { |
| 203 type: Boolean, | 215 type: Boolean, |
| 204 value: false, | 216 value: false, |
| 205 }, | 217 }, |
| 218 |
| 219 inManualFlow: { |
| 220 type: Boolean, |
| 221 }, |
| 222 |
| 223 /** @private {string} */ |
| 224 printerManufacturer_: { |
| 225 type: String, |
| 226 value: '', |
| 227 }, |
| 228 |
| 229 /** @private {string} */ |
| 230 printerModel_: { |
| 231 type: String, |
| 232 value: '', |
| 233 }, |
| 234 |
| 235 /** @private {string} */ |
| 236 printerPPDPath_: { |
| 237 type: String, |
| 238 value: '', |
| 239 }, |
| 206 }, | 240 }, |
| 207 | 241 |
| 208 observers: [ | 242 observers: [ |
| 209 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 243 'selectedManufacturerChanged_(printerManufacturer_)', |
| 244 'selectedModelChanged_(printerModel_)', |
| 210 ], | 245 ], |
| 211 | 246 |
| 212 /** @override */ | 247 /** @override */ |
| 213 ready: function() { | 248 ready: function() { |
| 214 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 249 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 215 getCupsPrinterManufacturersList().then( | 250 getCupsPrinterManufacturersList().then( |
| 216 this.manufacturerListChanged_.bind(this)); | 251 this.manufacturerListChanged_.bind(this)); |
| 217 }, | 252 }, |
| 218 | 253 |
| 219 /** | 254 /** |
| 220 * @param {string} manufacturer The manufacturer for which we are retrieving | 255 * @param {string} manufacturer The manufacturer for which we are retrieving |
| 221 * models. | 256 * models. |
| 222 * @private | 257 * @private |
| 223 */ | 258 */ |
| 224 selectedManufacturerChanged_: function(manufacturer) { | 259 selectedManufacturerChanged_: function(manufacturer) { |
| 260 if (this.inManualFlow) { |
| 261 this.set('newPrinter.printerManufacturer', manufacturer); |
| 262 this.set('newPrinter.printerModel', ''); |
| 263 } else { |
| 264 this.set('selectedPrinter.printerManufacturer', manufacturer); |
| 265 this.set('selectedPrinter.printerModel', ''); |
| 266 } |
| 225 // Reset model if manufacturer is changed. | 267 // Reset model if manufacturer is changed. |
| 226 this.set('newPrinter.printerModel', ''); | 268 this.printerModel_ = ''; |
| 227 if (manufacturer) { | 269 if (manufacturer) { |
| 228 settings.CupsPrintersBrowserProxyImpl.getInstance() | 270 settings.CupsPrintersBrowserProxyImpl.getInstance() |
| 229 .getCupsPrinterModelsList(manufacturer) | 271 .getCupsPrinterModelsList(manufacturer) |
| 230 .then(this.modelListChanged_.bind(this)); | 272 .then(this.modelListChanged_.bind(this)); |
| 231 } | 273 } |
| 232 }, | 274 }, |
| 233 | 275 |
| 234 /** @private */ | 276 /** @private */ |
| 277 selectedModelChanged_: function(model) { |
| 278 if (this.inManualFlow) |
| 279 this.set('newPrinter.printerModel', model); |
| 280 else |
| 281 this.set('selectedPrinter.printerModel', model); |
| 282 }, |
| 283 |
| 284 /** @private */ |
| 235 onBrowseFile_: function() { | 285 onBrowseFile_: function() { |
| 236 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 286 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| 237 getCupsPrinterPPDPath().then(this.printerPPDPathChanged_.bind(this)); | 287 getCupsPrinterPPDPath().then(this.printerPPDPathChanged_.bind(this)); |
| 238 }, | 288 }, |
| 239 | 289 |
| 240 /** | 290 /** |
| 241 * @param {string} path | 291 * @param {string} path |
| 242 * @private | 292 * @private |
| 243 */ | 293 */ |
| 244 printerPPDPathChanged_: function(path) { | 294 printerPPDPathChanged_: function(path) { |
| 245 this.set('newPrinter.printerPPDPath', path); | 295 this.printerPPDPath_ = path; |
| 296 if (this.inManualFlow) |
| 297 this.set('newPrinter.printerPPDPath', path); |
| 298 else |
| 299 this.set('selectedPrinter.printerPPDPath', path); |
| 246 this.$$('paper-input').value = this.getBaseName_(path); | 300 this.$$('paper-input').value = this.getBaseName_(path); |
| 247 }, | 301 }, |
| 248 | 302 |
| 249 /** | 303 /** |
| 250 * @param {!ManufacturersInfo} manufacturersInfo | 304 * @param {!ManufacturersInfo} manufacturersInfo |
| 251 * @private | 305 * @private |
| 252 */ | 306 */ |
| 253 manufacturerListChanged_: function(manufacturersInfo) { | 307 manufacturerListChanged_: function(manufacturersInfo) { |
| 254 if (manufacturersInfo.success) | 308 if (manufacturersInfo.success) |
| 255 this.manufacturerList = manufacturersInfo.manufacturers; | 309 this.manufacturerList = manufacturersInfo.manufacturers; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 newPrinter: { | 396 newPrinter: { |
| 343 type: Object, | 397 type: Object, |
| 344 }, | 398 }, |
| 345 | 399 |
| 346 /** @type {boolean} whether the new printer setup is failed. */ | 400 /** @type {boolean} whether the new printer setup is failed. */ |
| 347 setupFailed: { | 401 setupFailed: { |
| 348 type: Boolean, | 402 type: Boolean, |
| 349 value: false, | 403 value: false, |
| 350 }, | 404 }, |
| 351 | 405 |
| 406 inManualFlow: { |
| 407 type: Boolean, |
| 408 value: false, |
| 409 }, |
| 410 |
| 352 configuringDialogTitle: String, | 411 configuringDialogTitle: String, |
| 353 | 412 |
| 354 /** @private {string} */ | 413 /** @private {string} */ |
| 355 previousDialog_: String, | 414 previousDialog_: String, |
| 356 | 415 |
| 357 /** @private {string} */ | 416 /** @private {string} */ |
| 358 currentDialog_: String, | 417 currentDialog_: String, |
| 359 | 418 |
| 360 /** @private {boolean} */ | 419 /** @private {boolean} */ |
| 361 showDiscoveryDialog_: Boolean, | 420 showDiscoveryDialog_: Boolean, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 379 }, | 438 }, |
| 380 | 439 |
| 381 /** @override */ | 440 /** @override */ |
| 382 ready: function() { | 441 ready: function() { |
| 383 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); | 442 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); |
| 384 }, | 443 }, |
| 385 | 444 |
| 386 /** Opens the Add printer discovery dialog. */ | 445 /** Opens the Add printer discovery dialog. */ |
| 387 open: function() { | 446 open: function() { |
| 388 this.resetData_(); | 447 this.resetData_(); |
| 389 this.switchDialog_( | 448 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
| 390 '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_'); | |
| 391 }, | 449 }, |
| 392 | 450 |
| 393 /** | 451 /** |
| 394 * Reset all the printer data in the Add printer flow. | 452 * Reset all the printer data in the Add printer flow. |
| 395 * @private | 453 * @private |
| 396 */ | 454 */ |
| 397 resetData_: function() { | 455 resetData_: function() { |
| 398 if (this.selectedPrinter) | 456 if (this.selectedPrinter) |
| 399 this.selectedPrinter = this.getEmptyPrinter_(); | 457 this.selectedPrinter = this.getEmptyPrinter_(); |
| 400 if (this.newPrinter) | 458 if (this.newPrinter) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 431 openDiscoveryPrintersDialog_: function() { | 489 openDiscoveryPrintersDialog_: function() { |
| 432 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 490 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
| 433 'showDiscoveryDialog_'); | 491 'showDiscoveryDialog_'); |
| 434 }, | 492 }, |
| 435 | 493 |
| 436 /** @private */ | 494 /** @private */ |
| 437 openConfiguringPrinterDialog_: function() { | 495 openConfiguringPrinterDialog_: function() { |
| 438 this.switchDialog_( | 496 this.switchDialog_( |
| 439 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 497 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
| 440 'showConfiguringDialog_'); | 498 'showConfiguringDialog_'); |
| 441 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 499 if (!this.inManualFlow) { |
| 442 this.configuringDialogTitle = | 500 this.configuringDialogTitle = |
| 443 loadTimeData.getString('addPrintersNearbyTitle'); | 501 loadTimeData.getString('addPrintersNearbyTitle'); |
| 444 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 502 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| 445 this.selectedPrinter); | 503 this.selectedPrinter); |
| 446 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 504 } else { |
| 447 this.configuringDialogTitle = | 505 this.configuringDialogTitle = |
| 448 loadTimeData.getString('addPrintersManuallyTitle'); | 506 loadTimeData.getString('addPrintersManuallyTitle'); |
| 449 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 507 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| 450 this.newPrinter); | 508 this.newPrinter); |
| 451 } | 509 } |
| 452 }, | 510 }, |
| 453 | 511 |
| 454 /** @private */ | 512 /** @private */ |
| 455 openManufacturerModelDialog_: function() { | 513 openManufacturerModelDialog_: function() { |
| 514 if (this.currentDialog_ == AddPrinterDialogs.DISCOVERY) |
| 515 this.inManualFlow = false; |
| 516 else if (this.currentDialog_ == AddPrinterDialogs.MANUALLY) |
| 517 this.inManualFlow = true; |
| 518 |
| 456 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 519 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
| 457 'showManufacturerDialog_'); | 520 'showManufacturerDialog_'); |
| 458 }, | 521 }, |
| 459 | 522 |
| 460 /** @private */ | 523 /** @private */ |
| 461 configuringDialogClosed_: function() { | 524 configuringDialogClosed_: function() { |
| 462 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { | 525 if (this.inManualFlow) { |
| 463 this.switchDialog_( | 526 this.switchDialog_( |
| 464 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); | 527 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); |
| 465 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 528 } else { |
| 466 this.switchDialog_( | 529 this.switchDialog_( |
| 467 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_'); | 530 this.currentDialog_, this.previousDialog_, 'showDiscoveryDialog_'); |
| 468 } | 531 } |
| 469 }, | 532 }, |
| 470 | 533 |
| 471 /** | 534 /** |
| 472 * Switch dialog from |fromDialog| to |toDialog|. | 535 * Switch dialog from |fromDialog| to |toDialog|. |
| 473 * @param {string} fromDialog | 536 * @param {string} fromDialog |
| 474 * @param {string} toDialog | 537 * @param {string} toDialog |
| 475 * @param {string} domIfBooleanName The name of the boolean variable | 538 * @param {string} domIfBooleanName The name of the boolean variable |
| 476 * corresponding to the |toDialog|. | 539 * corresponding to the |toDialog|. |
| 477 * @private | 540 * @private |
| 478 */ | 541 */ |
| 479 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { | 542 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { |
| 480 this.previousDialog_ = fromDialog; | 543 this.previousDialog_ = fromDialog; |
| 481 this.currentDialog_ = toDialog; | 544 this.currentDialog_ = toDialog; |
| 482 | 545 |
| 483 this.set(domIfBooleanName, true); | 546 this.set(domIfBooleanName, true); |
| 484 this.async(function() { | 547 this.async(function() { |
| 485 var dialog = this.$$(toDialog); | 548 var dialog = this.$$(toDialog); |
| 486 dialog.addEventListener('close', function() { | 549 dialog.addEventListener('close', function() { |
| 487 this.set(domIfBooleanName, false); | 550 this.set(domIfBooleanName, false); |
| 488 }.bind(this)); | 551 }.bind(this)); |
| 489 }); | 552 }); |
| 490 }, | 553 }, |
| 491 | 554 |
| 492 /** | 555 /** |
| 493 * @return {string} The name of the current printer in configuration. | 556 * @return {string} The name of the current printer in configuration. |
| 494 * @private | 557 * @private |
| 495 */ | 558 */ |
| 496 getConfiguringPrinterName_: function() { | 559 getConfiguringPrinterName_: function() { |
| 497 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | 560 if (this.inManualFlow) |
| 561 return this.newPrinter.printerName; |
| 562 else |
| 498 return this.selectedPrinter.printerName; | 563 return this.selectedPrinter.printerName; |
| 499 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | |
| 500 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | |
| 501 return this.newPrinter.printerName; | |
| 502 } | |
| 503 return ''; | |
| 504 }, | 564 }, |
| 505 | 565 |
| 506 /** | 566 /** |
| 507 * @param {boolean} success | 567 * @param {boolean} success |
| 508 * @param {string} printerName | 568 * @param {string} printerName |
| 509 * @private | 569 * @private |
| 510 */ | 570 */ |
| 511 onAddPrinter_: function(success, printerName) { | 571 onAddPrinter_: function(success, printerName) { |
| 512 this.$$('add-printer-configuring-dialog').close(); | 572 this.$$('add-printer-configuring-dialog').close(); |
| 513 if (success) | 573 if (success) |
| 514 return; | 574 return; |
| 515 | 575 |
| 516 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 576 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| 517 this.setupFailed = true; | 577 this.setupFailed = true; |
| 518 } | 578 } |
| 519 }, | 579 }, |
| 520 }); | 580 }); |
| OLD | NEW |