Prev | Current Page 546 | Next

Frank Zammetti

"Practical DWR 2 Projects"


When the response returns, the file editor
is hidden, and the user is alerted that the
changes were saved. Couldn??™t be easier!
doDownload() Method
As you previously saw, downloading a file is implemented in the downloadFile.jsp file, so the
question is, how do we get the user there? The answer is found in the doDownload() method:
this.doDownload = function(inSelectedDirectory, inSelectedItem) {
// Only do something if both a directory and an item in the grid are
// selected.
if (inSelectedDirectory == null || inSelectedItem == null ||
inSelectedDirectory == "" || inSelectedItem == "") {
alert("Please select a file to download");
return;
}
// Make sure the selected item is a file.
var itemType = fileGrid.cells(inSelectedItem, 2).getValue();
if (itemType == "Directory") {
alert("Sorry, only files can be downloaded");
return;
}
// Get the name and path of the selected file.
var directoryPath = directoryTree.getUserData(inSelectedDirectory, "path");
var fileName = fileGrid.getUserData(inSelectedItem, "name");
CHAPTER 6 n REMOTELY MANAGING YOUR FILES: DWR FILE MANAGER 311
// Redirect to the file. This won't cause the current page to be lost,
// because the content disposition set by the server is set to download.


Pages:
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558