| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 * Gets estimated height of the destination list for the given number of | 138 * Gets estimated height of the destination list for the given number of |
| 139 * items. | 139 * items. |
| 140 * @param {number} numItems Number of items to render in the destination | 140 * @param {number} numItems Number of items to render in the destination |
| 141 * list. | 141 * list. |
| 142 * @return {number} Height (in pixels) of the destination list. | 142 * @return {number} Height (in pixels) of the destination list. |
| 143 */ | 143 */ |
| 144 getEstimatedHeightInPixels: function(numItems) { | 144 getEstimatedHeightInPixels: function(numItems) { |
| 145 numItems = Math.min(numItems, this.destinations_.length); | 145 numItems = Math.min(numItems, this.destinations_.length); |
| 146 var headerHeight = | 146 var headerHeight = |
| 147 this.getChildElement('.destination-list > header').offsetHeight; | 147 this.getChildElement('.destination-list > header').offsetHeight; |
| 148 return headerHeight + (numItems > 0 ? | 148 return headerHeight + |
| 149 numItems * DestinationList.HEIGHT_OF_ITEM_ : | 149 (numItems > 0 ? numItems * DestinationList.HEIGHT_OF_ITEM_ : |
| 150 // To account for "No destinations found" message. | 150 // To account for "No destinations found" message. |
| 151 DestinationList.HEIGHT_OF_ITEM_); | 151 DestinationList.HEIGHT_OF_ITEM_); |
| 152 }, | 152 }, |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @return {Element} The element that contains this one. Used for height | 155 * @return {Element} The element that contains this one. Used for height |
| 156 * calculations. | 156 * calculations. |
| 157 */ | 157 */ |
| 158 getContainerElement: function() { | 158 getContainerElement: function() { |
| 159 return this.getElement().parentNode; | 159 return this.getElement().parentNode; |
| 160 }, | 160 }, |
| 161 | 161 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 // If this is the case, we will only show the "Show All" button and | 174 // If this is the case, we will only show the "Show All" button and |
| 175 // nothing else. Increment the short list size by one so that we can see | 175 // nothing else. Increment the short list size by one so that we can see |
| 176 // at least one print destination. | 176 // at least one print destination. |
| 177 size++; | 177 size++; |
| 178 } | 178 } |
| 179 this.setShortListSizeInternal(size); | 179 this.setShortListSizeInternal(size); |
| 180 }, | 180 }, |
| 181 | 181 |
| 182 /** @override */ | 182 /** @override */ |
| 183 createDom: function() { | 183 createDom: function() { |
| 184 this.setElementInternal(this.cloneTemplateInternal( | 184 this.setElementInternal( |
| 185 'destination-list-template')); | 185 this.cloneTemplateInternal('destination-list-template')); |
| 186 this.getChildElement('.title').textContent = this.title_; | 186 this.getChildElement('.title').textContent = this.title_; |
| 187 if (this.actionLinkLabel_) { | 187 if (this.actionLinkLabel_) { |
| 188 var actionLinkEl = this.getChildElement('.action-link'); | 188 var actionLinkEl = this.getChildElement('.action-link'); |
| 189 actionLinkEl.textContent = this.actionLinkLabel_; | 189 actionLinkEl.textContent = this.actionLinkLabel_; |
| 190 setIsVisible(actionLinkEl, true); | 190 setIsVisible(actionLinkEl, true); |
| 191 } | 191 } |
| 192 }, | 192 }, |
| 193 | 193 |
| 194 /** @override */ | 194 /** @override */ |
| 195 enterDocument: function() { | 195 enterDocument: function() { |
| 196 print_preview.Component.prototype.enterDocument.call(this); | 196 print_preview.Component.prototype.enterDocument.call(this); |
| 197 this.tracker.add( | 197 this.tracker.add( |
| 198 this.getChildElement('.action-link'), | 198 this.getChildElement('.action-link'), 'click', |
| 199 'click', | |
| 200 this.onActionLinkClick_.bind(this)); | 199 this.onActionLinkClick_.bind(this)); |
| 201 this.tracker.add( | 200 this.tracker.add( |
| 202 this.getChildElement('.show-all-button'), | 201 this.getChildElement('.show-all-button'), 'click', |
| 203 'click', | |
| 204 this.setIsShowAll.bind(this, true)); | 202 this.setIsShowAll.bind(this, true)); |
| 205 }, | 203 }, |
| 206 | 204 |
| 207 /** | 205 /** |
| 208 * Updates the destinations to render in the destination list. | 206 * Updates the destinations to render in the destination list. |
| 209 * @param {!Array<print_preview.Destination>} destinations Destinations to | 207 * @param {!Array<print_preview.Destination>} destinations Destinations to |
| 210 * render. | 208 * render. |
| 211 */ | 209 */ |
| 212 updateDestinations: function(destinations) { | 210 updateDestinations: function(destinations) { |
| 213 this.destinations_ = destinations; | 211 this.destinations_ = destinations; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 }, | 256 }, |
| 259 | 257 |
| 260 /** | 258 /** |
| 261 * Renders all destinations in the given list. | 259 * Renders all destinations in the given list. |
| 262 * @param {!Array<print_preview.Destination>} destinations List of | 260 * @param {!Array<print_preview.Destination>} destinations List of |
| 263 * destinations to render. | 261 * destinations to render. |
| 264 * @private | 262 * @private |
| 265 */ | 263 */ |
| 266 renderDestinationsList_: function(destinations) { | 264 renderDestinationsList_: function(destinations) { |
| 267 // Update item counters, footers and other misc controls. | 265 // Update item counters, footers and other misc controls. |
| 268 setIsVisible(this.getChildElement('.no-destinations-message'), | 266 setIsVisible( |
| 269 destinations.length == 0); | 267 this.getChildElement('.no-destinations-message'), |
| 268 destinations.length == 0); |
| 270 setIsVisible(this.getChildElement('.destination-list > footer'), false); | 269 setIsVisible(this.getChildElement('.destination-list > footer'), false); |
| 271 var numItems = destinations.length; | 270 var numItems = destinations.length; |
| 272 if (destinations.length > this.shortListSize_ && !this.isShowAll_) { | 271 if (destinations.length > this.shortListSize_ && !this.isShowAll_) { |
| 273 numItems = this.shortListSize_ - 1; | 272 numItems = this.shortListSize_ - 1; |
| 274 this.getChildElement('.total').textContent = | 273 this.getChildElement('.total').textContent = |
| 275 loadTimeData.getStringF('destinationCount', destinations.length); | 274 loadTimeData.getStringF('destinationCount', destinations.length); |
| 276 setIsVisible(this.getChildElement('.destination-list > footer'), true); | 275 setIsVisible(this.getChildElement('.destination-list > footer'), true); |
| 277 } | 276 } |
| 278 // Remove obsolete list items (those with no corresponding destinations). | 277 // Remove obsolete list items (those with no corresponding destinations). |
| 279 this.listItems_ = this.listItems_.filter(function(item) { | 278 this.listItems_ = this.listItems_.filter(function(item) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 listItem.render(listEl); | 344 listItem.render(listEl); |
| 346 this.listItems_.push(listItem); | 345 this.listItems_.push(listItem); |
| 347 }, | 346 }, |
| 348 | 347 |
| 349 /** | 348 /** |
| 350 * Called when the action link is clicked. Dispatches an | 349 * Called when the action link is clicked. Dispatches an |
| 351 * ACTION_LINK_ACTIVATED event. | 350 * ACTION_LINK_ACTIVATED event. |
| 352 * @private | 351 * @private |
| 353 */ | 352 */ |
| 354 onActionLinkClick_: function() { | 353 onActionLinkClick_: function() { |
| 355 cr.dispatchSimpleEvent(this, | 354 cr.dispatchSimpleEvent( |
| 356 DestinationList.EventType.ACTION_LINK_ACTIVATED); | 355 this, DestinationList.EventType.ACTION_LINK_ACTIVATED); |
| 357 } | 356 } |
| 358 }; | 357 }; |
| 359 | 358 |
| 360 // Export | 359 // Export |
| 361 return { | 360 return {DestinationList: DestinationList}; |
| 362 DestinationList: DestinationList | |
| 363 }; | |
| 364 }); | 361 }); |
| OLD | NEW |