| 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 PageSettings object. This object encapsulates all settings and | 9 * Creates a PageSettings object. This object encapsulates all settings and |
| 10 * logic related to page selection. | 10 * logic related to page selection. |
| 11 * @param {!print_preview.ticket_items.PageRange} pageRangeTicketItem Used to | 11 * @param {!print_preview.ticket_items.PageRange} pageRangeTicketItem Used to |
| 12 * read and write page range settings. | 12 * read and write page range settings. |
| 13 * @constructor | 13 * @constructor |
| 14 * @extends {print_preview.Component} | 14 * @extends {print_preview.SettingsSection} |
| 15 */ | 15 */ |
| 16 function PageSettings(pageRangeTicketItem) { | 16 function PageSettings(pageRangeTicketItem) { |
| 17 print_preview.Component.call(this); | 17 print_preview.SettingsSection.call(this); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Used to read and write page range settings. | 20 * Used to read and write page range settings. |
| 21 * @type {!print_preview.ticket_items.PageRange} | 21 * @type {!print_preview.ticket_items.PageRange} |
| 22 * @private | 22 * @private |
| 23 */ | 23 */ |
| 24 this.pageRangeTicketItem_ = pageRangeTicketItem; | 24 this.pageRangeTicketItem_ = pageRangeTicketItem; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Timeout used to delay processing of the custom page range input. | 27 * Timeout used to delay processing of the custom page range input. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Delay in milliseconds before processing custom page range input. | 75 * Delay in milliseconds before processing custom page range input. |
| 76 * @type {number} | 76 * @type {number} |
| 77 * @private | 77 * @private |
| 78 */ | 78 */ |
| 79 PageSettings.CUSTOM_INPUT_DELAY_ = 500; | 79 PageSettings.CUSTOM_INPUT_DELAY_ = 500; |
| 80 | 80 |
| 81 PageSettings.prototype = { | 81 PageSettings.prototype = { |
| 82 __proto__: print_preview.Component.prototype, | 82 __proto__: print_preview.SettingsSection.prototype, |
| 83 | 83 |
| 84 /** @override */ |
| 85 isAvailable: function() { |
| 86 return this.pageRangeTicketItem_.isCapabilityAvailable(); |
| 87 }, |
| 88 |
| 89 /** @override */ |
| 90 hasCollapsibleContent: function() { |
| 91 return false; |
| 92 }, |
| 93 |
| 94 /** @override */ |
| 84 set isEnabled(isEnabled) { | 95 set isEnabled(isEnabled) { |
| 85 this.customInput_.disabled = !isEnabled; | 96 this.customInput_.disabled = !isEnabled; |
| 86 this.allRadio_.disabled = !isEnabled; | 97 this.allRadio_.disabled = !isEnabled; |
| 87 this.customRadio_.disabled = !isEnabled; | 98 this.customRadio_.disabled = !isEnabled; |
| 88 }, | 99 }, |
| 89 | 100 |
| 90 /** @override */ | 101 /** @override */ |
| 91 enterDocument: function() { | 102 enterDocument: function() { |
| 92 print_preview.Component.prototype.enterDocument.call(this); | 103 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 93 fadeOutOption(this.getElement(), true); | |
| 94 this.tracker.add( | 104 this.tracker.add( |
| 95 this.allRadio_, 'click', this.onAllRadioClick_.bind(this)); | 105 this.allRadio_, 'click', this.onAllRadioClick_.bind(this)); |
| 96 this.tracker.add( | 106 this.tracker.add( |
| 97 this.customRadio_, 'click', this.onCustomRadioClick_.bind(this)); | 107 this.customRadio_, 'click', this.onCustomRadioClick_.bind(this)); |
| 98 this.tracker.add( | 108 this.tracker.add( |
| 99 this.customInput_, 'blur', this.onCustomInputBlur_.bind(this)); | 109 this.customInput_, 'blur', this.onCustomInputBlur_.bind(this)); |
| 100 this.tracker.add( | 110 this.tracker.add( |
| 101 this.customInput_, 'focus', this.onCustomInputFocus_.bind(this)); | 111 this.customInput_, 'focus', this.onCustomInputFocus_.bind(this)); |
| 102 this.tracker.add( | 112 this.tracker.add( |
| 103 this.customInput_, 'keydown', this.onCustomInputKeyDown_.bind(this)); | 113 this.customInput_, 'keydown', this.onCustomInputKeyDown_.bind(this)); |
| 104 this.tracker.add( | 114 this.tracker.add( |
| 105 this.customInput_, 'keyup', this.onCustomInputKeyUp_.bind(this)); | 115 this.customInput_, 'keyup', this.onCustomInputKeyUp_.bind(this)); |
| 106 this.tracker.add( | 116 this.tracker.add( |
| 107 this.pageRangeTicketItem_, | 117 this.pageRangeTicketItem_, |
| 108 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 118 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 109 this.onPageRangeTicketItemChange_.bind(this)); | 119 this.onPageRangeTicketItemChange_.bind(this)); |
| 110 }, | 120 }, |
| 111 | 121 |
| 112 /** @override */ | 122 /** @override */ |
| 113 exitDocument: function() { | 123 exitDocument: function() { |
| 114 print_preview.Component.prototype.exitDocument.call(this); | 124 print_preview.SettingsSection.prototype.exitDocument.call(this); |
| 115 this.customInput_ = null; | 125 this.customInput_ = null; |
| 116 this.customRadio_ = null; | 126 this.customRadio_ = null; |
| 117 this.allRadio_ = null; | 127 this.allRadio_ = null; |
| 118 this.customHintEl_ = null; | 128 this.customHintEl_ = null; |
| 119 }, | 129 }, |
| 120 | 130 |
| 121 /** @override */ | 131 /** @override */ |
| 122 decorateInternal: function() { | 132 decorateInternal: function() { |
| 123 this.customInput_ = this.getElement().getElementsByClassName( | 133 this.customInput_ = this.getElement().getElementsByClassName( |
| 124 PageSettings.Classes_.CUSTOM_INPUT)[0]; | 134 PageSettings.Classes_.CUSTOM_INPUT)[0]; |
| 125 this.allRadio_ = this.getElement().getElementsByClassName( | 135 this.allRadio_ = this.getElement().getElementsByClassName( |
| 126 PageSettings.Classes_.ALL_RADIO)[0]; | 136 PageSettings.Classes_.ALL_RADIO)[0]; |
| 127 this.customRadio_ = this.getElement().getElementsByClassName( | 137 this.customRadio_ = this.getElement().getElementsByClassName( |
| 128 PageSettings.Classes_.CUSTOM_RADIO)[0]; | 138 PageSettings.Classes_.CUSTOM_RADIO)[0]; |
| 129 this.customHintEl_ = this.getElement().getElementsByClassName( | 139 this.customHintEl_ = this.getElement().getElementsByClassName( |
| 130 PageSettings.Classes_.CUSTOM_HINT)[0]; | 140 PageSettings.Classes_.CUSTOM_HINT)[0]; |
| 131 this.customHintEl_.textContent = localStrings.getStringF( | 141 this.customHintEl_.textContent = localStrings.getStringF( |
| 132 'pageRangeInstruction', | 142 'pageRangeInstruction', |
| 133 localStrings.getString('examplePageRangeText')); | 143 localStrings.getString('examplePageRangeText')); |
| 134 }, | 144 }, |
| 135 | 145 |
| 136 /** | 146 /** |
| 137 * @param {boolean} Whether the custom hint is visible. | 147 * @param {boolean} Whether the custom hint is visible. |
| 138 * @private | 148 * @private |
| 139 */ | 149 */ |
| 140 setInvalidStateVisible_: function(isVisible) { | 150 setInvalidStateVisible_: function(isVisible) { |
| 141 if (isVisible) { | 151 if (isVisible) { |
| 142 this.customInput_.classList.add('invalid'); | 152 this.customInput_.classList.add('invalid'); |
| 143 this.customHintEl_.setAttribute('aria-hidden', 'false'); | |
| 144 fadeInElement(this.customHintEl_); | 153 fadeInElement(this.customHintEl_); |
| 145 } else { | 154 } else { |
| 146 this.customInput_.classList.remove('invalid'); | 155 this.customInput_.classList.remove('invalid'); |
| 147 fadeOutElement(this.customHintEl_); | 156 fadeOutElement(this.customHintEl_); |
| 148 this.customHintEl_.setAttribute('aria-hidden', 'true'); | |
| 149 } | 157 } |
| 150 }, | 158 }, |
| 151 | 159 |
| 152 /** | 160 /** |
| 153 * Called when the all radio button is clicked. Updates the print ticket. | 161 * Called when the all radio button is clicked. Updates the print ticket. |
| 154 * @private | 162 * @private |
| 155 */ | 163 */ |
| 156 onAllRadioClick_: function() { | 164 onAllRadioClick_: function() { |
| 157 this.pageRangeTicketItem_.updateValue(null); | 165 this.pageRangeTicketItem_.updateValue(null); |
| 158 }, | 166 }, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 if (this.customRadio_.checked) { | 236 if (this.customRadio_.checked) { |
| 229 this.pageRangeTicketItem_.updateValue(this.customInput_.value); | 237 this.pageRangeTicketItem_.updateValue(this.customInput_.value); |
| 230 } | 238 } |
| 231 }, | 239 }, |
| 232 | 240 |
| 233 /** | 241 /** |
| 234 * Called when the print ticket changes. Updates the state of the component. | 242 * Called when the print ticket changes. Updates the state of the component. |
| 235 * @private | 243 * @private |
| 236 */ | 244 */ |
| 237 onPageRangeTicketItemChange_: function() { | 245 onPageRangeTicketItemChange_: function() { |
| 238 if (this.pageRangeTicketItem_.isCapabilityAvailable()) { | 246 if (this.isAvailable()) { |
| 239 var pageRangeStr = this.pageRangeTicketItem_.getValue(); | 247 var pageRangeStr = this.pageRangeTicketItem_.getValue(); |
| 240 if (pageRangeStr || this.customRadio_.checked) { | 248 if (pageRangeStr || this.customRadio_.checked) { |
| 241 if (!document.hasFocus() || | 249 if (!document.hasFocus() || |
| 242 document.activeElement != this.customInput_) { | 250 document.activeElement != this.customInput_) { |
| 243 this.customInput_.value = pageRangeStr; | 251 this.customInput_.value = pageRangeStr; |
| 244 } | 252 } |
| 245 this.customRadio_.checked = true; | 253 this.customRadio_.checked = true; |
| 246 this.setInvalidStateVisible_(!this.pageRangeTicketItem_.isValid()); | 254 this.setInvalidStateVisible_(!this.pageRangeTicketItem_.isValid()); |
| 247 } else { | 255 } else { |
| 248 this.allRadio_.checked = true; | 256 this.allRadio_.checked = true; |
| 249 this.setInvalidStateVisible_(false); | 257 this.setInvalidStateVisible_(false); |
| 250 } | 258 } |
| 251 fadeInOption(this.getElement()); | |
| 252 } else { | |
| 253 fadeOutOption(this.getElement()); | |
| 254 } | 259 } |
| 260 this.updateUiStateInternal(); |
| 255 } | 261 } |
| 256 }; | 262 }; |
| 257 | 263 |
| 258 // Export | 264 // Export |
| 259 return { | 265 return { |
| 260 PageSettings: PageSettings | 266 PageSettings: PageSettings |
| 261 }; | 267 }; |
| 262 }); | 268 }); |
| OLD | NEW |