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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 decorateInternal: function() { | 91 decorateInternal: function() { |
92 cr.ui.reverseButtonStrips(this.getElement()); | 92 cr.ui.reverseButtonStrips(this.getElement()); |
93 }, | 93 }, |
94 | 94 |
95 /** @override */ | 95 /** @override */ |
96 enterDocument: function() { | 96 enterDocument: function() { |
97 print_preview.Component.prototype.enterDocument.call(this); | 97 print_preview.Component.prototype.enterDocument.call(this); |
98 | 98 |
99 // User events | 99 // User events |
100 this.tracker.add( | 100 this.tracker.add( |
101 this.getChildElement('button.cancel'), | 101 this.getChildElement('button.cancel'), 'click', |
102 'click', | |
103 this.onCancelButtonClick_.bind(this)); | 102 this.onCancelButtonClick_.bind(this)); |
104 this.tracker.add( | 103 this.tracker.add( |
105 this.getChildElement('button.print'), | 104 this.getChildElement('button.print'), 'click', |
106 'click', | |
107 this.onPrintButtonClick_.bind(this)); | 105 this.onPrintButtonClick_.bind(this)); |
108 | 106 |
109 // Data events. | 107 // Data events. |
110 this.tracker.add( | 108 this.tracker.add( |
111 this.printTicketStore_, | 109 this.printTicketStore_, |
112 print_preview.PrintTicketStore.EventType.INITIALIZE, | 110 print_preview.PrintTicketStore.EventType.INITIALIZE, |
113 this.onTicketChange_.bind(this)); | 111 this.onTicketChange_.bind(this)); |
114 this.tracker.add( | 112 this.tracker.add( |
115 this.printTicketStore_, | 113 this.printTicketStore_, |
116 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE, | 114 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE, |
(...skipping 20 matching lines...) Expand all Loading... |
137 this.onTicketChange_.bind(this)); | 135 this.onTicketChange_.bind(this)); |
138 }, | 136 }, |
139 | 137 |
140 /** | 138 /** |
141 * Updates Print Button state. | 139 * Updates Print Button state. |
142 * @private | 140 * @private |
143 */ | 141 */ |
144 updatePrintButtonEnabledState_: function() { | 142 updatePrintButtonEnabledState_: function() { |
145 this.getChildElement('button.print').disabled = | 143 this.getChildElement('button.print').disabled = |
146 this.destinationStore_.selectedDestination == null || | 144 this.destinationStore_.selectedDestination == null || |
147 !this.isEnabled_ || | 145 !this.isEnabled_ || !this.isPrintButtonEnabled_ || |
148 !this.isPrintButtonEnabled_ || | |
149 !this.printTicketStore_.isTicketValid(); | 146 !this.printTicketStore_.isTicketValid(); |
150 }, | 147 }, |
151 | 148 |
152 /** | 149 /** |
153 * Updates the summary element based on the currently selected user options. | 150 * Updates the summary element based on the currently selected user options. |
154 * @private | 151 * @private |
155 */ | 152 */ |
156 updateSummary_: function() { | 153 updateSummary_: function() { |
157 if (!this.printTicketStore_.isTicketValid()) { | 154 if (!this.printTicketStore_.isTicketValid()) { |
158 this.getChildElement('.summary').innerHTML = ''; | 155 this.getChildElement('.summary').innerHTML = ''; |
159 return; | 156 return; |
160 } | 157 } |
161 | 158 |
162 var saveToPdfOrDrive = this.destinationStore_.selectedDestination && | 159 var saveToPdfOrDrive = this.destinationStore_.selectedDestination && |
163 (this.destinationStore_.selectedDestination.id == | 160 (this.destinationStore_.selectedDestination.id == |
164 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || | 161 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || |
165 this.destinationStore_.selectedDestination.id == | 162 this.destinationStore_.selectedDestination.id == |
166 print_preview.Destination.GooglePromotedId.DOCS); | 163 print_preview.Destination.GooglePromotedId.DOCS); |
167 | 164 |
168 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size; | 165 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size; |
169 var numSheets = numPages; | 166 var numSheets = numPages; |
170 if (!saveToPdfOrDrive && this.printTicketStore_.duplex.getValue()) { | 167 if (!saveToPdfOrDrive && this.printTicketStore_.duplex.getValue()) { |
171 numSheets = Math.ceil(numPages / 2); | 168 numSheets = Math.ceil(numPages / 2); |
172 } | 169 } |
173 | 170 |
174 var copies = this.printTicketStore_.copies.getValueAsNumber(); | 171 var copies = this.printTicketStore_.copies.getValueAsNumber(); |
175 numSheets *= copies; | 172 numSheets *= copies; |
176 numPages *= copies; | 173 numPages *= copies; |
177 | 174 |
178 var pagesLabel = loadTimeData.getString('printPreviewPageLabelPlural'); | 175 var pagesLabel = loadTimeData.getString('printPreviewPageLabelPlural'); |
179 var summaryLabel; | 176 var summaryLabel; |
180 if (numSheets > 1) { | 177 if (numSheets > 1) { |
181 summaryLabel = saveToPdfOrDrive ? pagesLabel : | 178 summaryLabel = saveToPdfOrDrive ? |
| 179 pagesLabel : |
182 loadTimeData.getString('printPreviewSheetsLabelPlural'); | 180 loadTimeData.getString('printPreviewSheetsLabelPlural'); |
183 } else { | 181 } else { |
184 summaryLabel = loadTimeData.getString( | 182 summaryLabel = loadTimeData.getString( |
185 saveToPdfOrDrive ? 'printPreviewPageLabelSingular' : | 183 saveToPdfOrDrive ? 'printPreviewPageLabelSingular' : |
186 'printPreviewSheetsLabelSingular'); | 184 'printPreviewSheetsLabelSingular'); |
187 } | 185 } |
188 | 186 |
189 var html; | 187 var html; |
190 var label; | 188 var label; |
191 if (numPages != numSheets) { | 189 if (numPages != numSheets) { |
192 html = loadTimeData.getStringF( | 190 html = loadTimeData.getStringF( |
193 'printPreviewSummaryFormatLong', | 191 'printPreviewSummaryFormatLong', |
194 '<b>' + numSheets.toLocaleString() + '</b>', | 192 '<b>' + numSheets.toLocaleString() + '</b>', |
195 '<b>' + summaryLabel + '</b>', | 193 '<b>' + summaryLabel + '</b>', numPages.toLocaleString(), |
196 numPages.toLocaleString(), | |
197 pagesLabel); | 194 pagesLabel); |
198 label = loadTimeData.getStringF('printPreviewSummaryFormatLong', | 195 label = loadTimeData.getStringF( |
199 numSheets.toLocaleString(), | 196 'printPreviewSummaryFormatLong', numSheets.toLocaleString(), |
200 summaryLabel, | 197 summaryLabel, numPages.toLocaleString(), pagesLabel); |
201 numPages.toLocaleString(), | |
202 pagesLabel); | |
203 } else { | 198 } else { |
204 html = loadTimeData.getStringF( | 199 html = loadTimeData.getStringF( |
205 'printPreviewSummaryFormatShort', | 200 'printPreviewSummaryFormatShort', |
206 '<b>' + numSheets.toLocaleString() + '</b>', | 201 '<b>' + numSheets.toLocaleString() + '</b>', |
207 '<b>' + summaryLabel + '</b>'); | 202 '<b>' + summaryLabel + '</b>'); |
208 label = loadTimeData.getStringF('printPreviewSummaryFormatShort', | 203 label = loadTimeData.getStringF( |
209 numSheets.toLocaleString(), | 204 'printPreviewSummaryFormatShort', numSheets.toLocaleString(), |
210 summaryLabel); | 205 summaryLabel); |
211 } | 206 } |
212 | 207 |
213 // Removing extra spaces from within the string. | 208 // Removing extra spaces from within the string. |
214 html = html.replace(/\s{2,}/g, ' '); | 209 html = html.replace(/\s{2,}/g, ' '); |
215 | 210 |
216 var summary = this.getChildElement('.summary'); | 211 var summary = this.getChildElement('.summary'); |
217 summary.innerHTML = html; | 212 summary.innerHTML = html; |
218 summary.setAttribute('aria-label', label); | 213 summary.setAttribute('aria-label', label); |
219 }, | 214 }, |
220 | 215 |
221 /** | 216 /** |
222 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT | 217 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT |
223 * common event. | 218 * common event. |
224 * @private | 219 * @private |
225 */ | 220 */ |
226 onPrintButtonClick_: function() { | 221 onPrintButtonClick_: function() { |
227 if (this.destinationStore_.selectedDestination.id != | 222 if (this.destinationStore_.selectedDestination.id != |
228 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 223 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
229 this.getChildElement('button.print').classList.add('loading'); | 224 this.getChildElement('button.print').classList.add('loading'); |
230 this.getChildElement('button.cancel').classList.add('loading'); | 225 this.getChildElement('button.cancel').classList.add('loading'); |
231 var isSaveLabel = (this.destinationStore_.selectedDestination.id == | 226 var isSaveLabel = |
| 227 (this.destinationStore_.selectedDestination.id == |
232 print_preview.Destination.GooglePromotedId.DOCS); | 228 print_preview.Destination.GooglePromotedId.DOCS); |
233 this.getChildElement('.summary').innerHTML = | 229 this.getChildElement('.summary').innerHTML = |
234 loadTimeData.getString(isSaveLabel ? 'saving' : 'printing'); | 230 loadTimeData.getString(isSaveLabel ? 'saving' : 'printing'); |
235 } | 231 } |
236 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK); | 232 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK); |
237 }, | 233 }, |
238 | 234 |
239 /** | 235 /** |
240 * Called when the cancel button is clicked. Dispatches a | 236 * Called when the cancel button is clicked. Dispatches a |
241 * CLOSE_PRINT_PREVIEW event. | 237 * CLOSE_PRINT_PREVIEW event. |
(...skipping 30 matching lines...) Expand all Loading... |
272 this.updatePrintButtonEnabledState_(); | 268 this.updatePrintButtonEnabledState_(); |
273 this.updateSummary_(); | 269 this.updateSummary_(); |
274 if (document.activeElement == null || | 270 if (document.activeElement == null || |
275 document.activeElement == document.body) { | 271 document.activeElement == document.body) { |
276 this.getChildElement('button.print').focus(); | 272 this.getChildElement('button.print').focus(); |
277 } | 273 } |
278 } | 274 } |
279 }; | 275 }; |
280 | 276 |
281 // Export | 277 // Export |
282 return { | 278 return {PrintHeader: PrintHeader}; |
283 PrintHeader: PrintHeader | |
284 }; | |
285 }); | 279 }); |
OLD | NEW |