1 // Copyright 2014 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() {
9 * Modal dialog for print destination's advanced settings.
10 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the
11 * print ticket to print.
13 * @extends {print_preview.Overlay}
15 function AdvancedSettings(printTicketStore) {
16 print_preview.Overlay.call(this);
19 * Contains the print ticket to print.
20 * @private {!print_preview.PrintTicketStore}
22 this.printTicketStore_ = printTicketStore;
25 * Used to record usage statistics.
26 * @private {!print_preview.PrintSettingsUiMetricsContext}
28 this.metrics_ = new print_preview.PrintSettingsUiMetricsContext();
30 /** @private {!print_preview.SearchBox} */
31 this.searchBox_ = new print_preview.SearchBox(
32 localStrings.getString('advancedSettingsSearchBoxPlaceholder'));
33 this.addChild(this.searchBox_);
35 /** @private {print_preview.Destination} */
36 this.destination_ = null;
38 /** @private {!Array.<!print_preview.AdvancedSettingsItem>} */
42 AdvancedSettings.prototype = {
43 __proto__: print_preview.Overlay.prototype,
46 * @param {!print_preview.Destination} destination Destination to show
47 * advanced settings for.
49 showForDestination: function(destination) {
50 assert(!this.destination_);
51 this.destination_ = destination;
52 this.getChildElement('.advanced-settings-title').textContent =
53 localStrings.getStringF('advancedSettingsDialogTitle',
54 this.destination_.displayName);
55 this.setIsVisible(true);
56 this.renderSettings_();
60 enterDocument: function() {
61 print_preview.Overlay.prototype.enterDocument.call(this);
64 this.getChildElement('#cancel-button'),
66 this.cancel.bind(this));
70 print_preview.SearchBox.EventType.SEARCH,
71 this.onSearch_.bind(this));
75 decorateInternal: function() {
76 this.searchBox_.render(this.getChildElement('.search-box-area'));
80 onSetVisibleInternal: function(isVisible) {
82 this.searchBox_.focus();
83 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket.
84 ADVANCED_SETTINGS_DIALOG_SHOWN);
86 this.searchBox_.setQuery(null);
87 this.filterLists_(null);
88 this.destination_ = null;
93 onCancelInternal: function() {
94 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket.
95 ADVANCED_SETTINGS_DIALOG_CANCELED);
99 * @return {number} Height available for settings, in pixels.
102 getAvailableContentHeight_: function() {
103 var elStyle = window.getComputedStyle(this.getElement());
104 return this.getElement().offsetHeight -
105 parseInt(elStyle.getPropertyValue('padding-top')) -
106 parseInt(elStyle.getPropertyValue('padding-bottom')) -
107 this.getChildElement('.settings-area').offsetTop -
108 this.getChildElement('.action-area').offsetHeight;
112 * Filters displayed settings with the given query.
113 * @param {?string} query Query to filter settings by.
116 filterLists_: function(query) {
120 * Resets the filter query.
123 resetSearch_: function() {
124 this.searchBox_.setQuery(null);
125 this.filterLists_(null);
129 * Renders all of the available settings.
132 renderSettings_: function() {
133 // Remove all children settings elements.
134 this.items_.forEach(function(item) {
135 this.removeChild(item);
139 var vendorCapabilities =
141 this.destination_.capabilities &&
142 this.destination_.capabilities.printer &&
143 this.destination_.capabilities.printer.vendor_capability;
144 if (!vendorCapabilities)
147 var availableHeight = this.getAvailableContentHeight_();
148 var containerEl = this.getChildElement('.settings-area');
149 containerEl.style.maxHeight = availableHeight + 'px';
151 vendorCapabilities.forEach(function(capability) {
152 var item = new print_preview.AdvancedSettingsItem(
153 this.eventTarget_, this.printTicketStore_, capability);
155 item.render(this.getChildElement('.settings'));
156 this.items_.push(item);
161 * Called when settings search query changes. Filters displayed settings
162 * with the given query.
163 * @param {Event} evt Contains search query.
166 onSearch_: function(evt) {
167 this.filterLists_(evt.query);
173 AdvancedSettings: AdvancedSettings