using iframe to manage upload of schemas - allows for calling an action listener once the upload is complete to validate the schema and present an error message inside the form in a pretty way.

added a small helper library for managing uploads without using a page reload.  modified uploadfileservlet to return a javascript snippet in the response body if the return-page parameter starts with javascript:

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4578 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-12-12 09:51:27 +00:00
parent cb80c75014
commit b89434674c
5 changed files with 159 additions and 51 deletions

View File

@@ -0,0 +1,50 @@
var _uploads = [];
function handle_upload_helper(fileInputElement,
uploadId,
callback,
contextPath)
{
var id = fileInputElement.getAttribute("name");
var d = fileInputElement.ownerDocument;
var iframe = d.createElement("iframe");
iframe.style.display = "none";
iframe.name = id + "upload_frame";
iframe.id = iframe.name;
document.body.appendChild(iframe);
// makes it possible to target the frame properly in ie.
window.frames[iframe.name].name = iframe.name;
_uploads[uploadId] = { path: fileInputElement.value, callback: callback };
var form = d.createElement("form");
d.body.appendChild(form);
form.style.display = "none";
form.method = "post";
form.encoding = "multipart/form-data";
form.enctype = "multipart/form-data";
form.target = iframe.name;
form.action = contextPath + "/uploadFileServlet";
form.appendChild(fileInputElement.cloneNode(true));
var id = document.createElement("input");
form.appendChild(id);
id.type = "hidden";
id.name = "upload-id";
id.value = uploadId;
var rp = document.createElement("input");
form.appendChild(rp);
rp.type = "hidden";
rp.name = "return-page";
rp.value = "javascript:window.parent.upload_complete_helper('" + uploadId + "')";
form.submit();
}
function upload_complete_helper(id)
{
var upload = _uploads[id];
upload.callback(id, upload.path);
}