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 LayoutSettings object. This object encapsulates all settings and |
| 10 * logic related to layout mode (portrait/landscape). |
| 11 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 12 * layout written to the print ticket. |
| 13 * @constructor |
| 14 * @extends {print_preview.Component} |
| 15 */ |
| 16 function LayoutSettings(printTicketStore) { |
| 17 print_preview.Component.call(this); |
| 18 |
| 19 /** |
| 20 * Used to get the layout written to the print ticket. |
| 21 * @type {!print_preview.PrintTicketStore} |
| 22 * @private |
| 23 */ |
| 24 this.printTicketStore_ = printTicketStore; |
| 25 }; |
| 26 |
| 27 /** |
| 28 * CSS classes used by the layout settings. |
| 29 * @enum {string} |
| 30 * @private |
| 31 */ |
| 32 LayoutSettings.Classes_ = { |
| 33 LANDSCAPE_RADIO: 'layout-settings-landscape-radio', |
| 34 PORTRAIT_RADIO: 'layout-settings-portrait-radio' |
| 35 }; |
| 36 |
| 37 LayoutSettings.prototype = { |
| 38 __proto__: print_preview.Component.prototype, |
| 39 |
| 40 /** @param {boolean} isEnabled Whether this component is enabled. */ |
| 41 set isEnabled(isEnabled) { |
| 42 this.landscapeRadioButton_.disabled = !isEnabled; |
| 43 this.portraitRadioButton_.disabled = !isEnabled; |
| 44 }, |
| 45 |
| 46 /** @override */ |
| 47 enterDocument: function() { |
| 48 print_preview.Component.prototype.enterDocument.call(this); |
| 49 this.tracker.add( |
| 50 this.portraitRadioButton_, |
| 51 'click', |
| 52 this.onLayoutButtonClick_.bind(this)); |
| 53 this.tracker.add( |
| 54 this.landscapeRadioButton_, |
| 55 'click', |
| 56 this.onLayoutButtonClick_.bind(this)); |
| 57 this.tracker.add( |
| 58 this.printTicketStore_, |
| 59 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE, |
| 60 this.onPrintTicketStoreChange_.bind(this)); |
| 61 this.tracker.add( |
| 62 this.printTicketStore_, |
| 63 print_preview.PrintTicketStore.EventType.CAPABILITIES_CHANGE, |
| 64 this.onPrintTicketStoreChange_.bind(this)); |
| 65 this.tracker.add( |
| 66 this.printTicketStore_, |
| 67 print_preview.PrintTicketStore.EventType.TICKET_CHANGE, |
| 68 this.onPrintTicketStoreChange_.bind(this)); |
| 69 this.tracker.add( |
| 70 this.printTicketStore_, |
| 71 print_preview.PrintTicketStore.EventType.INITIALIZE, |
| 72 this.onPrintTicketStoreChange_.bind(this)); |
| 73 }, |
| 74 |
| 75 /** |
| 76 * @return {HTMLInputElement} The portrait orientation radio button. |
| 77 * @private |
| 78 */ |
| 79 get portraitRadioButton_() { |
| 80 return this.getElement().getElementsByClassName( |
| 81 LayoutSettings.Classes_.PORTRAIT_RADIO)[0]; |
| 82 }, |
| 83 |
| 84 /** |
| 85 * @return {HTMLInputElement} The landscape orientation radio button. |
| 86 * @private |
| 87 */ |
| 88 get landscapeRadioButton_() { |
| 89 return this.getElement().getElementsByClassName( |
| 90 LayoutSettings.Classes_.LANDSCAPE_RADIO)[0]; |
| 91 }, |
| 92 |
| 93 /** |
| 94 * Called when one of the radio buttons is clicked. Updates the print ticket |
| 95 * store. |
| 96 * @private |
| 97 */ |
| 98 onLayoutButtonClick_: function() { |
| 99 this.printTicketStore_.updateOrientation( |
| 100 this.landscapeRadioButton_.checked); |
| 101 }, |
| 102 |
| 103 /** |
| 104 * Called when the print ticket store changes state. Updates the state of |
| 105 * the radio buttons and hides the setting if necessary. |
| 106 * @private |
| 107 */ |
| 108 onPrintTicketStoreChange_: function() { |
| 109 if (this.printTicketStore_.hasOrientationCapability()) { |
| 110 var isLandscapeEnabled = this.printTicketStore_.isLandscapeEnabled(); |
| 111 this.portraitRadioButton_.checked = !isLandscapeEnabled; |
| 112 this.landscapeRadioButton_.checked = isLandscapeEnabled; |
| 113 fadeInOption(this.getElement()); |
| 114 } else { |
| 115 fadeOutOption(this.getElement()); |
| 116 } |
| 117 } |
| 118 }; |
| 119 |
| 120 // Export |
| 121 return { |
| 122 LayoutSettings: LayoutSettings |
| 123 }; |
| 124 }); |
OLD | NEW |