OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 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 |
| 11 * be unavailable for modifying if the print destination doesn't support it or |
| 12 * if other ticket item constraints are not met. |
| 13 * @constructor |
| 14 */ |
| 15 function TicketItem() { |
| 16 /** |
| 17 * Backing store of the print ticket item. |
| 18 * @type {Object} |
| 19 * @private |
| 20 */ |
| 21 this.value_ = null; |
| 22 }; |
| 23 |
| 24 TicketItem.prototype = { |
| 25 /** |
| 26 * Determines whether a given value is valid for the ticket item. |
| 27 * @param {Object} value The value to check for validity. |
| 28 * @return {boolean} Whether the given value is valid for the ticket item. |
| 29 */ |
| 30 wouldValueBeValid: function(value) { |
| 31 throw Error('Abstract method not overridden'); |
| 32 }, |
| 33 |
| 34 /** |
| 35 * @return {boolean} Whether the print destination capability is available. |
| 36 */ |
| 37 isCapabilityAvailable: function() { |
| 38 throw Error('Abstract method not overridden'); |
| 39 }, |
| 40 |
| 41 /** @return {object} The value of the ticket item. */ |
| 42 getValue: function() { |
| 43 if (this.isCapabilityAvailable()) { |
| 44 if (this.value_ == null) { |
| 45 return this.getDefaultValueInternal(); |
| 46 } else { |
| 47 return this.value_; |
| 48 } |
| 49 } else { |
| 50 return this.getCapabilityNotAvailableValueInternal(); |
| 51 } |
| 52 }, |
| 53 |
| 54 /** @return {boolean} Whether the ticket item was modified by the user. */ |
| 55 isUserEdited: function() { |
| 56 return this.value_ != null; |
| 57 }, |
| 58 |
| 59 /** @return {boolean} Whether the ticket item's value is valid. */ |
| 60 isValid: function() { |
| 61 if (!this.isUserEdited()) { |
| 62 return true; |
| 63 } |
| 64 return this.wouldValueBeValid(this.value_); |
| 65 }, |
| 66 |
| 67 /** @param {object} Value to set as the value of the ticket item. */ |
| 68 updateValue: function(value) { |
| 69 this.value_ = value; |
| 70 }, |
| 71 |
| 72 /** |
| 73 * @return {object} Default value of the ticket item if no value was set by |
| 74 * the user. |
| 75 * @protected |
| 76 */ |
| 77 getDefaultValueInternal: function() { |
| 78 throw Error('Abstract method not overridden'); |
| 79 }, |
| 80 |
| 81 /** |
| 82 * @return {object} Default value of the ticket item if the capability is |
| 83 * not available. |
| 84 * @protected |
| 85 */ |
| 86 getCapabilityNotAvailableValueInternal: function() { |
| 87 throw Error('Abstract method not overridden'); |
| 88 } |
| 89 }; |
| 90 |
| 91 // Export |
| 92 return { |
| 93 TicketItem: TicketItem |
| 94 }; |
| 95 }); |
OLD | NEW |