mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- fixing various upload related bugs (resize issue, not handling file exists exception, not attaching uploaded files to workflow, loosing some of the uploaded files, and probably some more). - reusing upload_helper.js code from xforms.js. added facility for having the javascript return page return an error and file type image to support xform - doesn't effect other usages (create form). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4800 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
var _uploads = [];
|
|
|
|
function handle_upload_helper(fileInputElement,
|
|
uploadId,
|
|
callback,
|
|
contextPath,
|
|
actionUrl,
|
|
params)
|
|
{
|
|
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.id = id + "_upload_form";
|
|
form.name = form.id;
|
|
form.style.display = "none";
|
|
form.method = "post";
|
|
form.encoding = "multipart/form-data";
|
|
form.enctype = "multipart/form-data";
|
|
form.target = iframe.name;
|
|
actionUrl = actionUrl || "/uploadFileServlet";
|
|
form.action = contextPath + actionUrl;
|
|
form.appendChild(fileInputElement);
|
|
|
|
var id = document.createElement("input");
|
|
id.type = "hidden";
|
|
form.appendChild(id);
|
|
id.name = "upload-id";
|
|
id.value = uploadId;
|
|
|
|
for (var i in params)
|
|
{
|
|
var p = document.createElement("input");
|
|
p.type = "hidden";
|
|
form.appendChild(p);
|
|
id.name = i;
|
|
id.value = params[i];
|
|
}
|
|
|
|
var rp = document.createElement("input");
|
|
rp.type = "hidden";
|
|
form.appendChild(rp);
|
|
rp.name = "return-page";
|
|
rp.value = "javascript:window.parent.upload_complete_helper('" + uploadId +
|
|
"',{error: '${_UPLOAD_ERROR}', fileTypeImage: '${_FILE_TYPE_IMAGE}'})";
|
|
|
|
form.submit();
|
|
}
|
|
|
|
function upload_complete_helper(id, args)
|
|
{
|
|
var upload = _uploads[id];
|
|
upload.callback(id,
|
|
upload.path,
|
|
upload.path.replace(/.*[\/\\]([^\/\\]+)/, "$1"),
|
|
args.fileTypeImage,
|
|
args.error != "${_UPLOAD_ERROR}" ? args.error : null);
|
|
}
|