| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Modal dialog for print destination's advanced settings. | 9 * Modal dialog for print destination's advanced settings. |
| 10 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the | 10 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 /** @override */ | 59 /** @override */ |
| 60 enterDocument: function() { | 60 enterDocument: function() { |
| 61 print_preview.Overlay.prototype.enterDocument.call(this); | 61 print_preview.Overlay.prototype.enterDocument.call(this); |
| 62 | 62 |
| 63 this.tracker.add( | 63 this.tracker.add( |
| 64 this.getChildElement('#cancel-button'), | 64 this.getChildElement('#cancel-button'), |
| 65 'click', | 65 'click', |
| 66 this.cancel.bind(this)); | 66 this.cancel.bind(this)); |
| 67 | 67 |
| 68 this.tracker.add( | 68 this.tracker.add( |
| 69 this.getChildElement('#done-button'), |
| 70 'click', |
| 71 this.onApplySettings_.bind(this)); |
| 72 |
| 73 this.tracker.add( |
| 69 this.searchBox_, | 74 this.searchBox_, |
| 70 print_preview.SearchBox.EventType.SEARCH, | 75 print_preview.SearchBox.EventType.SEARCH, |
| 71 this.onSearch_.bind(this)); | 76 this.onSearch_.bind(this)); |
| 72 }, | 77 }, |
| 73 | 78 |
| 74 /** @override */ | 79 /** @override */ |
| 75 decorateInternal: function() { | 80 decorateInternal: function() { |
| 76 this.searchBox_.render(this.getChildElement('.search-box-area')); | 81 this.searchBox_.render(this.getChildElement('.search-box-area')); |
| 77 }, | 82 }, |
| 78 | 83 |
| 79 /** @override */ | 84 /** @override */ |
| 80 onSetVisibleInternal: function(isVisible) { | 85 onSetVisibleInternal: function(isVisible) { |
| 81 if (isVisible) { | 86 if (isVisible) { |
| 82 this.searchBox_.focus(); | 87 this.searchBox_.focus(); |
| 83 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. | 88 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. |
| 84 ADVANCED_SETTINGS_DIALOG_SHOWN); | 89 ADVANCED_SETTINGS_DIALOG_SHOWN); |
| 85 } else { | 90 } else { |
| 86 this.searchBox_.setQuery(null); | 91 this.searchBox_.setQuery(null); |
| 87 this.filterLists_(null); | 92 this.filterLists_(null); |
| 88 this.destination_ = null; | 93 this.destination_ = null; |
| 89 } | 94 } |
| 90 }, | 95 }, |
| 91 | 96 |
| 92 /** @override */ | 97 /** @override */ |
| 93 onCancelInternal: function() { | 98 onCancelInternal: function() { |
| 94 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. | 99 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. |
| 95 ADVANCED_SETTINGS_DIALOG_CANCELED); | 100 ADVANCED_SETTINGS_DIALOG_CANCELED); |
| 96 }, | 101 }, |
| 97 | 102 |
| 103 /** @override */ |
| 104 onEnterPressedInternal: function() { |
| 105 var doneButton = this.getChildElement('#done-button'); |
| 106 if (!doneButton.disabled) |
| 107 doneButton.click(); |
| 108 return !doneButton.disabled; |
| 109 }, |
| 110 |
| 98 /** | 111 /** |
| 99 * @return {number} Height available for settings, in pixels. | 112 * @return {number} Height available for settings, in pixels. |
| 100 * @private | 113 * @private |
| 101 */ | 114 */ |
| 102 getAvailableContentHeight_: function() { | 115 getAvailableContentHeight_: function() { |
| 103 var elStyle = window.getComputedStyle(this.getElement()); | 116 var elStyle = window.getComputedStyle(this.getElement()); |
| 104 return this.getElement().offsetHeight - | 117 return this.getElement().offsetHeight - |
| 105 parseInt(elStyle.getPropertyValue('padding-top')) - | 118 parseInt(elStyle.getPropertyValue('padding-top')) - |
| 106 parseInt(elStyle.getPropertyValue('padding-bottom')) - | 119 parseInt(elStyle.getPropertyValue('padding-bottom')) - |
| 107 this.getChildElement('.settings-area').offsetTop - | 120 this.getChildElement('.settings-area').offsetTop - |
| (...skipping 21 matching lines...) Expand all Loading... |
| 129 * Renders all of the available settings. | 142 * Renders all of the available settings. |
| 130 * @private | 143 * @private |
| 131 */ | 144 */ |
| 132 renderSettings_: function() { | 145 renderSettings_: function() { |
| 133 // Remove all children settings elements. | 146 // Remove all children settings elements. |
| 134 this.items_.forEach(function(item) { | 147 this.items_.forEach(function(item) { |
| 135 this.removeChild(item); | 148 this.removeChild(item); |
| 136 }.bind(this)); | 149 }.bind(this)); |
| 137 this.items_ = []; | 150 this.items_ = []; |
| 138 | 151 |
| 139 var vendorCapabilities = | 152 var vendorCapabilities = this.printTicketStore_.vendorItems.capability; |
| 140 this.destination_ && | |
| 141 this.destination_.capabilities && | |
| 142 this.destination_.capabilities.printer && | |
| 143 this.destination_.capabilities.printer.vendor_capability; | |
| 144 if (!vendorCapabilities) | 153 if (!vendorCapabilities) |
| 145 return; | 154 return; |
| 146 | 155 |
| 147 var availableHeight = this.getAvailableContentHeight_(); | 156 var availableHeight = this.getAvailableContentHeight_(); |
| 148 var containerEl = this.getChildElement('.settings-area'); | 157 var containerEl = this.getChildElement('.settings-area'); |
| 149 containerEl.style.maxHeight = availableHeight + 'px'; | 158 containerEl.style.maxHeight = availableHeight + 'px'; |
| 150 | 159 |
| 151 vendorCapabilities.forEach(function(capability) { | 160 vendorCapabilities.forEach(function(capability) { |
| 152 var item = new print_preview.AdvancedSettingsItem( | 161 var item = new print_preview.AdvancedSettingsItem( |
| 153 this.eventTarget_, this.printTicketStore_, capability); | 162 this.eventTarget_, this.printTicketStore_, capability); |
| 154 this.addChild(item); | 163 this.addChild(item); |
| 155 item.render(this.getChildElement('.settings')); | 164 item.render(this.getChildElement('.settings')); |
| 156 this.items_.push(item); | 165 this.items_.push(item); |
| 157 }.bind(this)); | 166 }.bind(this)); |
| 158 }, | 167 }, |
| 159 | 168 |
| 160 /** | 169 /** |
| 161 * Called when settings search query changes. Filters displayed settings | 170 * Called when settings search query changes. Filters displayed settings |
| 162 * with the given query. | 171 * with the given query. |
| 163 * @param {Event} evt Contains search query. | 172 * @param {Event} evt Contains search query. |
| 164 * @private | 173 * @private |
| 165 */ | 174 */ |
| 166 onSearch_: function(evt) { | 175 onSearch_: function(evt) { |
| 167 this.filterLists_(evt.query); | 176 this.filterLists_(evt.query); |
| 177 }, |
| 178 |
| 179 /** |
| 180 * Called when current settings selection need to be stored in the ticket. |
| 181 * @private |
| 182 */ |
| 183 onApplySettings_: function(evt) { |
| 184 this.setIsVisible(false); |
| 185 |
| 186 var values = {}; |
| 187 this.items_.forEach(function(item) { |
| 188 if (item.isModified()) |
| 189 values[item.id] = item.selectedValue; |
| 190 }.bind(this)); |
| 191 |
| 192 this.printTicketStore_.vendorItems.updateValue(values); |
| 168 } | 193 } |
| 169 }; | 194 }; |
| 170 | 195 |
| 171 // Export | 196 // Export |
| 172 return { | 197 return { |
| 173 AdvancedSettings: AdvancedSettings | 198 AdvancedSettings: AdvancedSettings |
| 174 }; | 199 }; |
| 175 }); | 200 }); |
| OLD | NEW |