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 // require: cr/ui/print_preview_cloud.js | |
| 6 | |
| 5 var localStrings = new LocalStrings(); | 7 var localStrings = new LocalStrings(); |
| 6 | 8 |
| 9 var useCloudPrint = false; | |
| 10 var maxCloudPrinters = 10; | |
| 11 | |
| 7 // The total page count of the previewed document regardless of which pages the | 12 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 13 // user has selected. |
| 9 var totalPageCount = -1; | 14 var totalPageCount = -1; |
| 10 | 15 |
| 11 // The previously selected pages by the user. It is used in | 16 // The previously selected pages by the user. It is used in |
| 12 // onPageSelectionMayHaveChanged() to make sure that a new preview is not | 17 // onPageSelectionMayHaveChanged() to make sure that a new preview is not |
| 13 // requested more often than necessary. | 18 // requested more often than necessary. |
| 14 var previouslySelectedPages = []; | 19 var previouslySelectedPages = []; |
| 15 | 20 |
| 16 // Timer id of the page range textfield. It is used to reset the timer whenever | 21 // Timer id of the page range textfield. It is used to reset the timer whenever |
| 17 // needed. | 22 // needed. |
| 18 var timerId; | 23 var timerId; |
| 19 | 24 |
| 20 // Store the last selected printer index. | 25 // Store the last selected printer index. |
| 21 var lastSelectedPrinterIndex = 0; | 26 var lastSelectedPrinterIndex = 0; |
| 22 | 27 |
| 23 // Used to disable some printing options when the preview is not modifiable. | 28 // Used to disable some printing options when the preview is not modifiable. |
| 24 var previewModifiable = false; | 29 var previewModifiable = false; |
| 25 | 30 |
| 26 // Destination list special value constants. | 31 // Destination list special value constants. |
| 32 const ADD_PRINTER = 'addPrinter'; | |
| 33 const MANAGE_CLOUD_PRINTERS = 'manageCloudPrinters'; | |
| 34 const MANAGE_LOCAL_PRINTERS = 'manageLocalPrinters'; | |
| 35 const MORE_PRINTERS = 'morePrinters'; | |
| 36 const SIGN_IN = 'signIn'; | |
| 27 const PRINT_TO_PDF = 'Print To PDF'; | 37 const PRINT_TO_PDF = 'Print To PDF'; |
| 28 const MANAGE_PRINTERS = 'Manage Printers'; | |
| 29 | 38 |
| 30 // State of the print preview settings. | 39 // State of the print preview settings. |
| 31 var printSettings = new PrintSettings(); | 40 var printSettings = new PrintSettings(); |
| 32 | 41 |
| 33 // The name of the default or last used printer. | 42 // The name of the default or last used printer. |
| 34 var defaultOrLastUsedPrinterName = ''; | 43 var defaultOrLastUsedPrinterName = ''; |
| 35 | 44 |
| 36 /** | 45 /** |
| 37 * 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 |
| 38 * the printer list. | 47 * the printer list. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 /** | 159 /** |
| 151 * Gets the selected printer capabilities and updates the controls accordingly. | 160 * Gets the selected printer capabilities and updates the controls accordingly. |
| 152 */ | 161 */ |
| 153 function updateControlsWithSelectedPrinterCapabilities() { | 162 function updateControlsWithSelectedPrinterCapabilities() { |
| 154 var printerList = $('printer-list'); | 163 var printerList = $('printer-list'); |
| 155 var selectedIndex = printerList.selectedIndex; | 164 var selectedIndex = printerList.selectedIndex; |
| 156 if (selectedIndex < 0) | 165 if (selectedIndex < 0) |
| 157 return; | 166 return; |
| 158 | 167 |
| 159 var selectedValue = printerList.options[selectedIndex].value; | 168 var selectedValue = printerList.options[selectedIndex].value; |
| 160 if (selectedValue == PRINT_TO_PDF) { | 169 if (printerList.options[selectedIndex].isCloudPrint) { |
| 170 updateWithCloudPrinterCapabilities(); | |
| 171 return; | |
|
sanjeevr
2011/06/10 18:13:48
Nit: Is there a way to restructure this so we don'
Albert Bodenhamer
2011/06/10 23:13:45
Done.
| |
| 172 } else if (selectedValue == SIGN_IN || | |
| 173 selectedValue == MANAGE_CLOUD_PRINTERS || | |
| 174 selectedValue == MANAGE_LOCAL_PRINTERS) { | |
| 175 printerList.selectedIndex = lastSelectedPrinterIndex; | |
| 176 chrome.send(selectedValue); | |
| 177 return; | |
| 178 } else if (selectedValue == PRINT_TO_PDF) { | |
| 161 updateWithPrinterCapabilities({'disableColorOption': true, | 179 updateWithPrinterCapabilities({'disableColorOption': true, |
| 162 'setColorAsDefault': true, | 180 'setColorAsDefault': true, |
| 163 'disableCopiesOption': true}); | 181 'disableCopiesOption': true, |
| 164 } else if (selectedValue == MANAGE_PRINTERS) { | 182 'disableLandscapeOption': false}); |
| 165 printerList.selectedIndex = lastSelectedPrinterIndex; | |
| 166 chrome.send('managePrinters'); | |
| 167 return; | |
| 168 } else { | 183 } else { |
| 169 // This message will call back to 'updateWithPrinterCapabilities' | 184 // This message will call back to 'updateWithPrinterCapabilities' |
| 170 // function. | 185 // function. |
| 171 chrome.send('getPrinterCapabilities', [selectedValue]); | 186 chrome.send('getPrinterCapabilities', [selectedValue]); |
| 172 } | 187 } |
| 173 | 188 |
| 174 lastSelectedPrinterIndex = selectedIndex; | 189 lastSelectedPrinterIndex = selectedIndex; |
| 175 | 190 |
| 176 // Regenerate the preview data based on selected printer settings. | 191 // Regenerate the preview data based on selected printer settings. |
| 177 setDefaultValuesAndRegeneratePreview(); | 192 setDefaultValuesAndRegeneratePreview(); |
| 178 } | 193 } |
| 179 | 194 |
| 195 function updateWithCloudPrinterCapabilities() { | |
| 196 var printerList = $('printer-list'); | |
| 197 var selectedIndex = printerList.selectedIndex; | |
| 198 if (printerList.options[selectedIndex].capabilities) { | |
| 199 doUpdateCloudPrinterCapabilities( | |
| 200 printerList.options[selectedIndex], | |
| 201 printerList.options[selectedIndex].capabilities); | |
| 202 } else { | |
| 203 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], | |
| 204 doUpdateCloudPrinterCapabilities); | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 function doUpdateCloudPrinterCapabilities(printer) { | |
| 209 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), | |
| 210 'setColorAsDefault': cloudprint.colorIsDefault(printer), | |
| 211 'disableCopiesOption': true, | |
| 212 'disableLandscapeOption': true}; | |
| 213 updateWithPrinterCapabilities(settings); | |
| 214 var printerList = $('printer-list'); | |
| 215 var selectedIndex = printerList.selectedIndex; | |
| 216 lastSelectedPrinterIndex = selectedIndex; | |
| 217 | |
| 218 // Regenerate the preview data based on selected printer settings. | |
| 219 setDefaultValuesAndRegeneratePreview(); | |
| 220 } | |
| 221 | |
| 180 /** | 222 /** |
| 181 * Updates the controls with printer capabilities information. | 223 * Updates the controls with printer capabilities information. |
| 182 * @param {Object} settingInfo printer setting information. | 224 * @param {Object} settingInfo printer setting information. |
| 183 */ | 225 */ |
| 184 function updateWithPrinterCapabilities(settingInfo) { | 226 function updateWithPrinterCapabilities(settingInfo) { |
| 185 var disableColorOption = settingInfo.disableColorOption; | 227 var disableColorOption = settingInfo.disableColorOption; |
| 186 var disableCopiesOption = settingInfo.disableCopiesOption; | 228 var disableCopiesOption = settingInfo.disableCopiesOption; |
| 187 var setColorAsDefault = settingInfo.setColorAsDefault; | 229 var setColorAsDefault = settingInfo.setColorAsDefault; |
| 230 var disableLandscapeOption = settingInfo.disableLandscapeOption; | |
| 188 var colorOption = $('color'); | 231 var colorOption = $('color'); |
| 189 var bwOption = $('bw'); | 232 var bwOption = $('bw'); |
| 190 | 233 |
| 191 if (disableCopiesOption) { | 234 if (disableCopiesOption) { |
| 192 fadeOutElement($('copies-option')); | 235 fadeOutElement($('copies-option')); |
| 193 $('hr-before-copies').classList.remove('invisible'); | 236 $('hr-before-copies').classList.remove('invisible'); |
| 194 } else { | 237 } else { |
| 195 fadeInElement($('copies-option')); | 238 fadeInElement($('copies-option')); |
| 196 $('hr-before-copies').classList.add('invisible'); | 239 $('hr-before-copies').classList.add('invisible'); |
| 197 } | 240 } |
| 198 | 241 |
| 242 if (disableLandscapeOption) { | |
| 243 fadeOutElement($('landscape-option')); | |
| 244 } else { | |
| 245 fadeInElement($('landscape-option')); | |
|
dpapad
2011/06/10 20:29:07
nit: Could you use the more compressed form?
disa
Albert Bodenhamer
2011/06/10 23:13:45
I have a strong dislike of the ternary operator fo
| |
| 246 } | |
| 247 | |
| 199 disableColorOption ? fadeOutElement($('color-options')) : | 248 disableColorOption ? fadeOutElement($('color-options')) : |
| 200 fadeInElement($('color-options')); | 249 fadeInElement($('color-options')); |
| 201 | 250 |
| 202 if (colorOption.checked != setColorAsDefault) { | 251 if (colorOption.checked != setColorAsDefault) { |
| 203 colorOption.checked = setColorAsDefault; | 252 colorOption.checked = setColorAsDefault; |
| 204 bwOption.checked = !setColorAsDefault; | 253 bwOption.checked = !setColorAsDefault; |
| 205 setColor(colorOption.checked); | 254 setColor(colorOption.checked); |
| 206 } | 255 } |
| 207 } | 256 } |
| 208 | 257 |
| 209 /** | 258 /** |
| 259 * Turn on the integration of Cloud Print. | |
| 260 * @param {enable} true if cloud print should be used. | |
| 261 */ | |
| 262 function setUseCloudPrint(enable, cloudPrintURL) { | |
| 263 useCloudPrint = enable; | |
| 264 cloudprint.setBaseURL(cloudPrintURL); | |
| 265 } | |
| 266 | |
| 267 /** | |
| 268 * Take the PDF data handed to us and submit it to the cloud, closing the print | |
| 269 * preview tab once the upload is successful. | |
| 270 * @param {pdfData} data to send as the print job. | |
| 271 */ | |
| 272 function printToCloud(data) { | |
| 273 cloudprint.printToCloud(data, finishedCloudPrinting); | |
| 274 } | |
| 275 | |
| 276 /** | |
| 277 * Cloud print upload of the PDF file is finished, time to close the dialog. | |
| 278 */ | |
| 279 function finishedCloudPrinting() { | |
| 280 window.location = cloudprint.getBaseURL(); | |
| 281 } | |
| 282 | |
| 283 /** | |
| 284 * Disables or enables all controls in the options pane except for the cancel | |
| 285 * button. | |
| 286 */ | |
| 287 function setControlsDisabled(disabled) { | |
|
dpapad
2011/06/10 20:29:07
This function was removed in earlier revisions, do
Albert Bodenhamer
2011/06/10 23:13:45
Done.
| |
| 288 var elementList = $('controls').elements; | |
| 289 for (var i = 0; i < elementList.length; ++i) { | |
| 290 if (elementList[i] == $('cancel-button')) | |
| 291 continue; | |
| 292 elementList[i].disabled = disabled; | |
| 293 } | |
| 294 } | |
| 295 | |
| 296 /** | |
| 210 * Validates the copies text field value. | 297 * Validates the copies text field value. |
| 211 * NOTE: An empty copies field text is considered valid because the blur event | 298 * NOTE: An empty copies field text is considered valid because the blur event |
| 212 * listener of this field will set it back to a default value. | 299 * listener of this field will set it back to a default value. |
| 213 * @return {boolean} true if the number of copies is valid else returns false. | 300 * @return {boolean} true if the number of copies is valid else returns false. |
| 214 */ | 301 */ |
| 215 function isNumberOfCopiesValid() { | 302 function isNumberOfCopiesValid() { |
| 216 var copiesFieldText = $('copies').value.replace(/\s/g, ''); | 303 var copiesFieldText = $('copies').value.replace(/\s/g, ''); |
| 217 if (copiesFieldText == '') | 304 if (copiesFieldText == '') |
| 218 return true; | 305 return true; |
| 219 | 306 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 const LONG_EDGE = 1; | 377 const LONG_EDGE = 1; |
| 291 return !isTwoSided() ? SIMPLEX : LONG_EDGE; | 378 return !isTwoSided() ? SIMPLEX : LONG_EDGE; |
| 292 } | 379 } |
| 293 | 380 |
| 294 /** | 381 /** |
| 295 * Creates a JSON string based on the values in the printer settings. | 382 * Creates a JSON string based on the values in the printer settings. |
| 296 * | 383 * |
| 297 * @return {string} JSON string with print job settings. | 384 * @return {string} JSON string with print job settings. |
| 298 */ | 385 */ |
| 299 function getSettingsJSON() { | 386 function getSettingsJSON() { |
| 387 var printerList = $('printer-list'); | |
| 388 var selectedPrinter = printerList.selectedIndex; | |
| 300 var printAll = $('all-pages').checked; | 389 var printAll = $('all-pages').checked; |
| 301 var deviceName = getSelectedPrinterName(); | 390 var deviceName = getSelectedPrinterName(); |
| 302 var printToPDF = (deviceName == PRINT_TO_PDF); | 391 var printToPDF = (deviceName == PRINT_TO_PDF); |
| 303 | 392 |
| 304 return JSON.stringify({'deviceName': deviceName, | 393 var settings = {'deviceName': deviceName, |
| 305 'pageRange': getSelectedPageRanges(), | 394 'pageRange': getSelectedPageRanges(), |
| 306 'printAll': printAll, | 395 'printAll': printAll, |
| 307 'duplex': getDuplexMode(), | 396 'duplex': getDuplexMode(), |
| 308 'copies': getCopies(), | 397 'copies': getCopies(), |
| 309 'collate': isCollated(), | 398 'collate': isCollated(), |
| 310 'landscape': isLandscape(), | 399 'landscape': isLandscape(), |
| 311 'color': isColor(), | 400 'color': isColor(), |
| 312 'printToPDF': printToPDF}); | 401 'printToPDF': printToPDF}; |
| 402 if (printerList.options[selectedPrinter].isCloudPrint) { | |
| 403 settings['cloudPrintID'] = | |
| 404 printerList.options[selectedPrinter].value; | |
| 405 } | |
| 406 | |
| 407 return JSON.stringify(settings); | |
| 313 } | 408 } |
| 314 | 409 |
| 315 /** | 410 /** |
| 316 * Returns the name of the selected printer or the empty string if no | 411 * Returns the name of the selected printer or the empty string if no |
| 317 * printer is selected. | 412 * printer is selected. |
| 318 */ | 413 */ |
| 319 function getSelectedPrinterName() { | 414 function getSelectedPrinterName() { |
| 320 var printerList = $('printer-list') | 415 var printerList = $('printer-list') |
| 321 var selectedPrinter = printerList.selectedIndex; | 416 var selectedPrinter = printerList.selectedIndex; |
| 322 var deviceName = ''; | 417 var deviceName = ''; |
| 323 if (selectedPrinter >= 0) | 418 if (selectedPrinter >= 0) |
| 324 deviceName = printerList.options[selectedPrinter].value; | 419 deviceName = printerList.options[selectedPrinter].value; |
| 325 return deviceName; | 420 return deviceName; |
| 326 } | 421 } |
| 327 | 422 |
| 328 /** | 423 /** |
| 329 * Asks the browser to print the preview PDF based on current print settings. | 424 * Asks the browser to print the preview PDF based on current print settings. |
| 330 */ | 425 */ |
| 331 function printFile() { | 426 function printFile() { |
| 332 if (getSelectedPrinterName() != PRINT_TO_PDF) { | 427 if (getSelectedPrinterName() != PRINT_TO_PDF) { |
| 333 $('print-button').classList.add('loading'); | 428 $('print-button').classList.add('loading'); |
| 334 $('cancel-button').classList.add('loading'); | 429 $('cancel-button').classList.add('loading'); |
| 335 $('print-summary').innerHTML = localStrings.getString('printing'); | 430 $('print-summary').innerHTML = localStrings.getString('printing'); |
| 336 removeEventListeners(); | 431 removeEventListeners(); |
| 337 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, | 432 var printerList = $('printer-list') |
| 338 1000); | 433 var printer = printerList[printerList.selectedIndex]; |
| 434 window.setTimeout(function() { chrome.send('print', | |
| 435 [getSettingsJSON(), cloudprint.getPrintTicketJSON(printer)]); }, 1000); | |
|
sanjeevr
2011/06/10 18:13:48
You probably need to check whether this is a cloud
Albert Bodenhamer
2011/06/10 23:13:45
getPrintTicketJSON now returns null for non-cloud
| |
| 339 } else | 436 } else |
| 340 chrome.send('print', [getSettingsJSON()]); | 437 chrome.send('print', [getSettingsJSON(), null]); |
| 341 } | 438 } |
| 342 | 439 |
| 343 /** | 440 /** |
| 344 * Asks the browser to generate a preview PDF based on current print settings. | 441 * Asks the browser to generate a preview PDF based on current print settings. |
| 345 */ | 442 */ |
| 346 function requestPrintPreview() { | 443 function requestPrintPreview() { |
| 347 removeEventListeners(); | 444 removeEventListeners(); |
| 348 printSettings.save(); | 445 printSettings.save(); |
| 349 showLoadingAnimation(); | 446 showLoadingAnimation(); |
| 350 chrome.send('getPreview', [getSettingsJSON()]); | 447 chrome.send('getPreview', [getSettingsJSON()]); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 365 chrome.send('getPrinters'); | 462 chrome.send('getPrinters'); |
| 366 } | 463 } |
| 367 | 464 |
| 368 /** | 465 /** |
| 369 * Fill the printer list drop down. | 466 * Fill the printer list drop down. |
| 370 * Called from PrintPreviewHandler::SendPrinterList(). | 467 * Called from PrintPreviewHandler::SendPrinterList(). |
| 371 * @param {Array} printers Array of printer info objects. | 468 * @param {Array} printers Array of printer info objects. |
| 372 */ | 469 */ |
| 373 function setPrinters(printers) { | 470 function setPrinters(printers) { |
| 374 var printerList = $('printer-list'); | 471 var printerList = $('printer-list'); |
| 472 if (useCloudPrint) { | |
| 473 cloudprint.fetchPrinters(addCloudPrinters); | |
| 474 if (printers.length > 0) { | |
| 475 option = addDestinationListOption('', '', false, true); | |
| 476 option = addDestinationListOption(localStrings.getString('localPrinters'), | |
| 477 '', | |
| 478 false, | |
| 479 true); | |
| 480 } | |
| 481 } | |
| 375 // If there exists a dummy printer value, then setDefaultPrinter() already | 482 // If there exists a dummy printer value, then setDefaultPrinter() already |
| 376 // requested a preview, so no need to do it again. | 483 // requested a preview, so no need to do it again. |
| 377 var needPreview = (printerList[0].value == ''); | 484 var needPreview = (printerList[0].value == ''); |
| 378 for (var i = 0; i < printers.length; ++i) { | 485 for (var i = 0; i < printers.length; ++i) { |
| 379 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); | 486 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); |
| 380 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 487 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
| 381 isDefault, false); | 488 isDefault, false); |
| 382 } | 489 } |
| 383 | 490 |
| 384 // Remove the dummy printer added in setDefaultPrinter(). | 491 // Remove the dummy printer added in setDefaultPrinter(). |
| 385 printerList.remove(0); | 492 printerList.remove(0); |
| 386 | 493 |
| 387 if (printers.length != 0) | 494 if (printers.length != 0) |
| 388 addDestinationListOption('', '', false, true); | 495 addDestinationListOption('', '', false, true); |
| 389 | 496 |
| 390 // Adding option for saving PDF to disk. | 497 // Adding option for saving PDF to disk. |
| 391 addDestinationListOption(localStrings.getString('printToPDF'), | 498 addDestinationListOption(localStrings.getString('printToPDF'), |
| 392 PRINT_TO_PDF, | 499 PRINT_TO_PDF, |
| 393 defaultOrLastUsedPrinterName == PRINT_TO_PDF, | 500 defaultOrLastUsedPrinterName == PRINT_TO_PDF, |
| 394 false); | 501 false); |
| 395 addDestinationListOption('', '', false, true); | 502 addDestinationListOption('', '', false, true); |
| 396 | 503 |
| 397 // Add an option to manage printers. | 504 // Add options to manage printers. |
| 398 addDestinationListOption(localStrings.getString('managePrinters'), | 505 if (!cr.isChromeOS) { |
| 399 MANAGE_PRINTERS, false, false); | 506 addDestinationListOption(localStrings.getString('manageLocalPrinters'), |
| 507 MANAGE_LOCAL_PRINTERS, false, false); | |
| 508 } | |
| 509 if (useCloudPrint) { | |
| 510 addDestinationListOption(localStrings.getString('manageCloudPrinters'), | |
| 511 MANAGE_CLOUD_PRINTERS, false, false); | |
| 512 } | |
| 400 | 513 |
| 401 printerList.disabled = false; | 514 printerList.disabled = false; |
| 402 | 515 |
| 403 if (needPreview) | 516 if (needPreview) |
| 404 updateControlsWithSelectedPrinterCapabilities(); | 517 updateControlsWithSelectedPrinterCapabilities(); |
| 405 } | 518 } |
| 406 | 519 |
| 407 /** | 520 /** |
| 408 * Adds an option to the printer destination list. | 521 * Adds an option to the printer destination list. |
| 409 * @param {String} optionText specifies the option text content. | 522 * @param {String} optionText specifies the option text content. |
| 410 * @param {String} optionValue specifies the option value. | 523 * @param {String} optionValue specifies the option value. |
| 411 * @param {boolean} isDefault is true if the option needs to be selected. | 524 * @param {boolean} isDefault is true if the option needs to be selected. |
| 412 * @param {boolean} isDisabled is true if the option needs to be disabled. | 525 * @param {boolean} isDisabled is true if the option needs to be disabled. |
|
dpapad
2011/06/10 20:29:07
Update comments since it is now returning a value.
Albert Bodenhamer
2011/06/10 23:13:45
Done.
| |
| 413 */ | 526 */ |
| 414 function addDestinationListOption(optionText, optionValue, isDefault, | 527 function addDestinationListOption(optionText, optionValue, isDefault, |
| 415 isDisabled) { | 528 isDisabled) { |
| 416 var option = document.createElement('option'); | 529 var option = document.createElement('option'); |
| 417 option.textContent = optionText; | 530 option.textContent = optionText; |
| 418 option.value = optionValue; | 531 option.value = optionValue; |
| 419 $('printer-list').add(option); | 532 $('printer-list').add(option); |
| 420 option.selected = isDefault; | 533 option.selected = isDefault; |
| 421 option.disabled = isDisabled; | 534 option.disabled = isDisabled; |
| 535 return option; | |
| 422 } | 536 } |
| 423 | 537 |
| 424 /** | 538 /** |
| 539 * Add cloud printers to the list drop down. | |
| 540 * Called from the cloudprint object on receipt of printer information from the | |
| 541 * cloud print server. | |
| 542 */ | |
| 543 function addCloudPrinters(printers) { | |
| 544 addDestinationListOption(localStrings.getString('cloudPrinters'), | |
| 545 '', | |
| 546 false, | |
| 547 true); | |
| 548 if (printers != null) { | |
| 549 var l = printers.length; | |
| 550 if (l > maxCloudPrinters) { | |
| 551 l = maxCloudPrinters; | |
| 552 } | |
| 553 for (var i = 0; i < l; i++) { | |
| 554 var option = addDestinationListOption(printers[i]['name'], | |
| 555 printers[i]['id'], | |
| 556 i == 0, | |
|
dpapad
2011/06/10 20:29:07
I believe this should be
printers[i]['name'] == d
Albert Bodenhamer
2011/06/10 23:13:45
Done.
| |
| 557 false); | |
| 558 option.isCloudPrint = true; | |
| 559 } | |
| 560 if (printers.length == 0) { | |
| 561 addDestinationListOption(localStrings.getString('addCloudPrinter'), | |
| 562 ADD_PRINTER, false, false); | |
| 563 } | |
| 564 if (l < printers.length) { | |
| 565 var option = addDestinationListOption('', '', false, true); | |
| 566 addDestinationListOption(localStrings.getString('morePrinters'), | |
| 567 MORE_PRINTERS, false, false); | |
| 568 } | |
| 569 } else { | |
| 570 addDestinationListOption(localStrings.getString('signIn'), | |
| 571 SIGN_IN, false, false); | |
| 572 } | |
| 573 } | |
| 574 | |
| 575 /** | |
| 425 * Sets the color mode for the PDF plugin. | 576 * Sets the color mode for the PDF plugin. |
| 426 * Called from PrintPreviewHandler::ProcessColorSetting(). | 577 * Called from PrintPreviewHandler::ProcessColorSetting(). |
| 427 * @param {boolean} color is true if the PDF plugin should display in color. | 578 * @param {boolean} color is true if the PDF plugin should display in color. |
| 428 */ | 579 */ |
| 429 function setColor(color) { | 580 function setColor(color) { |
| 430 var pdfViewer = $('pdf-viewer'); | 581 var pdfViewer = $('pdf-viewer'); |
| 431 if (!pdfViewer) { | 582 if (!pdfViewer) { |
| 432 return; | 583 return; |
| 433 } | 584 } |
| 434 pdfViewer.grayscale(!color); | 585 pdfViewer.grayscale(!color); |
| 586 var printerList = $('printer-list') | |
| 587 cloudprint.setColor(printerList[printerList.selectedIndex], color); | |
| 435 } | 588 } |
| 436 | 589 |
| 437 /** | 590 /** |
| 438 * Display an error message in the center of the preview area. | 591 * Display an error message in the center of the preview area. |
| 439 * @param {string} errorMessage The error message to be displayed. | 592 * @param {string} errorMessage The error message to be displayed. |
| 440 * @param {boolean} showButton Indivates whether the "Reopen the page" button | 593 * @param {boolean} showButton Indivates whether the "Reopen the page" button |
| 441 * should be displayed. | 594 * should be displayed. |
| 442 */ | 595 */ |
| 443 function displayErrorMessage(errorMessage, showButton) { | 596 function displayErrorMessage(errorMessage, showButton) { |
| 444 $('overlay-layer').classList.remove('invisible'); | 597 $('overlay-layer').classList.remove('invisible'); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 this.isLandscape = ''; | 1108 this.isLandscape = ''; |
| 956 } | 1109 } |
| 957 | 1110 |
| 958 /** | 1111 /** |
| 959 * Takes a snapshot of the print settings. | 1112 * Takes a snapshot of the print settings. |
| 960 */ | 1113 */ |
| 961 PrintSettings.prototype.save = function() { | 1114 PrintSettings.prototype.save = function() { |
| 962 this.deviceName = getSelectedPrinterName(); | 1115 this.deviceName = getSelectedPrinterName(); |
| 963 this.isLandscape = isLandscape(); | 1116 this.isLandscape = isLandscape(); |
| 964 } | 1117 } |
| 1118 | |
| OLD | NEW |