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 15 matching lines...) Expand all Loading... |
26 MANUFACTURER: 'add-printer-manufacturer-model-dialog', | 26 MANUFACTURER: 'add-printer-manufacturer-model-dialog', |
27 }; | 27 }; |
28 | 28 |
29 /** | 29 /** |
30 * The maximum height of the discovered printers list when the searching spinner | 30 * The maximum height of the discovered printers list when the searching spinner |
31 * is not showing. | 31 * is not showing. |
32 * @const {number} | 32 * @const {number} |
33 */ | 33 */ |
34 var kPrinterListFullHeight = 350; | 34 var kPrinterListFullHeight = 350; |
35 | 35 |
| 36 /** |
| 37 * Return a reset CupsPrinterInfo object. |
| 38 * @return {!CupsPrinterInfo} |
| 39 */ |
| 40 function getEmptyPrinter_() { |
| 41 return { |
| 42 printerAddress: '', |
| 43 printerDescription: '', |
| 44 printerId: '', |
| 45 printerManufacturer: '', |
| 46 printerModel: '', |
| 47 printerName: '', |
| 48 printerPPDPath: '', |
| 49 printerProtocol: 'ipp', |
| 50 printerQueue: '', |
| 51 printerStatus: '', |
| 52 }; |
| 53 } |
| 54 |
36 Polymer({ | 55 Polymer({ |
37 is: 'add-printer-discovery-dialog', | 56 is: 'add-printer-discovery-dialog', |
38 | 57 |
39 behaviors: [WebUIListenerBehavior], | 58 behaviors: [WebUIListenerBehavior], |
40 | 59 |
41 properties: { | 60 properties: { |
42 /** @type {!Array<!CupsPrinterInfo>|undefined} */ | 61 /** @type {!Array<!CupsPrinterInfo>|undefined} */ |
43 discoveredPrinters: { | 62 discoveredPrinters: { |
44 type: Array, | 63 type: Array, |
45 }, | 64 }, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 /** @private */ | 111 /** @private */ |
93 stopDiscoveringPrinters_: function() { | 112 stopDiscoveringPrinters_: function() { |
94 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 113 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
95 stopDiscoveringPrinters(); | 114 stopDiscoveringPrinters(); |
96 this.discovering_ = false; | 115 this.discovering_ = false; |
97 }, | 116 }, |
98 | 117 |
99 /** @private */ | 118 /** @private */ |
100 switchToManualAddDialog_: function() { | 119 switchToManualAddDialog_: function() { |
101 this.stopDiscoveringPrinters_(); | 120 this.stopDiscoveringPrinters_(); |
| 121 // We're abandoning discovery in favor of manual specification, so |
| 122 // drop the selection if one exists. |
| 123 this.selectedPrinter = getEmptyPrinter_(); |
102 this.$$('add-printer-dialog').close(); | 124 this.$$('add-printer-dialog').close(); |
103 this.fire('open-manually-add-printer-dialog'); | 125 this.fire('open-manually-add-printer-dialog'); |
104 }, | 126 }, |
105 | 127 |
106 /** @private */ | 128 /** @private */ |
107 onCancelTap_: function() { | 129 onCancelTap_: function() { |
108 this.stopDiscoveringPrinters_(); | 130 this.stopDiscoveringPrinters_(); |
109 this.$$('add-printer-dialog').close(); | 131 this.$$('add-printer-dialog').close(); |
110 }, | 132 }, |
111 | 133 |
112 /** @private */ | 134 /** @private */ |
113 switchToConfiguringDialog_: function() { | 135 switchToManufacturerDialog_: function() { |
114 this.stopDiscoveringPrinters_(); | 136 this.stopDiscoveringPrinters_(); |
| 137 // If we're switching to the manufacturer/model dialog, clear the existing |
| 138 // data we have about the PPD (if any), as we're dropping that in favor of |
| 139 // user selections. |
| 140 this.selectedPrinter.printerManufacturer = ''; |
| 141 this.selectedPrinter.printerModel = ''; |
| 142 this.selectedPrinter.printerPPDPath = ''; |
115 this.$$('add-printer-dialog').close(); | 143 this.$$('add-printer-dialog').close(); |
116 this.fire('open-configuring-printer-dialog'); | 144 this.fire('open-manufacturer-model-dialog'); |
117 }, | 145 }, |
118 }); | 146 }); |
119 | 147 |
120 Polymer({ | 148 Polymer({ |
121 is: 'add-printer-manually-dialog', | 149 is: 'add-printer-manually-dialog', |
122 | 150 |
123 properties: { | 151 properties: { |
124 /** @type {!CupsPrinterInfo} */ | 152 /** @type {!CupsPrinterInfo} */ |
125 newPrinter: { | 153 newPrinter: { |
126 type: Object, | 154 type: Object, |
127 notify: true, | 155 notify: true, |
128 value: function() { | 156 value: getEmptyPrinter_ |
129 return { | |
130 printerAddress: '', | |
131 printerDescription: '', | |
132 printerId: '', | |
133 printerManufacturer: '', | |
134 printerModel: '', | |
135 printerName: '', | |
136 printerPPDPath: '', | |
137 printerProtocol: 'ipp', | |
138 printerQueue: '', | |
139 printerStatus: '', | |
140 }; | |
141 }, | |
142 }, | 157 }, |
143 }, | 158 }, |
144 | 159 |
145 /** @private */ | 160 /** @private */ |
146 switchToDiscoveryDialog_: function() { | 161 switchToDiscoveryDialog_: function() { |
147 this.$$('add-printer-dialog').close(); | 162 this.$$('add-printer-dialog').close(); |
148 this.fire('open-discovery-printers-dialog'); | 163 this.fire('open-discovery-printers-dialog'); |
149 }, | 164 }, |
150 | 165 |
151 /** @private */ | 166 /** @private */ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 /** @type {?Array<string>} */ | 207 /** @type {?Array<string>} */ |
193 manufacturerList: { | 208 manufacturerList: { |
194 type: Array, | 209 type: Array, |
195 }, | 210 }, |
196 | 211 |
197 /** @type {?Array<string>} */ | 212 /** @type {?Array<string>} */ |
198 modelList: { | 213 modelList: { |
199 type: Array, | 214 type: Array, |
200 }, | 215 }, |
201 | 216 |
| 217 /** @type {string} */ |
| 218 previousDialog: String, |
| 219 |
202 setupFailed: { | 220 setupFailed: { |
203 type: Boolean, | 221 type: Boolean, |
204 value: false, | 222 value: false, |
205 }, | 223 }, |
206 }, | 224 }, |
207 | 225 |
208 observers: [ | 226 observers: [ |
209 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 227 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', |
210 ], | 228 ], |
211 | 229 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 /** | 274 /** |
257 * @param {!ModelsInfo} modelsInfo | 275 * @param {!ModelsInfo} modelsInfo |
258 * @private | 276 * @private |
259 */ | 277 */ |
260 modelListChanged_: function(modelsInfo) { | 278 modelListChanged_: function(modelsInfo) { |
261 if (modelsInfo.success) | 279 if (modelsInfo.success) |
262 this.modelList = modelsInfo.models; | 280 this.modelList = modelsInfo.models; |
263 }, | 281 }, |
264 | 282 |
265 /** @private */ | 283 /** @private */ |
266 switchToManualAddDialog_: function() { | 284 switchToPreviousDialog_: function() { |
267 this.$$('add-printer-dialog').close(); | 285 this.$$('add-printer-dialog').close(); |
268 this.fire('open-manually-add-printer-dialog'); | 286 if (this.previousDialog == AddPrinterDialogs.DISCOVERY) { |
| 287 this.fire('open-discovery-printers-dialog'); |
| 288 } else if (this.previousDialog == AddPrinterDialogs.MANUALLY) { |
| 289 this.fire('open-manually-add-printer-dialog'); |
| 290 } |
269 }, | 291 }, |
270 | 292 |
271 /** @private */ | 293 /** @private */ |
272 onCancelTap_: function() { | 294 onCancelTap_: function() { |
273 this.$$('add-printer-dialog').close(); | 295 this.$$('add-printer-dialog').close(); |
274 }, | 296 }, |
275 | 297 |
276 /** @private */ | 298 /** @private */ |
277 switchToConfiguringDialog_: function() { | 299 switchToConfiguringDialog_: function() { |
278 this.$$('add-printer-dialog').close(); | 300 this.$$('add-printer-dialog').close(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 }, | 336 }, |
315 }); | 337 }); |
316 | 338 |
317 Polymer({ | 339 Polymer({ |
318 is: 'settings-cups-add-printer-dialog', | 340 is: 'settings-cups-add-printer-dialog', |
319 | 341 |
320 behaviors: [WebUIListenerBehavior], | 342 behaviors: [WebUIListenerBehavior], |
321 | 343 |
322 properties: { | 344 properties: { |
323 /** @type {!CupsPrinterInfo} */ | 345 /** @type {!CupsPrinterInfo} */ |
324 selectedPrinter: { | |
325 type: Object, | |
326 }, | |
327 | |
328 /** @type {!CupsPrinterInfo} */ | |
329 newPrinter: { | 346 newPrinter: { |
330 type: Object, | 347 type: Object, |
331 }, | 348 }, |
332 | 349 |
333 /** @type {boolean} whether the new printer setup is failed. */ | 350 /** @type {boolean} whether the new printer setup is failed. */ |
334 setupFailed: { | 351 setupFailed: { |
335 type: Boolean, | 352 type: Boolean, |
336 value: false, | 353 value: false, |
337 }, | 354 }, |
338 | 355 |
339 configuringDialogTitle: String, | 356 configuringDialogTitle: String, |
340 | 357 |
341 /** @private {string} */ | 358 /** @type {string} */ |
342 previousDialog_: String, | 359 previousDialog: String, |
343 | 360 |
344 /** @private {string} */ | 361 /** @private {string} */ |
345 currentDialog_: String, | 362 currentDialog_: String, |
346 | 363 |
347 /** @private {boolean} */ | 364 /** @private {boolean} */ |
348 showDiscoveryDialog_: Boolean, | 365 showDiscoveryDialog_: Boolean, |
349 | 366 |
350 /** @private {boolean} */ | 367 /** @private {boolean} */ |
351 showManuallyAddDialog_: Boolean, | 368 showManuallyAddDialog_: Boolean, |
352 | 369 |
(...skipping 13 matching lines...) Expand all Loading... |
366 }, | 383 }, |
367 | 384 |
368 /** @override */ | 385 /** @override */ |
369 ready: function() { | 386 ready: function() { |
370 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); | 387 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); |
371 }, | 388 }, |
372 | 389 |
373 /** Opens the Add printer discovery dialog. */ | 390 /** Opens the Add printer discovery dialog. */ |
374 open: function() { | 391 open: function() { |
375 this.resetData_(); | 392 this.resetData_(); |
376 this.switchDialog_( | 393 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
377 '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_'); | |
378 }, | 394 }, |
379 | 395 |
380 /** | 396 /** |
381 * Reset all the printer data in the Add printer flow. | 397 * Reset all the printer data in the Add printer flow. |
382 * @private | 398 * @private |
383 */ | 399 */ |
384 resetData_: function() { | 400 resetData_: function() { |
385 if (this.selectedPrinter) | |
386 this.selectedPrinter = this.getEmptyPrinter_(); | |
387 if (this.newPrinter) | 401 if (this.newPrinter) |
388 this.newPrinter = this.getEmptyPrinter_(); | 402 this.newPrinter = getEmptyPrinter_(); |
389 this.setupFailed = false; | 403 this.setupFailed = false; |
390 }, | 404 }, |
391 | 405 |
392 /** | |
393 * @return {!CupsPrinterInfo} | |
394 * @private | |
395 */ | |
396 getEmptyPrinter_: function() { | |
397 return { | |
398 printerAddress: '', | |
399 printerDescription: '', | |
400 printerId: '', | |
401 printerManufacturer: '', | |
402 printerModel: '', | |
403 printerName: '', | |
404 printerPPDPath: '', | |
405 printerProtocol: 'ipp', | |
406 printerQueue: '', | |
407 printerStatus: '', | |
408 }; | |
409 }, | |
410 | |
411 /** @private */ | 406 /** @private */ |
412 openManuallyAddPrinterDialog_: function() { | 407 openManuallyAddPrinterDialog_: function() { |
413 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, | 408 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
414 'showManuallyAddDialog_'); | 409 'showManuallyAddDialog_'); |
415 }, | 410 }, |
416 | 411 |
417 /** @private */ | 412 /** @private */ |
418 openDiscoveryPrintersDialog_: function() { | 413 openDiscoveryPrintersDialog_: function() { |
419 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 414 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
420 'showDiscoveryDialog_'); | 415 'showDiscoveryDialog_'); |
421 }, | 416 }, |
422 | 417 |
423 /** @private */ | 418 /** @private */ |
424 openConfiguringPrinterDialog_: function() { | 419 openConfiguringPrinterDialog_: function() { |
425 this.switchDialog_( | 420 this.switchDialog_( |
426 this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 421 this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
427 'showConfiguringDialog_'); | 422 'showConfiguringDialog_'); |
428 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { | 423 if (this.previousDialog == AddPrinterDialogs.DISCOVERY) { |
429 this.configuringDialogTitle = | 424 this.configuringDialogTitle = |
430 loadTimeData.getString('addPrintersNearbyTitle'); | 425 loadTimeData.getString('addPrintersNearbyTitle'); |
431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 426 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
432 this.selectedPrinter); | 427 this.newPrinter); |
433 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 428 } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) { |
434 this.configuringDialogTitle = | 429 this.configuringDialogTitle = |
435 loadTimeData.getString('addPrintersManuallyTitle'); | 430 loadTimeData.getString('addPrintersManuallyTitle'); |
436 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( | 431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
437 this.newPrinter); | 432 this.newPrinter); |
438 } | 433 } |
439 }, | 434 }, |
440 | 435 |
441 /** @private */ | 436 /** @private */ |
442 openManufacturerModelDialog_: function() { | 437 openManufacturerModelDialog_: function() { |
443 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 438 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
444 'showManufacturerDialog_'); | 439 'showManufacturerDialog_'); |
445 }, | 440 }, |
446 | 441 |
447 /** @private */ | 442 /** @private */ |
448 configuringDialogClosed_: function() { | 443 configuringDialogClosed_: function() { |
449 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { | 444 // If the configuring dialog is closed, we want to return whence we came. |
| 445 // |
| 446 // TODO(justincarlson) - This shouldn't need to be a conditional; |
| 447 // clean up the way we switch dialogs so we don't have to supply |
| 448 // redundant information and can just return to the previous |
| 449 // dialog. |
| 450 if (this.previousDialog == AddPrinterDialogs.DISCOVERY) { |
450 this.switchDialog_( | 451 this.switchDialog_( |
451 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); | 452 this.currentDialog_, this.previousDialog, 'showDiscoveryDialog_'); |
452 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 453 } else if (this.previousDialog == AddPrinterDialogs.MANUALLY) { |
453 this.switchDialog_( | 454 this.switchDialog_( |
454 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_'); | 455 this.currentDialog_, this.previousDialog, 'showManuallyAddDialog_'); |
| 456 } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) { |
| 457 this.switchDialog_( |
| 458 this.currentDialog_, this.previousDialog, 'showManufacturerDialog_'); |
455 } | 459 } |
456 }, | 460 }, |
457 | 461 |
458 /** | 462 /** |
459 * Switch dialog from |fromDialog| to |toDialog|. | 463 * Switch dialog from |fromDialog| to |toDialog|. |
460 * @param {string} fromDialog | 464 * @param {string} fromDialog |
461 * @param {string} toDialog | 465 * @param {string} toDialog |
462 * @param {string} domIfBooleanName The name of the boolean variable | 466 * @param {string} domIfBooleanName The name of the boolean variable |
463 * corresponding to the |toDialog|. | 467 * corresponding to the |toDialog|. |
464 * @private | 468 * @private |
465 */ | 469 */ |
466 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { | 470 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { |
467 this.previousDialog_ = fromDialog; | 471 this.previousDialog = fromDialog; |
468 this.currentDialog_ = toDialog; | 472 this.currentDialog_ = toDialog; |
469 | 473 |
470 this.set(domIfBooleanName, true); | 474 this.set(domIfBooleanName, true); |
471 this.async(function() { | 475 this.async(function() { |
472 var dialog = this.$$(toDialog); | 476 var dialog = this.$$(toDialog); |
473 dialog.addEventListener('close', function() { | 477 dialog.addEventListener('close', function() { |
474 this.set(domIfBooleanName, false); | 478 this.set(domIfBooleanName, false); |
475 }.bind(this)); | 479 }.bind(this)); |
476 }); | 480 }); |
477 }, | 481 }, |
478 | 482 |
479 /** | 483 /** |
480 * @return {string} The name of the current printer in configuration. | |
481 * @private | |
482 */ | |
483 getConfiguringPrinterName_: function() { | |
484 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | |
485 return this.selectedPrinter.printerName; | |
486 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | |
487 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | |
488 return this.newPrinter.printerName; | |
489 } | |
490 return ''; | |
491 }, | |
492 | |
493 /** | |
494 * @param {boolean} success | 484 * @param {boolean} success |
495 * @param {string} printerName | 485 * @param {string} printerName |
496 * @private | 486 * @private |
497 */ | 487 */ |
498 onAddPrinter_: function(success, printerName) { | 488 onAddPrinter_: function(success, printerName) { |
499 this.$$('add-printer-configuring-dialog').close(); | 489 this.$$('add-printer-configuring-dialog').close(); |
500 if (success) | 490 if (success) |
501 return; | 491 return; |
502 | 492 |
503 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 493 if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) { |
504 this.setupFailed = true; | 494 this.setupFailed = true; |
505 } | 495 } |
506 }, | 496 }, |
507 }); | 497 }); |
OLD | NEW |