| 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 |
| 11 * and write the copies value. | 11 * and write the copies value. |
| 12 * @param {!print_preview.ticket_items.Collate} collateTicketItem Used to read | 12 * @param {!print_preview.ticket_items.Collate} collateTicketItem Used to read |
| 13 * and write the collate value. | 13 * and write the collate value. |
| 14 * @constructor | 14 * @constructor |
| 15 * @extends {print_preview.Component} | 15 * @extends {print_preview.SettingsSection} |
| 16 */ | 16 */ |
| 17 function CopiesSettings(copiesTicketItem, collateTicketItem) { | 17 function CopiesSettings(copiesTicketItem, collateTicketItem) { |
| 18 print_preview.Component.call(this); | 18 print_preview.SettingsSection.call(this); |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Used to read and write the copies value. | 21 * Used to read and write the copies value. |
| 22 * @type {!print_preview.ticket_items.Copies} | 22 * @type {!print_preview.ticket_items.Copies} |
| 23 * @private | 23 * @private |
| 24 */ | 24 */ |
| 25 this.copiesTicketItem_ = copiesTicketItem; | 25 this.copiesTicketItem_ = copiesTicketItem; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Used to read and write the collate value. | 28 * Used to read and write the collate value. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Delay in milliseconds before processing the textfield. | 50 * Delay in milliseconds before processing the textfield. |
| 51 * @type {number} | 51 * @type {number} |
| 52 * @private | 52 * @private |
| 53 */ | 53 */ |
| 54 CopiesSettings.TEXTFIELD_DELAY_ = 250; | 54 CopiesSettings.TEXTFIELD_DELAY_ = 250; |
| 55 | 55 |
| 56 CopiesSettings.prototype = { | 56 CopiesSettings.prototype = { |
| 57 __proto__: print_preview.Component.prototype, | 57 __proto__: print_preview.SettingsSection.prototype, |
| 58 | 58 |
| 59 /** @param {boolean} isEnabled Whether the copies settings is enabled. */ | 59 /** @override */ |
| 60 isAvailable: function() { |
| 61 return this.copiesTicketItem_.isCapabilityAvailable(); |
| 62 }, |
| 63 |
| 64 /** @override */ |
| 65 hasCollapsibleContent: function() { |
| 66 return false; |
| 67 }, |
| 68 |
| 69 /** @override */ |
| 60 set isEnabled(isEnabled) { | 70 set isEnabled(isEnabled) { |
| 61 this.getChildElement('input.copies').disabled = !isEnabled; | 71 this.getChildElement('input.copies').disabled = !isEnabled; |
| 62 this.getChildElement('input.collate').disabled = !isEnabled; | 72 this.getChildElement('input.collate').disabled = !isEnabled; |
| 63 this.isEnabled_ = isEnabled; | 73 this.isEnabled_ = isEnabled; |
| 64 if (isEnabled) { | 74 if (isEnabled) { |
| 65 this.updateState_(); | 75 this.updateState_(); |
| 66 } else { | 76 } else { |
| 67 this.getChildElement('button.increment').disabled = true; | 77 this.getChildElement('button.increment').disabled = true; |
| 68 this.getChildElement('button.decrement').disabled = true; | 78 this.getChildElement('button.decrement').disabled = true; |
| 69 } | 79 } |
| 70 }, | 80 }, |
| 71 | 81 |
| 72 /** @override */ | 82 /** @override */ |
| 73 enterDocument: function() { | 83 enterDocument: function() { |
| 74 print_preview.Component.prototype.enterDocument.call(this); | 84 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 75 fadeOutOption(this.getElement(), true); | |
| 76 this.tracker.add( | 85 this.tracker.add( |
| 77 this.getChildElement('input.copies'), | 86 this.getChildElement('input.copies'), |
| 78 'keydown', | 87 'keydown', |
| 79 this.onTextfieldKeyDown_.bind(this)); | 88 this.onTextfieldKeyDown_.bind(this)); |
| 80 this.tracker.add( | 89 this.tracker.add( |
| 81 this.getChildElement('input.copies'), | 90 this.getChildElement('input.copies'), |
| 82 'input', | 91 'input', |
| 83 this.onTextfieldInput_.bind(this)); | 92 this.onTextfieldInput_.bind(this)); |
| 84 this.tracker.add( | 93 this.tracker.add( |
| 85 this.getChildElement('input.copies'), | 94 this.getChildElement('input.copies'), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 this.collateTicketItem_, | 114 this.collateTicketItem_, |
| 106 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 115 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 107 this.updateState_.bind(this)); | 116 this.updateState_.bind(this)); |
| 108 }, | 117 }, |
| 109 | 118 |
| 110 /** | 119 /** |
| 111 * Updates the state of the copies settings UI controls. | 120 * Updates the state of the copies settings UI controls. |
| 112 * @private | 121 * @private |
| 113 */ | 122 */ |
| 114 updateState_: function() { | 123 updateState_: function() { |
| 115 if (!this.copiesTicketItem_.isCapabilityAvailable()) { | 124 if (this.isAvailable()) { |
| 116 fadeOutOption(this.getElement()); | 125 if (this.getChildElement('input.copies').value != |
| 117 return; | 126 this.copiesTicketItem_.getValue()) { |
| 127 this.getChildElement('input.copies').value = |
| 128 this.copiesTicketItem_.getValue(); |
| 129 } |
| 130 |
| 131 var currentValueGreaterThan1 = false; |
| 132 if (this.copiesTicketItem_.isValid()) { |
| 133 this.getChildElement('input.copies').classList.remove('invalid'); |
| 134 fadeOutElement(this.getChildElement('.hint')); |
| 135 var currentValue = this.copiesTicketItem_.getValueAsNumber(); |
| 136 var currentValueGreaterThan1 = currentValue > 1; |
| 137 this.getChildElement('button.increment').disabled = |
| 138 !this.isEnabled_ || |
| 139 !this.copiesTicketItem_.wouldValueBeValid(currentValue + 1); |
| 140 this.getChildElement('button.decrement').disabled = |
| 141 !this.isEnabled_ || |
| 142 !this.copiesTicketItem_.wouldValueBeValid(currentValue - 1); |
| 143 } else { |
| 144 this.getChildElement('input.copies').classList.add('invalid'); |
| 145 fadeInElement(this.getChildElement('.hint')); |
| 146 this.getChildElement('button.increment').disabled = true; |
| 147 this.getChildElement('button.decrement').disabled = true; |
| 148 } |
| 149 |
| 150 if (!(this.getChildElement('.collate-container').hidden = |
| 151 !this.collateTicketItem_.isCapabilityAvailable() || |
| 152 !currentValueGreaterThan1)) { |
| 153 this.getChildElement('input.collate').checked = |
| 154 this.collateTicketItem_.getValue(); |
| 155 } |
| 118 } | 156 } |
| 119 | 157 this.updateUiStateInternal(); |
| 120 if (this.getChildElement('input.copies').value != | |
| 121 this.copiesTicketItem_.getValue()) { | |
| 122 this.getChildElement('input.copies').value = | |
| 123 this.copiesTicketItem_.getValue(); | |
| 124 } | |
| 125 | |
| 126 var currentValueGreaterThan1 = false; | |
| 127 if (this.copiesTicketItem_.isValid()) { | |
| 128 this.getChildElement('input.copies').classList.remove('invalid'); | |
| 129 fadeOutElement(this.getChildElement('.hint')); | |
| 130 this.getChildElement('.hint').setAttribute('aria-hidden', true); | |
| 131 var currentValue = this.copiesTicketItem_.getValueAsNumber(); | |
| 132 var currentValueGreaterThan1 = currentValue > 1; | |
| 133 this.getChildElement('button.increment').disabled = | |
| 134 !this.isEnabled_ || | |
| 135 !this.copiesTicketItem_.wouldValueBeValid(currentValue + 1); | |
| 136 this.getChildElement('button.decrement').disabled = | |
| 137 !this.isEnabled_ || | |
| 138 !this.copiesTicketItem_.wouldValueBeValid(currentValue - 1); | |
| 139 } else { | |
| 140 this.getChildElement('input.copies').classList.add('invalid'); | |
| 141 this.getChildElement('.hint').setAttribute('aria-hidden', false); | |
| 142 fadeInElement(this.getChildElement('.hint')); | |
| 143 this.getChildElement('button.increment').disabled = true; | |
| 144 this.getChildElement('button.decrement').disabled = true; | |
| 145 } | |
| 146 | |
| 147 if (!(this.getChildElement('.collate-container').hidden = | |
| 148 !this.collateTicketItem_.isCapabilityAvailable() || | |
| 149 !currentValueGreaterThan1)) { | |
| 150 this.getChildElement('input.collate').checked = | |
| 151 this.collateTicketItem_.getValue(); | |
| 152 } | |
| 153 | |
| 154 fadeInOption(this.getElement()); | |
| 155 }, | 158 }, |
| 156 | 159 |
| 157 /** | 160 /** |
| 158 * Called whenever the increment/decrement buttons are clicked. | 161 * Called whenever the increment/decrement buttons are clicked. |
| 159 * @param {number} delta Must be 1 for an increment button click and -1 for | 162 * @param {number} delta Must be 1 for an increment button click and -1 for |
| 160 * a decrement button click. | 163 * a decrement button click. |
| 161 * @private | 164 * @private |
| 162 */ | 165 */ |
| 163 onButtonClicked_: function(delta) { | 166 onButtonClicked_: function(delta) { |
| 164 // Assumes text field has a valid number. | 167 // Assumes text field has a valid number. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 this.collateTicketItem_.updateValue( | 228 this.collateTicketItem_.updateValue( |
| 226 this.getChildElement('input.collate').checked); | 229 this.getChildElement('input.collate').checked); |
| 227 } | 230 } |
| 228 }; | 231 }; |
| 229 | 232 |
| 230 // Export | 233 // Export |
| 231 return { | 234 return { |
| 232 CopiesSettings: CopiesSettings | 235 CopiesSettings: CopiesSettings |
| 233 }; | 236 }; |
| 234 }); | 237 }); |
| OLD | NEW |