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