| 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 that displays a list of destinations with a heading, action link, | 9 * Component that displays a list of destinations with a heading, action link, |
| 10 * and "Show All..." button. An event is dispatched when the action link is | 10 * and "Show All..." button. An event is dispatched when the action link is |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Label of the action link. | 40 * Label of the action link. |
| 41 * @type {?string} | 41 * @type {?string} |
| 42 * @private | 42 * @private |
| 43 */ | 43 */ |
| 44 this.actionLinkLabel_ = actionLinkLabel; | 44 this.actionLinkLabel_ = actionLinkLabel; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Backing store for the destination list. | 47 * Backing store for the destination list. |
| 48 * @type {!Array.<print_preview.Destination>} | 48 * @type {!Array<print_preview.Destination>} |
| 49 * @private | 49 * @private |
| 50 */ | 50 */ |
| 51 this.destinations_ = []; | 51 this.destinations_ = []; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Set of destination ids. | 54 * Set of destination ids. |
| 55 * @type {!Object.<string, boolean>} | 55 * @type {!Object<string, boolean>} |
| 56 * @private | 56 * @private |
| 57 */ | 57 */ |
| 58 this.destinationIds_ = {}; | 58 this.destinationIds_ = {}; |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Current query used for filtering. | 61 * Current query used for filtering. |
| 62 * @type {RegExp} | 62 * @type {RegExp} |
| 63 * @private | 63 * @private |
| 64 */ | 64 */ |
| 65 this.query_ = null; | 65 this.query_ = null; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Whether the destination list is fully expanded. | 68 * Whether the destination list is fully expanded. |
| 69 * @type {boolean} | 69 * @type {boolean} |
| 70 * @private | 70 * @private |
| 71 */ | 71 */ |
| 72 this.isShowAll_ = opt_showAll || false; | 72 this.isShowAll_ = opt_showAll || false; |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Maximum number of destinations before showing the "Show All..." button. | 75 * Maximum number of destinations before showing the "Show All..." button. |
| 76 * @type {number} | 76 * @type {number} |
| 77 * @private | 77 * @private |
| 78 */ | 78 */ |
| 79 this.shortListSize_ = DestinationList.DEFAULT_SHORT_LIST_SIZE_; | 79 this.shortListSize_ = DestinationList.DEFAULT_SHORT_LIST_SIZE_; |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * List items representing destinations. | 82 * List items representing destinations. |
| 83 * @type {!Array.<!print_preview.DestinationListItem>} | 83 * @type {!Array<!print_preview.DestinationListItem>} |
| 84 * @private | 84 * @private |
| 85 */ | 85 */ |
| 86 this.listItems_ = []; | 86 this.listItems_ = []; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Enumeration of event types dispatched by the destination list. | 90 * Enumeration of event types dispatched by the destination list. |
| 91 * @enum {string} | 91 * @enum {string} |
| 92 */ | 92 */ |
| 93 DestinationList.EventType = { | 93 DestinationList.EventType = { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 'click', | 191 'click', |
| 192 this.onActionLinkClick_.bind(this)); | 192 this.onActionLinkClick_.bind(this)); |
| 193 this.tracker.add( | 193 this.tracker.add( |
| 194 this.getChildElement('.show-all-button'), | 194 this.getChildElement('.show-all-button'), |
| 195 'click', | 195 'click', |
| 196 this.setIsShowAll.bind(this, true)); | 196 this.setIsShowAll.bind(this, true)); |
| 197 }, | 197 }, |
| 198 | 198 |
| 199 /** | 199 /** |
| 200 * Updates the destinations to render in the destination list. | 200 * Updates the destinations to render in the destination list. |
| 201 * @param {!Array.<print_preview.Destination>} destinations Destinations to | 201 * @param {!Array<print_preview.Destination>} destinations Destinations to |
| 202 * render. | 202 * render. |
| 203 */ | 203 */ |
| 204 updateDestinations: function(destinations) { | 204 updateDestinations: function(destinations) { |
| 205 this.destinations_ = destinations; | 205 this.destinations_ = destinations; |
| 206 this.destinationIds_ = destinations.reduce(function(ids, destination) { | 206 this.destinationIds_ = destinations.reduce(function(ids, destination) { |
| 207 ids[destination.id] = true; | 207 ids[destination.id] = true; |
| 208 return ids; | 208 return ids; |
| 209 }, {}); | 209 }, {}); |
| 210 this.renderDestinations_(); | 210 this.renderDestinations_(); |
| 211 }, | 211 }, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } else { | 244 } else { |
| 245 var filteredDests = this.destinations_.filter(function(destination) { | 245 var filteredDests = this.destinations_.filter(function(destination) { |
| 246 return destination.matches(this.query_); | 246 return destination.matches(this.query_); |
| 247 }, this); | 247 }, this); |
| 248 this.renderDestinationsList_(filteredDests); | 248 this.renderDestinationsList_(filteredDests); |
| 249 } | 249 } |
| 250 }, | 250 }, |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * Renders all destinations in the given list. | 253 * Renders all destinations in the given list. |
| 254 * @param {!Array.<print_preview.Destination>} destinations List of | 254 * @param {!Array<print_preview.Destination>} destinations List of |
| 255 * destinations to render. | 255 * destinations to render. |
| 256 * @private | 256 * @private |
| 257 */ | 257 */ |
| 258 renderDestinationsList_: function(destinations) { | 258 renderDestinationsList_: function(destinations) { |
| 259 // Update item counters, footers and other misc controls. | 259 // Update item counters, footers and other misc controls. |
| 260 setIsVisible(this.getChildElement('.no-destinations-message'), | 260 setIsVisible(this.getChildElement('.no-destinations-message'), |
| 261 destinations.length == 0); | 261 destinations.length == 0); |
| 262 setIsVisible(this.getChildElement('.destination-list > footer'), false); | 262 setIsVisible(this.getChildElement('.destination-list > footer'), false); |
| 263 var numItems = destinations.length; | 263 var numItems = destinations.length; |
| 264 if (destinations.length > this.shortListSize_ && !this.isShowAll_) { | 264 if (destinations.length > this.shortListSize_ && !this.isShowAll_) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 cr.dispatchSimpleEvent(this, | 347 cr.dispatchSimpleEvent(this, |
| 348 DestinationList.EventType.ACTION_LINK_ACTIVATED); | 348 DestinationList.EventType.ACTION_LINK_ACTIVATED); |
| 349 } | 349 } |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 // Export | 352 // Export |
| 353 return { | 353 return { |
| 354 DestinationList: DestinationList | 354 DestinationList: DestinationList |
| 355 }; | 355 }; |
| 356 }); | 356 }); |
| OLD | NEW |