| 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-printers-list' is a component for a list of | 6 * @fileoverview 'settings-cups-printers-list' is a component for a list of |
| 7 * CUPS printers. | 7 * CUPS printers. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-cups-printers-list', | 10 is: 'settings-cups-printers-list', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @type {!Array<!CupsPrinterInfo>} */ | 13 /** @type {!Array<!CupsPrinterInfo>} */ |
| 14 printers: { | 14 printers: { |
| 15 type: Array, | 15 type: Array, |
| 16 notify: true, | 16 notify: true, |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 searchTerm: { | 19 searchTerm: { |
| 20 type: String, | 20 type: String, |
| 21 }, | 21 }, |
| 22 |
| 23 /** |
| 24 * The model for the printer action menu. |
| 25 * @private {?CupsPrinterInfo} |
| 26 */ |
| 27 activePrinter_: Object, |
| 22 }, | 28 }, |
| 23 | 29 |
| 24 /** @private {settings.CupsPrintersBrowserProxy} */ | 30 /** @private {settings.CupsPrintersBrowserProxy} */ |
| 25 browserProxy_: null, | 31 browserProxy_: null, |
| 26 | 32 |
| 27 /** @override */ | 33 /** @override */ |
| 28 created: function() { | 34 created: function() { |
| 29 this.browserProxy_ = settings.CupsPrintersBrowserProxyImpl.getInstance(); | 35 this.browserProxy_ = settings.CupsPrintersBrowserProxyImpl.getInstance(); |
| 30 }, | 36 }, |
| 31 | 37 |
| 32 /** | 38 /** |
| 39 * @param {!{model: !{item: !CupsPrinterInfo}}} e |
| 40 * @private |
| 41 */ |
| 42 onOpenActionMenuTap_: function(e) { |
| 43 this.activePrinter_ = e.model.item; |
| 44 var menu = /** @type {!SettingsActionMenuElement} */ ( |
| 45 this.$$('dialog[is=settings-action-menu]')); |
| 46 menu.showAt(/** @type {!Element} */ ( |
| 47 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); |
| 48 }, |
| 49 |
| 50 /** |
| 33 * @param {{model:Object}} event | 51 * @param {{model:Object}} event |
| 34 * @private | 52 * @private |
| 35 */ | 53 */ |
| 36 onDetailsTap_: function(event) { | 54 onDetailsTap_: function(event) { |
| 55 // Event is caught by 'settings-printing-page'. |
| 56 this.fire('show-cups-printer-details', this.activePrinter_); |
| 37 this.closeDropdownMenu_(); | 57 this.closeDropdownMenu_(); |
| 38 | |
| 39 // Event is caught by 'settings-printing-page'. | |
| 40 this.fire('show-cups-printer-details', event.model.item); | |
| 41 }, | 58 }, |
| 42 | 59 |
| 43 /** | 60 /** |
| 44 * @param {{model:Object}} event | 61 * @param {{model:Object}} event |
| 45 * @private | 62 * @private |
| 46 */ | 63 */ |
| 47 onRemoveTap_: function(event) { | 64 onRemoveTap_: function(event) { |
| 65 var index = this.printers.indexOf(assert(this.activePrinter_)); |
| 66 this.splice('printers', index, 1); |
| 67 this.browserProxy_.removeCupsPrinter(this.activePrinter_.printerId, |
| 68 this.activePrinter_.printerName); |
| 48 this.closeDropdownMenu_(); | 69 this.closeDropdownMenu_(); |
| 49 | |
| 50 var index = this.printers.indexOf(event.model.item); | |
| 51 this.splice('printers', index, 1); | |
| 52 this.browserProxy_.removeCupsPrinter(event.model.item.printerId, | |
| 53 event.model.item.printerName); | |
| 54 }, | 70 }, |
| 55 | 71 |
| 56 /** @private */ | 72 /** @private */ |
| 57 closeDropdownMenu_: function() { | 73 closeDropdownMenu_: function() { |
| 58 this.$$('iron-dropdown').close(); | 74 this.activePrinter_ = null; |
| 75 var menu = /** @type {!SettingsActionMenuElement} */ ( |
| 76 this.$$('dialog[is=settings-action-menu]')); |
| 77 menu.close(); |
| 59 }, | 78 }, |
| 60 | 79 |
| 61 /** | 80 /** |
| 62 * The filter callback function to show printers based on |searchTerm|. | 81 * The filter callback function to show printers based on |searchTerm|. |
| 63 * @param {string} searchTerm | 82 * @param {string} searchTerm |
| 64 * @private | 83 * @private |
| 65 */ | 84 */ |
| 66 filterPrinter_: function(searchTerm) { | 85 filterPrinter_: function(searchTerm) { |
| 67 if (!searchTerm) | 86 if (!searchTerm) |
| 68 return null; | 87 return null; |
| 69 return function(printer) { | 88 return function(printer) { |
| 70 return printer.printerName.toLowerCase().includes( | 89 return printer.printerName.toLowerCase().includes( |
| 71 searchTerm.toLowerCase()); | 90 searchTerm.toLowerCase()); |
| 72 }; | 91 }; |
| 73 }, | 92 }, |
| 74 }); | 93 }); |
| OLD | NEW |