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

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: Set --bary flag Created 8 years, 6 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_.isLocal) {
80 iconUrl = DestinationListItem.Icons_.LOCAL;
81 } else if (this.destination_.type ==
82 print_preview.Destination.Type.MOBILE && this.destination_.isOwned) {
83 iconUrl = DestinationListItem.Icons_.MOBILE;
84 } else if (this.destination_.type ==
85 print_preview.Destination.Type.MOBILE && !this.destination_.isOwned) {
86 iconUrl = DestinationListItem.Icons_.MOBILE_SHARED;
87 } else if (this.destination_.type ==
88 print_preview.Destination.Type.GOOGLE && this.destination_.isOwned) {
89 iconUrl = DestinationListItem.Icons_.CLOUD;
90 } else {
91 iconUrl = DestinationListItem.Icons_.CLOUD_SHARED;
92 }
93
94 var iconImg = this.getElement().getElementsByClassName(
95 print_preview.DestinationListItem.Classes_.ICON)[0];
96 iconImg.src = iconUrl;
97 var nameEl = this.getElement().getElementsByClassName(
98 DestinationListItem.Classes_.NAME)[0];
99 nameEl.textContent = this.destination_.displayName;
100 },
101
102 /** @override */
103 enterDocument: function() {
104 print_preview.Component.prototype.enterDocument.call(this);
105 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this));
106 },
107
108 /**
109 * Called when the destination item is activated. Dispatches a SELECT event
110 * on the given event target.
111 * @private
112 */
113 onActivate_: function() {
114 var selectEvt = new cr.Event(DestinationListItem.EventType.SELECT);
115 selectEvt.destination = this.destination_;
116 this.eventTarget_.dispatchEvent(selectEvt);
117 }
118 };
119
120 // Export
121 return {
122 DestinationListItem: DestinationListItem
123 };
124 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698