Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('print_preview', function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 /** | |
| 9 * Component that renders a destination item in a destination list. | |
| 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection | |
| 11 * events to. | |
| 12 * @param {!print_preview.Destination} destination Destination data object to | |
| 13 * render. | |
| 14 * @constructor | |
| 15 * @extends {print_preview.Component} | |
| 16 */ | |
| 17 function DestinationListItem(eventTarget, destination) { | |
| 18 print_preview.Component.call(this); | |
| 19 | |
| 20 /** | |
| 21 * Event target to dispatch selection events to. | |
| 22 * @type {!cr.EventTarget} | |
| 23 * @private | |
| 24 */ | |
| 25 this.eventTarget_ = eventTarget; | |
| 26 | |
| 27 /** | |
| 28 * Destination that the list item renders. | |
| 29 * @type {!print_preview.Destination} | |
| 30 * @private | |
| 31 */ | |
| 32 this.destination_ = destination; | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 36 * Event types dispatched by the destination list item. | |
| 37 * @enum {string} | |
| 38 */ | |
| 39 DestinationListItem.EventType = { | |
| 40 // Dispatched when the list item is activated. | |
| 41 SELECT: 'print_preview.DestinationListItem.SELECT' | |
| 42 }; | |
| 43 | |
| 44 /** | |
| 45 * CSS classes used by the destination list item. | |
| 46 * @enum {string} | |
| 47 * @private | |
| 48 */ | |
| 49 DestinationListItem.Classes_ = { | |
| 50 ICON: 'destination-list-item-icon', | |
| 51 NAME: 'destination-list-item-name' | |
| 52 }; | |
| 53 | |
| 54 /** | |
| 55 * URLs of the various destination list item icons. | |
| 56 * @enum {string} | |
| 57 * @private | |
| 58 */ | |
| 59 DestinationListItem.Icons_ = { | |
| 60 CLOUD: 'images/cloud_printer_32.png', | |
| 61 CLOUD_SHARED: 'images/cloud_printer_shared_32.png', | |
| 62 LOCAL: 'images/classic_printer_32.png', | |
| 63 MOBILE: 'images/mobile_32.png', | |
| 64 MOBILE_SHARED: 'images/mobile_shared_32.png', | |
| 65 GOOGLE_PROMOTED: 'images/google_promoted_printer_32.png' | |
| 66 }, | |
| 67 | |
| 68 DestinationListItem.prototype = { | |
| 69 __proto__: print_preview.Component.prototype, | |
| 70 | |
| 71 /** @override */ | |
| 72 createDom: function() { | |
| 73 this.setElementInternal(this.cloneTemplateInternal( | |
| 74 'destination-list-item-template')); | |
| 75 | |
| 76 var iconUrl; | |
| 77 if (this.destination_.isGooglePromoted) { | |
| 78 iconUrl = DestinationListItem.Icons_.GOOGLE_PROMOTED; | |
| 79 } else if (this.destination_.type == | |
|
dpapad
2012/05/29 16:41:02
I think that there are helpers now, this.destinati
Robert Toscano
2012/05/29 18:00:43
I had isLocal from before, but now that I've intro
dpapad
2012/05/29 18:15:08
I am fine with that. But I do feel that the "type"
| |
| 80 print_preview.Destination.Type.LOCAL) { | |
| 81 iconUrl = DestinationListItem.Icons_.LOCAL; | |
| 82 } else if (this.destination_.type == | |
| 83 print_preview.Destination.Type.MOBILE && this.destination_.isOwned) { | |
| 84 iconUrl = DestinationListItem.Icons_.MOBILE; | |
| 85 } else if (this.destination_.type == | |
| 86 print_preview.Destination.Type.MOBILE && !this.destination_.isOwned) { | |
| 87 iconUrl = DestinationListItem.Icons_.MOBILE_SHARED; | |
| 88 } else if (this.destination_.type == | |
| 89 print_preview.Destination.Type.GOOGLE && this.destination_.isOwned) { | |
| 90 iconUrl = DestinationListItem.Icons_.CLOUD; | |
| 91 } else { | |
| 92 iconUrl = DestinationListItem.Icons_.CLOUD_SHARED; | |
| 93 } | |
| 94 | |
| 95 var iconImg = this.getElement().getElementsByClassName( | |
| 96 print_preview.DestinationListItem.Classes_.ICON)[0]; | |
| 97 iconImg.src = iconUrl; | |
| 98 var nameEl = this.getElement().getElementsByClassName( | |
| 99 DestinationListItem.Classes_.NAME)[0]; | |
| 100 nameEl.textContent = this.destination_.displayName; | |
| 101 }, | |
| 102 | |
| 103 /** @override */ | |
| 104 enterDocument: function() { | |
| 105 print_preview.Component.prototype.enterDocument.call(this); | |
| 106 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this)); | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * Called when the destination item is activated. Dispatches a SELECT event | |
| 111 * on the given event target. | |
| 112 * @private | |
| 113 */ | |
| 114 onActivate_: function() { | |
| 115 var selectEvt = new cr.Event(DestinationListItem.EventType.SELECT); | |
| 116 selectEvt.destination = this.destination_; | |
| 117 this.eventTarget_.dispatchEvent(selectEvt); | |
| 118 } | |
| 119 }; | |
| 120 | |
| 121 // Export | |
| 122 return { | |
| 123 DestinationListItem: DestinationListItem | |
| 124 }; | |
| 125 }); | |
| OLD | NEW |