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

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

Issue 606213002: Compile print_preview, part 6: reduce down to 48 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@J_print_preview_5
Patch Set: Created 6 years, 2 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 unified diff | Download patch
OLDNEW
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 /**
6 * @typedef {Object|number|boolean|string}
7 */
8 print_preview.ValueType;
9
10 cr.define('print_preview.ticket_items', function() { 5 cr.define('print_preview.ticket_items', function() {
11 'use strict'; 6 'use strict';
12 7
13 /** 8 /**
14 * 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
15 * 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
16 * 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
17 * if other ticket item constraints are not met. 12 * if other ticket item constraints are not met.
18 * @param {?print_preview.AppState} appState Application state model to update 13 * @param {?print_preview.AppState} appState Application state model to update
19 * when ticket items update. 14 * when ticket items update.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 */ 79 */
85 TicketItem.EventType = { 80 TicketItem.EventType = {
86 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE' 81 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE'
87 }; 82 };
88 83
89 TicketItem.prototype = { 84 TicketItem.prototype = {
90 __proto__: cr.EventTarget.prototype, 85 __proto__: cr.EventTarget.prototype,
91 86
92 /** 87 /**
93 * Determines whether a given value is valid for the ticket item. 88 * Determines whether a given value is valid for the ticket item.
94 * @param {print_preview.ValueType} value The value to check for validity. 89 * @param {?} value The value to check for validity.
95 * @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.
96 */ 91 */
97 wouldValueBeValid: function(value) { 92 wouldValueBeValid: function(value) {
98 throw Error('Abstract method not overridden'); 93 throw Error('Abstract method not overridden');
99 }, 94 },
100 95
101 /** 96 /**
102 * @return {boolean} Whether the print destination capability is available. 97 * @return {boolean} Whether the print destination capability is available.
103 */ 98 */
104 isCapabilityAvailable: function() { 99 isCapabilityAvailable: function() {
105 throw Error('Abstract method not overridden'); 100 throw Error('Abstract method not overridden');
106 }, 101 },
107 102
108 /** @return {print_preview.ValueType} The value of the ticket item. */ 103 /** @return {?} The value of the ticket item. */
109 getValue: function() { 104 getValue: function() {
110 if (this.isCapabilityAvailable()) { 105 if (this.isCapabilityAvailable()) {
111 if (this.value_ == null) { 106 if (this.value_ == null) {
112 return this.getDefaultValueInternal(); 107 return this.getDefaultValueInternal();
113 } else { 108 } else {
114 return this.value_; 109 return this.value_;
115 } 110 }
116 } else { 111 } else {
117 return this.getCapabilityNotAvailableValueInternal(); 112 return this.getCapabilityNotAvailableValueInternal();
118 } 113 }
119 }, 114 },
120 115
121 /** @return {boolean} Whether the ticket item was modified by the user. */ 116 /** @return {boolean} Whether the ticket item was modified by the user. */
122 isUserEdited: function() { 117 isUserEdited: function() {
123 return this.value_ != null; 118 return this.value_ != null;
124 }, 119 },
125 120
126 /** @return {boolean} Whether the ticket item's value is valid. */ 121 /** @return {boolean} Whether the ticket item's value is valid. */
127 isValid: function() { 122 isValid: function() {
128 if (!this.isUserEdited()) { 123 if (!this.isUserEdited()) {
129 return true; 124 return true;
130 } 125 }
131 return this.wouldValueBeValid(this.value_); 126 return this.wouldValueBeValid(this.value_);
132 }, 127 },
133 128
134 /** 129 /**
135 * @param {print_preview.ValueType} value Value to compare to the value of 130 * @param {?} value Value to compare to the value of
136 * this ticket item. 131 * this ticket item.
137 * @return {boolean} Whether the given value is equal to the value of the 132 * @return {boolean} Whether the given value is equal to the value of the
138 * ticket item. 133 * ticket item.
139 */ 134 */
140 isValueEqual: function(value) { 135 isValueEqual: function(value) {
141 return this.getValue() == value; 136 return this.getValue() == value;
142 }, 137 },
143 138
144 /** 139 /**
145 * @param {print_preview.ValueType} value Value to set as the value of the 140 * @param {?} value Value to set as the value of the
146 * ticket item. 141 * ticket item.
147 */ 142 */
148 updateValue: function(value) { 143 updateValue: function(value) {
149 // Use comparison with capabilities for event. 144 // Use comparison with capabilities for event.
150 var sendUpdateEvent = !this.isValueEqual(value); 145 var sendUpdateEvent = !this.isValueEqual(value);
151 // Don't lose requested value if capability is not available. 146 // Don't lose requested value if capability is not available.
152 this.updateValueInternal(value); 147 this.updateValueInternal(value);
153 if (this.appState_) { 148 if (this.appState_) {
154 this.appState_.persistField(this.field_, value); 149 this.appState_.persistField(assert(this.field_), value);
155 } 150 }
156 if (sendUpdateEvent) 151 if (sendUpdateEvent)
157 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE); 152 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE);
158 }, 153 },
159 154
160 /** 155 /**
161 * @return {?} Default value of the ticket item if no value was set by 156 * @return {?} Default value of the ticket item if no value was set by
162 * the user. 157 * the user.
163 * @protected 158 * @protected
164 */ 159 */
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 this.dispatchChangeEventInternal.bind(this)); 234 this.dispatchChangeEventInternal.bind(this));
240 } 235 }
241 }, 236 },
242 }; 237 };
243 238
244 // Export 239 // Export
245 return { 240 return {
246 TicketItem: TicketItem 241 TicketItem: TicketItem
247 }; 242 };
248 }); 243 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698