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' is a component for showing CUPS | 6 * @fileoverview 'settings-cups-printers' is a component for showing CUPS |
7 * Printer settings subpage (chrome://md-settings/cupsPrinters). It is used to | 7 * Printer settings subpage (chrome://md-settings/cupsPrinters). It is used to |
8 * set up legacy & non-CloudPrint printers on ChromeOS by leveraging CUPS (the | 8 * set up legacy & non-CloudPrint printers on ChromeOS by leveraging CUPS (the |
9 * unix printing system) and the many open source drivers built for CUPS. | 9 * unix printing system) and the many open source drivers built for CUPS. |
10 */ | 10 */ |
11 // TODO(xdai): Rename it to 'settings-cups-printers-page'. | 11 // TODO(xdai): Rename it to 'settings-cups-printers-page'. |
12 Polymer({ | 12 Polymer({ |
13 is: 'settings-cups-printers', | 13 is: 'settings-cups-printers', |
14 | 14 |
| 15 behaviors: [WebUIListenerBehavior], |
| 16 |
15 properties: { | 17 properties: { |
16 /** @type {!Array<!CupsPrinterInfo>} */ | 18 /** @type {!Array<!CupsPrinterInfo>} */ |
17 printers: { | 19 printers: { |
18 type: Array, | 20 type: Array, |
19 notify: true, | 21 notify: true, |
20 }, | 22 }, |
21 | 23 |
22 searchTerm: { | 24 searchTerm: { |
23 type: String, | 25 type: String, |
24 }, | 26 }, |
25 }, | 27 }, |
26 | 28 |
27 /** @override */ | 29 /** @override */ |
28 ready: function() { | 30 ready: function() { |
| 31 this.updateCupsPrintersList_(); |
| 32 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); |
| 33 }, |
| 34 |
| 35 /** |
| 36 * @param {boolean} success |
| 37 * @param {string} printerName |
| 38 * @private |
| 39 */ |
| 40 onAddPrinter_: function(success, printerName) { |
| 41 if (!success) |
| 42 return; |
| 43 |
| 44 this.updateCupsPrintersList_(); |
| 45 var message = this.$.addPrinterMessage; |
| 46 message.textContent = loadTimeData.getStringF( |
| 47 'printerAddedSuccessfulMessage', printerName); |
| 48 message.hidden = false; |
| 49 window.setTimeout(function() { |
| 50 message.hidden = true; |
| 51 }, 3000); |
| 52 }, |
| 53 |
| 54 /** @private */ |
| 55 updateCupsPrintersList_: function() { |
29 settings.CupsPrintersBrowserProxyImpl.getInstance(). | 56 settings.CupsPrintersBrowserProxyImpl.getInstance(). |
30 getCupsPrintersList().then(this.printersChanged_.bind(this)); | 57 getCupsPrintersList().then(this.printersChanged_.bind(this)); |
31 }, | 58 }, |
32 | 59 |
33 /** | 60 /** |
34 * @param {!CupsPrintersList} cupsPrintersList | 61 * @param {!CupsPrintersList} cupsPrintersList |
35 * @private | 62 * @private |
36 */ | 63 */ |
37 printersChanged_: function(cupsPrintersList) { | 64 printersChanged_: function(cupsPrintersList) { |
38 this.printers = cupsPrintersList.printerList; | 65 this.printers = cupsPrintersList.printerList; |
39 }, | 66 }, |
40 | 67 |
41 /** @private */ | 68 /** @private */ |
42 onAddPrinterTap_: function() { | 69 onAddPrinterTap_: function() { |
43 this.$.addPrinterDialog.open(); | 70 this.$.addPrinterDialog.open(); |
44 }, | 71 }, |
45 }); | 72 }); |
OLD | NEW |