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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 summaryLabel = 159 var summaryLabel =
163 loadTimeData.getString('printPreviewSheetsLabelSingular'); 160 loadTimeData.getString('printPreviewSheetsLabelSingular');
164 var pagesLabel = loadTimeData.getString('printPreviewPageLabelPlural'); 161 var pagesLabel = loadTimeData.getString('printPreviewPageLabelPlural');
165 162
166 var saveToPdfOrDrive = this.destinationStore_.selectedDestination && 163 var saveToPdfOrDrive = this.destinationStore_.selectedDestination &&
167 (this.destinationStore_.selectedDestination.id == 164 (this.destinationStore_.selectedDestination.id ==
168 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF || 165 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ||
169 this.destinationStore_.selectedDestination.id == 166 this.destinationStore_.selectedDestination.id ==
170 print_preview.Destination.GooglePromotedId.DOCS); 167 print_preview.Destination.GooglePromotedId.DOCS);
171 if (saveToPdfOrDrive) { 168 if (saveToPdfOrDrive) {
172 summaryLabel = loadTimeData.getString('printPreviewPageLabelSingular'); 169 summaryLabel = loadTimeData.getString('printPreviewPageLabelSingular');
173 } 170 }
174 171
175 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size; 172 var numPages = this.printTicketStore_.pageRange.getPageNumberSet().size;
176 var numSheets = numPages; 173 var numSheets = numPages;
177 if (!saveToPdfOrDrive && this.printTicketStore_.duplex.getValue()) { 174 if (!saveToPdfOrDrive && this.printTicketStore_.duplex.getValue()) {
178 numSheets = Math.ceil(numPages / 2); 175 numSheets = Math.ceil(numPages / 2);
179 } 176 }
180 177
181 var copies = this.printTicketStore_.copies.getValueAsNumber(); 178 var copies = this.printTicketStore_.copies.getValueAsNumber();
182 numSheets *= copies; 179 numSheets *= copies;
183 numPages *= copies; 180 numPages *= copies;
184 181
185 if (numSheets > 1) { 182 if (numSheets > 1) {
186 summaryLabel = saveToPdfOrDrive ? pagesLabel : 183 summaryLabel = saveToPdfOrDrive ?
184 pagesLabel :
187 loadTimeData.getString('printPreviewSheetsLabelPlural'); 185 loadTimeData.getString('printPreviewSheetsLabelPlural');
188 } 186 }
189 187
190 var html; 188 var html;
191 var label; 189 var label;
192 if (numPages != numSheets) { 190 if (numPages != numSheets) {
193 html = loadTimeData.getStringF( 191 html = loadTimeData.getStringF(
194 'printPreviewSummaryFormatLong', 192 'printPreviewSummaryFormatLong',
195 '<b>' + numSheets.toLocaleString() + '</b>', 193 '<b>' + numSheets.toLocaleString() + '</b>',
196 '<b>' + summaryLabel + '</b>', 194 '<b>' + summaryLabel + '</b>', numPages.toLocaleString(),
197 numPages.toLocaleString(),
198 pagesLabel); 195 pagesLabel);
199 label = loadTimeData.getStringF('printPreviewSummaryFormatLong', 196 label = loadTimeData.getStringF(
200 numSheets.toLocaleString(), 197 'printPreviewSummaryFormatLong', numSheets.toLocaleString(),
201 summaryLabel, 198 summaryLabel, numPages.toLocaleString(), pagesLabel);
202 numPages.toLocaleString(),
203 pagesLabel);
204 } else { 199 } else {
205 html = loadTimeData.getStringF( 200 html = loadTimeData.getStringF(
206 'printPreviewSummaryFormatShort', 201 'printPreviewSummaryFormatShort',
207 '<b>' + numSheets.toLocaleString() + '</b>', 202 '<b>' + numSheets.toLocaleString() + '</b>',
208 '<b>' + summaryLabel + '</b>'); 203 '<b>' + summaryLabel + '</b>');
209 label = loadTimeData.getStringF('printPreviewSummaryFormatShort', 204 label = loadTimeData.getStringF(
210 numSheets.toLocaleString(), 205 'printPreviewSummaryFormatShort', numSheets.toLocaleString(),
211 summaryLabel); 206 summaryLabel);
212 } 207 }
213 208
214 // Removing extra spaces from within the string. 209 // Removing extra spaces from within the string.
215 html = html.replace(/\s{2,}/g, ' '); 210 html = html.replace(/\s{2,}/g, ' ');
216 211
217 var summary = this.getChildElement('.summary'); 212 var summary = this.getChildElement('.summary');
218 summary.innerHTML = html; 213 summary.innerHTML = html;
219 summary.setAttribute('aria-label', label); 214 summary.setAttribute('aria-label', label);
220 }, 215 },
221 216
222 /** 217 /**
223 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT 218 * Called when the print button is clicked. Dispatches a PRINT_DOCUMENT
224 * common event. 219 * common event.
225 * @private 220 * @private
226 */ 221 */
227 onPrintButtonClick_: function() { 222 onPrintButtonClick_: function() {
228 if (this.destinationStore_.selectedDestination.id != 223 if (this.destinationStore_.selectedDestination.id !=
229 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { 224 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
230 this.getChildElement('button.print').classList.add('loading'); 225 this.getChildElement('button.print').classList.add('loading');
231 this.getChildElement('button.cancel').classList.add('loading'); 226 this.getChildElement('button.cancel').classList.add('loading');
232 var isSaveLabel = (this.destinationStore_.selectedDestination.id == 227 var isSaveLabel =
228 (this.destinationStore_.selectedDestination.id ==
233 print_preview.Destination.GooglePromotedId.DOCS); 229 print_preview.Destination.GooglePromotedId.DOCS);
234 this.getChildElement('.summary').innerHTML = 230 this.getChildElement('.summary').innerHTML =
235 loadTimeData.getString(isSaveLabel ? 'saving' : 'printing'); 231 loadTimeData.getString(isSaveLabel ? 'saving' : 'printing');
236 } 232 }
237 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK); 233 cr.dispatchSimpleEvent(this, PrintHeader.EventType.PRINT_BUTTON_CLICK);
238 }, 234 },
239 235
240 /** 236 /**
241 * Called when the cancel button is clicked. Dispatches a 237 * Called when the cancel button is clicked. Dispatches a
242 * CLOSE_PRINT_PREVIEW event. 238 * CLOSE_PRINT_PREVIEW event.
(...skipping 30 matching lines...) Expand all
273 this.updatePrintButtonEnabledState_(); 269 this.updatePrintButtonEnabledState_();
274 this.updateSummary_(); 270 this.updateSummary_();
275 if (document.activeElement == null || 271 if (document.activeElement == null ||
276 document.activeElement == document.body) { 272 document.activeElement == document.body) {
277 this.getChildElement('button.print').focus(); 273 this.getChildElement('button.print').focus();
278 } 274 }
279 } 275 }
280 }; 276 };
281 277
282 // Export 278 // Export
283 return { 279 return {PrintHeader: PrintHeader};
284 PrintHeader: PrintHeader
285 };
286 }); 280 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698