| Index: chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
|
| diff --git a/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js b/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..47e8ef05542c4c84e959eefda511170cfafd2c18
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
|
| @@ -0,0 +1,106 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +cr.define('print_preview.ticket_items', function() {
|
| + 'use strict';
|
| +
|
| + /**
|
| + * An object that represents a user modifiable item in a print ticket. Each
|
| + * ticket item has a value which can be set by the user. Ticket items can also
|
| + * be unavailable for modifying if the print destination doesn't support it or
|
| + * if other ticket item constraints are not met.
|
| + * @constructor
|
| + */
|
| + function TicketItem() {
|
| + /**
|
| + * Backing store of the print ticket item.
|
| + * @type {Object}
|
| + * @private
|
| + */
|
| + this.value_ = null;
|
| +
|
| + /**
|
| + * A cache of whether the ticket item's value is valid.
|
| + * @type {?boolean}
|
| + * @private
|
| + */
|
| + this.isValid_ = null;
|
| + };
|
| +
|
| + TicketItem.prototype = {
|
| + /**
|
| + * Determines whether a given value is valid for the ticket item.
|
| + * @param {Object} value The value to check for validity.
|
| + * @return {boolean} Whether the given value is valid for the ticket item.
|
| + */
|
| + wouldValueBeValid: function(value) {
|
| + throw Error('Abstract method not overriden');
|
| + },
|
| +
|
| + /**
|
| + * @return {boolean} Whether the print destination capability is available.
|
| + */
|
| + isCapabilityAvailable: function() {
|
| + throw Error('Abstract method not overriden');
|
| + },
|
| +
|
| + /** @return {object} The value of the ticket item. */
|
| + getValue: function() {
|
| + if (this.isCapabilityAvailable()) {
|
| + if (this.value_ == null) {
|
| + return this.getDefaultValueInternal();
|
| + } else {
|
| + return this.value_;
|
| + }
|
| + } else {
|
| + return this.getCapabilityNotAvailableValueInternal();
|
| + }
|
| + },
|
| +
|
| + /** @return {boolean} Whether the ticket item was modified by the user. */
|
| + isUserEdited: function() {
|
| + return this.value_ != null;
|
| + },
|
| +
|
| + /** @return {boolean} Whether the ticket item's value is valid. */
|
| + isValid: function() {
|
| + if (!this.isUserEdited()) {
|
| + return true;
|
| + }
|
| + if (this.isValid_ == null) {
|
| + this.isValid_ = this.wouldValueBeValid(this.value_);
|
| + }
|
| + return this.isValid_;
|
| + },
|
| +
|
| + /** @param {object} Value to set as the value of the ticket item. */
|
| + updateValue: function(value) {
|
| + this.value_ = value;
|
| + this.isValid_ = null;
|
| + },
|
| +
|
| + /**
|
| + * @return {object} Default value of the ticket item if no value was set by
|
| + * the user.
|
| + * @protected
|
| + */
|
| + getDefaultValueInternal: function() {
|
| + throw Error('Abstract method not overriden');
|
| + },
|
| +
|
| + /**
|
| + * @return {object} Default value of the ticket item if the capability is
|
| + * not available.
|
| + * @protected
|
| + */
|
| + getCapabilityNotAvailableValueInternal: function() {
|
| + throw Error('Abstract method not overriden');
|
| + }
|
| + };
|
| +
|
| + // Export
|
| + return {
|
| + TicketItem: TicketItem
|
| + };
|
| +});
|
|
|