Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(851)

Side by Side Diff: chrome/browser/resources/print_preview/search/destination_list_item.js

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduces size of search image. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 ==
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 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698