| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (isEnabled) { | 81 if (isEnabled) { |
| 82 this.updateState_(); | 82 this.updateState_(); |
| 83 } | 83 } |
| 84 }, | 84 }, |
| 85 | 85 |
| 86 /** @override */ | 86 /** @override */ |
| 87 enterDocument: function() { | 87 enterDocument: function() { |
| 88 this.inputField_ = this.getChildElement('input.user-value'); | 88 this.inputField_ = this.getChildElement('input.user-value'); |
| 89 print_preview.SettingsSection.prototype.enterDocument.call(this); | 89 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 90 this.tracker.add( | 90 this.tracker.add( |
| 91 this.inputField_, | 91 this.inputField_, 'keydown', this.onTextfieldKeyDown_.bind(this)); |
| 92 'keydown', | |
| 93 this.onTextfieldKeyDown_.bind(this)); | |
| 94 this.tracker.add( | 92 this.tracker.add( |
| 95 this.inputField_, | 93 this.inputField_, 'input', this.onTextfieldInput_.bind(this)); |
| 96 'input', | |
| 97 this.onTextfieldInput_.bind(this)); | |
| 98 this.tracker.add( | 94 this.tracker.add( |
| 99 this.inputField_, | 95 this.inputField_, 'blur', this.onTextfieldBlur_.bind(this)); |
| 100 'blur', | |
| 101 this.onTextfieldBlur_.bind(this)); | |
| 102 this.tracker.add( | 96 this.tracker.add( |
| 103 this.getChildElement('input.collate'), | 97 this.getChildElement('input.collate'), 'click', |
| 104 'click', | |
| 105 this.onCollateCheckboxClick_.bind(this)); | 98 this.onCollateCheckboxClick_.bind(this)); |
| 106 this.tracker.add( | 99 this.tracker.add( |
| 107 this.copiesTicketItem_, | 100 this.copiesTicketItem_, |
| 108 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 101 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 109 this.updateState_.bind(this)); | 102 this.updateState_.bind(this)); |
| 110 this.tracker.add( | 103 this.tracker.add( |
| 111 this.collateTicketItem_, | 104 this.collateTicketItem_, |
| 112 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 105 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 113 this.updateState_.bind(this)); | 106 this.updateState_.bind(this)); |
| 114 }, | 107 }, |
| 115 | 108 |
| 116 /** | 109 /** |
| 117 * Updates the state of the copies settings UI controls. | 110 * Updates the state of the copies settings UI controls. |
| 118 * @private | 111 * @private |
| 119 */ | 112 */ |
| 120 updateState_: function() { | 113 updateState_: function() { |
| 121 if (this.isAvailable()) { | 114 if (this.isAvailable()) { |
| 122 if (!this.inputField_.validity.valid) { | 115 if (!this.inputField_.validity.valid) { |
| 123 this.inputField_.classList.add('invalid'); | 116 this.inputField_.classList.add('invalid'); |
| 124 fadeInElement(this.getChildElement('.hint')); | 117 fadeInElement(this.getChildElement('.hint')); |
| 125 this.getChildElement('.collate-container').hidden = true; | 118 this.getChildElement('.collate-container').hidden = true; |
| 126 this.updateUiStateInternal(); | 119 this.updateUiStateInternal(); |
| 127 return; | 120 return; |
| 128 } | 121 } |
| 129 if (this.inputField_.value != this.copiesTicketItem_.getValue()) | 122 if (this.inputField_.value != this.copiesTicketItem_.getValue()) |
| 130 this.inputField_.value = this.copiesTicketItem_.getValue(); | 123 this.inputField_.value = this.copiesTicketItem_.getValue(); |
| 131 this.inputField_.classList.remove('invalid'); | 124 this.inputField_.classList.remove('invalid'); |
| 132 fadeOutElement(this.getChildElement('.hint')); | 125 fadeOutElement(this.getChildElement('.hint')); |
| 133 if (!(this.getChildElement('.collate-container').hidden = | 126 if (!(this.getChildElement('.collate-container').hidden = |
| 134 !this.collateTicketItem_.isCapabilityAvailable() || | 127 !this.collateTicketItem_.isCapabilityAvailable() || |
| 135 this.copiesTicketItem_.getValueAsNumber() <= 1)) { | 128 this.copiesTicketItem_.getValueAsNumber() <= 1)) { |
| 136 this.getChildElement('input.collate').checked = | 129 this.getChildElement('input.collate').checked = |
| 137 this.collateTicketItem_.getValue(); | 130 this.collateTicketItem_.getValue(); |
| 138 } | 131 } |
| 139 } | 132 } |
| 140 this.updateUiStateInternal(); | 133 this.updateUiStateInternal(); |
| 141 }, | 134 }, |
| 142 | 135 |
| 143 /** | 136 /** |
| 144 * Called after a timeout after user input into the textfield. | 137 * Called after a timeout after user input into the textfield. |
| 145 * @private | 138 * @private |
| 146 */ | 139 */ |
| 147 onTextfieldTimeout_: function() { | 140 onTextfieldTimeout_: function() { |
| 148 this.textfieldTimeout_ = null; | 141 this.textfieldTimeout_ = null; |
| 149 var newValue = (this.inputField_.validity.valid && | 142 var newValue = |
| 150 this.inputField_.value != '') ? | 143 (this.inputField_.validity.valid && this.inputField_.value != '') ? |
| 151 this.inputField_.valueAsNumber.toString() : ''; | 144 this.inputField_.valueAsNumber.toString() : |
| 145 ''; |
| 152 if (this.copiesTicketItem_.getValue() === newValue) { | 146 if (this.copiesTicketItem_.getValue() === newValue) { |
| 153 this.updateState_(); | 147 this.updateState_(); |
| 154 return; | 148 return; |
| 155 } | 149 } |
| 156 this.copiesTicketItem_.updateValue(newValue); | 150 this.copiesTicketItem_.updateValue(newValue); |
| 157 }, | 151 }, |
| 158 | 152 |
| 159 /** | 153 /** |
| 160 * Called when a key is pressed on the custom input. | 154 * Called when a key is pressed on the custom input. |
| 161 * @param {Event} event Contains the key that was pressed. | 155 * @param {Event} event Contains the key that was pressed. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 188 * Called when the focus leaves the textfield. If the textfield is empty, | 182 * Called when the focus leaves the textfield. If the textfield is empty, |
| 189 * its value is set to 1. | 183 * its value is set to 1. |
| 190 * @private | 184 * @private |
| 191 */ | 185 */ |
| 192 onTextfieldBlur_: function() { | 186 onTextfieldBlur_: function() { |
| 193 if (this.inputField_.validity.valid && this.inputField_.value == '') { | 187 if (this.inputField_.validity.valid && this.inputField_.value == '') { |
| 194 if (this.copiesTicketItem_.getValue() == '1') { | 188 if (this.copiesTicketItem_.getValue() == '1') { |
| 195 // No need to update the ticket, but change the display to match. | 189 // No need to update the ticket, but change the display to match. |
| 196 this.inputField_.value = '1'; | 190 this.inputField_.value = '1'; |
| 197 } else { | 191 } else { |
| 198 setTimeout((function() { | 192 setTimeout( |
| 199 this.copiesTicketItem_.updateValue('1'); | 193 (function() { |
| 200 }).bind(this), 0); | 194 this.copiesTicketItem_.updateValue('1'); |
| 195 }).bind(this), |
| 196 0); |
| 201 } | 197 } |
| 202 } | 198 } |
| 203 }, | 199 }, |
| 204 | 200 |
| 205 /** | 201 /** |
| 206 * Called when the collate checkbox is clicked. Updates the print ticket. | 202 * Called when the collate checkbox is clicked. Updates the print ticket. |
| 207 * @private | 203 * @private |
| 208 */ | 204 */ |
| 209 onCollateCheckboxClick_: function() { | 205 onCollateCheckboxClick_: function() { |
| 210 this.collateTicketItem_.updateValue( | 206 this.collateTicketItem_.updateValue( |
| 211 this.getChildElement('input.collate').checked); | 207 this.getChildElement('input.collate').checked); |
| 212 } | 208 } |
| 213 }; | 209 }; |
| 214 | 210 |
| 215 // Export | 211 // Export |
| 216 return { | 212 return {CopiesSettings: CopiesSettings}; |
| 217 CopiesSettings: CopiesSettings | |
| 218 }; | |
| 219 }); | 213 }); |
| OLD | NEW |