| OLD | NEW |
| 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Print destination data object that holds data for both local and cloud | 9 * Print destination data object that holds data for both local and cloud |
| 10 * destinations. | 10 * destinations. |
| 11 * @param {string} id ID of the destination. | 11 * @param {string} id ID of the destination. |
| 12 * @param {!print_preview.Destination.Type} type Type of the destination. |
| 12 * @param {string} displayName Display name of the destination. | 13 * @param {string} displayName Display name of the destination. |
| 13 * @param {boolean} isRecent Whether the destination has been used recently. | 14 * @param {boolean} isRecent Whether the destination has been used recently. |
| 14 * @param {boolean} isLocal Whether the destination is local or cloud-based. | |
| 15 * @param {Array.<string>=} opt_tags Tags associated with the destination. | 15 * @param {Array.<string>=} opt_tags Tags associated with the destination. |
| 16 * @param {boolean=} opt_isOwned Whether the destination is owned by the user. |
| 17 * Only applies to cloud-based destinations. |
| 16 * @constructor | 18 * @constructor |
| 17 */ | 19 */ |
| 18 function Destination(id, displayName, isRecent, isLocal, opt_tags) { | 20 function Destination(id, type, displayName, isRecent, opt_tags, opt_isOwned) { |
| 19 /** | 21 /** |
| 20 * ID of the destination. | 22 * ID of the destination. |
| 21 * @type {string} | 23 * @type {string} |
| 22 * @private | 24 * @private |
| 23 */ | 25 */ |
| 24 this.id_ = id; | 26 this.id_ = id; |
| 25 | 27 |
| 26 /** | 28 /** |
| 29 * Type of the destination. |
| 30 * @type {!print_preview.Destination.Type} |
| 31 * @private |
| 32 */ |
| 33 this.type_ = type; |
| 34 |
| 35 /** |
| 27 * Display name of the destination. | 36 * Display name of the destination. |
| 28 * @type {string} | 37 * @type {string} |
| 29 * @private | 38 * @private |
| 30 */ | 39 */ |
| 31 this.displayName_ = displayName; | 40 this.displayName_ = displayName; |
| 32 | 41 |
| 33 /** | 42 /** |
| 34 * Whether the destination has been used recently. | 43 * Whether the destination has been used recently. |
| 35 * @type {boolean} | 44 * @type {boolean} |
| 36 * @private | 45 * @private |
| 37 */ | 46 */ |
| 38 this.isRecent_ = isRecent; | 47 this.isRecent_ = isRecent; |
| 39 | 48 |
| 40 /** | 49 /** |
| 41 * Whether the destination is local or cloud-based. | |
| 42 * @type {boolean} | |
| 43 * @private | |
| 44 */ | |
| 45 this.isLocal_ = isLocal; | |
| 46 | |
| 47 /** | |
| 48 * Tags associated with the destination. | 50 * Tags associated with the destination. |
| 49 * @type {!Array.<string>} | 51 * @type {!Array.<string>} |
| 50 * @private | 52 * @private |
| 51 */ | 53 */ |
| 52 this.tags_ = opt_tags || []; | 54 this.tags_ = opt_tags || []; |
| 53 | 55 |
| 54 /** | 56 /** |
| 55 * Print capabilities of the destination. | 57 * Print capabilities of the destination. |
| 56 * @type {print_preview.ChromiumCapabilities} | 58 * @type {print_preview.ChromiumCapabilities} |
| 57 * @private | 59 * @private |
| 58 */ | 60 */ |
| 59 this.capabilities_ = null; | 61 this.capabilities_ = null; |
| 60 | 62 |
| 61 /** | 63 /** |
| 64 * Whether the destination is owned by the user. |
| 65 * @type {boolean} |
| 66 * @private |
| 67 */ |
| 68 this.isOwned_ = opt_isOwned || false; |
| 69 |
| 70 /** |
| 62 * Cache of destination location fetched from tags. | 71 * Cache of destination location fetched from tags. |
| 63 * @type {string} | 72 * @type {?string} |
| 64 * @private | 73 * @private |
| 65 */ | 74 */ |
| 66 this.location_ = null; | 75 this.location_ = null; |
| 67 }; | 76 }; |
| 68 | 77 |
| 69 /** | 78 /** |
| 70 * Prefix of the location destination tag. | 79 * Prefix of the location destination tag. |
| 71 * @type {string} | 80 * @type {string} |
| 72 * @const | 81 * @const |
| 73 */ | 82 */ |
| 74 Destination.LOCATION_TAG_PREFIX = '__cp__printer-location='; | 83 Destination.LOCATION_TAG_PREFIX = '__cp__printer-location='; |
| 75 | 84 |
| 76 /** | 85 /** |
| 77 * Enumeration of Google-promoted destination IDs. | 86 * Enumeration of Google-promoted destination IDs. |
| 78 * @enum {string} | 87 * @enum {string} |
| 79 */ | 88 */ |
| 80 Destination.GooglePromotedId = { | 89 Destination.GooglePromotedId = { |
| 81 DOCS: '__google__docs', | 90 DOCS: '__google__docs', |
| 82 SAVE_AS_PDF: 'Save as PDF', | 91 FEDEX: '__google__fedex', |
| 83 PRINT_WITH_CLOUD_PRINT: 'printWithCloudPrint' | 92 SAVE_AS_PDF: 'Save as PDF' |
| 93 }; |
| 94 |
| 95 /** |
| 96 * Enumeration of the types of destinations. |
| 97 * @enum {string} |
| 98 */ |
| 99 Destination.Type = { |
| 100 GOOGLE: 'google', |
| 101 LOCAL: 'local', |
| 102 MOBILE: 'mobile' |
| 84 }; | 103 }; |
| 85 | 104 |
| 86 Destination.prototype = { | 105 Destination.prototype = { |
| 87 /** @return {string} ID of the destination. */ | 106 /** @return {string} ID of the destination. */ |
| 88 get id() { | 107 get id() { |
| 89 return this.id_; | 108 return this.id_; |
| 90 }, | 109 }, |
| 91 | 110 |
| 111 /** @return {!print_preview.Destination.Type} Type of the destination. */ |
| 112 get type() { |
| 113 return this.type_; |
| 114 }, |
| 115 |
| 92 /** @return {string} Display name of the destination. */ | 116 /** @return {string} Display name of the destination. */ |
| 93 get displayName() { | 117 get displayName() { |
| 94 return this.displayName_; | 118 return this.displayName_; |
| 95 }, | 119 }, |
| 96 | 120 |
| 97 /** @return {boolean} Whether the destination has been used recently. */ | 121 /** @return {boolean} Whether the destination has been used recently. */ |
| 98 get isRecent() { | 122 get isRecent() { |
| 99 return this.isRecent_; | 123 return this.isRecent_; |
| 100 }, | 124 }, |
| 101 | 125 |
| 102 /** | 126 /** |
| 103 * @param {boolean} isRecent Whether the destination has been used recently. | 127 * @param {boolean} isRecent Whether the destination has been used recently. |
| 104 */ | 128 */ |
| 105 set isRecent(isRecent) { | 129 set isRecent(isRecent) { |
| 106 this.isRecent_ = isRecent; | 130 this.isRecent_ = isRecent; |
| 107 }, | 131 }, |
| 108 | 132 |
| 133 /** |
| 134 * @return {boolean} Whether the user owns the destination. Only applies to |
| 135 * cloud-based destinations. |
| 136 */ |
| 137 get isOwned() { |
| 138 return this.isOwned_; |
| 139 }, |
| 140 |
| 109 /** @return {boolean} Whether the destination is local or cloud-based. */ | 141 /** @return {boolean} Whether the destination is local or cloud-based. */ |
| 110 get isLocal() { | 142 get isLocal() { |
| 111 return this.isLocal_; | 143 return this.type_ == Destination.Type.LOCAL; |
| 112 }, | 144 }, |
| 113 | 145 |
| 114 /** @return {boolean} Whether the destination is promoted by Google. */ | 146 /** @return {boolean} Whether the destination is promoted by Google. */ |
| 115 get isGooglePromoted() { | 147 get isGooglePromoted() { |
| 116 for (var key in Destination.GooglePromotedId) { | 148 for (var key in Destination.GooglePromotedId) { |
| 117 if (Destination.GooglePromotedId[key] == this.id_) { | 149 if (Destination.GooglePromotedId[key] == this.id_) { |
| 118 return true; | 150 return true; |
| 119 } | 151 } |
| 120 } | 152 } |
| 121 return false; | 153 return false; |
| 122 }, | 154 }, |
| 123 | 155 |
| 124 /** | 156 /** |
| 125 * @return {boolean} Whether the destination is the "Print with Cloud Print" | |
| 126 * destination. | |
| 127 */ | |
| 128 get isPrintWithCloudPrint() { | |
| 129 return this.id_ == Destination.GooglePromotedId.PRINT_WITH_CLOUD_PRINT; | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * @return {string} The location of the destination, or an empty string if | 157 * @return {string} The location of the destination, or an empty string if |
| 134 * the location is unknown. | 158 * the location is unknown. |
| 135 */ | 159 */ |
| 136 get location() { | 160 get location() { |
| 137 if (this.location_ == null) { | 161 if (this.location_ == null) { |
| 138 for (var tag, i = 0; tag = this.tags_[i]; i++) { | 162 for (var tag, i = 0; tag = this.tags_[i]; i++) { |
| 139 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) { | 163 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) { |
| 140 this.location_ = tag.substring( | 164 this.location_ = tag.substring( |
| 141 Destination.LOCATION_TAG_PREFIX.length); | 165 Destination.LOCATION_TAG_PREFIX.length) || ''; |
| 166 break; |
| 142 } | 167 } |
| 143 } | 168 } |
| 144 if (this.location_ == null) { | |
| 145 this.location_ = ''; | |
| 146 } | |
| 147 } | 169 } |
| 148 return this.location_; | 170 return this.location_; |
| 149 }, | 171 }, |
| 150 | 172 |
| 151 /** @return {!Array.<string>} Tags associated with the destination. */ | 173 /** @return {!Array.<string>} Tags associated with the destination. */ |
| 152 get tags() { | 174 get tags() { |
| 153 return this.tags_.slice(0); | 175 return this.tags_.slice(0); |
| 154 }, | 176 }, |
| 155 | 177 |
| 156 /** | 178 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 179 return this.displayName_.toLowerCase().indexOf( | 201 return this.displayName_.toLowerCase().indexOf( |
| 180 query.toLowerCase().trim()) != -1; | 202 query.toLowerCase().trim()) != -1; |
| 181 } | 203 } |
| 182 }; | 204 }; |
| 183 | 205 |
| 184 // Export | 206 // Export |
| 185 return { | 207 return { |
| 186 Destination: Destination | 208 Destination: Destination |
| 187 }; | 209 }; |
| 188 }); | 210 }); |
| OLD | NEW |