OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // require: cr/ui/print_preview_cloud.js | 5 // require: cr/ui/print_preview_cloud.js |
6 | 6 |
7 var localStrings = new LocalStrings(); | 7 var localStrings = new LocalStrings(); |
8 | 8 |
9 // If useCloudPrint is true we attempt to connect to cloud print | 9 // If useCloudPrint is true we attempt to connect to cloud print |
10 // and populate the list of printers with cloud print printers. | 10 // and populate the list of printers with cloud print printers. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 88 } |
89 | 89 |
90 /** | 90 /** |
91 * Adds event listeners to the settings controls. | 91 * Adds event listeners to the settings controls. |
92 */ | 92 */ |
93 function addEventListeners() { | 93 function addEventListeners() { |
94 // Controls that require preview rendering. | 94 // Controls that require preview rendering. |
95 $('landscape').onclick = onLayoutModeToggle; | 95 $('landscape').onclick = onLayoutModeToggle; |
96 $('portrait').onclick = onLayoutModeToggle; | 96 $('portrait').onclick = onLayoutModeToggle; |
97 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 97 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
98 $('header-footer').onclick = onHeaderFooterChanged; | |
98 | 99 |
99 // Controls that do not require preview rendering. | 100 // Controls that do not require preview rendering. |
100 $('color').onclick = function() { setColor(true); }; | 101 $('color').onclick = function() { setColor(true); }; |
101 $('bw').onclick = function() { setColor(false); }; | 102 $('bw').onclick = function() { setColor(false); }; |
102 } | 103 } |
103 | 104 |
104 /** | 105 /** |
105 * Removes event listeners from the settings controls. | 106 * Removes event listeners from the settings controls. |
106 */ | 107 */ |
107 function removeEventListeners() { | 108 function removeEventListeners() { |
108 clearTimeout(pageSettings.timerId_); | 109 clearTimeout(pageSettings.timerId_); |
109 | 110 |
110 // Controls that require preview rendering | 111 // Controls that require preview rendering |
111 $('landscape').onclick = null; | 112 $('landscape').onclick = null; |
112 $('portrait').onclick = null; | 113 $('portrait').onclick = null; |
113 $('printer-list').onchange = null; | 114 $('printer-list').onchange = null; |
115 $('header-footer').onclick = null; | |
114 | 116 |
115 // Controls that don't require preview rendering. | 117 // Controls that don't require preview rendering. |
116 $('color').onclick = null; | 118 $('color').onclick = null; |
117 $('bw').onclick = null; | 119 $('bw').onclick = null; |
118 } | 120 } |
119 | 121 |
120 /** | 122 /** |
121 * Disables the input elements in the sidebar. | 123 * Disables the input elements in the sidebar. |
122 */ | 124 */ |
123 function disableInputElementsInSidebar() { | 125 function disableInputElementsInSidebar() { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 * @return {number} duplex mode. | 336 * @return {number} duplex mode. |
335 */ | 337 */ |
336 function getDuplexMode() { | 338 function getDuplexMode() { |
337 // Constants values matches printing::DuplexMode enum. | 339 // Constants values matches printing::DuplexMode enum. |
338 const SIMPLEX = 0; | 340 const SIMPLEX = 0; |
339 const LONG_EDGE = 1; | 341 const LONG_EDGE = 1; |
340 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE; | 342 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE; |
341 } | 343 } |
342 | 344 |
343 /** | 345 /** |
346 * Checks whether the Headers and Footers checkbox is checked or not. | |
347 * | |
348 * @return {boolean} true if Headers and Footers are checked. | |
349 */ | |
350 function hasHeaderFooter() { | |
351 return $('header-footer').checked; | |
352 } | |
353 | |
354 /** | |
344 * Creates a JSON string based on the values in the printer settings. | 355 * Creates a JSON string based on the values in the printer settings. |
345 * | 356 * |
346 * @return {string} JSON string with print job settings. | 357 * @return {string} JSON string with print job settings. |
347 */ | 358 */ |
348 function getSettingsJSON() { | 359 function getSettingsJSON() { |
349 var deviceName = getSelectedPrinterName(); | 360 var deviceName = getSelectedPrinterName(); |
350 var printToPDF = (deviceName == PRINT_TO_PDF); | 361 var printToPDF = (deviceName == PRINT_TO_PDF); |
351 | 362 |
352 var settings = {'deviceName': deviceName, | 363 var settings = {'deviceName': deviceName, |
353 'pageRange': pageSettings.selectedPageRanges, | 364 'pageRange': pageSettings.selectedPageRanges, |
354 'printAll': pageSettings.allPagesRadioButton.checked, | 365 'printAll': pageSettings.allPagesRadioButton.checked, |
355 'duplex': getDuplexMode(), | 366 'duplex': getDuplexMode(), |
356 'copies': copiesSettings.numberOfCopies, | 367 'copies': copiesSettings.numberOfCopies, |
357 'collate': isCollated(), | 368 'collate': isCollated(), |
358 'landscape': isLandscape(), | 369 'landscape': isLandscape(), |
359 'color': isColor(), | 370 'color': isColor(), |
360 'printToPDF': printToPDF}; | 371 'printToPDF': printToPDF, |
372 'headerFooter': hasHeaderFooter()}; | |
361 var printerList = $('printer-list'); | 373 var printerList = $('printer-list'); |
362 var selectedPrinter = printerList.selectedIndex; | 374 var selectedPrinter = printerList.selectedIndex; |
363 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 375 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
364 settings['cloudPrintID'] = | 376 settings['cloudPrintID'] = |
365 printerList.options[selectedPrinter].value; | 377 printerList.options[selectedPrinter].value; |
366 } | 378 } |
367 | 379 |
368 return JSON.stringify(settings); | 380 return JSON.stringify(settings); |
369 } | 381 } |
370 | 382 |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 tempPrintSettings.save(); | 840 tempPrintSettings.save(); |
829 | 841 |
830 if (printSettings.deviceName != tempPrintSettings.deviceName) { | 842 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
831 updateControlsWithSelectedPrinterCapabilities(); | 843 updateControlsWithSelectedPrinterCapabilities(); |
832 return true; | 844 return true; |
833 } | 845 } |
834 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | 846 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { |
835 setDefaultValuesAndRegeneratePreview(); | 847 setDefaultValuesAndRegeneratePreview(); |
836 return true; | 848 return true; |
837 } | 849 } |
850 if (printSettings.hasHeaderFooter != tempPrintSettings.hasHeaderFooter) { | |
851 requestPrintPreview(); | |
852 return true; | |
853 } | |
838 if (pageSettings.requestPrintPreviewIfNeeded()) | 854 if (pageSettings.requestPrintPreviewIfNeeded()) |
839 return true; | 855 return true; |
840 | 856 |
841 return false; | 857 return false; |
842 } | 858 } |
843 | 859 |
844 /** | 860 /** |
845 * Create the PDF plugin or reload the existing one. | 861 * Create the PDF plugin or reload the existing one. |
846 * @param {string} previewUid Preview unique identifier. | 862 * @param {string} previewUid Preview unique identifier. |
847 */ | 863 */ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
960 * Even if they are still valid the content of these pages will be different. | 976 * Even if they are still valid the content of these pages will be different. |
961 */ | 977 */ |
962 function onLayoutModeToggle() { | 978 function onLayoutModeToggle() { |
963 // If the chosen layout is same as before, nothing needs to be done. | 979 // If the chosen layout is same as before, nothing needs to be done. |
964 if (printSettings.isLandscape == isLandscape()) | 980 if (printSettings.isLandscape == isLandscape()) |
965 return; | 981 return; |
966 setDefaultValuesAndRegeneratePreview(); | 982 setDefaultValuesAndRegeneratePreview(); |
967 } | 983 } |
968 | 984 |
969 /** | 985 /** |
986 * When the user selects or de-selects the Headers and footers option then we | |
kmadhusu
2011/07/14 01:50:15
Headers -> headers
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
987 * regenerate the preview pdf. | |
988 */ | |
989 function onHeaderFooterChanged() { | |
dpapad
2011/07/14 15:59:35
Are headers and footers always available? For exam
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
990 requestPrintPreview(); | |
991 } | |
992 | |
993 /** | |
970 * Sets the default values and sends a request to regenerate preview data. | 994 * Sets the default values and sends a request to regenerate preview data. |
971 */ | 995 */ |
972 function setDefaultValuesAndRegeneratePreview() { | 996 function setDefaultValuesAndRegeneratePreview() { |
973 pageSettings.resetState(); | 997 pageSettings.resetState(); |
974 requestPrintPreview(); | 998 requestPrintPreview(); |
975 } | 999 } |
976 | 1000 |
977 /** | 1001 /** |
978 * Class that represents the state of the print settings. | 1002 * Class that represents the state of the print settings. |
979 */ | 1003 */ |
980 function PrintSettings() { | 1004 function PrintSettings() { |
981 this.deviceName = ''; | 1005 this.deviceName = ''; |
982 this.isLandscape = ''; | 1006 this.isLandscape = ''; |
1007 this.hasHeaderFooter = ''; | |
983 } | 1008 } |
984 | 1009 |
985 /** | 1010 /** |
986 * Takes a snapshot of the print settings. | 1011 * Takes a snapshot of the print settings. |
987 */ | 1012 */ |
988 PrintSettings.prototype.save = function() { | 1013 PrintSettings.prototype.save = function() { |
989 this.deviceName = getSelectedPrinterName(); | 1014 this.deviceName = getSelectedPrinterName(); |
990 this.isLandscape = isLandscape(); | 1015 this.isLandscape = isLandscape(); |
1016 this.hasHeaderFooter = hasHeaderFooter(); | |
991 } | 1017 } |
992 | 1018 |
OLD | NEW |