| 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * An object that represents a user modifiable item in a print ticket. Each | 9 * An object that represents a user modifiable item in a print ticket. Each |
| 10 * ticket item has a value which can be set by the user. Ticket items can also | 10 * ticket item has a value which can be set by the user. Ticket items can also |
| 11 * be unavailable for modifying if the print destination doesn't support it or | 11 * be unavailable for modifying if the print destination doesn't support it or |
| 12 * if other ticket item constraints are not met. | 12 * if other ticket item constraints are not met. |
| 13 * @param {print_preview.AppState=} appState Application state model to update | 13 * @param {?print_preview.AppState} appState Application state model to update |
| 14 * when ticket items update. | 14 * when ticket items update. |
| 15 * @param {print_preview.AppState.Field=} field Field of the app state to | 15 * @param {?print_preview.AppState.Field} field Field of the app state to |
| 16 * update when ticket item is updated. | 16 * update when ticket item is updated. |
| 17 * @param {print_preview.DestinationStore=} destinationStore Used listen for | 17 * @param {?print_preview.DestinationStore} destinationStore Used listen for |
| 18 * changes in the currently selected destination's capabilities. Since | 18 * changes in the currently selected destination's capabilities. Since |
| 19 * this is a common dependency of ticket items, it's handled in the base | 19 * this is a common dependency of ticket items, it's handled in the base |
| 20 * class. | 20 * class. |
| 21 * @param {print_preview.DocumentInfo=} documentInfo Used to listen for | 21 * @param {?print_preview.DocumentInfo=} opt_documentInfo Used to listen for |
| 22 * changes in the document. Since this is a common dependency of ticket | 22 * changes in the document. Since this is a common dependency of ticket |
| 23 * items, it's handled in the base class. | 23 * items, it's handled in the base class. |
| 24 * @constructor | 24 * @constructor |
| 25 * @extends {cr.EventTarget} | 25 * @extends {cr.EventTarget} |
| 26 */ | 26 */ |
| 27 function TicketItem(appState, field, destinationStore, documentInfo) { | 27 function TicketItem(appState, field, destinationStore, opt_documentInfo) { |
| 28 cr.EventTarget.call(this); | 28 cr.EventTarget.call(this); |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Application state model to update when ticket items update. | 31 * Application state model to update when ticket items update. |
| 32 * @type {print_preview.AppState} | 32 * @type {print_preview.AppState} |
| 33 * @private | 33 * @private |
| 34 */ | 34 */ |
| 35 this.appState_ = appState || null; | 35 this.appState_ = appState || null; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Field of the app state to update when ticket item is updated. | 38 * Field of the app state to update when ticket item is updated. |
| 39 * @type {?print_preview.AppState.Field} | 39 * @type {?print_preview.AppState.Field} |
| 40 * @private | 40 * @private |
| 41 */ | 41 */ |
| 42 this.field_ = field || null; | 42 this.field_ = field || null; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * Used listen for changes in the currently selected destination's | 45 * Used listen for changes in the currently selected destination's |
| 46 * capabilities. | 46 * capabilities. |
| 47 * @type {print_preview.DestinationStore} | 47 * @type {print_preview.DestinationStore} |
| 48 * @private | 48 * @private |
| 49 */ | 49 */ |
| 50 this.destinationStore_ = destinationStore || null; | 50 this.destinationStore_ = destinationStore || null; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Used to listen for changes in the document. | 53 * Used to listen for changes in the document. |
| 54 * @type {print_preview.DocumentInfo} | 54 * @type {print_preview.DocumentInfo} |
| 55 * @private | 55 * @private |
| 56 */ | 56 */ |
| 57 this.documentInfo_ = documentInfo || null; | 57 this.documentInfo_ = opt_documentInfo || null; |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Backing store of the print ticket item. | 60 * Backing store of the print ticket item. |
| 61 * @type {Object} | 61 * @type {Object} |
| 62 * @private | 62 * @private |
| 63 */ | 63 */ |
| 64 this.value_ = null; | 64 this.value_ = null; |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Keeps track of event listeners for the ticket item. | 67 * Keeps track of event listeners for the ticket item. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 */ | 79 */ |
| 80 TicketItem.EventType = { | 80 TicketItem.EventType = { |
| 81 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE' | 81 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE' |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 TicketItem.prototype = { | 84 TicketItem.prototype = { |
| 85 __proto__: cr.EventTarget.prototype, | 85 __proto__: cr.EventTarget.prototype, |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Determines whether a given value is valid for the ticket item. | 88 * Determines whether a given value is valid for the ticket item. |
| 89 * @param {Object} value The value to check for validity. | 89 * @param {?} value The value to check for validity. |
| 90 * @return {boolean} Whether the given value is valid for the ticket item. | 90 * @return {boolean} Whether the given value is valid for the ticket item. |
| 91 */ | 91 */ |
| 92 wouldValueBeValid: function(value) { | 92 wouldValueBeValid: function(value) { |
| 93 throw Error('Abstract method not overridden'); | 93 throw Error('Abstract method not overridden'); |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @return {boolean} Whether the print destination capability is available. | 97 * @return {boolean} Whether the print destination capability is available. |
| 98 */ | 98 */ |
| 99 isCapabilityAvailable: function() { | 99 isCapabilityAvailable: function() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 120 | 120 |
| 121 /** @return {boolean} Whether the ticket item's value is valid. */ | 121 /** @return {boolean} Whether the ticket item's value is valid. */ |
| 122 isValid: function() { | 122 isValid: function() { |
| 123 if (!this.isUserEdited()) { | 123 if (!this.isUserEdited()) { |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 return this.wouldValueBeValid(this.value_); | 126 return this.wouldValueBeValid(this.value_); |
| 127 }, | 127 }, |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @param {Object} value Value to compare to the value of this ticket item. | 130 * @param {?} value Value to compare to the value of this ticket item. |
| 131 * @return {boolean} Whether the given value is equal to the value of the | 131 * @return {boolean} Whether the given value is equal to the value of the |
| 132 * ticket item. | 132 * ticket item. |
| 133 */ | 133 */ |
| 134 isValueEqual: function(value) { | 134 isValueEqual: function(value) { |
| 135 return this.getValue() == value; | 135 return this.getValue() == value; |
| 136 }, | 136 }, |
| 137 | 137 |
| 138 /** @param {!Object} value Value to set as the value of the ticket item. */ | 138 /** |
| 139 * @param {?} value Value to set as the value of the ticket item. |
| 140 */ |
| 139 updateValue: function(value) { | 141 updateValue: function(value) { |
| 140 // Use comparison with capabilities for event. | 142 // Use comparison with capabilities for event. |
| 141 var sendUpdateEvent = !this.isValueEqual(value); | 143 var sendUpdateEvent = !this.isValueEqual(value); |
| 142 // Don't lose requested value if capability is not available. | 144 // Don't lose requested value if capability is not available. |
| 143 this.updateValueInternal(value); | 145 this.updateValueInternal(value); |
| 144 if (this.appState_) { | 146 if (this.appState_) { |
| 145 this.appState_.persistField(this.field_, value); | 147 this.appState_.persistField(this.field_, value); |
| 146 } | 148 } |
| 147 if (sendUpdateEvent) | 149 if (sendUpdateEvent) |
| 148 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE); | 150 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 this.dispatchChangeEventInternal.bind(this)); | 232 this.dispatchChangeEventInternal.bind(this)); |
| 231 } | 233 } |
| 232 }, | 234 }, |
| 233 }; | 235 }; |
| 234 | 236 |
| 235 // Export | 237 // Export |
| 236 return { | 238 return { |
| 237 TicketItem: TicketItem | 239 TicketItem: TicketItem |
| 238 }; | 240 }; |
| 239 }); | 241 }); |
| OLD | NEW |