Author: andrei_exadel
Date: 2008-05-14 11:49:12 -0400 (Wed, 14 May 2008)
New Revision: 8580
Modified:
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
Log:
RF-3409
Modified:
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
---
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-05-14
15:17:12 UTC (rev 8579)
+++
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-05-14
15:49:12 UTC (rev 8580)
@@ -187,7 +187,7 @@
},
clear: function() {
- this._clearInput();
+ this._clearInput();
this._clearEntry();
},
@@ -275,26 +275,39 @@
LoadWatcher = Class.create();
Object.extend(LoadWatcher.prototype, {
initialize: function(iframe, callback, viewStateUpdater) {
- this.iframe = iframe;
+ this.iframe = $(iframe.id);
this.callback = callback;
this.viewStateUpdater = viewStateUpdater;
+
this.loadObserver = function() {
if (!this.stopped) {
this.stop();
this.onload();
}
+ return false;
}.bind(this);
-
+
Event.observe(this.iframe, 'load', this.loadObserver);
- this.interval = setInterval(function() {
+ this.isError = function() {
+ try {
+ if (this.iframe.contentWindow && this.iframe.contentWindow.document) {
+ this.iframe.contentWindow.document.readyState;
+ }
+ }catch(e) {
+ return true;
+ }
+ return false;
+ }.bind(this);
+
+ this.interval = window.setInterval(function() {
if (!this.stopped) {
var loaded = false;
var error = null;
try {
- if (this.iframe.contentWindow && this.iframe.contentWindow.document) {
+ if (!Prototype.Browser.Opera && this.iframe.contentWindow &&
this.iframe.contentWindow.document) {
loaded = /complete/.test(this.iframe.contentWindow.document.readyState);
}
} catch (e) {
@@ -304,50 +317,57 @@
if (error) {
this.stop();
this.onerror();
- } else if (loaded) {
- this.stop();
- this.onload();
- }
+ }
}
- }.bind(this), 200);
+ return false;
+ }.bind(this),200);
+
},
-
+
onerror: function() {
this.callback(FileUploadEntry.UPLOAD_TRANSFER_ERROR);
},
onload: function() {
+ if (this.isError()) {
+ this.callback(FileUploadEntry.UPLOAD_TRANSFER_ERROR);
+ return;
+ }
var iframeDocument = this.iframe.contentWindow.document;
var elt = iframeDocument.getElementById('_richfaces_file_upload_stopped');
var restr =
iframeDocument.getElementById('_richfaces_file_upload_size_restricted');
var forb = iframeDocument.getElementById('_richfaces_file_upload_forbidden');
+ var state = iframeDocument.getElementById("javax.faces.ViewState");
+ if (!state && this.iframe.document) {
+ state = this.iframe.document.getElementById("javax.faces.ViewState")
+ }
+
if (elt) {
this.callback(FileUploadEntry.UPLOAD_CANCELED);
} else if (restr) {
this.callback(FileUploadEntry.UPLOAD_SIZE_ERROR);
} else if (forb) {
this.callback(FileUploadEntry.UPLOAD_SIZE_ERROR);
+ } else if (state) {
+ this.viewStateUpdater(state.value);
+ this.callback(FileUploadEntry.UPLOAD_SUCCESS);
} else {
- var state = iframeDocument.getElementById('javax.faces.ViewState');
- if (state) {
- this.viewStateUpdater(state.value);
- }
- this.callback(FileUploadEntry.UPLOAD_SUCCESS);
+ this.callback(FileUploadEntry.UPLOAD_TRANSFER_ERROR);
}
},
stop: function() {
this.stopped = true;
+ if (this.interval) {
+ window.clearInterval(this.interval);
+ this.interval = null;
+ }
+
if (this.loadObserver) {
Event.stopObserving(this.iframe, 'load', this.loadObserver);
this.loadObserver = null;
}
-
- if (this.interval) {
- clearInterval(this.interval);
- this.interval = null;
- }
}
});
@@ -596,7 +616,6 @@
if (this.runUpload) {
this.upload();
}
-
},
remove: function(entry) {
@@ -635,6 +654,7 @@
}
}
}
+ return false;
},
stop: function() {
@@ -644,6 +664,7 @@
if (this.activeEntry) {
this.activeEntry.stop();
}
+ return false;
},
clear: function(entry) {
@@ -675,6 +696,7 @@
this.setupAutoUpload();
}
this.processButtons();
+ return false;
},
processButtons: function () {
@@ -718,13 +740,13 @@
var d = $(this.id + ":upload2");
d.innerHTML = FileUploadEntry.LABELS['stop'];
d.onclick = function () {
- this.stop();
+ return this.stop();
}.bind(this);
}else {
var d = $(this.id + ":upload2");
d.innerHTML = FileUploadEntry.LABELS['upload'];;
d.onclick = function () {
- this.upload();
+ return this.upload();
}.bind(this);
}
},
Show replies by date