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

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

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(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.
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.
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.CapabilityList}
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-sponsored destination IDs.
80 * @enum {string}
81 * @private
82 */
83 Destination.GoogleSponsoredIds_ = {
84 DOCS: '__google__docs',
85 LOCAL_PDF: PRINT_TO_PDF
86 };
87
88 Destination.prototype = {
89 get id() {
90 return this.id_;
91 },
92
93 get displayName() {
94 return this.displayName_;
95 },
96
97 get isRecent() {
98 return this.isRecent_;
99 },
100
101 set isRecent(isRecent) {
102 this.isRecent_ = isRecent;
103 },
104
105 get isLocal() {
106 return this.isLocal_;
107 },
108
109 get isGoogleSponsored() {
110 for (var key in Destination.GoogleSponsoredIds_) {
111 if (Destination.GoogleSponsoredIds_[key] == this.id_) {
112 return true;
113 }
114 }
115 return false;
116 },
117
118 get isPrintToPdf() {
119 return this.id_ == Destination.GoogleSponsoredIds_.LOCAL_PDF;
120 },
121
122 get location() {
123 if (this.location_ == null) {
124 for (var tag, i = 0; tag = this.tags_[i]; i++) {
125 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) {
126 this.location_ = tag.substring(
127 Destination.LOCATION_TAG_PREFIX.length);
128 }
129 }
130 if (this.location_ == null) {
131 this.location_ = '';
132 }
133 }
134 return this.location_;
135 },
136
137 get tags() {
138 return this.tags_.slice(0);
139 },
140
141 get capabilities() {
142 return this.capabilities_;
143 },
144
145 set capabilities(capabilities) {
146 this.capabilities_ = capabilities;
147 },
148
149 /**
150 * Matches a query against the destination.
151 * @param {string} query Query to match against the destination.
152 * @return {boolean} {@code true} if the query matches this destination,
153 * {@code false} otherwise.
154 */
155 matches: function(query) {
156 return this.displayName_.toLowerCase().indexOf(
157 query.toLowerCase().trim()) != -1;
158 }
159 };
160
161 // Export
162 return {
163 Destination: Destination
164 };
165 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698