| 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 * Component that renders the copies settings UI. | 9 * Component that renders the copies settings UI. |
| 10 * @param {!print_preview.ticket_items.Copies} copiesTicketItem Used to read | 10 * @param {!print_preview.ticket_items.Copies} copiesTicketItem Used to read |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 112 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 113 this.updateState_.bind(this)); | 113 this.updateState_.bind(this)); |
| 114 }, | 114 }, |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Updates the state of the copies settings UI controls. | 117 * Updates the state of the copies settings UI controls. |
| 118 * @private | 118 * @private |
| 119 */ | 119 */ |
| 120 updateState_: function() { | 120 updateState_: function() { |
| 121 if (this.isAvailable()) { | 121 if (this.isAvailable()) { |
| 122 if (!this.inputField_.validity.valid) { |
| 123 this.inputField_.classList.add('invalid'); |
| 124 fadeInElement(this.getChildElement('.hint')); |
| 125 this.getChildElement('.collate-container').hidden = true; |
| 126 this.updateUiStateInternal(); |
| 127 return; |
| 128 } |
| 122 if (this.inputField_.value != this.copiesTicketItem_.getValue()) | 129 if (this.inputField_.value != this.copiesTicketItem_.getValue()) |
| 123 this.inputField_.value = this.copiesTicketItem_.getValue(); | 130 this.inputField_.value = this.copiesTicketItem_.getValue(); |
| 124 | 131 this.inputField_.classList.remove('invalid'); |
| 125 var currentValueGreaterThan1 = false; | 132 fadeOutElement(this.getChildElement('.hint')); |
| 126 if (this.copiesTicketItem_.isValid()) { | |
| 127 this.inputField_.classList.remove('invalid'); | |
| 128 fadeOutElement(this.getChildElement('.hint')); | |
| 129 var currentValue = this.copiesTicketItem_.getValueAsNumber(); | |
| 130 currentValueGreaterThan1 = currentValue > 1; | |
| 131 } else { | |
| 132 this.inputField_.classList.add('invalid'); | |
| 133 fadeInElement(this.getChildElement('.hint')); | |
| 134 } | |
| 135 | |
| 136 if (!(this.getChildElement('.collate-container').hidden = | 133 if (!(this.getChildElement('.collate-container').hidden = |
| 137 !this.collateTicketItem_.isCapabilityAvailable() || | 134 !this.collateTicketItem_.isCapabilityAvailable() || |
| 138 !currentValueGreaterThan1)) { | 135 this.copiesTicketItem_.getValueAsNumber() <= 1)) { |
| 139 this.getChildElement('input.collate').checked = | 136 this.getChildElement('input.collate').checked = |
| 140 this.collateTicketItem_.getValue(); | 137 this.collateTicketItem_.getValue(); |
| 141 } | 138 } |
| 142 } | 139 } |
| 143 this.updateUiStateInternal(); | 140 this.updateUiStateInternal(); |
| 144 }, | 141 }, |
| 145 | 142 |
| 146 /** | 143 /** |
| 147 * Called after a timeout after user input into the textfield. | 144 * Called after a timeout after user input into the textfield. |
| 148 * @private | 145 * @private |
| 149 */ | 146 */ |
| 150 onTextfieldTimeout_: function() { | 147 onTextfieldTimeout_: function() { |
| 151 this.textfieldTimeout_ = null; | 148 this.textfieldTimeout_ = null; |
| 152 var copiesVal = this.inputField_.value; | 149 var newValue = (this.inputField_.validity.valid && |
| 153 if (copiesVal != '') { | 150 this.inputField_.value != '') ? |
| 154 this.copiesTicketItem_.updateValue(copiesVal); | 151 this.inputField_.valueAsNumber.toString() : ''; |
| 152 if (this.copiesTicketItem_.getValue() === newValue) { |
| 153 this.updateState_(); |
| 154 return; |
| 155 } | 155 } |
| 156 this.copiesTicketItem_.updateValue(newValue); |
| 156 }, | 157 }, |
| 157 | 158 |
| 158 /** | 159 /** |
| 159 * Called when a key is pressed on the custom input. | 160 * Called when a key is pressed on the custom input. |
| 160 * @param {Event} event Contains the key that was pressed. | 161 * @param {Event} event Contains the key that was pressed. |
| 161 * @private | 162 * @private |
| 162 */ | 163 */ |
| 163 onTextfieldKeyDown_: function(event) { | 164 onTextfieldKeyDown_: function(event) { |
| 164 if (event.keyCode != 'Enter') | 165 if (event.keyCode != 'Enter') |
| 165 return; | 166 return; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 182 this.onTextfieldTimeout_.bind(this), | 183 this.onTextfieldTimeout_.bind(this), |
| 183 CopiesSettings.TEXTFIELD_DELAY_MS_); | 184 CopiesSettings.TEXTFIELD_DELAY_MS_); |
| 184 }, | 185 }, |
| 185 | 186 |
| 186 /** | 187 /** |
| 187 * Called when the focus leaves the textfield. If the textfield is empty, | 188 * Called when the focus leaves the textfield. If the textfield is empty, |
| 188 * its value is set to 1. | 189 * its value is set to 1. |
| 189 * @private | 190 * @private |
| 190 */ | 191 */ |
| 191 onTextfieldBlur_: function() { | 192 onTextfieldBlur_: function() { |
| 192 if (this.inputField_.value == '') { | 193 if (this.inputField_.validity.valid && this.inputField_.value == '') { |
| 193 if (this.copiesTicketItem_.getValue() == '1') { | 194 if (this.copiesTicketItem_.getValue() == '1') { |
| 194 // No need to update the ticket, but change the display to match. | 195 // No need to update the ticket, but change the display to match. |
| 195 this.inputField_.value = '1'; | 196 this.inputField_.value = '1'; |
| 196 } else { | 197 } else { |
| 197 setTimeout((function() { | 198 setTimeout((function() { |
| 198 this.copiesTicketItem_.updateValue('1'); | 199 this.copiesTicketItem_.updateValue('1'); |
| 199 }).bind(this), 0); | 200 }).bind(this), 0); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 }, | 203 }, |
| 203 | 204 |
| 204 /** | 205 /** |
| 205 * Called when the collate checkbox is clicked. Updates the print ticket. | 206 * Called when the collate checkbox is clicked. Updates the print ticket. |
| 206 * @private | 207 * @private |
| 207 */ | 208 */ |
| 208 onCollateCheckboxClick_: function() { | 209 onCollateCheckboxClick_: function() { |
| 209 this.collateTicketItem_.updateValue( | 210 this.collateTicketItem_.updateValue( |
| 210 this.getChildElement('input.collate').checked); | 211 this.getChildElement('input.collate').checked); |
| 211 } | 212 } |
| 212 }; | 213 }; |
| 213 | 214 |
| 214 // Export | 215 // Export |
| 215 return { | 216 return { |
| 216 CopiesSettings: CopiesSettings | 217 CopiesSettings: CopiesSettings |
| 217 }; | 218 }; |
| 218 }); | 219 }); |
| OLD | NEW |