| 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 MarginSettings object. This object encapsulates all settings and | 9 * Creates a MarginSettings object. This object encapsulates all settings and |
| 10 * logic related to the margins mode. | 10 * logic related to the margins mode. |
| 11 * @param {!print_preview.ticket_items.MarginsType} marginsTypeTicketItem Used | 11 * @param {!print_preview.ticket_items.MarginsType} marginsTypeTicketItem Used |
| 12 * to read and write the margins type ticket item. | 12 * to read and write the margins type ticket item. |
| 13 * @constructor | 13 * @constructor |
| 14 * @extends {print_preview.Component} | 14 * @extends {print_preview.SettingsSection} |
| 15 */ | 15 */ |
| 16 function MarginSettings(marginsTypeTicketItem) { | 16 function MarginSettings(marginsTypeTicketItem) { |
| 17 print_preview.Component.call(this); | 17 print_preview.SettingsSection.call(this); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Used to read and write the margins type ticket item. | 20 * Used to read and write the margins type ticket item. |
| 21 * @type {!print_preview.ticket_items.MarginsType} | 21 * @type {!print_preview.ticket_items.MarginsType} |
| 22 * @private | 22 * @private |
| 23 */ | 23 */ |
| 24 this.marginsTypeTicketItem_ = marginsTypeTicketItem; | 24 this.marginsTypeTicketItem_ = marginsTypeTicketItem; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * CSS classes used by the margin settings component. | 28 * CSS classes used by the margin settings component. |
| 29 * @enum {string} | 29 * @enum {string} |
| 30 * @private | 30 * @private |
| 31 */ | 31 */ |
| 32 MarginSettings.Classes_ = { | 32 MarginSettings.Classes_ = { |
| 33 SELECT: 'margin-settings-select' | 33 SELECT: 'margin-settings-select' |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 MarginSettings.prototype = { | 36 MarginSettings.prototype = { |
| 37 __proto__: print_preview.Component.prototype, | 37 __proto__: print_preview.SettingsSection.prototype, |
| 38 | 38 |
| 39 /** @param {boolean} isEnabled Whether this component is enabled. */ | 39 /** @override */ |
| 40 isAvailable: function() { |
| 41 return this.marginsTypeTicketItem_.isCapabilityAvailable(); |
| 42 }, |
| 43 |
| 44 /** @override */ |
| 45 hasCollapsibleContent: function() { |
| 46 return this.isAvailable(); |
| 47 }, |
| 48 |
| 49 /** @override */ |
| 40 set isEnabled(isEnabled) { | 50 set isEnabled(isEnabled) { |
| 41 this.select_.disabled = !isEnabled; | 51 this.select_.disabled = !isEnabled; |
| 42 }, | 52 }, |
| 43 | 53 |
| 44 /** @override */ | 54 /** @override */ |
| 45 enterDocument: function() { | 55 enterDocument: function() { |
| 46 print_preview.Component.prototype.enterDocument.call(this); | 56 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 47 fadeOutOption(this.getElement(), true); | |
| 48 this.tracker.add( | 57 this.tracker.add( |
| 49 this.select_, 'change', this.onSelectChange_.bind(this)); | 58 this.select_, 'change', this.onSelectChange_.bind(this)); |
| 50 this.tracker.add( | 59 this.tracker.add( |
| 51 this.marginsTypeTicketItem_, | 60 this.marginsTypeTicketItem_, |
| 52 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 61 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 53 this.onMarginsTypeTicketItemChange_.bind(this)); | 62 this.onMarginsTypeTicketItemChange_.bind(this)); |
| 54 }, | 63 }, |
| 55 | 64 |
| 56 /** | 65 /** |
| 57 * @return {HTMLSelectElement} Select element containing the margin options. | 66 * @return {HTMLSelectElement} Select element containing the margin options. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 select.selectedIndex); | 83 select.selectedIndex); |
| 75 this.marginsTypeTicketItem_.updateValue(marginsType); | 84 this.marginsTypeTicketItem_.updateValue(marginsType); |
| 76 }, | 85 }, |
| 77 | 86 |
| 78 /** | 87 /** |
| 79 * Called when the print ticket store changes. Selects the corresponding | 88 * Called when the print ticket store changes. Selects the corresponding |
| 80 * select option. | 89 * select option. |
| 81 * @private | 90 * @private |
| 82 */ | 91 */ |
| 83 onMarginsTypeTicketItemChange_: function() { | 92 onMarginsTypeTicketItemChange_: function() { |
| 84 if (this.marginsTypeTicketItem_.isCapabilityAvailable()) { | 93 if (this.isAvailable()) { |
| 85 var select = this.select_; | 94 var select = this.select_; |
| 86 var marginsType = this.marginsTypeTicketItem_.getValue(); | 95 var marginsType = this.marginsTypeTicketItem_.getValue(); |
| 87 var selectedMarginsType = | 96 var selectedMarginsType = |
| 88 /** @type {!print_preview.ticket_items.MarginsType.Value} */ ( | 97 /** @type {!print_preview.ticket_items.MarginsType.Value} */ ( |
| 89 select.selectedIndex); | 98 select.selectedIndex); |
| 90 if (marginsType != selectedMarginsType) { | 99 if (marginsType != selectedMarginsType) { |
| 91 select.options[selectedMarginsType].selected = false; | 100 select.options[selectedMarginsType].selected = false; |
| 92 select.options[marginsType].selected = true; | 101 select.options[marginsType].selected = true; |
| 93 } | 102 } |
| 94 fadeInOption(this.getElement()); | |
| 95 } else { | |
| 96 fadeOutOption(this.getElement()); | |
| 97 } | 103 } |
| 104 this.updateUiStateInternal(); |
| 98 } | 105 } |
| 99 }; | 106 }; |
| 100 | 107 |
| 101 // Export | 108 // Export |
| 102 return { | 109 return { |
| 103 MarginSettings: MarginSettings | 110 MarginSettings: MarginSettings |
| 104 }; | 111 }; |
| 105 }); | 112 }); |
| OLD | NEW |