OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 cr.define('print_preview', function() { | |
6 'use strict'; | |
7 | |
8 /** | |
9 * Destination data object. | |
10 * | |
11 * This data object holds data for both local and cloud destinations. | |
12 * | |
13 * @param {string} id ID of the destination. | |
14 * @param {string} displayName Display name of the destination. | |
15 * @param {boolean} isRecent Whether the destination has been used recently. | |
16 * @param {boolean} isLocal Whether the destination is local or cloud-based. | |
17 * @param {Array.<string>} tags Tags associated with the destination. | |
dpapad1
2012/04/19 22:45:01
If this is optional (seems like it is judging from
Robert Toscano
2012/04/23 23:00:09
Done.
| |
18 * @constructor | |
19 */ | |
20 function Destination(id, displayName, isRecent, isLocal, tags) { | |
21 /** | |
22 * ID of the destination. | |
23 * @type {string} | |
24 * @private | |
25 */ | |
26 this.id_ = id; | |
27 | |
28 /** | |
29 * Display name of the destination. | |
30 * @type {string} | |
31 * @private | |
32 */ | |
33 this.displayName_ = displayName; | |
34 | |
35 /** | |
36 * Whether the destination has been used recently. | |
37 * @type {boolean} | |
38 * @private | |
39 */ | |
40 this.isRecent_ = isRecent; | |
41 | |
42 /** | |
43 * Whether the destination is local or cloud-based. | |
dpapad1
2012/04/19 22:45:01
Nit (optional): "{@code true} if destination is l
Robert Toscano
2012/04/23 23:00:09
I'll leave as is. FWIW, "Whether ...." is a bit mo
| |
44 * @type {boolean} | |
45 * @private | |
46 */ | |
47 this.isLocal_ = isLocal; | |
48 | |
49 /** | |
50 * Tags associated with the destination. | |
51 * @type {Array.<string>} | |
52 * @private | |
53 */ | |
54 this.tags_ = tags || []; | |
55 | |
56 /** | |
57 * Print capabilities of the destination. | |
58 * @type {print_preview.ChromiumCapabilities} | |
59 * @private | |
60 */ | |
61 this.capabilities_ = null; | |
62 | |
63 /** | |
64 * Cache of destination location fetched from tags. | |
65 * @type {string} | |
66 * @private | |
67 */ | |
68 this.location_ = null; | |
69 }; | |
70 | |
71 /** | |
72 * Prefix of the location destination tag. | |
73 * @type {string} | |
74 * @const | |
75 */ | |
76 Destination.LOCATION_TAG_PREFIX = '__cp__printer-location='; | |
77 | |
78 /** | |
79 * Enumeration of Google-promoted destination IDs. | |
80 * @enum {string} | |
81 * @private | |
82 */ | |
83 Destination.GooglePromotedIds_ = { | |
84 DOCS: '__google__docs', | |
85 LOCAL_PDF: PRINT_TO_PDF, | |
86 PRINT_WITH_CLOUD_PRINT: 'printWithCloudPrint' | |
87 }; | |
88 | |
89 Destination.prototype = { | |
90 get id() { | |
91 return this.id_; | |
92 }, | |
93 | |
94 get displayName() { | |
95 return this.displayName_; | |
96 }, | |
97 | |
98 get isRecent() { | |
99 return this.isRecent_; | |
100 }, | |
101 | |
102 set isRecent(isRecent) { | |
103 this.isRecent_ = isRecent; | |
104 }, | |
105 | |
106 get isLocal() { | |
107 return this.isLocal_; | |
108 }, | |
109 | |
110 get isGooglePromoted() { | |
dpapad1
2012/04/19 22:45:01
I believe is better to use the "get foo() {...}" s
Robert Toscano
2012/04/23 23:00:09
I agree with you on this point, but I'm also worri
| |
111 for (var key in Destination.GooglePromotedIds_) { | |
112 if (Destination.GooglePromotedIds_[key] == this.id_) { | |
113 return true; | |
114 } | |
115 } | |
116 return false; | |
117 }, | |
118 | |
119 get isPrintToPdf() { | |
120 return this.id_ == Destination.GooglePromotedIds_.LOCAL_PDF; | |
121 }, | |
122 | |
123 get isPrintWithCloudPrint() { | |
124 return this.id_ == Destination.GooglePromotedIds_.PRINT_WITH_CLOUD_PRINT; | |
125 }, | |
126 | |
127 get location() { | |
128 if (this.location_ == null) { | |
129 for (var tag, i = 0; tag = this.tags_[i]; i++) { | |
130 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) { | |
131 this.location_ = tag.substring( | |
132 Destination.LOCATION_TAG_PREFIX.length); | |
133 } | |
134 } | |
135 if (this.location_ == null) { | |
136 this.location_ = ''; | |
137 } | |
138 } | |
139 return this.location_; | |
140 }, | |
141 | |
142 get tags() { | |
143 return this.tags_.slice(0); | |
144 }, | |
145 | |
146 get capabilities() { | |
147 return this.capabilities_; | |
148 }, | |
149 | |
150 set capabilities(capabilities) { | |
151 this.capabilities_ = capabilities; | |
152 }, | |
153 | |
154 /** | |
155 * Matches a query against the destination. | |
156 * @param {string} query Query to match against the destination. | |
157 * @return {boolean} {@code true} if the query matches this destination, | |
158 * {@code false} otherwise. | |
159 */ | |
160 matches: function(query) { | |
161 return this.displayName_.toLowerCase().indexOf( | |
162 query.toLowerCase().trim()) != -1; | |
163 } | |
164 }; | |
165 | |
166 // Export | |
167 return { | |
168 Destination: Destination | |
169 }; | |
170 }); | |
OLD | NEW |