Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve conflicts Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1dffd201449cc44e9110c6a2b1a6aa395f7e1627
--- /dev/null
+++ b/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
@@ -0,0 +1,95 @@
+// 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;
+ };
+
+ 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 overridden');
+ },
+
+ /**
+ * @return {boolean} Whether the print destination capability is available.
+ */
+ isCapabilityAvailable: function() {
+ throw Error('Abstract method not overridden');
+ },
+
+ /** @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;
+ }
+ return this.wouldValueBeValid(this.value_);
+ },
+
+ /** @param {object} Value to set as the value of the ticket item. */
+ updateValue: function(value) {
+ this.value_ = value;
+ },
+
+ /**
+ * @return {object} Default value of the ticket item if no value was set by
+ * the user.
+ * @protected
+ */
+ getDefaultValueInternal: function() {
+ throw Error('Abstract method not overridden');
+ },
+
+ /**
+ * @return {object} Default value of the ticket item if the capability is
+ * not available.
+ * @protected
+ */
+ getCapabilityNotAvailableValueInternal: function() {
+ throw Error('Abstract method not overridden');
+ }
+ };
+
+ // Export
+ return {
+ TicketItem: TicketItem
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698