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

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

Issue 2862203002: Print Preview: Fix data/ errors (Closed)
Patch Set: Make tests pass Created 3 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 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 * @typedef {Object|number|boolean|string} 5 * @typedef {Object|number|boolean|string}
6 */ 6 */
7 print_preview.ValueType; 7 print_preview.ValueType;
8 8
9 cr.define('print_preview.ticket_items', function() { 9 cr.define('print_preview.ticket_items', function() {
10 'use strict'; 10 'use strict';
11 11
12 /** 12 /**
13 * An object that represents a user modifiable item in a print ticket. Each 13 * An object that represents a user modifiable item in a print ticket. Each
14 * ticket item has a value which can be set by the user. Ticket items can also 14 * ticket item has a value which can be set by the user. Ticket items can also
15 * be unavailable for modifying if the print destination doesn't support it or 15 * be unavailable for modifying if the print destination doesn't support it or
16 * if other ticket item constraints are not met. 16 * if other ticket item constraints are not met.
17 * @param {?print_preview.AppState} appState Application state model to update 17 * @param {?print_preview.AppState} appState Application state model to update
18 * when ticket items update. 18 * when ticket items update.
19 * @param {?print_preview.AppState.Field} field Field of the app state to 19 * @param {?print_preview.AppStateField} field Field of the app state to
20 * update when ticket item is updated. 20 * update when ticket item is updated.
21 * @param {?print_preview.DestinationStore} destinationStore Used listen for 21 * @param {?print_preview.DestinationStore} destinationStore Used listen for
22 * changes in the currently selected destination's capabilities. Since 22 * changes in the currently selected destination's capabilities. Since
23 * this is a common dependency of ticket items, it's handled in the base 23 * this is a common dependency of ticket items, it's handled in the base
24 * class. 24 * class.
25 * @param {?print_preview.DocumentInfo=} opt_documentInfo Used to listen for 25 * @param {?print_preview.DocumentInfo=} opt_documentInfo Used to listen for
26 * changes in the document. Since this is a common dependency of ticket 26 * changes in the document. Since this is a common dependency of ticket
27 * items, it's handled in the base class. 27 * items, it's handled in the base class.
28 * @constructor 28 * @constructor
29 * @extends {cr.EventTarget} 29 * @extends {cr.EventTarget}
30 */ 30 */
31 function TicketItem(appState, field, destinationStore, opt_documentInfo) { 31 function TicketItem(appState, field, destinationStore, opt_documentInfo) {
32 cr.EventTarget.call(this); 32 cr.EventTarget.call(this);
33 33
34 /** 34 /**
35 * Application state model to update when ticket items update. 35 * Application state model to update when ticket items update.
36 * @type {print_preview.AppState} 36 * @type {print_preview.AppState}
37 * @private 37 * @private
38 */ 38 */
39 this.appState_ = appState || null; 39 this.appState_ = appState || null;
40 40
41 /** 41 /**
42 * Field of the app state to update when ticket item is updated. 42 * Field of the app state to update when ticket item is updated.
43 * @type {?print_preview.AppState.Field} 43 * @type {?print_preview.AppStateField}
44 * @private 44 * @private
45 */ 45 */
46 this.field_ = field || null; 46 this.field_ = field || null;
47 47
48 /** 48 /**
49 * Used listen for changes in the currently selected destination's 49 * Used listen for changes in the currently selected destination's
50 * capabilities. 50 * capabilities.
51 * @type {print_preview.DestinationStore} 51 * @type {print_preview.DestinationStore}
52 * @private 52 * @private
53 */ 53 */
(...skipping 14 matching lines...) Expand all
68 this.value_ = null; 68 this.value_ = null;
69 69
70 /** 70 /**
71 * Keeps track of event listeners for the ticket item. 71 * Keeps track of event listeners for the ticket item.
72 * @type {!EventTracker} 72 * @type {!EventTracker}
73 * @private 73 * @private
74 */ 74 */
75 this.tracker_ = new EventTracker(); 75 this.tracker_ = new EventTracker();
76 76
77 this.addEventHandlers_(); 77 this.addEventHandlers_();
78 }; 78 }
79 79
80 /** 80 /**
81 * Event types dispatched by this class. 81 * Event types dispatched by this class.
82 * @enum {string} 82 * @enum {string}
83 */ 83 */
84 TicketItem.EventType = { 84 TicketItem.EventType = {
85 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE' 85 CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE'
86 }; 86 };
87 87
88 TicketItem.prototype = { 88 TicketItem.prototype = {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }, 140 },
141 141
142 /** 142 /**
143 * @param {?} value Value to set as the value of the ticket item. 143 * @param {?} value Value to set as the value of the ticket item.
144 */ 144 */
145 updateValue: function(value) { 145 updateValue: function(value) {
146 // Use comparison with capabilities for event. 146 // Use comparison with capabilities for event.
147 var sendUpdateEvent = !this.isValueEqual(value); 147 var sendUpdateEvent = !this.isValueEqual(value);
148 // Don't lose requested value if capability is not available. 148 // Don't lose requested value if capability is not available.
149 this.updateValueInternal(value); 149 this.updateValueInternal(value);
150 if (this.appState_) { 150 if (this.appState_ && this.field_) {
dpapad 2017/05/05 17:32:53 Is this 100% equivalent? What if |this.field_| was
rbpotter 2017/05/05 18:25:46 Done.
151 this.appState_.persistField(this.field_, value); 151 this.appState_.persistField(this.field_, value);
152 } 152 }
153 if (sendUpdateEvent) 153 if (sendUpdateEvent)
154 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE); 154 cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE);
155 }, 155 },
156 156
157 /** 157 /**
158 * @return {?} Default value of the ticket item if no value was set by 158 * @return {?} Default value of the ticket item if no value was set by
159 * the user. 159 * the user.
160 * @protected 160 * @protected
dpapad 2017/05/05 17:32:52 Maybe add @abstract here and below (not necessaril
rbpotter 2017/05/05 18:25:46 Done.
161 */ 161 */
162 getDefaultValueInternal: function() { 162 getDefaultValueInternal: function() {
163 throw Error('Abstract method not overridden'); 163 throw Error('Abstract method not overridden');
164 }, 164 },
165 165
166 /** 166 /**
167 * @return {?} Default value of the ticket item if the capability is 167 * @return {?} Default value of the ticket item if the capability is
168 * not available. 168 * not available.
169 * @protected 169 * @protected
170 */ 170 */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 this.dispatchChangeEventInternal.bind(this)); 236 this.dispatchChangeEventInternal.bind(this));
237 } 237 }
238 }, 238 },
239 }; 239 };
240 240
241 // Export 241 // Export
242 return { 242 return {
243 TicketItem: TicketItem 243 TicketItem: TicketItem
244 }; 244 };
245 }); 245 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698