| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates a LayoutSettings object. This object encapsulates all settings and | 9 * Creates a LayoutSettings object. This object encapsulates all settings and |
| 10 * logic related to layout mode (portrait/landscape). | 10 * logic related to layout mode (portrait/landscape). |
| 11 * @param {!print_preview.ticket_items.Landscape} landscapeTicketItem Used to | 11 * @param {!print_preview.ticket_items.Landscape} landscapeTicketItem Used to |
| 12 * get the layout written to the print ticket. | 12 * get the layout written to the print ticket. |
| 13 * @constructor | 13 * @constructor |
| 14 * @extends {print_preview.SettingsSection} | 14 * @extends {print_preview.SettingsSection} |
| 15 */ | 15 */ |
| 16 function LayoutSettings(landscapeTicketItem) { | 16 function LayoutSettings(landscapeTicketItem) { |
| 17 print_preview.SettingsSection.call(this); | 17 print_preview.SettingsSection.call(this); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Used to get the layout written to the print ticket. | 20 * Used to get the layout written to the print ticket. |
| 21 * @type {!print_preview.ticket_items.Landscape} | 21 * @type {!print_preview.ticket_items.Landscape} |
| 22 * @private | 22 * @private |
| 23 */ | 23 */ |
| 24 this.landscapeTicketItem_ = landscapeTicketItem; | 24 this.landscapeTicketItem_ = landscapeTicketItem; |
| 25 }; | 25 }; |
| 26 | 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 = { | 27 LayoutSettings.prototype = { |
| 38 __proto__: print_preview.SettingsSection.prototype, | 28 __proto__: print_preview.SettingsSection.prototype, |
| 39 | 29 |
| 40 /** @override */ | 30 /** @override */ |
| 41 isAvailable: function() { | 31 isAvailable: function() { |
| 42 return this.landscapeTicketItem_.isCapabilityAvailable(); | 32 return this.landscapeTicketItem_.isCapabilityAvailable(); |
| 43 }, | 33 }, |
| 44 | 34 |
| 45 /** @override */ | 35 /** @override */ |
| 46 hasCollapsibleContent: function() { | 36 hasCollapsibleContent: function() { |
| 47 return false; | 37 return false; |
| 48 }, | 38 }, |
| 49 | 39 |
| 50 /** @override */ | 40 /** @override */ |
| 51 set isEnabled(isEnabled) { | 41 set isEnabled(isEnabled) { |
| 52 this.landscapeRadioButton_.disabled = !isEnabled; | 42 this.select_.disabled = !isEnabled; |
| 53 this.portraitRadioButton_.disabled = !isEnabled; | |
| 54 }, | 43 }, |
| 55 | 44 |
| 56 /** @override */ | 45 /** @override */ |
| 57 enterDocument: function() { | 46 enterDocument: function() { |
| 58 print_preview.SettingsSection.prototype.enterDocument.call(this); | 47 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 59 this.tracker.add( | 48 this.tracker.add( |
| 60 this.portraitRadioButton_, | 49 this.select_, 'change', this.onSelectChange_.bind(this)); |
| 61 'click', | |
| 62 this.onLayoutButtonClick_.bind(this)); | |
| 63 this.tracker.add( | |
| 64 this.landscapeRadioButton_, | |
| 65 'click', | |
| 66 this.onLayoutButtonClick_.bind(this)); | |
| 67 this.tracker.add( | 50 this.tracker.add( |
| 68 this.landscapeTicketItem_, | 51 this.landscapeTicketItem_, |
| 69 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 52 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 70 this.onLandscapeTicketItemChange_.bind(this)); | 53 this.onLandscapeTicketItemChange_.bind(this)); |
| 71 }, | 54 }, |
| 72 | 55 |
| 73 /** | 56 /** |
| 74 * @return {HTMLInputElement} The portrait orientation radio button. | 57 * Called when the select element is changed. Updates the print ticket |
| 58 * layout selection. |
| 75 * @private | 59 * @private |
| 76 */ | 60 */ |
| 77 get portraitRadioButton_() { | 61 onSelectChange_: function() { |
| 78 return this.getElement().getElementsByClassName( | 62 var select = this.select_; |
| 79 LayoutSettings.Classes_.PORTRAIT_RADIO)[0]; | 63 var isLandscape = |
| 64 select.options[select.selectedIndex].value == 'landscape'; |
| 65 this.landscapeTicketItem_.updateValue(isLandscape); |
| 80 }, | 66 }, |
| 81 | 67 |
| 82 /** | 68 /** |
| 83 * @return {HTMLInputElement} The landscape orientation radio button. | 69 * @return {HTMLSelectElement} Select element containing the layout options. |
| 84 * @private | 70 * @private |
| 85 */ | 71 */ |
| 86 get landscapeRadioButton_() { | 72 get select_() { |
| 87 return this.getElement().getElementsByClassName( | 73 return this.getChildElement('.layout-settings-select'); |
| 88 LayoutSettings.Classes_.LANDSCAPE_RADIO)[0]; | |
| 89 }, | 74 }, |
| 90 | 75 |
| 91 /** | 76 /** |
| 92 * Called when one of the radio buttons is clicked. Updates the print ticket | |
| 93 * store. | |
| 94 * @private | |
| 95 */ | |
| 96 onLayoutButtonClick_: function() { | |
| 97 this.landscapeTicketItem_.updateValue(this.landscapeRadioButton_.checked); | |
| 98 }, | |
| 99 | |
| 100 /** | |
| 101 * Called when the print ticket store changes state. Updates the state of | 77 * Called when the print ticket store changes state. Updates the state of |
| 102 * the radio buttons and hides the setting if necessary. | 78 * the radio buttons and hides the setting if necessary. |
| 103 * @private | 79 * @private |
| 104 */ | 80 */ |
| 105 onLandscapeTicketItemChange_: function() { | 81 onLandscapeTicketItemChange_: function() { |
| 106 if (this.isAvailable()) { | 82 if (this.isAvailable()) { |
| 107 var isLandscapeEnabled = this.landscapeTicketItem_.getValue(); | 83 var select = this.select_; |
| 108 this.portraitRadioButton_.checked = !isLandscapeEnabled; | 84 var valueToSelect = |
| 109 this.landscapeRadioButton_.checked = isLandscapeEnabled; | 85 this.landscapeTicketItem_.getValue() ? 'landscape' : 'portrait'; |
| 86 for (var i = 0; i < select.options.length; i++) { |
| 87 if (select.options[i].value == valueToSelect) { |
| 88 select.selectedIndex = i; |
| 89 break; |
| 90 } |
| 91 } |
| 110 } | 92 } |
| 111 this.updateUiStateInternal(); | 93 this.updateUiStateInternal(); |
| 112 } | 94 } |
| 113 }; | 95 }; |
| 114 | 96 |
| 115 // Export | 97 // Export |
| 116 return { | 98 return { |
| 117 LayoutSettings: LayoutSettings | 99 LayoutSettings: LayoutSettings |
| 118 }; | 100 }; |
| 119 }); | 101 }); |
| OLD | NEW |