Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/resources/print_preview/print_header.js

Issue 590643002: Move Print Preview onto newer i18nTemplate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update new invitations code Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 * Updates the summary element based on the currently selected user options. 142 * Updates the summary element based on the currently selected user options.
143 * @private 143 * @private
144 */ 144 */
145 updateSummary_: function() { 145 updateSummary_: function() {
146 if (!this.printTicketStore_.isTicketValid()) { 146 if (!this.printTicketStore_.isTicketValid()) {
147 this.getChildElement('.summary').innerHTML = ''; 147 this.getChildElement('.summary').innerHTML = '';
148 return; 148 return;
149 } 149 }
150 150
151 var summaryLabel = 151 var summaryLabel =
152 localStrings.getString('printPreviewSheetsLabelSingular'); 152 loadTimeData.getString('printPreviewSheetsLabelSingular');
153 var pagesLabel = localStrings.getString('printPreviewPageLabelPlural'); 153 var pagesLabel = loadTimeData.getString('printPreviewPageLabelPlural');
154 154
155 var saveToPdf = this.destinationStore_.selectedDestination && 155 var saveToPdf = this.destinationStore_.selectedDestination &&
156 this.destinationStore_.selectedDestination.id == 156 this.destinationStore_.selectedDestination.id ==
157 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; 157 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
158 if (saveToPdf) { 158 if (saveToPdf) {
159 summaryLabel = localStrings.getString('printPreviewPageLabelSingular'); 159 summaryLabel = loadTimeData.getString('printPreviewPageLabelSingular');
160 } 160 }
161 161
162 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size; 162 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size;
163 var numSheets = numPages; 163 var numSheets = numPages;
164 if (!saveToPdf && this.printTicketStore_.duplex.getValue()) { 164 if (!saveToPdf && this.printTicketStore_.duplex.getValue()) {
165 numSheets = Math.ceil(numPages / 2); 165 numSheets = Math.ceil(numPages / 2);
166 } 166 }
167 167
168 var copies = this.printTicketStore_.copies.getValueAsNumber(); 168 var copies = this.printTicketStore_.copies.getValueAsNumber();
169 numSheets *= copies; 169 numSheets *= copies;
170 numPages *= copies; 170 numPages *= copies;
171 171
172 if (numSheets > 1) { 172 if (numSheets > 1) {
173 summaryLabel = saveToPdf ? pagesLabel : 173 summaryLabel = saveToPdf ? pagesLabel :
174 localStrings.getString('printPreviewSheetsLabelPlural'); 174 loadTimeData.getString('printPreviewSheetsLabelPlural');
175 } 175 }
176 176
177 var html; 177 var html;
178 if (numPages != numSheets) { 178 if (numPages != numSheets) {
179 html = localStrings.getStringF('printPreviewSummaryFormatLong', 179 html = loadTimeData.getStringF('printPreviewSummaryFormatLong',
180 '<b>' + numSheets + '</b>', 180 '<b>' + numSheets + '</b>',
181 '<b>' + summaryLabel + '</b>', 181 '<b>' + summaryLabel + '</b>',
182 numPages, 182 numPages,
183 pagesLabel); 183 pagesLabel);
184 } else { 184 } else {
185 html = localStrings.getStringF('printPreviewSummaryFormatShort', 185 html = loadTimeData.getStringF('printPreviewSummaryFormatShort',
186 '<b>' + numSheets + '</b>', 186 '<b>' + numSheets + '</b>',
187 '<b>' + summaryLabel + '</b>'); 187 '<b>' + summaryLabel + '</b>');
188 } 188 }
189 189
190 // Removing extra spaces from within the string. 190 // Removing extra spaces from within the string.
191 html = html.replace(/\s{2,}/g, ' '); 191 html = html.replace(/\s{2,}/g, ' ');
192 this.getChildElement('.summary').innerHTML = html; 192 this.getChildElement('.summary').innerHTML = html;
193 }, 193 },
194 194
195 /** 195 /**
196 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT 196 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT
197 * common event. 197 * common event.
198 * @private 198 * @private
199 */ 199 */
200 onPrintButtonClick_: function() { 200 onPrintButtonClick_: function() {
201 if (this.destinationStore_.selectedDestination.id != 201 if (this.destinationStore_.selectedDestination.id !=
202 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { 202 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
203 this.getChildElement('button.print').classList.add('loading'); 203 this.getChildElement('button.print').classList.add('loading');
204 this.getChildElement('button.cancel').classList.add('loading'); 204 this.getChildElement('button.cancel').classList.add('loading');
205 this.getChildElement('.summary').innerHTML = 205 this.getChildElement('.summary').innerHTML =
206 localStrings.getString('printing'); 206 loadTimeData.getString('printing');
207 } 207 }
208 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK); 208 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK);
209 }, 209 },
210 210
211 /** 211 /**
212 * Called when the cancel button is clicked. Dispatches a 212 * Called when the cancel button is clicked. Dispatches a
213 * CLOSE_PRINT_PREVIEW event. 213 * CLOSE_PRINT_PREVIEW event.
214 * @private 214 * @private
215 */ 215 */
216 onCancelButtonClick_: function() { 216 onCancelButtonClick_: function() {
217 cr.dispatchSimpleEvent(this, PrintHeader.EventType.CANCEL_BUTTON_CLICK); 217 cr.dispatchSimpleEvent(this, PrintHeader.EventType.CANCEL_BUTTON_CLICK);
218 }, 218 },
219 219
220 /** 220 /**
221 * 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
222 * button. 222 * button.
223 * @private 223 * @private
224 */ 224 */
225 onDestinationSelect_: function() { 225 onDestinationSelect_: function() {
226 var isSaveLabel = this.destinationStore_.selectedDestination && 226 var isSaveLabel = this.destinationStore_.selectedDestination &&
227 (this.destinationStore_.selectedDestination.id == 227 (this.destinationStore_.selectedDestination.id ==
228 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || 228 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ||
229 this.destinationStore_.selectedDestination.id == 229 this.destinationStore_.selectedDestination.id ==
230 print_preview.Destination.GooglePromotedId.DOCS); 230 print_preview.Destination.GooglePromotedId.DOCS);
231 this.getChildElement('button.print').textContent = 231 this.getChildElement('button.print').textContent =
232 localStrings.getString(isSaveLabel ? 'saveButton' : 'printButton'); 232 loadTimeData.getString(isSaveLabel ? 'saveButton' : 'printButton');
233 if (this.destinationStore_.selectedDestination) { 233 if (this.destinationStore_.selectedDestination) {
234 this.getChildElement('button.print').focus(); 234 this.getChildElement('button.print').focus();
235 } 235 }
236 }, 236 },
237 237
238 /** 238 /**
239 * 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
240 * any of the settings are invalid. 240 * any of the settings are invalid.
241 * @private 241 * @private
242 */ 242 */
243 onTicketChange_: function() { 243 onTicketChange_: function() {
244 this.updatePrintButtonEnabledState_(); 244 this.updatePrintButtonEnabledState_();
245 this.updateSummary_(); 245 this.updateSummary_();
246 if (document.activeElement == null || 246 if (document.activeElement == null ||
247 document.activeElement == document.body) { 247 document.activeElement == document.body) {
248 this.getChildElement('button.print').focus(); 248 this.getChildElement('button.print').focus();
249 } 249 }
250 } 250 }
251 }; 251 };
252 252
253 // Export 253 // Export
254 return { 254 return {
255 PrintHeader: PrintHeader 255 PrintHeader: PrintHeader
256 }; 256 };
257 }); 257 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698