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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = { |
94 // Dispatched when the action linked is activated. | 94 // Dispatched when the action linked is activated. |
95 ACTION_LINK_ACTIVATED: 'print_preview.DestinationList.ACTION_LINK_ACTIVATED' | 95 ACTION_LINK_ACTIVATED: 'print_preview.DestinationList.ACTION_LINK_ACTIVATED' |
96 }; | 96 }; |
97 | 97 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 /** | 256 /** |
257 * Renders all destinations in the list that match the current query. | 257 * Renders all destinations in the list that match the current query. |
258 * @private | 258 * @private |
259 */ | 259 */ |
260 renderDestinations_: function() { | 260 renderDestinations_: function() { |
261 if (!this.query_) { | 261 if (!this.query_) { |
262 this.renderDestinationsList_(this.destinations_); | 262 this.renderDestinationsList_(this.destinations_); |
263 } else { | 263 } else { |
264 var filteredDests = this.destinations_.filter(function(destination) { | 264 var filteredDests = this.destinations_.filter(function(destination) { |
265 return destination.matches(this.query_); | 265 return destination.matches(assert(this.query_)); |
266 }, this); | 266 }, this); |
267 this.renderDestinationsList_(filteredDests); | 267 this.renderDestinationsList_(filteredDests); |
268 } | 268 } |
269 }, | 269 }, |
270 | 270 |
271 /** | 271 /** |
272 * Renders all destinations in the given list. | 272 * Renders all destinations in the given list. |
273 * @param {!Array<print_preview.Destination>} destinations List of | 273 * @param {!Array<print_preview.Destination>} destinations List of |
274 * destinations to render. | 274 * destinations to render. |
275 * @private | 275 * @private |
(...skipping 25 matching lines...) Expand all Loading... |
301 this.listItems_.forEach(function(item) { | 301 this.listItems_.forEach(function(item) { |
302 var isVisible = visibleListItems.hasOwnProperty(item.destination.id); | 302 var isVisible = visibleListItems.hasOwnProperty(item.destination.id); |
303 setIsVisible(item.getElement(), isVisible); | 303 setIsVisible(item.getElement(), isVisible); |
304 if (isVisible) | 304 if (isVisible) |
305 visibleListItems[item.destination.id] = item; | 305 visibleListItems[item.destination.id] = item; |
306 }); | 306 }); |
307 // Update the existing items, add the new ones (preserve the focused one). | 307 // Update the existing items, add the new ones (preserve the focused one). |
308 var listEl = this.getChildElement('.destination-list > ul'); | 308 var listEl = this.getChildElement('.destination-list > ul'); |
309 var focusedEl = listEl.querySelector(':focus'); | 309 var focusedEl = listEl.querySelector(':focus'); |
310 for (var i = 0; i < numItems; i++) { | 310 for (var i = 0; i < numItems; i++) { |
311 var listItem = visibleListItems[destinations[i].id]; | 311 var destination = assert(destinations[i]); |
| 312 var listItem = visibleListItems[destination.id]; |
312 if (listItem) { | 313 if (listItem) { |
313 // Destination ID is the same, but it can be registered to a different | 314 // Destination ID is the same, but it can be registered to a different |
314 // user account, hence passing it to the item update. | 315 // user account, hence passing it to the item update. |
315 this.updateListItem_(listEl, listItem, focusedEl, destinations[i]); | 316 this.updateListItem_(listEl, listItem, focusedEl, destination); |
316 } else { | 317 } else { |
317 this.renderListItem_(listEl, destinations[i]); | 318 this.renderListItem_(listEl, destination); |
318 } | 319 } |
319 } | 320 } |
320 }, | 321 }, |
321 | 322 |
322 /** | 323 /** |
323 * @param {Element} listEl List element. | 324 * @param {Element} listEl List element. |
324 * @param {!print_preview.DestinationListItem} listItem List item to update. | 325 * @param {!print_preview.DestinationListItem} listItem List item to update. |
325 * @param {Element} focusedEl Currently focused element within the listEl. | 326 * @param {Element} focusedEl Currently focused element within the listEl. |
326 * @param {!print_preview.Destination} destination Destination to render. | 327 * @param {!print_preview.Destination} destination Destination to render. |
327 * @private | 328 * @private |
(...skipping 18 matching lines...) Expand all Loading... |
346 | 347 |
347 /** | 348 /** |
348 * @param {Element} listEl List element. | 349 * @param {Element} listEl List element. |
349 * @param {!print_preview.Destination} destination Destination to render. | 350 * @param {!print_preview.Destination} destination Destination to render. |
350 * @private | 351 * @private |
351 */ | 352 */ |
352 renderListItem_: function(listEl, destination) { | 353 renderListItem_: function(listEl, destination) { |
353 var listItem = new print_preview.DestinationListItem( | 354 var listItem = new print_preview.DestinationListItem( |
354 this.eventTarget_, destination, this.query_); | 355 this.eventTarget_, destination, this.query_); |
355 this.addChild(listItem); | 356 this.addChild(listItem); |
356 listItem.render(listEl); | 357 listItem.render(assert(listEl)); |
357 this.listItems_.push(listItem); | 358 this.listItems_.push(listItem); |
358 }, | 359 }, |
359 | 360 |
360 /** | 361 /** |
361 * Called when the action link is clicked. Dispatches an | 362 * Called when the action link is clicked. Dispatches an |
362 * ACTION_LINK_ACTIVATED event. | 363 * ACTION_LINK_ACTIVATED event. |
363 * @private | 364 * @private |
364 */ | 365 */ |
365 onActionLinkClick_: function() { | 366 onActionLinkClick_: function() { |
366 cr.dispatchSimpleEvent(this, | 367 cr.dispatchSimpleEvent(this, |
367 DestinationList.EventType.ACTION_LINK_ACTIVATED); | 368 DestinationList.EventType.ACTION_LINK_ACTIVATED); |
368 } | 369 } |
369 }; | 370 }; |
370 | 371 |
371 // Export | 372 // Export |
372 return { | 373 return { |
373 DestinationList: DestinationList | 374 DestinationList: DestinationList |
374 }; | 375 }; |
375 }); | 376 }); |
OLD | NEW |