Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 96500c0

Browse files
committed
ENH: refs #0446. Refactor upload client code
-Use SWF uploader for IE for the simple uploader -Refactor revision upload, simple upload, and java upload javascript code -Somewhat refactor our SWF upload hooks to be more reusable
1 parent 5cf1f42 commit 96500c0

File tree

6 files changed

+633
-545
lines changed

6 files changed

+633
-545
lines changed

core/public/js/swfupload/js/handlers.js

Lines changed: 136 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -12,180 +12,181 @@ The FileProgress class is not part of SWFUpload.
1212
of the actions SWFUpload makes will show up in my application.
1313
********************** */
1414
function preLoad() {
15-
if (!this.support.loading) {
15+
if (!this.support.loading) {
1616
$('#swfuploadContent').hide();
1717
$('#jqueryFileUploadContent').show();
18-
initJqueryFileupload();
19-
return false;
20-
}
18+
this.customSettings.pageObj.initJqueryFileupload();
19+
return false;
20+
}
2121
}
22+
2223
function loadFailed() {
23-
$('#swfuploadContent').hide();
24+
$('#swfuploadContent').hide();
2425
$('#jqueryFileUploadContent').show();
25-
initJqueryFileupload();
26+
this.customSettings.pageObj.initJqueryFileupload();
2627
}
2728

2829
function fileQueued(file) {
29-
try {
30-
var progress = new FileProgress(file, this.customSettings.progressTarget);
31-
progress.setStatus("Pending...");
32-
progress.toggleCancel(true, this);
30+
try {
31+
var progress = new FileProgress(file, this.customSettings.progressTarget);
32+
progress.setStatus("Pending...");
33+
progress.toggleCancel(true, this);
3334

34-
} catch (ex) {
35-
this.debug(ex);
36-
}
35+
} catch (ex) {
36+
this.debug(ex);
37+
}
3738

3839
}
3940

4041
function fileQueueError(file, errorCode, message) {
41-
try {
42-
if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
43-
alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
44-
return;
45-
}
46-
47-
var progress = new FileProgress(file, this.customSettings.progressTarget);
48-
progress.setError();
49-
progress.toggleCancel(false);
50-
51-
switch (errorCode) {
52-
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
53-
progress.setStatus("File is too big.");
54-
this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
55-
break;
56-
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
57-
progress.setStatus("Cannot upload Zero Byte files.");
58-
this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
59-
break;
60-
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
61-
progress.setStatus("Invalid File Type.");
62-
this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
63-
break;
64-
default:
65-
if (file !== null) {
66-
progress.setStatus("Unhandled Error");
67-
}
68-
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
69-
break;
70-
}
71-
} catch (ex) {
42+
try {
43+
if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
44+
alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
45+
return;
46+
}
47+
48+
var progress = new FileProgress(file, this.customSettings.progressTarget);
49+
progress.setError();
50+
progress.toggleCancel(false);
51+
52+
switch (errorCode) {
53+
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
54+
progress.setStatus("File is too big.");
55+
this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
56+
break;
57+
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
58+
progress.setStatus("Cannot upload Zero Byte files.");
59+
this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
60+
break;
61+
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
62+
progress.setStatus("Invalid File Type.");
63+
this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
64+
break;
65+
default:
66+
if (file !== null) {
67+
progress.setStatus("Unhandled Error");
68+
}
69+
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
70+
break;
71+
}
72+
} catch (ex) {
7273
this.debug(ex);
7374
}
7475
}
7576

7677
function fileDialogComplete(numFilesSelected, numFilesQueued) {
77-
try {
78-
if (numFilesSelected > 0) {
79-
document.getElementById(this.customSettings.cancelButtonId).disabled = false;
80-
}
81-
$('#fsUploadProgress').show();
78+
try {
79+
if (numFilesSelected > 0) {
80+
document.getElementById(this.customSettings.cancelButtonId).disabled = false;
81+
}
82+
$('#fsUploadProgress').show();
8283
$('#dropFileZone').hide();
83-
/* I want auto start the upload and I can do that here */
84-
//this.startUpload();
85-
} catch (ex) {
84+
/* I want auto start the upload and I can do that here */
85+
//this.startUpload();
86+
} catch (ex) {
8687
this.debug(ex);
87-
}
88+
}
8889
}
8990

9091
function uploadStart(file) {
91-
try {
92-
/* I don't want to do any file validation or anything, I'll just update the UI and
93-
return true to indicate that the upload should start.
94-
It's important to update the UI here because in Linux no uploadProgress events are called. The best
95-
we can do is say we are uploading.
96-
*/
97-
var progress = new FileProgress(file, this.customSettings.progressTarget);
98-
progress.setStatus("Uploading...");
99-
progress.toggleCancel(true, this);
100-
}
101-
catch (ex) {}
102-
103-
return true;
92+
try {
93+
/* I don't want to do any file validation or anything, I'll just update the UI and
94+
return true to indicate that the upload should start.
95+
It's important to update the UI here because in Linux no uploadProgress events are called. The best
96+
we can do is say we are uploading.
97+
*/
98+
var progress = new FileProgress(file, this.customSettings.progressTarget);
99+
progress.setStatus("Uploading...");
100+
progress.toggleCancel(true, this);
101+
}
102+
catch (ex) {}
103+
104+
return true;
104105
}
105106

106107
function uploadProgress(file, bytesLoaded, bytesTotal) {
107-
try {
108-
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
109-
110-
var progress = new FileProgress(file, this.customSettings.progressTarget);
111-
progress.setProgress(percent);
112-
progress.setStatus("Uploading...");
113-
} catch (ex) {
114-
this.debug(ex);
115-
}
108+
try {
109+
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
110+
111+
var progress = new FileProgress(file, this.customSettings.progressTarget);
112+
progress.setProgress(percent);
113+
progress.setStatus("Uploading...");
114+
} catch (ex) {
115+
this.debug(ex);
116+
}
116117
}
117118

118119
function uploadSuccess(file, serverData) {
119-
try {
120-
var progress = new FileProgress(file, this.customSettings.progressTarget);
121-
progress.setComplete();
122-
progress.setStatus("Complete.");
123-
progress.toggleCancel(false);
124-
125-
} catch (ex) {
126-
this.debug(ex);
127-
}
120+
try {
121+
var progress = new FileProgress(file, this.customSettings.progressTarget);
122+
progress.setComplete();
123+
progress.setStatus("Complete.");
124+
progress.toggleCancel(false);
125+
126+
} catch (ex) {
127+
this.debug(ex);
128+
}
128129
}
129130

130131
function uploadError(file, errorCode, message) {
131-
try {
132-
var progress = new FileProgress(file, this.customSettings.progressTarget);
133-
progress.setError();
134-
progress.toggleCancel(false);
135-
136-
switch (errorCode) {
137-
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
138-
progress.setStatus("Upload Error: " + message);
139-
this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
140-
break;
141-
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
142-
progress.setStatus("Upload Failed.");
143-
this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
144-
break;
145-
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
146-
progress.setStatus("Server (IO) Error");
147-
this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
148-
break;
149-
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
150-
progress.setStatus("Security Error");
151-
this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
152-
break;
153-
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
154-
progress.setStatus("Upload limit exceeded.");
155-
this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
156-
break;
157-
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
158-
progress.setStatus("Failed Validation. Upload skipped.");
159-
this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
160-
break;
161-
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
162-
// If there aren't any files left (they were all cancelled) disable the cancel button
163-
if (this.getStats().files_queued === 0) {
164-
document.getElementById(this.customSettings.cancelButtonId).disabled = true;
165-
}
166-
progress.setStatus("Cancelled");
167-
progress.setCancelled();
168-
break;
169-
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
170-
progress.setStatus("Stopped");
171-
break;
172-
default:
173-
progress.setStatus("Unhandled Error: " + errorCode);
174-
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
175-
break;
176-
}
177-
} catch (ex) {
132+
try {
133+
var progress = new FileProgress(file, this.customSettings.progressTarget);
134+
progress.setError();
135+
progress.toggleCancel(false);
136+
137+
switch (errorCode) {
138+
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
139+
progress.setStatus("Upload Error: " + message);
140+
this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
141+
break;
142+
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
143+
progress.setStatus("Upload Failed.");
144+
this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
145+
break;
146+
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
147+
progress.setStatus("Server (IO) Error");
148+
this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
149+
break;
150+
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
151+
progress.setStatus("Security Error");
152+
this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
153+
break;
154+
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
155+
progress.setStatus("Upload limit exceeded.");
156+
this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
157+
break;
158+
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
159+
progress.setStatus("Failed Validation. Upload skipped.");
160+
this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
161+
break;
162+
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
163+
// If there aren't any files left (they were all cancelled) disable the cancel button
164+
if (this.getStats().files_queued === 0) {
165+
document.getElementById(this.customSettings.cancelButtonId).disabled = true;
166+
}
167+
progress.setStatus("Cancelled");
168+
progress.setCancelled();
169+
break;
170+
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
171+
progress.setStatus("Stopped");
172+
break;
173+
default:
174+
progress.setStatus("Unhandled Error: " + errorCode);
175+
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
176+
break;
177+
}
178+
} catch (ex) {
178179
this.debug(ex);
179180
}
180181
}
181182

182183
function uploadComplete(file) {
183-
if (this.getStats().files_queued === 0) {
184-
document.getElementById(this.customSettings.cancelButtonId).disabled = true;
184+
if (this.getStats().files_queued === 0) {
185+
document.getElementById(this.customSettings.cancelButtonId).disabled = true;
185186

186-
}
187+
}
187188
$('.uploadedSimple').val(parseInt($('.uploadedSimple').val())+1);
188-
updateUploadedCount();
189+
this.customSettings.pageObj.updateUploadedCount();
189190
}
190191

191192
// This event comes from the Queue Plugin

core/public/js/upload/upload.javaupload.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
var midas = midas || {};
2+
midas.upload = midas.upload || {};
3+
midas.upload.javaupload = {};
4+
5+
midas.upload.javaupload.sendParentToJavaSession = function()
6+
{
7+
$.post(json.global.webroot+'/upload/javaupload', {
8+
parent: $('#destinationId').val(),
9+
license: $('select[name=licenseSelect]:last').val()
10+
});
11+
}
12+
113
$('.browseMIDASLink').click(function() {
214
loadDialog("select","/browse/selectfolder/?policy=write");
315
showDialog('Browse', null, {
@@ -12,17 +24,17 @@ $('.destinationId').val($('#destinationId').val());
1224
$('.destinationUpload').html($('#destinationUpload').html());
1325

1426
// Save initial state to the session
15-
sendParentToJavaSession();
27+
midas.upload.javaupload.sendParentToJavaSession();
1628

1729
// Save license change to the session
1830
$('select[name=licenseSelect]:last').change(function() {
19-
sendParentToJavaSession();
31+
midas.upload.javaupload.sendParentToJavaSession();
2032
});
2133

2234
// Save parent folder to the session
2335
function folderSelectionCallback()
2436
{
25-
sendParentToJavaSession();
37+
midas.upload.javaupload.sendParentToJavaSession();
2638
}
2739

2840
midas.doCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED');

0 commit comments

Comments
 (0)