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.
5 cr.define('print_preview', function() {
8 // TODO(rltoscano): This class needs a throbber while loading the destination
9 // or another solution is persist the settings of the printer so that next
13 * Component used to render the print destination.
14 * @param {!print_preview.DestinationStore} destinationStore Used to determine
15 * the selected destination.
17 * @extends {print_preview.Component}
19 function DestinationSettings(destinationStore) {
20 print_preview.Component.call(this);
23 * Used to determine the selected destination.
24 * @type {!print_preview.DestinationStore}
27 this.destinationStore_ = destinationStore;
30 * Current CSS class of the destination icon.
31 * @type {?DestinationSettings.Classes_}
34 this.iconClass_ = null;
38 * Event types dispatched by the component.
41 DestinationSettings.EventType = {
42 CHANGE_BUTTON_ACTIVATE:
43 'print_preview.DestinationSettings.CHANGE_BUTTON_ACTIVATE'
47 * CSS classes used by the component.
51 DestinationSettings.Classes_ = {
52 CHANGE_BUTTON: 'destination-settings-change-button',
53 ICON: 'destination-settings-icon',
54 ICON_CLOUD: 'destination-settings-icon-cloud',
55 ICON_CLOUD_SHARED: 'destination-settings-icon-cloud-shared',
56 ICON_GOOGLE_PROMOTED: 'destination-settings-icon-google-promoted',
57 ICON_LOCAL: 'destination-settings-icon-local',
58 ICON_MOBILE: 'destination-settings-icon-mobile',
59 ICON_MOBILE_SHARED: 'destination-settings-icon-mobile-shared',
60 LOCATION: 'destination-settings-location',
61 NAME: 'destination-settings-name'
64 DestinationSettings.prototype = {
65 __proto__: print_preview.Component.prototype,
67 /** @param {boolean} Whether the component is enabled. */
68 set isEnabled(isEnabled) {
69 var changeButton = this.getElement().getElementsByClassName(
70 DestinationSettings.Classes_.CHANGE_BUTTON)[0];
71 changeButton.disabled = !isEnabled;
75 enterDocument: function() {
76 print_preview.Component.prototype.enterDocument.call(this);
77 var changeButton = this.getElement().getElementsByClassName(
78 DestinationSettings.Classes_.CHANGE_BUTTON)[0];
80 changeButton, 'click', this.onChangeButtonClick_.bind(this));
82 this.destinationStore_,
83 print_preview.DestinationStore.EventType.DESTINATION_SELECT,
84 this.onDestinationSelect_.bind(this));
88 * Called when the "Change" button is clicked. Dispatches the
89 * CHANGE_BUTTON_ACTIVATE event.
92 onChangeButtonClick_: function() {
93 cr.dispatchSimpleEvent(
94 this, DestinationSettings.EventType.CHANGE_BUTTON_ACTIVATE);
98 * Called when the destination selection has changed. Updates UI elements.
101 onDestinationSelect_: function() {
102 var destination = this.destinationStore_.selectedDestination;
103 var nameEl = this.getElement().getElementsByClassName(
104 DestinationSettings.Classes_.NAME)[0];
105 nameEl.textContent = destination.displayName;
106 nameEl.title = destination.displayName;
108 var iconEl = this.getElement().getElementsByClassName(
109 DestinationSettings.Classes_.ICON)[0];
110 iconEl.src = destination.iconUrl;
112 var locationEl = this.getElement().getElementsByClassName(
113 DestinationSettings.Classes_.LOCATION)[0];
114 locationEl.textContent = destination.location;
115 locationEl.title = destination.location;
117 setIsVisible(this.getElement().querySelector('.throbber'), false);
119 this.getElement().querySelector('.destination-settings-box'), true);
125 DestinationSettings: DestinationSettings