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

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

Issue 7056070: PrintPreview: Preview generation should not block print button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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 // The name of the default or last used printer. 33 // The name of the default or last used printer.
34 var defaultOrLastUsedPrinterName = ''; 34 var defaultOrLastUsedPrinterName = '';
35 35
36 // True when a pending print preview request exists.
37 var hasPendingPreviewRequest = false;
38
39 // True when a pending print file request exists.
40 var hasPendingPrintFileRequest = false;
41
42 // True when a compatible plugin exists.
43 var hasCompatiblePlugin = true;
Lei Zhang 2011/06/09 09:54:55 Probably safer to start with this set to false and
kmadhusu 2011/06/09 18:11:44 Done.
44
45 // True when initiator tab is closed.
46 var isInitiatorTabClosed = false;
47
36 /** 48 /**
37 * Window onload handler, sets up the page and starts print preview by getting 49 * Window onload handler, sets up the page and starts print preview by getting
38 * the printer list. 50 * the printer list.
39 */ 51 */
40 function onLoad() { 52 function onLoad() {
41 $('system-dialog-link').addEventListener('click', showSystemDialog); 53 $('system-dialog-link').addEventListener('click', showSystemDialog);
42 $('cancel-button').addEventListener('click', handleCancelButtonClick); 54 $('cancel-button').addEventListener('click', handleCancelButtonClick);
43 55
44 if (!checkCompatiblePluginExists()) { 56 if (!checkCompatiblePluginExists()) {
57 hasCompatiblePlugin = false;
45 displayErrorMessage(localStrings.getString('noPlugin'), false); 58 displayErrorMessage(localStrings.getString('noPlugin'), false);
46 $('mainview').parentElement.removeChild($('dummy-viewer')); 59 $('mainview').parentElement.removeChild($('dummy-viewer'));
47 return; 60 return;
48 } 61 }
49 $('mainview').parentElement.removeChild($('dummy-viewer')); 62 $('mainview').parentElement.removeChild($('dummy-viewer'));
50 63
51 $('printer-list').disabled = true; 64 $('printer-list').disabled = true;
52 $('print-button').disabled = true; 65 $('print-button').onclick = printFile;
66
67 setDefaultHandlersForCopiesControls();
68 setDefaultHandlersForPagesControls();
53 showLoadingAnimation(); 69 showLoadingAnimation();
54 chrome.send('getDefaultPrinter'); 70 chrome.send('getDefaultPrinter');
55 } 71 }
56 72
57 /** 73 /**
74 * Handles all pages checkbox click event.
75 */
76 function handleAllPagesCheckbox() {
dpapad 2011/06/09 16:33:35 Could you remove this function and also change lin
kmadhusu 2011/06/09 18:11:44 Done.
77 updatePrintButtonState();
78 }
79
80 /**
81 * Validates the individual pages text format.
82 */
83 function validateIndividualPagesText() {
84 $('print-pages').checked = true;
dpapad 2011/06/09 16:33:35 Why is this necessary? If the print-pages checkbox
kmadhusu 2011/06/09 18:11:44 It is required. Test case: When you navigate to
85 validatePageRangesField();
86 updatePrintButtonState();
87 }
88
89 /**
90 * Handles the individual pages input event.
91 */
92 function handleIndividualPagesInputEvent() {
Lei Zhang 2011/06/09 09:54:55 nit: can you put this next to handleAllPagesCheckb
kmadhusu 2011/06/09 18:11:44 Done.
93 $('print-pages').checked = true;
94 resetPageRangeFieldTimer();
95 }
96
97 /**
98 * Sets the default event handlers for pages controls.
99 */
100 function setDefaultHandlersForPagesControls() {
101 var allPages = $('all-pages');
102 var printPages = $('print-pages');
103 var individualPages = $('individual-pages');
104
105 allPages.onclick = null;
106 printPages.onclick = null;
107 individualPages.oninput = null;
108 individualPages.onfocus = null;
109 individualPages.onblur = null;
110
111 if (hasCompatiblePlugin && !isInitiatorTabClosed) {
112 allPages.onclick = handleAllPagesCheckbox;
113 printPages.onclick = handleIndividualPagesCheckbox;
114 individualPages.onblur = validateIndividualPagesText;
115 }
116 }
117
118 /**
119 * Sets the default event handlers for copies controls.
120 */
121 function setDefaultHandlersForCopiesControls() {
122 $('copies').oninput = copiesFieldChanged;
123 $('increment').onclick = function() { onCopiesButtonsClicked(1); };
124 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); };
125 }
126
127 /**
58 * Adds event listeners to the settings controls. 128 * Adds event listeners to the settings controls.
59 */ 129 */
60 function addEventListeners() { 130 function addEventListeners() {
61 $('print-button').onclick = printFile;
62
63 // Controls that require preview rendering. 131 // Controls that require preview rendering.
64 $('all-pages').onclick = onPageSelectionMayHaveChanged; 132 $('all-pages').onclick = onPageSelectionMayHaveChanged;
65 $('print-pages').onclick = handleIndividualPagesCheckbox; 133 $('print-pages').onclick = handleIndividualPagesCheckbox;
66 var individualPages = $('individual-pages'); 134 var individualPages = $('individual-pages');
67 individualPages.onblur = function() { 135 individualPages.onblur = function() {
68 clearTimeout(timerId); 136 clearTimeout(timerId);
69 onPageSelectionMayHaveChanged(); 137 onPageSelectionMayHaveChanged();
70 }; 138 };
71 individualPages.onfocus = addTimerToPageRangeField; 139 individualPages.onfocus = addTimerToPageRangeField;
72 individualPages.oninput = resetPageRangeFieldTimer; 140 individualPages.oninput = handleIndividualPagesInputEvent;
73 $('landscape').onclick = onLayoutModeToggle; 141 $('landscape').onclick = onLayoutModeToggle;
74 $('portrait').onclick = onLayoutModeToggle; 142 $('portrait').onclick = onLayoutModeToggle;
75 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 143 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
76 144
77 // Controls that dont require preview rendering. 145 // Controls that dont require preview rendering.
78 $('copies').oninput = function() { 146 $('copies').oninput = function() {
79 copiesFieldChanged(); 147 copiesFieldChanged();
80 updatePrintButtonState(); 148 updatePrintButtonState();
81 updatePrintSummary(); 149 updatePrintSummary();
82 }; 150 };
83 $('two-sided').onclick = handleTwoSidedClick; 151 $('two-sided').onclick = handleTwoSidedClick;
84 $('color').onclick = function() { setColor(true); }; 152 $('color').onclick = function() { setColor(true); };
85 $('bw').onclick = function() { setColor(false); }; 153 $('bw').onclick = function() { setColor(false); };
86 $('increment').onclick = function() { 154 $('increment').onclick = function() {
87 onCopiesButtonsClicked(1); 155 onCopiesButtonsClicked(1);
88 updatePrintButtonState(); 156 updatePrintButtonState();
89 updatePrintSummary(); 157 updatePrintSummary();
90 }; 158 };
91 $('decrement').onclick = function() { 159 $('decrement').onclick = function() {
92 onCopiesButtonsClicked(-1); 160 onCopiesButtonsClicked(-1);
93 updatePrintButtonState(); 161 updatePrintButtonState();
94 updatePrintSummary(); 162 updatePrintSummary();
95 }; 163 };
96 } 164 }
97 165
98 /** 166 /**
99 * Removes event listeners from the settings controls. 167 * Removes event listeners from the settings controls.
100 */ 168 */
101 function removeEventListeners() { 169 function removeEventListeners() {
102 // Controls that require preview rendering.
103 $('print-button').disabled = true;
104 $('all-pages').onclick = null;
105 $('print-pages').onclick = null;
106 var individualPages = $('individual-pages');
107 individualPages.onblur = null;
108 individualPages.onfocus = null;
109 individualPages.oninput = null;
110 clearTimeout(timerId); 170 clearTimeout(timerId);
171
172 // Controls that require preview rendering
173 setDefaultHandlersForPagesControls();
111 $('landscape').onclick = null; 174 $('landscape').onclick = null;
112 $('portrait').onclick = null; 175 $('portrait').onclick = null;
113 $('printer-list').onchange = null; 176 $('printer-list').onchange = null;
114 177
115 // Controls that dont require preview rendering. 178 // Controls that dont require preview rendering.
116 $('copies').oninput = copiesFieldChanged;
117 $('two-sided').onclick = null; 179 $('two-sided').onclick = null;
118 $('color').onclick = null; 180 $('color').onclick = null;
119 $('bw').onclick = null; 181 $('bw').onclick = null;
120 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; 182 setDefaultHandlersForCopiesControls();
Lei Zhang 2011/06/09 09:54:55 Does this need to be here for can it be at line 17
kmadhusu 2011/06/09 18:11:44 Done.
121 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); };
122 } 183 }
123 184
124 /** 185 /**
125 * Asks the browser to close the preview tab. 186 * Asks the browser to close the preview tab.
126 */ 187 */
127 function handleCancelButtonClick() { 188 function handleCancelButtonClick() {
128 chrome.send('closePrintPreviewTab'); 189 chrome.send('closePrintPreviewTab');
129 } 190 }
130 191
131 /** 192 /**
132 * Asks the browser to show the native print dialog for printing. 193 * Asks the browser to show the native print dialog for printing.
133 */ 194 */
134 function showSystemDialog() { 195 function showSystemDialog() {
135 chrome.send('showSystemDialog'); 196 chrome.send('showSystemDialog');
136 } 197 }
137 198
138 /** 199 /**
139 * Disables the controls which need the initiator tab to generate preview 200 * Disables the controls which need the initiator tab to generate preview
140 * data. This function is called when the initiator tab is closed. 201 * data. This function is called when the initiator tab is closed.
141 * @param {string} initiatorTabURL The URL of the initiator tab. 202 * @param {string} initiatorTabURL The URL of the initiator tab.
142 */ 203 */
143 function onInitiatorTabClosed(initiatorTabURL) { 204 function onInitiatorTabClosed(initiatorTabURL) {
205 isInitiatorTabClosed = true;
144 $('reopen-page').addEventListener('click', function() { 206 $('reopen-page').addEventListener('click', function() {
145 window.location = initiatorTabURL; 207 window.location = initiatorTabURL;
146 }); 208 });
147 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); 209 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true);
148 } 210 }
149 211
150 /** 212 /**
151 * Gets the selected printer capabilities and updates the controls accordingly. 213 * Gets the selected printer capabilities and updates the controls accordingly.
152 */ 214 */
153 function updateControlsWithSelectedPrinterCapabilities() { 215 function updateControlsWithSelectedPrinterCapabilities() {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 var deviceName = ''; 384 var deviceName = '';
323 if (selectedPrinter >= 0) 385 if (selectedPrinter >= 0)
324 deviceName = printerList.options[selectedPrinter].value; 386 deviceName = printerList.options[selectedPrinter].value;
325 return deviceName; 387 return deviceName;
326 } 388 }
327 389
328 /** 390 /**
329 * Asks the browser to print the preview PDF based on current print settings. 391 * Asks the browser to print the preview PDF based on current print settings.
330 */ 392 */
331 function printFile() { 393 function printFile() {
394 hasPendingPrintFileRequest = hasPendingPreviewRequest ? true : false;
Lei Zhang 2011/06/09 09:54:55 Uhh, isn't this the same as: hasPendingPrintFileRe
kmadhusu 2011/06/09 18:11:44 Just for better readability I used tri-state forma
Lei Zhang 2011/06/09 21:03:27 I don't understand how that enhances readability.
395
396 if (hasPendingPrintFileRequest) {
397 if (getSelectedPrinterName() != PRINT_TO_PDF)
398 chrome.send('hidePreview');
399 return;
400 }
401
332 if (getSelectedPrinterName() != PRINT_TO_PDF) { 402 if (getSelectedPrinterName() != PRINT_TO_PDF) {
333 $('print-button').classList.add('loading'); 403 $('print-button').classList.add('loading');
334 $('cancel-button').classList.add('loading'); 404 $('cancel-button').classList.add('loading');
335 $('print-summary').innerHTML = localStrings.getString('printing'); 405 $('print-summary').innerHTML = localStrings.getString('printing');
336 removeEventListeners(); 406 removeEventListeners();
337 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, 407 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); },
338 1000); 408 1000);
339 } else 409 } else {
340 chrome.send('print', [getSettingsJSON()]); 410 chrome.send('print', [getSettingsJSON()]);
411 }
341 } 412 }
342 413
343 /** 414 /**
344 * Asks the browser to generate a preview PDF based on current print settings. 415 * Asks the browser to generate a preview PDF based on current print settings.
345 */ 416 */
346 function requestPrintPreview() { 417 function requestPrintPreview() {
418 hasPendingPreviewRequest = true;
347 removeEventListeners(); 419 removeEventListeners();
348 printSettings.save(); 420 printSettings.save();
349 showLoadingAnimation(); 421 showLoadingAnimation();
350 chrome.send('getPreview', [getSettingsJSON()]); 422 chrome.send('getPreview', [getSettingsJSON()]);
351 } 423 }
352 424
353 /** 425 /**
354 * Set the default printer. If there is one, generate a print preview. 426 * Set the default printer. If there is one, generate a print preview.
355 * @param {string} printer Name of the default printer. Empty if none. 427 * @param {string} printer Name of the default printer. Empty if none.
356 */ 428 */
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 var pdfViewer = $('pdf-viewer'); 502 var pdfViewer = $('pdf-viewer');
431 if (!pdfViewer) { 503 if (!pdfViewer) {
432 return; 504 return;
433 } 505 }
434 pdfViewer.grayscale(!color); 506 pdfViewer.grayscale(!color);
435 } 507 }
436 508
437 /** 509 /**
438 * Display an error message in the center of the preview area. 510 * Display an error message in the center of the preview area.
439 * @param {string} errorMessage The error message to be displayed. 511 * @param {string} errorMessage The error message to be displayed.
440 * @param {boolean} showButton Indivates whether the "Reopen the page" button 512 * @param {boolean} showButton Indicates whether the "Reopen the page" button
441 * should be displayed. 513 * should be displayed.
442 */ 514 */
443 function displayErrorMessage(errorMessage, showButton) { 515 function displayErrorMessage(errorMessage, showButton) {
516 $('print-button').disabled = true;
444 $('overlay-layer').classList.remove('invisible'); 517 $('overlay-layer').classList.remove('invisible');
445 $('dancing-dots-text').classList.add('hidden'); 518 $('dancing-dots-text').classList.add('hidden');
446 $('error-text').innerHTML = errorMessage; 519 $('error-text').innerHTML = errorMessage;
447 $('error-text').classList.remove('hidden'); 520 $('error-text').classList.remove('hidden');
448 if (showButton) 521 if (showButton)
449 $('reopen-page').classList.remove('hidden'); 522 $('reopen-page').classList.remove('hidden');
450 else 523 else
451 $('reopen-page').classList.add('hidden'); 524 $('reopen-page').classList.add('hidden');
452 525
453 removeEventListeners(); 526 removeEventListeners();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 * @param {string} jobTitle The print job title. 562 * @param {string} jobTitle The print job title.
490 * @param {boolean} modifiable If the preview is modifiable. 563 * @param {boolean} modifiable If the preview is modifiable.
491 * @param {string} previewUid Preview unique identifier. 564 * @param {string} previewUid Preview unique identifier.
492 */ 565 */
493 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { 566 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) {
494 var tempPrintSettings = new PrintSettings(); 567 var tempPrintSettings = new PrintSettings();
495 tempPrintSettings.save(); 568 tempPrintSettings.save();
496 569
497 previewModifiable = modifiable; 570 previewModifiable = modifiable;
498 571
572 hasPendingPreviewRequest = false;
573
499 if (totalPageCount == -1) 574 if (totalPageCount == -1)
500 totalPageCount = pageCount; 575 totalPageCount = pageCount;
501 576
502 if (previouslySelectedPages.length == 0) 577 if (previouslySelectedPages.length == 0)
503 for (var i = 0; i < totalPageCount; i++) 578 for (var i = 0; i < totalPageCount; i++)
504 previouslySelectedPages.push(i+1); 579 previouslySelectedPages.push(i+1);
505 580
506 if (printSettings.deviceName != tempPrintSettings.deviceName) { 581 if (printSettings.deviceName != tempPrintSettings.deviceName) {
507 updateControlsWithSelectedPrinterCapabilities(); 582 updateControlsWithSelectedPrinterCapabilities();
508 return; 583 return;
509 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { 584 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) {
510 setDefaultValuesAndRegeneratePreview(); 585 setDefaultValuesAndRegeneratePreview();
511 return; 586 return;
512 } else if (isSelectedPagesValid()) { 587 } else if (isSelectedPagesValid()) {
513 var currentlySelectedPages = getSelectedPagesSet(); 588 var currentlySelectedPages = getSelectedPagesSet();
514 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { 589 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) {
515 previouslySelectedPages = currentlySelectedPages; 590 previouslySelectedPages = currentlySelectedPages;
516 requestPrintPreview(); 591 requestPrintPreview();
517 return; 592 return;
518 } 593 }
519 } 594 }
520 595
521 if (!isSelectedPagesValid()) 596 if (!isSelectedPagesValid())
522 pageRangesFieldChanged(); 597 pageRangesFieldChanged();
523 598
524 // Update the current tab title. 599 // Update the current tab title.
525 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); 600 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle);
526 601
527 createPDFPlugin(previewUid); 602 createPDFPlugin(previewUid);
603
528 updatePrintSummary(); 604 updatePrintSummary();
529 updatePrintButtonState(); 605 updatePrintButtonState();
530 addEventListeners(); 606 addEventListeners();
607
608 if (hasPendingPrintFileRequest) {
609 printFile();
610 return;
dpapad 2011/06/09 16:33:35 Remove return since it is not needed here.
kmadhusu 2011/06/09 18:11:44 Done.
611 }
531 } 612 }
532 613
533 /** 614 /**
534 * Create the PDF plugin or reload the existing one. 615 * Create the PDF plugin or reload the existing one.
535 * @param {string} previewUid Preview unique identifier. 616 * @param {string} previewUid Preview unique identifier.
536 */ 617 */
537 function createPDFPlugin(previewUid) { 618 function createPDFPlugin(previewUid) {
538 // Enable the print button. 619 // Enable the print button.
539 if (!$('printer-list').disabled) { 620 if (!$('printer-list').disabled) {
540 $('print-button').disabled = false; 621 $('print-button').disabled = false;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 /** 680 /**
600 * Listener function that executes whenever a change occurs in the 'copies' 681 * Listener function that executes whenever a change occurs in the 'copies'
601 * field. 682 * field.
602 */ 683 */
603 function copiesFieldChanged() { 684 function copiesFieldChanged() {
604 updateCopiesButtonsState(); 685 updateCopiesButtonsState();
605 $('collate-option').hidden = getCopies() <= 1; 686 $('collate-option').hidden = getCopies() <= 1;
606 } 687 }
607 688
608 /** 689 /**
609 * Executes whenever a blur event occurs on the 'individual-pages' 690 * Validates the page ranges text and updates the hint accordingly.
610 * field or when the timer expires. It takes care of
611 * 1) showing/hiding warnings/suggestions
612 * 2) updating print button/summary
613 */ 691 */
614 function pageRangesFieldChanged() { 692 function validatePageRangesField() {
615 var currentlySelectedPages = getSelectedPagesSet();
616 var individualPagesField = $('individual-pages'); 693 var individualPagesField = $('individual-pages');
617 var individualPagesHint = $('individual-pages-hint'); 694 var individualPagesHint = $('individual-pages-hint');
618 695
619 if (isSelectedPagesValid()) { 696 if (isSelectedPagesValid()) {
620 individualPagesField.classList.remove('invalid'); 697 individualPagesField.classList.remove('invalid');
621 fadeOutElement(individualPagesHint); 698 fadeOutElement(individualPagesHint);
622 } else { 699 } else {
623 individualPagesField.classList.add('invalid'); 700 individualPagesField.classList.add('invalid');
624 individualPagesHint.classList.remove('suggestion'); 701 individualPagesHint.classList.remove('suggestion');
625 individualPagesHint.innerHTML = 702 individualPagesHint.innerHTML =
626 localStrings.getStringF('pageRangeInstruction', 703 localStrings.getStringF('pageRangeInstruction',
627 localStrings.getString( 704 localStrings.getString(
628 'examplePageRangeText')); 705 'examplePageRangeText'));
629 fadeInElement(individualPagesHint); 706 fadeInElement(individualPagesHint);
630 } 707 }
708 }
709
710 /**
711 * Executes whenever a blur event occurs on the 'individual-pages'
712 * field or when the timer expires. It takes care of
713 * 1) showing/hiding warnings/suggestions
714 * 2) updating print button/summary
715 */
716 function pageRangesFieldChanged() {
717 validatePageRangesField();
631 718
632 resetPageRangeFieldTimer(); 719 resetPageRangeFieldTimer();
633 updatePrintButtonState(); 720 updatePrintButtonState();
634 updatePrintSummary(); 721 updatePrintSummary();
635 } 722 }
636 723
637 /** 724 /**
638 * Updates the state of the increment/decrement buttons based on the current 725 * Updates the state of the increment/decrement buttons based on the current
639 * 'copies' value. 726 * 'copies' value.
640 */ 727 */
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 var successfullyParsed = 0; 886 var successfullyParsed = 0;
800 var parts = pageText.split(/,/); 887 var parts = pageText.split(/,/);
801 888
802 for (var i = 0; i < parts.length; ++i) { 889 for (var i = 0; i < parts.length; ++i) {
803 var part = parts[i].replace(/\s*/g, ''); 890 var part = parts[i].replace(/\s*/g, '');
804 if (part.length == 0) 891 if (part.length == 0)
805 continue; 892 continue;
806 893
807 var match = part.match(/^([0-9]+)-([0-9]*)$/); 894 var match = part.match(/^([0-9]+)-([0-9]*)$/);
808 if (match && isValidNonZeroPositiveInteger(match[1])) { 895 if (match && isValidNonZeroPositiveInteger(match[1])) {
896 if (!match[2] && totalPageCount == -1) {
897 successfullyParsed += 1;
898 continue;
899 }
809 var from = parseInt(match[1], 10); 900 var from = parseInt(match[1], 10);
810 var to = match[2] ? parseInt(match[2], 10) : totalPageCount; 901 var to = match[2] ? parseInt(match[2], 10) : totalPageCount;
811 902
812 if (!to || from > to) 903 if (!to || from > to)
813 return false; 904 return false;
814 } else if (!isValidNonZeroPositiveInteger(part) || 905 } else if (!isValidNonZeroPositiveInteger(part) || (totalPageCount != -1 &&
815 !(parseInt(part, 10) <= totalPageCount)) { 906 !(parseInt(part, 10) <= totalPageCount))) {
816 return false; 907 return false;
817 } 908 }
818 successfullyParsed += 1; 909 successfullyParsed += 1;
819 } 910 }
820 return successfullyParsed > 0 911 return successfullyParsed > 0
821 } 912 }
822 913
823 /** 914 /**
824 * Returns true if |value| is a valid non zero positive integer. 915 * Returns true if |value| is a valid non zero positive integer.
825 * @param {string} value The string to be tested. 916 * @param {string} value The string to be tested.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 this.isLandscape = ''; 1046 this.isLandscape = '';
956 } 1047 }
957 1048
958 /** 1049 /**
959 * Takes a snapshot of the print settings. 1050 * Takes a snapshot of the print settings.
960 */ 1051 */
961 PrintSettings.prototype.save = function() { 1052 PrintSettings.prototype.save = function() {
962 this.deviceName = getSelectedPrinterName(); 1053 this.deviceName = getSelectedPrinterName();
963 this.isLandscape = isLandscape(); 1054 this.isLandscape = isLandscape();
964 } 1055 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698