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

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

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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 *
11 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection
12 * events to.
13 * @param {!print_preview.Destination} destination Destination data object to
14 * render.
15 * @constructor
16 * @extends {print_preview.Component}
17 */
18 function DestinationListItem(eventTarget, destination) {
19 print_preview.Component.call(this);
20
21 /**
22 * Event target to dispatch selection events to.
23 * @type {!cr.EventTarget}
24 * @private
25 */
26 this.eventTarget_ = eventTarget;
27
28 /**
29 * Destination that the widget renders.
30 * @type {!print_preview.Destination}
31 * @private
32 */
33 this.destination_ = destination;
34 };
35
36 /**
37 * Events dispatched by the destination list item.
38 * @enum {string}
39 */
40 DestinationListItem.Event = {
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 ICON_CLOUD: 'destination-list-item-icon-cloud',
52 ICON_GOOGLE_SPONSORED: 'destination-list-item-icon-google-sponsored',
53 ICON_LOCAL: 'destination-list-item-icon-local',
54 NAME: 'destination-list-item-name'
55 };
56
57 DestinationListItem.prototype = {
58 __proto__: print_preview.Component.prototype,
59
60 /** @override */
61 createDom: function() {
62 this.setElementInternal(this.cloneTemplateInternal(
63 'destination-list-item-template'));
64 var iconEl = this.getElement().getElementsByClassName(
65 DestinationListItem.Classes_.ICON)[0];
66 if (this.destination_.isLocal) {
67 iconEl.classList.add(DestinationListItem.Classes_.ICON_LOCAL);
68 } else if (this.destination_.isGoogleSponsored) {
69 iconEl.classList.add(
70 DestinationListItem.Classes_.ICON_GOOGLE_SPONSORED);
71 } else {
72 iconEl.classList.add(DestinationListItem.Classes_.ICON_CLOUD);
73 }
74 var nameEl = this.getElement().getElementsByClassName(
75 DestinationListItem.Classes_.NAME)[0];
76 nameEl.textContent = this.destination_.displayName;
77 },
78
79 /** @override */
80 enterDocument: function() {
81 print_preview.Component.prototype.enterDocument.call(this);
82 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this));
83 },
84
85 /**
86 * Called when the destination item is activated. Dispatches a SELECT event
87 * on the given event target.
88 * @private
89 */
90 onActivate_: function() {
91 var selectEvt = new cr.Event(DestinationListItem.Event.SELECT);
92 selectEvt.destination = this.destination_;
93 this.eventTarget_.dispatchEvent(selectEvt);
94 }
95 };
96
97 // Export
98 return {
99 DestinationListItem: DestinationListItem
100 };
101 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698