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.
5 cr.define('print_preview', function() {
9 * Print destination data object that holds data for both local and cloud
11 * @param {string} id ID of the destination.
12 * @param {!print_preview.Destination.Type} type Type of the destination.
13 * @param {!print_preview.Destination.Origin} origin Origin of the
15 * @param {string} displayName Display name of the destination.
16 * @param {boolean} isRecent Whether the destination has been used recently.
17 * @param {!print_preview.Destination.ConnectionStatus} connectionStatus
18 * Connection status of the print destination.
19 * @param {{tags: Array.<string>,
21 * lastAccessTime: ?number,
22 * isTosAccepted: ?boolean}=} opt_params Optional parameters for the
26 function Destination(id, type, origin, displayName, isRecent,
27 connectionStatus, opt_params) {
29 * ID of the destination.
36 * Type of the destination.
37 * @type {!print_preview.Destination.Type}
43 * Origin of the destination.
44 * @type {!print_preview.Destination.Origin}
47 this.origin_ = origin;
50 * Display name of the destination.
54 this.displayName_ = displayName;
57 * Whether the destination has been used recently.
61 this.isRecent_ = isRecent;
64 * Tags associated with the destination.
65 * @type {!Array.<string>}
68 this.tags_ = (opt_params && opt_params.tags) || [];
71 * Print capabilities of the destination.
72 * @type {print_preview.Cdd}
75 this.capabilities_ = null;
78 * Whether the destination is owned by the user.
82 this.isOwned_ = (opt_params && opt_params.isOwned) || false;
85 * Cache of destination location fetched from tags.
89 this.location_ = null;
92 * Connection status of the destination.
93 * @type {!print_preview.Destination.ConnectionStatus}
96 this.connectionStatus_ = connectionStatus;
99 * Number of milliseconds since the epoch when the printer was last
104 this.lastAccessTime_ = (opt_params && opt_params.lastAccessTime) ||
108 * Whether the user has accepted the terms-of-service for the print
109 * destination. Only applies to the FedEx Office cloud-based printer.
110 * {@code} null if terms-of-service does not apply to the print destination.
114 this.isTosAccepted_ = (opt_params && opt_params.isTosAccepted) || false;
118 * Prefix of the location destination tag.
122 Destination.LOCATION_TAG_PREFIX = '__cp__printer-location=';
125 * Enumeration of Google-promoted destination IDs.
128 Destination.GooglePromotedId = {
129 DOCS: '__google__docs',
130 FEDEX: '__google__fedex',
131 SAVE_AS_PDF: 'Save as PDF'
135 * Enumeration of the types of destinations.
145 * Enumeration of the origin types for cloud destinations.
148 Destination.Origin = {
156 * Enumeration of the connection statuses of printer destinations.
159 Destination.ConnectionStatus = {
167 * Enumeration of relative icon URLs for various types of destinations.
171 Destination.IconUrl_ = {
172 CLOUD: 'images/printer.png',
173 CLOUD_SHARED: 'images/printer_shared.png',
174 LOCAL: 'images/printer.png',
175 MOBILE: 'images/mobile.png',
176 MOBILE_SHARED: 'images/mobile_shared.png',
177 THIRD_PARTY: 'images/third_party.png',
178 PDF: 'images/pdf.png',
179 DOCS: 'images/google_doc.png',
180 FEDEX: 'images/third_party_fedex.png'
183 Destination.prototype = {
184 /** @return {string} ID of the destination. */
189 /** @return {!print_preview.Destination.Type} Type of the destination. */
195 * @return {!print_preview.Destination.Origin} Origin of the destination.
201 /** @return {string} Display name of the destination. */
203 return this.displayName_;
206 /** @return {boolean} Whether the destination has been used recently. */
208 return this.isRecent_;
212 * @param {boolean} isRecent Whether the destination has been used recently.
214 set isRecent(isRecent) {
215 this.isRecent_ = isRecent;
219 * @return {boolean} Whether the user owns the destination. Only applies to
220 * cloud-based destinations.
223 return this.isOwned_;
226 /** @return {boolean} Whether the destination is local or cloud-based. */
228 return this.origin_ == Destination.Origin.LOCAL;
232 * @return {string} The location of the destination, or an empty string if
233 * the location is unknown.
236 if (this.location_ == null) {
237 for (var tag, i = 0; tag = this.tags_[i]; i++) {
238 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) {
239 this.location_ = tag.substring(
240 Destination.LOCATION_TAG_PREFIX.length) || '';
245 return this.location_;
248 /** @return {!Array.<string>} Tags associated with the destination. */
250 return this.tags_.slice(0);
253 /** @return {print_preview.Cdd} Print capabilities of the destination. */
255 return this.capabilities_;
259 * @param {!print_preview.Cdd} capabilities Print capabilities of the
262 set capabilities(capabilities) {
263 this.capabilities_ = capabilities;
267 * @return {!print_preview.Destination.ConnectionStatus} Connection status
268 * of the print destination.
270 get connectionStatus() {
271 return this.connectionStatus_;
275 * @param {!print_preview.Destination.ConnectionStatus} status Connection
276 * status of the print destination.
278 set connectionStatus(status) {
279 this.connectionStatus_ = status;
283 * @return {number} Number of milliseconds since the epoch when the printer
286 get lastAccessTime() {
287 return this.lastAccessTime_;
290 /** @return {string} Relative URL of the destination's icon. */
292 if (this.id_ == Destination.GooglePromotedId.DOCS) {
293 return Destination.IconUrl_.DOCS;
294 } else if (this.id_ == Destination.GooglePromotedId.FEDEX) {
295 return Destination.IconUrl_.FEDEX;
296 } else if (this.id_ == Destination.GooglePromotedId.SAVE_AS_PDF) {
297 return Destination.IconUrl_.PDF;
298 } else if (this.isLocal) {
299 return Destination.IconUrl_.LOCAL;
300 } else if (this.type_ == Destination.Type.MOBILE && this.isOwned_) {
301 return Destination.IconUrl_.MOBILE;
302 } else if (this.type_ == Destination.Type.MOBILE) {
303 return Destination.IconUrl_.MOBILE_SHARED;
304 } else if (this.isOwned_) {
305 return Destination.IconUrl_.CLOUD;
307 return Destination.IconUrl_.CLOUD_SHARED;
312 * @return {?boolean} Whether the user has accepted the terms-of-service of
313 * the print destination or {@code null} if a terms-of-service does not
316 get isTosAccepted() {
317 return this.isTosAccepted_;
321 * @param {?boolean} Whether the user has accepted the terms-of-service of
322 * the print destination or {@code null} if a terms-of-service does not
325 set isTosAccepted(isTosAccepted) {
326 this.isTosAccepted_ = isTosAccepted;
330 * Matches a query against the destination.
331 * @param {string} query Query to match against the destination.
332 * @return {boolean} {@code true} if the query matches this destination,
333 * {@code false} otherwise.
335 matches: function(query) {
336 return this.displayName_.toLowerCase().indexOf(
337 query.toLowerCase().trim()) != -1;
342 * The CDD (Cloud Device Description) describes the capabilities of a print
348 * vendor_capability: !Array.<{Object}>,
349 * collate: {default: boolean=}=,
353 * vendor_id: string=,
354 * custom_display_name: string=,
355 * is_default: boolean=
358 * copies: {default: number=, max: number=}=,
359 * duplex: {option: !Array.<{type: string=, is_default: boolean=}>}=,
360 * page_orientation: {
361 * option: !Array.<{type: string=, is_default: boolean=}>
370 Destination: Destination,