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

Side by Side Diff: chrome/browser/resources/print_preview/settings/destination_settings.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 // TODO This class needs a throbber while loading the destination.
9
10 /**
11 * Component used to render the print destination.
12 *
13 * The component dispatches a CHANGE event when it's "Change" button is
14 * clicked.
15 *
16 * @param {print_preview.DestinationStore!} destinationStore Used to determine
17 * the selected destination.
18 * @constructor
19 * @extends {print_preview.Component}
20 */
21 function DestinationSettings(destinationStore) {
22 print_preview.Component.call(this);
23
24 /**
25 * Used to determine the selected destination.
26 * @type {print_preview.DestinationStore!}
27 * @private
28 */
29 this.destinationStore_ = destinationStore;
30 };
31
32 /**
33 * Enumeration of events the component dispatches.
34 * @enum {string}
35 */
36 DestinationSettings.Event = {
37 CHANGE_BUTTON_ACTIVATE:
38 'print_preview.DestinationSettings.CHANGE_BUTTON_ACTIVATE'
39 };
40
41 /**
42 * CSS classes used by the component.
43 * @enum {string}
44 * @private
45 */
46 DestinationSettings.Classes_ = {
47 CHANGE_BUTTON: 'destination-settings-change-button',
48 ICON: 'destination-settings-icon',
49 ICON_CLOUD: 'destination-settings-icon-cloud',
50 ICON_LOCAL: 'destination-settings-icon-local',
51 ICON_GOOGLE_SPONSORED: 'destination-settings-icon-google-sponsored',
52 LOCATION: 'destination-settings-location',
53 NAME: 'destination-settings-name'
54 };
55
56 DestinationSettings.prototype = {
57 __proto__: print_preview.Component.prototype,
58
59 set isEnabled(isEnabled) {
60 var changeButton = this.getElement().getElementsByClassName(
61 DestinationSettings.Classes_.CHANGE_BUTTON)[0];
62 changeButton.disabled = !isEnabled;
63 },
64
65 /** @override */
66 enterDocument: function() {
67 print_preview.Component.prototype.enterDocument.call(this);
68 var changeButton = this.getElement().getElementsByClassName(
69 DestinationSettings.Classes_.CHANGE_BUTTON)[0];
70 this.tracker.add(
71 changeButton, 'click', this.onChangeButtonClick_.bind(this));
72 this.tracker.add(
73 this.destinationStore_,
74 print_preview.DestinationStore.Event.DESTINATION_SELECT,
75 this.onDestinationSelect_.bind(this));
76 },
77
78 /**
79 * Called when the "Change" button is clicked. Dispatches the
80 * CHANGE_BUTTON_ACTIVATE event.
81 * @private
82 */
83 onChangeButtonClick_: function() {
84 cr.dispatchSimpleEvent(
85 this, DestinationSettings.Event.CHANGE_BUTTON_ACTIVATE);
86 },
87
88 /**
89 * Called when the destination selection has changed. Updates UI elements.
90 * @private
91 */
92 onDestinationSelect_: function() {
93 var destination = this.destinationStore_.selectedDestination;
94 var nameEl = this.getElement().getElementsByClassName(
95 DestinationSettings.Classes_.NAME)[0];
96 nameEl.textContent = destination.displayName;
97
98 var iconEl = this.getElement().getElementsByClassName(
99 DestinationSettings.Classes_.ICON)[0];
100 iconEl.classList.remove(DestinationSettings.Classes_.ICON_LOCAL);
101 iconEl.classList.remove(DestinationSettings.Classes_.ICON_CLOUD);
102 iconEl.classList.remove(
103 DestinationSettings.Classes_.ICON_GOOGLE_SPONSORED);
104 if (destination.isGoogleSponsored) {
105 iconEl.classList.add(
106 DestinationSettings.Classes_.ICON_GOOGLE_SPONSORED);
107 } else if (destination.isLocal) {
108 iconEl.classList.add(DestinationSettings.Classes_.ICON_LOCAL);
109 } else {
110 iconEl.classList.add(DestinationSettings.Classes_.ICON_CLOUD);
111 }
112
113 var locationEl = this.getElement().getElementsByClassName(
114 DestinationSettings.Classes_.LOCATION)[0];
115 locationEl.textContent = destination.location;
116 }
117 };
118
119 return {
120 DestinationSettings: DestinationSettings
121 };
122 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698