OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Creates a HeaderFooterSettings object. This object encapsulates all |
| 10 * settings and logic related to the headers and footers checkbox. |
| 11 * @param {!print_preview.PrintTicketStore} printTicketStore Used to monitor |
| 12 * the state of the print ticket. |
| 13 * @constructor |
| 14 * @extends {print_preview.Component} |
| 15 */ |
| 16 function HeaderFooterSettings(printTicketStore) { |
| 17 print_preview.Component.call(this); |
| 18 |
| 19 /** |
| 20 * Used to monitor the state of the print ticket. |
| 21 * @type {!print_preview.PrintTicketStore} |
| 22 * @private |
| 23 */ |
| 24 this.printTicketStore_ = printTicketStore; |
| 25 }; |
| 26 |
| 27 /** |
| 28 * CSS classes used by the header footer settings. |
| 29 * @enum {string} |
| 30 * @private |
| 31 */ |
| 32 HeaderFooterSettings.Classes_ = { |
| 33 CHECKBOX: 'header-footer-settings-checkbox' |
| 34 }; |
| 35 |
| 36 HeaderFooterSettings.prototype = { |
| 37 __proto__: print_preview.Component.prototype, |
| 38 |
| 39 set isEnabled(isEnabled) { |
| 40 this.checkbox_.disabled = !isEnabled; |
| 41 }, |
| 42 |
| 43 /** @override */ |
| 44 enterDocument: function() { |
| 45 print_preview.Component.prototype.enterDocument.call(this); |
| 46 this.addEventListeners_(); |
| 47 }, |
| 48 |
| 49 /** |
| 50 * @return {HTMLInputElement} The header-footer checkbox element. |
| 51 * @private |
| 52 */ |
| 53 get checkbox_() { |
| 54 return this.getElement().getElementsByClassName( |
| 55 HeaderFooterSettings.Classes_.CHECKBOX)[0]; |
| 56 }, |
| 57 |
| 58 /** |
| 59 * Adding listeners to header footer related controls. |
| 60 * @private |
| 61 */ |
| 62 addEventListeners_: function() { |
| 63 this.tracker.add( |
| 64 this.checkbox_, 'click', this.onCheckboxClick_.bind(this)); |
| 65 this.tracker.add( |
| 66 this.printTicketStore_, |
| 67 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE, |
| 68 this.onPrintTicketStoreChange_.bind(this)); |
| 69 this.tracker.add( |
| 70 this.printTicketStore_, |
| 71 print_preview.PrintTicketStore.EventType.CAPABILITIES_CHANGE, |
| 72 this.onPrintTicketStoreChange_.bind(this)); |
| 73 this.tracker.add( |
| 74 this.printTicketStore_, |
| 75 print_preview.PrintTicketStore.EventType.TICKET_CHANGE, |
| 76 this.onPrintTicketStoreChange_.bind(this)); |
| 77 }, |
| 78 |
| 79 /** |
| 80 * Called when the checkbox is clicked. Updates the print ticket. |
| 81 * @private |
| 82 */ |
| 83 onCheckboxClick_: function() { |
| 84 this.printTicketStore_.updateHeaderFooter(this.checkbox_.checked); |
| 85 }, |
| 86 |
| 87 /** |
| 88 * Called when the print ticket store has changed. Hides or shows the |
| 89 * setting. |
| 90 * @private |
| 91 */ |
| 92 onPrintTicketStoreChange_: function() { |
| 93 if (this.printTicketStore_.hasHeaderFooterCapability()) { |
| 94 this.checkbox_.checked = this.printTicketStore_.isHeaderFooterEnabled(); |
| 95 fadeInOption(this.getElement()); |
| 96 } else { |
| 97 fadeOutOption(this.getElement()); |
| 98 } |
| 99 } |
| 100 }; |
| 101 |
| 102 // Export |
| 103 return { |
| 104 HeaderFooterSettings: HeaderFooterSettings |
| 105 }; |
| 106 }); |
OLD | NEW |