| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Encapsulates all settings and logic related to the media size selection UI. | 9 * Encapsulates all settings and logic related to the media size selection UI. |
| 10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and | 10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and |
| 11 * write the media size ticket item. | 11 * write the media size ticket item. |
| 12 * @constructor | 12 * @constructor |
| 13 * @extends {print_preview.Component} | 13 * @extends {print_preview.SettingsSection} |
| 14 */ | 14 */ |
| 15 function MediaSizeSettings(ticketItem) { | 15 function MediaSizeSettings(ticketItem) { |
| 16 print_preview.Component.call(this); | 16 print_preview.SettingsSection.call(this); |
| 17 | 17 |
| 18 /** @private {!print_preview.ticket_items.MediaSize} */ | 18 /** @private {!print_preview.ticket_items.MediaSize} */ |
| 19 this.ticketItem_ = ticketItem; | 19 this.ticketItem_ = ticketItem; |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 MediaSizeSettings.prototype = { | 22 MediaSizeSettings.prototype = { |
| 23 __proto__: print_preview.Component.prototype, | 23 __proto__: print_preview.SettingsSection.prototype, |
| 24 | 24 |
| 25 /** @param {boolean} isEnabled Whether this component is enabled. */ | 25 /** @override */ |
| 26 isAvailable: function() { |
| 27 return this.ticketItem_.isCapabilityAvailable(); |
| 28 }, |
| 29 |
| 30 /** @override */ |
| 31 hasCollapsibleContent: function() { |
| 32 return this.isAvailable(); |
| 33 }, |
| 34 |
| 35 /** @override */ |
| 26 set isEnabled(isEnabled) { | 36 set isEnabled(isEnabled) { |
| 27 this.select_.disabled = !isEnabled; | 37 this.select_.disabled = !isEnabled; |
| 28 }, | 38 }, |
| 29 | 39 |
| 30 /** @override */ | 40 /** @override */ |
| 31 enterDocument: function() { | 41 enterDocument: function() { |
| 32 print_preview.Component.prototype.enterDocument.call(this); | 42 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 33 fadeOutOption(this.getElement(), true); | |
| 34 this.tracker.add(this.select_, 'change', this.onSelectChange_.bind(this)); | 43 this.tracker.add(this.select_, 'change', this.onSelectChange_.bind(this)); |
| 35 this.tracker.add( | 44 this.tracker.add( |
| 36 this.ticketItem_, | 45 this.ticketItem_, |
| 37 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 46 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 38 this.onTicketItemChange_.bind(this)); | 47 this.onTicketItemChange_.bind(this)); |
| 39 }, | 48 }, |
| 40 | 49 |
| 41 /** | 50 /** |
| 42 * @return {HTMLSelectElement} Select element containing media size options. | 51 * @return {HTMLSelectElement} Select element containing media size options. |
| 43 * @private | 52 * @private |
| 44 */ | 53 */ |
| 45 get select_() { | 54 get select_() { |
| 46 return this.getElement().getElementsByClassName( | 55 return this.getElement().getElementsByClassName( |
| 47 'media-size-settings-select')[0]; | 56 'media-size-settings-select')[0]; |
| 48 }, | 57 }, |
| 49 | 58 |
| 50 /** | 59 /** |
| 51 * Makes sure the content of the select element matches the capabilities of | 60 * Makes sure the content of the select element matches the capabilities of |
| 52 * the destination. | 61 * the destination. |
| 53 * @private | 62 * @private |
| 54 */ | 63 */ |
| 55 updateSelect_: function() { | 64 updateSelect_: function() { |
| 56 var select = this.select_; | 65 var select = this.select_; |
| 57 if (!this.ticketItem_.isCapabilityAvailable()) { | 66 if (!this.isAvailable()) { |
| 58 select.innerHTML = ''; | 67 select.innerHTML = ''; |
| 59 return; | 68 return; |
| 60 } | 69 } |
| 61 // Should the select content be updated? | 70 // Should the select content be updated? |
| 62 var sameContent = | 71 var sameContent = |
| 63 this.ticketItem_.capability.option.length == select.length && | 72 this.ticketItem_.capability.option.length == select.length && |
| 64 this.ticketItem_.capability.option.every(function(option, index) { | 73 this.ticketItem_.capability.option.every(function(option, index) { |
| 65 return select.options[index].value == JSON.stringify(option); | 74 return select.options[index].value == JSON.stringify(option); |
| 66 }); | 75 }); |
| 67 var indexToSelect = select.selectedIndex; | 76 var indexToSelect = select.selectedIndex; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 var mediaSize = JSON.parse(select.options[select.selectedIndex].value); | 127 var mediaSize = JSON.parse(select.options[select.selectedIndex].value); |
| 119 this.ticketItem_.updateValue(mediaSize); | 128 this.ticketItem_.updateValue(mediaSize); |
| 120 }, | 129 }, |
| 121 | 130 |
| 122 /** | 131 /** |
| 123 * Called when the print ticket store changes. Selects the corresponding | 132 * Called when the print ticket store changes. Selects the corresponding |
| 124 * select option. | 133 * select option. |
| 125 * @private | 134 * @private |
| 126 */ | 135 */ |
| 127 onTicketItemChange_: function() { | 136 onTicketItemChange_: function() { |
| 128 if (this.ticketItem_.isCapabilityAvailable()) { | 137 this.updateSelect_(); |
| 129 this.updateSelect_(); | 138 this.updateUiStateInternal(); |
| 130 fadeInOption(this.getElement()); | |
| 131 } else { | |
| 132 fadeOutOption(this.getElement()); | |
| 133 } | |
| 134 } | 139 } |
| 135 }; | 140 }; |
| 136 | 141 |
| 137 // Export | 142 // Export |
| 138 return { | 143 return { |
| 139 MediaSizeSettings: MediaSizeSettings | 144 MediaSizeSettings: MediaSizeSettings |
| 140 }; | 145 }; |
| 141 }); | 146 }); |
| OLD | NEW |