Menu

[r707]: / swfupload / trunk / demos / formsdemo / js / handlers.js  Maximize  Restore  History

Download this file

234 lines (203 with data), 8.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
function swfUploadLoaded() {
var btnSubmit = document.getElementById("btnSubmit");
var txtLastName = document.getElementById("lastname");
var txtFirstName = document.getElementById("firstname");
var txtEducation = document.getElementById("education");
var txtReferences = document.getElementById("references");
btnSubmit.onclick = doSubmit;
btnSubmit.disabled = true;
txtLastName.onchange = validateForm;
txtFirstName.onchange = validateForm;
txtEducation.onchange = validateForm;
txtReferences.onchange = validateForm;
validateForm();
}
function validateForm() {
var txtLastName = document.getElementById("lastname");
var txtFirstName = document.getElementById("firstname");
var txtEducation = document.getElementById("education");
var txtFileName = document.getElementById("txtFileName");
var txtReferences = document.getElementById("references");
var is_valid = true;
if (txtLastName.value === "") {
is_valid = false;
}
if (txtFirstName.value === "") {
is_valid = false;
}
if (txtEducation.value === "") {
is_valid = false;
}
if (txtFileName.value === "") {
is_valid = false;
}
if (txtReferences.value === "") {
is_valid = false;
}
document.getElementById("btnSubmit").disabled = !is_valid;
}
function fileBrowse() {
var txtFileName = document.getElementById("txtFileName");
txtFileName.value = "";
this.cancelUpload();
this.selectFile();
}
// Called by the submit button to start the upload
function doSubmit(e) {
e = e || window.event;
if (e.stopPropagation) {
e.stopPropagation();
}
e.cancelBubble = true;
try {
swfu.startUpload();
} catch (ex) {
}
return false;
}
// Called by the queue complete handler to submit the form
function uploadDone() {
try {
document.forms[0].submit();
} catch (ex) {
alert("Error submitting form");
}
}
function fileQueueError(file, errorCode, message) {
try {
// Handle this error separately because we don't want to create a FileProgress element for it.
switch (errorCode) {
case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
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.")));
return;
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
alert("The file you selected is too big.");
this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
alert("The file you selected is empty. Please select another file.");
this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
alert("The file you choose is not an allowed file type.");
this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
default:
alert("An error occurred in the upload. Try again later.");
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
}
} catch (e) {
}
}
function fileQueued(file) {
try {
var txtFileName = document.getElementById("txtFileName");
txtFileName.value = file.name;
} catch (e) {
}
}
function fileDialogComplete(numFilesSelected, numFilesQueued) {
validateForm();
}
function uploadProgress(file, bytesLoaded, bytesTotal) {
try {
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
file.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file
var progress = new FileProgress(file, this.customSettings.progress_target);
progress.SetProgress(percent);
progress.SetStatus("Uploading...");
} catch (e) {
}
}
function uploadSuccess(file, serverData) {
try {
file.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file
var progress = new FileProgress(file, this.customSettings.progress_target);
progress.SetComplete();
progress.SetStatus("Complete.");
progress.ToggleCancel(false);
if (serverData === " ") {
this.customSettings.upload_successful = false;
} else {
this.customSettings.upload_successful = true;
document.getElementById("hidFileID").value = serverData;
}
} catch (e) {
}
}
function uploadComplete(file) {
try {
if (this.customSettings.upload_successful) {
document.getElementById("btnBrowse").disabled = "true";
uploadDone();
} else {
file.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file
var progress = new FileProgress(file, this.customSettings.progress_target);
progress.SetError();
progress.SetStatus("File rejected");
progress.ToggleCancel(false);
var txtFileName = document.getElementById("txtFileName");
txtFileName.value = "";
validateForm();
alert("There was a problem with the upload.\nThe server did not accept it.");
}
} catch (e) {
}
}
function uploadError(file, errorCode, message) {
try {
var txtFileName = document.getElementById("txtFileName");
txtFileName.value = "";
validateForm();
// Handle this error separately because we don't want to create a FileProgress element for it.
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
alert("There was a configuration error. You will not be able to upload a resume at this time.");
this.debug("Error Code: No backend file, File name: " + file.name + ", Message: " + message);
return;
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
alert("You may only upload 1 file.");
this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
break;
default:
alert("An error occurred in the upload. Try again later.");
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
return;
}
file.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file
var progress = new FileProgress(file, this.customSettings.progress_target);
progress.SetError();
progress.ToggleCancel(false);
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
progress.SetStatus("Upload Error");
this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
progress.SetStatus("Upload Failed.");
this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
progress.SetStatus("Server (IO) Error");
this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
progress.SetStatus("Security Error");
this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
progress.SetStatus("Upload Cancelled");
this.debug("Error Code: Upload Cancelled, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
progress.SetStatus("Upload Stopped");
this.debug("Error Code: Upload Stopped, File name: " + file.name + ", Message: " + message);
break;
}
} catch (ex) {
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.