OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 * Creates a PrintHeader object. This object encapsulates all the elements | 9 * Creates a PrintHeader object. This object encapsulates all the elements |
10 * and logic related to the top part of the left pane in print_preview.html. | 10 * and logic related to the top part of the left pane in print_preview.html. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 125 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
126 this.onTicketChange_.bind(this)); | 126 this.onTicketChange_.bind(this)); |
127 }, | 127 }, |
128 | 128 |
129 /** | 129 /** |
130 * Updates Print Button state. | 130 * Updates Print Button state. |
131 * @private | 131 * @private |
132 */ | 132 */ |
133 updatePrintButtonEnabledState_: function() { | 133 updatePrintButtonEnabledState_: function() { |
134 this.getChildElement('button.print').disabled = | 134 this.getChildElement('button.print').disabled = |
| 135 this.destinationStore_.selectedDestination == null || |
135 !this.isEnabled_ || | 136 !this.isEnabled_ || |
136 !this.isPrintButtonEnabled_ || | 137 !this.isPrintButtonEnabled_ || |
137 !this.printTicketStore_.isTicketValid(); | 138 !this.printTicketStore_.isTicketValid(); |
138 }, | 139 }, |
139 | 140 |
140 /** | 141 /** |
141 * Updates the summary element based on the currently selected user options. | 142 * Updates the summary element based on the currently selected user options. |
142 * @private | 143 * @private |
143 */ | 144 */ |
144 updateSummary_: function() { | 145 updateSummary_: function() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 onCancelButtonClick_: function() { | 216 onCancelButtonClick_: function() { |
216 cr.dispatchSimpleEvent(this, PrintHeader.EventType.CANCEL_BUTTON_CLICK); | 217 cr.dispatchSimpleEvent(this, PrintHeader.EventType.CANCEL_BUTTON_CLICK); |
217 }, | 218 }, |
218 | 219 |
219 /** | 220 /** |
220 * Called when a new destination is selected. Updates the text on the print | 221 * Called when a new destination is selected. Updates the text on the print |
221 * button. | 222 * button. |
222 * @private | 223 * @private |
223 */ | 224 */ |
224 onDestinationSelect_: function() { | 225 onDestinationSelect_: function() { |
225 var isSaveLabel = this.destinationStore_.selectedDestination.id == | 226 var isSaveLabel = this.destinationStore_.selectedDestination && |
226 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || | 227 (this.destinationStore_.selectedDestination.id == |
227 this.destinationStore_.selectedDestination.id == | 228 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || |
228 print_preview.Destination.GooglePromotedId.DOCS; | 229 this.destinationStore_.selectedDestination.id == |
229 this.getChildElement('button.print').textContent = isSaveLabel ? | 230 print_preview.Destination.GooglePromotedId.DOCS); |
230 localStrings.getString('saveButton') : | 231 this.getChildElement('button.print').textContent = |
231 localStrings.getString('printButton'); | 232 localStrings.getString(isSaveLabel ? 'saveButton' : 'printButton'); |
232 this.getChildElement('button.print').focus(); | 233 if (this.destinationStore_.selectedDestination) { |
| 234 this.getChildElement('button.print').focus(); |
| 235 } |
233 }, | 236 }, |
234 | 237 |
235 /** | 238 /** |
236 * Called when the print ticket has changed. Disables the print button if | 239 * Called when the print ticket has changed. Disables the print button if |
237 * any of the settings are invalid. | 240 * any of the settings are invalid. |
238 * @private | 241 * @private |
239 */ | 242 */ |
240 onTicketChange_: function() { | 243 onTicketChange_: function() { |
241 this.updatePrintButtonEnabledState_(); | 244 this.updatePrintButtonEnabledState_(); |
242 this.updateSummary_(); | 245 this.updateSummary_(); |
243 if (document.activeElement == null || | 246 if (document.activeElement == null || |
244 document.activeElement == document.body) { | 247 document.activeElement == document.body) { |
245 this.getChildElement('button.print').focus(); | 248 this.getChildElement('button.print').focus(); |
246 } | 249 } |
247 } | 250 } |
248 }; | 251 }; |
249 | 252 |
250 // Export | 253 // Export |
251 return { | 254 return { |
252 PrintHeader: PrintHeader | 255 PrintHeader: PrintHeader |
253 }; | 256 }; |
254 }); | 257 }); |
OLD | NEW |