Chromium Code Reviews| 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // Used to disable some printing options when the preview is not modifiable. | 23 // Used to disable some printing options when the preview is not modifiable. |
| 24 var previewModifiable = false; | 24 var previewModifiable = false; |
| 25 | 25 |
| 26 // Destination list special value constants. | 26 // Destination list special value constants. |
| 27 const PRINT_TO_PDF = 'Print To PDF'; | 27 const PRINT_TO_PDF = 'Print To PDF'; |
| 28 const MANAGE_PRINTERS = 'Manage Printers'; | 28 const MANAGE_PRINTERS = 'Manage Printers'; |
| 29 | 29 |
| 30 // State of the print preview settings. | 30 // State of the print preview settings. |
| 31 var printSettings = new PrintSettings(); | 31 var printSettings = new PrintSettings(); |
| 32 | 32 |
| 33 // True when a pending print preview request exists. | |
| 34 var hasPendingPreviewRequest = false; | |
| 35 | |
| 36 // True when a pending print file request exists. | |
| 37 var hasPendingPrintFileRequest = false; | |
| 38 | |
| 39 // True when a compatible plugin exists. | |
| 40 var hasCompatiblePlugin = true; | |
| 41 | |
| 42 // True when initiator tab is closed. | |
| 43 var isInitiatorTabClosed = false; | |
| 44 | |
| 33 /** | 45 /** |
| 34 * Window onload handler, sets up the page and starts print preview by getting | 46 * Window onload handler, sets up the page and starts print preview by getting |
| 35 * the printer list. | 47 * the printer list. |
| 36 */ | 48 */ |
| 37 function onLoad() { | 49 function onLoad() { |
| 38 $('system-dialog-link').addEventListener('click', showSystemDialog); | 50 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 39 $('cancel-button').addEventListener('click', handleCancelButtonClick); | 51 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 40 | 52 |
| 41 if (!checkCompatiblePluginExists()) { | 53 if (!checkCompatiblePluginExists()) { |
| 54 hasCompatiblePlugin = false; | |
| 55 $('print-button').disabled = true; | |
| 42 displayErrorMessage(localStrings.getString('noPlugin'), false); | 56 displayErrorMessage(localStrings.getString('noPlugin'), false); |
| 43 $('mainview').parentElement.removeChild($('dummy-viewer')); | 57 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 44 return; | 58 return; |
| 45 } | 59 } |
| 46 $('mainview').parentElement.removeChild($('dummy-viewer')); | 60 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 47 | 61 |
| 48 $('printer-list').disabled = true; | 62 $('printer-list').disabled = true; |
| 49 $('print-button').disabled = true; | 63 $('print-button').onclick = printFile; |
| 64 | |
| 65 setDefaultHandlersForCopiesControls(); | |
| 66 setDefaultHandlersForPagesControls(); | |
| 50 showLoadingAnimation(); | 67 showLoadingAnimation(); |
| 51 chrome.send('getDefaultPrinter'); | 68 chrome.send('getDefaultPrinter'); |
| 52 } | 69 } |
| 53 | 70 |
| 54 /** | 71 /** |
| 72 * Handles all pages checkbox click event. | |
| 73 */ | |
| 74 function handleAllPagesCheckbox() { | |
| 75 updatePrintButtonState(); | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * Validates the individual pages text format. | |
| 80 */ | |
| 81 function validateIndividualPagesText() { | |
| 82 $('print-pages').checked = true; | |
| 83 validatePageRangesField(); | |
| 84 updatePrintButtonState(); | |
| 85 } | |
| 86 | |
| 87 /** | |
| 88 * Handles the individual pages input event. | |
| 89 */ | |
| 90 function handleIndividualPagesInputEvent() { | |
| 91 $('print-pages').checked = true; | |
| 92 resetPageRangeFieldTimer(); | |
| 93 } | |
| 94 | |
| 95 /** | |
| 96 * Sets the default event handlers for pages controls. | |
| 97 */ | |
| 98 function setDefaultHandlersForPagesControls() { | |
| 99 var allPages = $('all-pages'); | |
| 100 var printPages = $('print-pages'); | |
| 101 var individualPages = $('individual-pages'); | |
| 102 individualPages.onblur = null; | |
| 103 individualPages.onfocus = null; | |
| 104 | |
| 105 if (!hasCompatiblePlugin || isInitiatorTabClosed) { | |
| 106 allPages.onclick = null; | |
| 107 printPages.onclick = null; | |
| 108 individualPages.oninput = null; | |
| 109 } else { | |
| 110 allPages.onclick = handleAllPagesCheckbox; | |
| 111 printPages.onclick = handleIndividualPagesCheckbox; | |
| 112 individualPages.oninput = validateIndividualPagesText; | |
|
dpapad
2011/06/07 20:47:14
Shouldn't we validate the the page range field onl
kmadhusu
2011/06/08 00:39:15
Fixed. Changed the behavior to validate on onblur
| |
| 113 } | |
| 114 } | |
| 115 | |
| 116 /** | |
| 117 * Sets the default event handlers for copies controls. | |
| 118 */ | |
| 119 function setDefaultHandlersForCopiesControls() { | |
| 120 $('copies').oninput = copiesFieldChanged; | |
| 121 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; | |
| 122 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); }; | |
| 123 } | |
| 124 | |
| 125 /** | |
| 55 * Adds event listeners to the settings controls. | 126 * Adds event listeners to the settings controls. |
| 56 */ | 127 */ |
| 57 function addEventListeners() { | 128 function addEventListeners() { |
| 58 $('print-button').onclick = printFile; | |
| 59 | |
| 60 // Controls that require preview rendering. | 129 // Controls that require preview rendering. |
| 61 $('all-pages').onclick = onPageSelectionMayHaveChanged; | 130 $('all-pages').onclick = onPageSelectionMayHaveChanged; |
| 62 $('print-pages').onclick = handleIndividualPagesCheckbox; | 131 $('print-pages').onclick = handleIndividualPagesCheckbox; |
| 63 var individualPages = $('individual-pages'); | 132 var individualPages = $('individual-pages'); |
| 64 individualPages.onblur = function() { | 133 individualPages.onblur = function() { |
| 65 clearTimeout(timerId); | 134 clearTimeout(timerId); |
| 66 onPageSelectionMayHaveChanged(); | 135 onPageSelectionMayHaveChanged(); |
| 67 }; | 136 }; |
| 68 individualPages.onfocus = addTimerToPageRangeField; | 137 individualPages.onfocus = addTimerToPageRangeField; |
| 69 individualPages.oninput = resetPageRangeFieldTimer; | 138 individualPages.oninput = handleIndividualPagesInputEvent; |
| 70 $('landscape').onclick = onLayoutModeToggle; | 139 $('landscape').onclick = onLayoutModeToggle; |
| 71 $('portrait').onclick = onLayoutModeToggle; | 140 $('portrait').onclick = onLayoutModeToggle; |
| 72 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 141 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 73 | 142 |
| 74 // Controls that dont require preview rendering. | 143 // Controls that dont require preview rendering. |
| 75 $('copies').oninput = function() { | 144 $('copies').oninput = function() { |
| 76 copiesFieldChanged(); | 145 copiesFieldChanged(); |
| 77 updatePrintButtonState(); | 146 updatePrintButtonState(); |
| 78 updatePrintSummary(); | 147 updatePrintSummary(); |
| 79 }; | 148 }; |
| 80 $('two-sided').onclick = handleTwoSidedClick; | 149 $('two-sided').onclick = handleTwoSidedClick; |
| 81 $('color').onclick = function() { setColor(true); }; | 150 $('color').onclick = function() { setColor(true); }; |
| 82 $('bw').onclick = function() { setColor(false); }; | 151 $('bw').onclick = function() { setColor(false); }; |
| 83 $('increment').onclick = function() { | 152 $('increment').onclick = function() { |
| 84 onCopiesButtonsClicked(1); | 153 onCopiesButtonsClicked(1); |
| 85 updatePrintButtonState(); | 154 updatePrintButtonState(); |
| 86 updatePrintSummary(); | 155 updatePrintSummary(); |
| 87 }; | 156 }; |
| 88 $('decrement').onclick = function() { | 157 $('decrement').onclick = function() { |
| 89 onCopiesButtonsClicked(-1); | 158 onCopiesButtonsClicked(-1); |
| 90 updatePrintButtonState(); | 159 updatePrintButtonState(); |
| 91 updatePrintSummary(); | 160 updatePrintSummary(); |
| 92 }; | 161 }; |
| 93 } | 162 } |
| 94 | 163 |
| 95 /** | 164 /** |
| 96 * Removes event listeners from the settings controls. | 165 * Removes event listeners from the settings controls. |
| 97 */ | 166 */ |
| 98 function removeEventListeners() { | 167 function removeEventListeners() { |
| 99 // Controls that require preview rendering. | |
| 100 $('print-button').disabled = true; | |
| 101 $('all-pages').onclick = null; | |
| 102 $('print-pages').onclick = null; | |
| 103 var individualPages = $('individual-pages'); | |
| 104 individualPages.onblur = null; | |
| 105 individualPages.onfocus = null; | |
| 106 individualPages.oninput = null; | |
| 107 clearTimeout(timerId); | 168 clearTimeout(timerId); |
| 169 | |
| 170 // Controls that require preview rendering | |
| 171 setDefaultHandlersForPagesControls(); | |
| 108 $('landscape').onclick = null; | 172 $('landscape').onclick = null; |
| 109 $('portrait').onclick = null; | 173 $('portrait').onclick = null; |
| 110 $('printer-list').onchange = null; | 174 $('printer-list').onchange = null; |
| 111 | 175 |
| 112 // Controls that dont require preview rendering. | 176 // Controls that dont require preview rendering. |
| 113 $('copies').oninput = copiesFieldChanged; | |
| 114 $('two-sided').onclick = null; | 177 $('two-sided').onclick = null; |
| 115 $('color').onclick = null; | 178 $('color').onclick = null; |
| 116 $('bw').onclick = null; | 179 $('bw').onclick = null; |
| 117 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; | 180 setDefaultHandlersForCopiesControls(); |
| 118 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); }; | |
| 119 } | 181 } |
| 120 | 182 |
| 121 /** | 183 /** |
| 122 * Asks the browser to close the preview tab. | 184 * Asks the browser to close the preview tab. |
| 123 */ | 185 */ |
| 124 function handleCancelButtonClick() { | 186 function handleCancelButtonClick() { |
| 125 chrome.send('closePrintPreviewTab'); | 187 chrome.send('closePrintPreviewTab'); |
| 126 } | 188 } |
| 127 | 189 |
| 128 /** | 190 /** |
| 129 * Asks the browser to show the native print dialog for printing. | 191 * Asks the browser to show the native print dialog for printing. |
| 130 */ | 192 */ |
| 131 function showSystemDialog() { | 193 function showSystemDialog() { |
| 132 chrome.send('showSystemDialog'); | 194 chrome.send('showSystemDialog'); |
| 133 } | 195 } |
| 134 | 196 |
| 135 /** | 197 /** |
| 136 * Disables the controls which need the initiator tab to generate preview | 198 * Disables the controls which need the initiator tab to generate preview |
| 137 * data. This function is called when the initiator tab is closed. | 199 * data. This function is called when the initiator tab is closed. |
| 138 * @param {string} initiatorTabURL The URL of the initiator tab. | 200 * @param {string} initiatorTabURL The URL of the initiator tab. |
| 139 */ | 201 */ |
| 140 function onInitiatorTabClosed(initiatorTabURL) { | 202 function onInitiatorTabClosed(initiatorTabURL) { |
| 203 isInitiatorTabClosed = true; | |
| 141 $('reopen-page').addEventListener('click', function() { | 204 $('reopen-page').addEventListener('click', function() { |
| 142 window.location = initiatorTabURL; | 205 window.location = initiatorTabURL; |
| 143 }); | 206 }); |
| 144 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); | 207 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); |
| 208 $('print-button').disabled = true; | |
|
dpapad
2011/06/07 20:47:14
Should we move this line within displayErrorMessag
kmadhusu
2011/06/08 00:39:15
Fixed. (Removed line #208 and #55).
| |
| 145 } | 209 } |
| 146 | 210 |
| 147 /** | 211 /** |
| 148 * Gets the selected printer capabilities and updates the controls accordingly. | 212 * Gets the selected printer capabilities and updates the controls accordingly. |
| 149 */ | 213 */ |
| 150 function updateControlsWithSelectedPrinterCapabilities() { | 214 function updateControlsWithSelectedPrinterCapabilities() { |
| 151 var printerList = $('printer-list'); | 215 var printerList = $('printer-list'); |
| 152 var selectedIndex = printerList.selectedIndex; | 216 var selectedIndex = printerList.selectedIndex; |
| 153 if (selectedIndex < 0) | 217 if (selectedIndex < 0) |
| 154 return; | 218 return; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 var deviceName = ''; | 383 var deviceName = ''; |
| 320 if (selectedPrinter >= 0) | 384 if (selectedPrinter >= 0) |
| 321 deviceName = printerList.options[selectedPrinter].value; | 385 deviceName = printerList.options[selectedPrinter].value; |
| 322 return deviceName; | 386 return deviceName; |
| 323 } | 387 } |
| 324 | 388 |
| 325 /** | 389 /** |
| 326 * Asks the browser to print the preview PDF based on current print settings. | 390 * Asks the browser to print the preview PDF based on current print settings. |
| 327 */ | 391 */ |
| 328 function printFile() { | 392 function printFile() { |
| 393 hasPendingPrintFileRequest = hasPendingPreviewRequest ? true : false; | |
|
dpapad
2011/06/07 20:47:14
hasPendingPrintFileRequest = hasPendingPreviewRequ
kmadhusu
2011/06/08 00:39:15
Just for better readability of the code, I used th
| |
| 394 | |
| 395 if (hasPendingPrintFileRequest) { | |
| 396 if (getSelectedPrinterName() != PRINT_TO_PDF) | |
| 397 chrome.send('hidePreview'); | |
| 398 return; | |
| 399 } | |
| 400 | |
| 329 if (getSelectedPrinterName() != PRINT_TO_PDF) { | 401 if (getSelectedPrinterName() != PRINT_TO_PDF) { |
| 330 $('print-button').classList.add('loading'); | 402 $('print-button').classList.add('loading'); |
| 331 $('cancel-button').classList.add('loading'); | 403 $('cancel-button').classList.add('loading'); |
| 332 $('print-summary').innerHTML = localStrings.getString('printing'); | 404 $('print-summary').innerHTML = localStrings.getString('printing'); |
| 333 removeEventListeners(); | 405 removeEventListeners(); |
| 334 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, | 406 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, |
| 335 1000); | 407 1000); |
| 336 } else | 408 } else { |
| 337 chrome.send('print', [getSettingsJSON()]); | 409 chrome.send('print', [getSettingsJSON()]); |
| 410 } | |
| 338 } | 411 } |
| 339 | 412 |
| 340 /** | 413 /** |
| 341 * Asks the browser to generate a preview PDF based on current print settings. | 414 * Asks the browser to generate a preview PDF based on current print settings. |
| 342 */ | 415 */ |
| 343 function requestPrintPreview() { | 416 function requestPrintPreview() { |
| 417 hasPendingPreviewRequest = true; | |
| 344 removeEventListeners(); | 418 removeEventListeners(); |
| 345 printSettings.save(); | 419 printSettings.save(); |
| 346 showLoadingAnimation(); | 420 showLoadingAnimation(); |
| 347 chrome.send('getPreview', [getSettingsJSON()]); | 421 chrome.send('getPreview', [getSettingsJSON()]); |
| 348 } | 422 } |
| 349 | 423 |
| 350 /** | 424 /** |
| 351 * Set the default printer. If there is one, generate a print preview. | 425 * Set the default printer. If there is one, generate a print preview. |
| 352 * @param {string} printer Name of the default printer. Empty if none. | 426 * @param {string} printer Name of the default printer. Empty if none. |
| 353 */ | 427 */ |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 * @param {string} jobTitle The print job title. | 564 * @param {string} jobTitle The print job title. |
| 491 * @param {boolean} modifiable If the preview is modifiable. | 565 * @param {boolean} modifiable If the preview is modifiable. |
| 492 * @param {string} previewUid Preview unique identifier. | 566 * @param {string} previewUid Preview unique identifier. |
| 493 */ | 567 */ |
| 494 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { | 568 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { |
| 495 var tempPrintSettings = new PrintSettings(); | 569 var tempPrintSettings = new PrintSettings(); |
| 496 tempPrintSettings.save(); | 570 tempPrintSettings.save(); |
| 497 | 571 |
| 498 previewModifiable = modifiable; | 572 previewModifiable = modifiable; |
| 499 | 573 |
| 574 hasPendingPreviewRequest = false; | |
| 575 | |
| 500 if (totalPageCount == -1) | 576 if (totalPageCount == -1) |
| 501 totalPageCount = pageCount; | 577 totalPageCount = pageCount; |
| 502 | 578 |
| 503 if (previouslySelectedPages.length == 0) | 579 if (previouslySelectedPages.length == 0) |
| 504 for (var i = 0; i < totalPageCount; i++) | 580 for (var i = 0; i < totalPageCount; i++) |
| 505 previouslySelectedPages.push(i+1); | 581 previouslySelectedPages.push(i+1); |
| 506 | 582 |
| 507 if (printSettings.deviceName != tempPrintSettings.deviceName) { | 583 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
| 508 updateControlsWithSelectedPrinterCapabilities(); | 584 updateControlsWithSelectedPrinterCapabilities(); |
| 509 return; | 585 return; |
| 510 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | 586 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { |
| 511 setDefaultValuesAndRegeneratePreview(); | 587 setDefaultValuesAndRegeneratePreview(); |
| 512 return; | 588 return; |
| 513 } else if (getSelectedPagesValidityLevel() == 1) { | 589 } else if (getSelectedPagesValidityLevel() == 1) { |
| 514 var currentlySelectedPages = getSelectedPagesSet(); | 590 var currentlySelectedPages = getSelectedPagesSet(); |
| 515 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { | 591 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { |
| 516 previouslySelectedPages = currentlySelectedPages; | 592 previouslySelectedPages = currentlySelectedPages; |
| 517 requestPrintPreview(); | 593 requestPrintPreview(); |
| 518 return; | 594 return; |
| 519 } | 595 } |
| 520 } | 596 } |
| 521 | 597 |
| 522 if (getSelectedPagesValidityLevel() != 1) | 598 if (getSelectedPagesValidityLevel() != 1) |
| 523 pageRangesFieldChanged(); | 599 pageRangesFieldChanged(); |
| 524 | 600 |
| 525 // Update the current tab title. | 601 // Update the current tab title. |
| 526 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 602 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 527 | 603 |
| 528 createPDFPlugin(previewUid); | 604 createPDFPlugin(previewUid); |
| 605 | |
| 606 if (hasPendingPrintFileRequest) { | |
| 607 printFile(); | |
| 608 return; | |
| 609 } | |
| 610 | |
| 529 updatePrintSummary(); | 611 updatePrintSummary(); |
| 530 updatePrintButtonState(); | 612 updatePrintButtonState(); |
| 531 addEventListeners(); | 613 addEventListeners(); |
| 532 } | 614 } |
| 533 | 615 |
| 534 /** | 616 /** |
| 535 * Create the PDF plugin or reload the existing one. | 617 * Create the PDF plugin or reload the existing one. |
| 536 * @param {string} previewUid Preview unique identifier. | 618 * @param {string} previewUid Preview unique identifier. |
| 537 */ | 619 */ |
| 538 function createPDFPlugin(previewUid) { | 620 function createPDFPlugin(previewUid) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 /** | 682 /** |
| 601 * Listener function that executes whenever a change occurs in the 'copies' | 683 * Listener function that executes whenever a change occurs in the 'copies' |
| 602 * field. | 684 * field. |
| 603 */ | 685 */ |
| 604 function copiesFieldChanged() { | 686 function copiesFieldChanged() { |
| 605 updateCopiesButtonsState(); | 687 updateCopiesButtonsState(); |
| 606 $('collate-option').hidden = getCopies() <= 1; | 688 $('collate-option').hidden = getCopies() <= 1; |
| 607 } | 689 } |
| 608 | 690 |
| 609 /** | 691 /** |
| 610 * Executes whenever a blur event occurs on the 'individual-pages' | 692 * Validates the page ranges text and updates the hint accordingly. |
| 611 * field or when the timer expires. It takes care of | |
| 612 * 1) showing/hiding warnings/suggestions | |
| 613 * 2) updating print button/summary | |
| 614 */ | 693 */ |
| 615 function pageRangesFieldChanged() { | 694 function validatePageRangesField() { |
| 616 var currentlySelectedPages = getSelectedPagesSet(); | |
| 617 var individualPagesField = $('individual-pages'); | 695 var individualPagesField = $('individual-pages'); |
| 618 var individualPagesHint = $('individual-pages-hint'); | 696 var individualPagesHint = $('individual-pages-hint'); |
| 619 var validityLevel = getSelectedPagesValidityLevel(); | 697 var validityLevel = getSelectedPagesValidityLevel(); |
| 620 | 698 |
| 621 if (validityLevel == 1) { | 699 if (validityLevel == 1) { |
| 622 individualPagesField.classList.remove('invalid'); | 700 individualPagesField.classList.remove('invalid'); |
| 623 fadeOutElement(individualPagesHint); | 701 fadeOutElement(individualPagesHint); |
| 624 } else { | 702 } else { |
| 625 individualPagesField.classList.add('invalid'); | 703 individualPagesField.classList.add('invalid'); |
| 626 individualPagesHint.classList.remove('suggestion'); | 704 individualPagesHint.classList.remove('suggestion'); |
| 627 individualPagesHint.innerHTML = | 705 individualPagesHint.innerHTML = |
| 628 localStrings.getStringF('pageRangeInstruction', | 706 localStrings.getStringF('pageRangeInstruction', |
| 629 localStrings.getString( | 707 localStrings.getString( |
| 630 'examplePageRangeText')); | 708 'examplePageRangeText')); |
| 631 fadeInElement(individualPagesHint); | 709 fadeInElement(individualPagesHint); |
| 632 } | 710 } |
| 711 } | |
| 712 | |
| 713 /** | |
| 714 * Executes whenever a blur event occurs on the 'individual-pages' | |
| 715 * field or when the timer expires. It takes care of | |
| 716 * 1) showing/hiding warnings/suggestions | |
| 717 * 2) updating print button/summary | |
| 718 */ | |
| 719 function pageRangesFieldChanged() { | |
| 720 validatePageRangesField(); | |
| 633 | 721 |
| 634 resetPageRangeFieldTimer(); | 722 resetPageRangeFieldTimer(); |
| 635 updatePrintButtonState(); | 723 updatePrintButtonState(); |
| 636 updatePrintSummary(); | 724 updatePrintSummary(); |
| 637 } | 725 } |
| 638 | 726 |
| 639 /** | 727 /** |
| 640 * Updates the state of the increment/decrement buttons based on the current | 728 * Updates the state of the increment/decrement buttons based on the current |
| 641 * 'copies' value. | 729 * 'copies' value. |
| 642 */ | 730 */ |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 var failedToParse = 0; | 891 var failedToParse = 0; |
| 804 | 892 |
| 805 var parts = pageText.split(/,/); | 893 var parts = pageText.split(/,/); |
| 806 | 894 |
| 807 for (var i = 0; i < parts.length; ++i) { | 895 for (var i = 0; i < parts.length; ++i) { |
| 808 var part = parts[i].replace(/\s*/g, ''); | 896 var part = parts[i].replace(/\s*/g, ''); |
| 809 if (part.length == 0) | 897 if (part.length == 0) |
| 810 continue; | 898 continue; |
| 811 | 899 |
| 812 var match = part.match(/^([0-9]+)-([0-9]*)$/); | 900 var match = part.match(/^([0-9]+)-([0-9]*)$/); |
| 813 if (match && match[1]) { | 901 if (totalPageCount != -1) { |
| 814 var from = parseInt(match[1], 10); | 902 if (match && match[1]) { |
| 815 var to = match[2] ? parseInt(match[2], 10) : totalPageCount; | 903 var from = parseInt(match[1], 10); |
| 904 var to = match[2] ? parseInt(match[2], 10) : totalPageCount; | |
| 816 | 905 |
| 817 if (from && to && from <= to) | 906 if (from && to && from <= to) |
| 907 successfullyParsed += 1; | |
| 908 else | |
| 909 failedToParse += 1; | |
| 910 } else if (isInteger(part) && parseInt(part, 10) <= totalPageCount && | |
| 911 parseInt(part, 10) > 0) { | |
| 818 successfullyParsed += 1; | 912 successfullyParsed += 1; |
| 819 else | 913 } else { |
| 820 failedToParse += 1; | 914 failedToParse += 1; |
| 821 | 915 } |
| 822 } else if (isInteger(part) && parseInt(part, 10) <= totalPageCount && | 916 } else { |
| 823 parseInt(part, 10) > 0) | 917 // totalPageCount is -1. Just validate the page range format. |
| 824 successfullyParsed += 1; | 918 if (match && isInteger(match[1])) { |
| 825 else | 919 if (match[2] && !isInteger(match[2])) |
| 826 failedToParse += 1; | 920 failedToParse += 1; |
| 921 successfullyParsed += 1; | |
| 922 } else if (isInteger(part)) { | |
|
dpapad
2011/06/07 20:47:14
Shouldn't we check also for parseInt(part, 10) > 0
kmadhusu
2011/06/08 00:39:15
Fixed.
| |
| 923 successfullyParsed += 1; | |
| 924 } else { | |
| 925 failedToParse += 1; | |
| 926 } | |
| 927 } | |
| 827 } | 928 } |
| 828 if (successfullyParsed > 0 && failedToParse == 0) | 929 if (successfullyParsed > 0 && failedToParse == 0) |
| 829 return 1; | 930 return 1; |
| 830 else if (successfullyParsed > 0 && failedToParse > 0) | 931 else if (successfullyParsed > 0 && failedToParse > 0) |
| 831 return 0; | 932 return 0; |
| 832 else | 933 else |
| 833 return -1; | 934 return -1; |
| 834 } | 935 } |
| 835 | 936 |
| 836 function isSelectedPagesFieldValid() { | 937 function isSelectedPagesFieldValid() { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 this.isLandscape = ''; | 1066 this.isLandscape = ''; |
| 966 } | 1067 } |
| 967 | 1068 |
| 968 /** | 1069 /** |
| 969 * Takes a snapshot of the print settings. | 1070 * Takes a snapshot of the print settings. |
| 970 */ | 1071 */ |
| 971 PrintSettings.prototype.save = function() { | 1072 PrintSettings.prototype.save = function() { |
| 972 this.deviceName = getSelectedPrinterName(); | 1073 this.deviceName = getSelectedPrinterName(); |
| 973 this.isLandscape = isLandscape(); | 1074 this.isLandscape = isLandscape(); |
| 974 } | 1075 } |
| OLD | NEW |