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 * Component used for searching for a print destination. | 9 * Component used for searching for a print destination. |
10 * This is a modal dialog that allows the user to search and select a | 10 * This is a modal dialog that allows the user to search and select a |
11 * destination to print to. When a destination is selected, it is written to | 11 * destination to print to. When a destination is selected, it is written to |
12 * the destination store. | 12 * the destination store. |
13 * @param {!print_preview.DestinationStore} destinationStore Data store | 13 * @param {!print_preview.DestinationStore} destinationStore Data store |
14 * containing the destinations to search through. | 14 * containing the destinations to search through. |
15 * @param {!print_preview.UserInfo} userInfo Event target that contains | 15 * @param {!print_preview.UserInfo} userInfo Event target that contains |
16 * information about the logged in user. | 16 * information about the logged in user. |
| 17 * @param {!print_preview.Metrics} metrics Used to record usage statistics. |
17 * @constructor | 18 * @constructor |
18 * @extends {print_preview.Component} | 19 * @extends {print_preview.Component} |
19 */ | 20 */ |
20 function DestinationSearch(destinationStore, userInfo) { | 21 function DestinationSearch(destinationStore, userInfo, metrics) { |
21 print_preview.Component.call(this); | 22 print_preview.Component.call(this); |
22 | 23 |
23 /** | 24 /** |
24 * Data store containing the destinations to search through. | 25 * Data store containing the destinations to search through. |
25 * @type {!print_preview.DestinationStore} | 26 * @type {!print_preview.DestinationStore} |
26 * @private | 27 * @private |
27 */ | 28 */ |
28 this.destinationStore_ = destinationStore; | 29 this.destinationStore_ = destinationStore; |
29 | 30 |
30 /** | 31 /** |
31 * Event target that contains information about the logged in user. | 32 * Event target that contains information about the logged in user. |
32 * @type {!print_preview.UserInfo} | 33 * @type {!print_preview.UserInfo} |
33 * @private | 34 * @private |
34 */ | 35 */ |
35 this.userInfo_ = userInfo; | 36 this.userInfo_ = userInfo; |
36 | 37 |
37 /** | 38 /** |
| 39 * Used to record usage statistics. |
| 40 * @type {!print_preview.Metrics} |
| 41 * @private |
| 42 */ |
| 43 this.metrics_ = metrics; |
| 44 |
| 45 /** |
38 * Search box used to search through the destination lists. | 46 * Search box used to search through the destination lists. |
39 * @type {!print_preview.SearchBox} | 47 * @type {!print_preview.SearchBox} |
40 * @private | 48 * @private |
41 */ | 49 */ |
42 this.searchBox_ = new print_preview.SearchBox(); | 50 this.searchBox_ = new print_preview.SearchBox(); |
43 this.addChild(this.searchBox_); | 51 this.addChild(this.searchBox_); |
44 | 52 |
45 /** | 53 /** |
46 * Destination list containing recent destinations. | 54 * Destination list containing recent destinations. |
47 * @type {!print_preview.DestinationList} | 55 * @type {!print_preview.DestinationList} |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return !this.getElement().classList.contains( | 137 return !this.getElement().classList.contains( |
130 DestinationSearch.Classes_.TRANSPARENT); | 138 DestinationSearch.Classes_.TRANSPARENT); |
131 }, | 139 }, |
132 | 140 |
133 /** @param {boolean} isVisible Whether the component is visible. */ | 141 /** @param {boolean} isVisible Whether the component is visible. */ |
134 setIsVisible: function(isVisible) { | 142 setIsVisible: function(isVisible) { |
135 if (isVisible) { | 143 if (isVisible) { |
136 this.searchBox_.focus(); | 144 this.searchBox_.focus(); |
137 this.getElement().classList.remove( | 145 this.getElement().classList.remove( |
138 DestinationSearch.Classes_.TRANSPARENT); | 146 DestinationSearch.Classes_.TRANSPARENT); |
| 147 var promoEl = this.getElement().getElementsByClassName( |
| 148 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; |
| 149 if (getIsVisible(promoEl)) { |
| 150 this.metrics_.increment( |
| 151 print_preview.Metrics.Bucket.CLOUDPRINT_PROMO_SHOWN); |
| 152 } |
139 } else { | 153 } else { |
140 this.getElement().classList.add(DestinationSearch.Classes_.TRANSPARENT); | 154 this.getElement().classList.add(DestinationSearch.Classes_.TRANSPARENT); |
141 // Collapse all destination lists | 155 // Collapse all destination lists |
142 this.localList_.setIsShowAll(false); | 156 this.localList_.setIsShowAll(false); |
143 this.cloudList_.setIsShowAll(false); | 157 this.cloudList_.setIsShowAll(false); |
144 this.searchBox_.setQuery(''); | 158 this.searchBox_.setQuery(''); |
145 this.filterLists_(null); | 159 this.filterLists_(null); |
146 } | 160 } |
147 }, | 161 }, |
148 | 162 |
(...skipping 11 matching lines...) Expand all Loading... |
160 var promoEl = this.getElement().getElementsByClassName( | 174 var promoEl = this.getElement().getElementsByClassName( |
161 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; | 175 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; |
162 setIsVisible(promoEl, false); | 176 setIsVisible(promoEl, false); |
163 }, | 177 }, |
164 | 178 |
165 /** Shows the Google Cloud Print promotion banner. */ | 179 /** Shows the Google Cloud Print promotion banner. */ |
166 showCloudPrintPromo: function() { | 180 showCloudPrintPromo: function() { |
167 var promoEl = this.getElement().getElementsByClassName( | 181 var promoEl = this.getElement().getElementsByClassName( |
168 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; | 182 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; |
169 setIsVisible(promoEl, true); | 183 setIsVisible(promoEl, true); |
| 184 if (this.getIsVisible()) { |
| 185 this.metrics_.increment( |
| 186 print_preview.Metrics.Bucket.CLOUDPRINT_PROMO_SHOWN); |
| 187 } |
170 }, | 188 }, |
171 | 189 |
172 /** @override */ | 190 /** @override */ |
173 enterDocument: function() { | 191 enterDocument: function() { |
174 print_preview.Component.prototype.enterDocument.call(this); | 192 print_preview.Component.prototype.enterDocument.call(this); |
175 var closeButtonEl = this.getElement().getElementsByClassName( | 193 var closeButtonEl = this.getElement().getElementsByClassName( |
176 DestinationSearch.Classes_.CLOSE_BUTTON)[0]; | 194 DestinationSearch.Classes_.CLOSE_BUTTON)[0]; |
177 var signInButton = this.getElement().getElementsByClassName( | 195 var signInButton = this.getElement().getElementsByClassName( |
178 DestinationSearch.Classes_.SIGN_IN)[0]; | 196 DestinationSearch.Classes_.SIGN_IN)[0]; |
179 var cloudprintPromoCloseButton = this.getElement().getElementsByClassName( | 197 var cloudprintPromoCloseButton = this.getElement().getElementsByClassName( |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 this.filterLists_(evt.query); | 312 this.filterLists_(evt.query); |
295 }, | 313 }, |
296 | 314 |
297 /** | 315 /** |
298 * Called when the close button is clicked. Hides the search widget. | 316 * Called when the close button is clicked. Hides the search widget. |
299 * @private | 317 * @private |
300 */ | 318 */ |
301 onCloseClick_: function() { | 319 onCloseClick_: function() { |
302 this.setIsVisible(false); | 320 this.setIsVisible(false); |
303 this.resetSearch_(); | 321 this.resetSearch_(); |
| 322 this.metrics_.increment( |
| 323 print_preview.Metrics.Bucket.DESTINATION_SELECTION_CANCELED); |
304 }, | 324 }, |
305 | 325 |
306 /** | 326 /** |
307 * Called when a destination is selected. Clears the search and hides the | 327 * Called when a destination is selected. Clears the search and hides the |
308 * widget. | 328 * widget. |
309 * @param {cr.Event} evt Contains the selected destination. | 329 * @param {cr.Event} evt Contains the selected destination. |
310 * @private | 330 * @private |
311 */ | 331 */ |
312 onDestinationSelect_: function(evt) { | 332 onDestinationSelect_: function(evt) { |
313 this.setIsVisible(false); | 333 this.setIsVisible(false); |
314 this.resetSearch_(); | 334 this.resetSearch_(); |
315 this.destinationStore_.selectDestination(evt.destination); | 335 this.destinationStore_.selectDestination(evt.destination); |
| 336 this.metrics_.increment( |
| 337 print_preview.Metrics.Bucket.DESTINATION_SELECTED); |
316 }, | 338 }, |
317 | 339 |
318 /** | 340 /** |
319 * Called when destinations are added to the destination store. Refreshes UI | 341 * Called when destinations are added to the destination store. Refreshes UI |
320 * with new destinations. | 342 * with new destinations. |
321 * @private | 343 * @private |
322 */ | 344 */ |
323 onDestinationsInserted_: function() { | 345 onDestinationsInserted_: function() { |
324 var recentDestinations = []; | 346 var recentDestinations = []; |
325 var localDestinations = []; | 347 var localDestinations = []; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 print_preview.DestinationSearch.EventType.MANAGE_LOCAL_DESTINATIONS); | 397 print_preview.DestinationSearch.EventType.MANAGE_LOCAL_DESTINATIONS); |
376 }, | 398 }, |
377 | 399 |
378 /** | 400 /** |
379 * Called when the "Sign in" link on the Google Cloud Print promo is | 401 * Called when the "Sign in" link on the Google Cloud Print promo is |
380 * activated. | 402 * activated. |
381 * @private | 403 * @private |
382 */ | 404 */ |
383 onSignInActivated_: function() { | 405 onSignInActivated_: function() { |
384 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.SIGN_IN); | 406 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.SIGN_IN); |
| 407 this.metrics_.increment(print_preview.Metrics.Bucket.SIGNIN_TRIGGERED); |
385 }, | 408 }, |
386 | 409 |
387 /** | 410 /** |
388 * Called when the close button on the cloud print promo is clicked. Hides | 411 * Called when the close button on the cloud print promo is clicked. Hides |
389 * the promo. | 412 * the promo. |
390 * @private | 413 * @private |
391 */ | 414 */ |
392 onCloudprintPromoCloseButtonClick_: function() { | 415 onCloudprintPromoCloseButtonClick_: function() { |
393 var promoEl = this.getElement().getElementsByClassName( | 416 var promoEl = this.getElement().getElementsByClassName( |
394 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; | 417 DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; |
(...skipping 29 matching lines...) Expand all Loading... |
424 this.setCloudPrintEmail(userEmail); | 447 this.setCloudPrintEmail(userEmail); |
425 } | 448 } |
426 } | 449 } |
427 }; | 450 }; |
428 | 451 |
429 // Export | 452 // Export |
430 return { | 453 return { |
431 DestinationSearch: DestinationSearch | 454 DestinationSearch: DestinationSearch |
432 }; | 455 }; |
433 }); | 456 }); |
OLD | NEW |