- finishing off ui changes to file upload widget based on linton's updated mockups.

- 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
This commit is contained in:
Ariel Backenroth
2007-01-12 01:03:35 +00:00
parent e2915b245a
commit 7e6ad08ad8
7 changed files with 264 additions and 183 deletions

View File

@@ -350,6 +350,12 @@ public class CreateWebContentWizard extends BaseContentWizard
{ {
srcPaths.add(AVMConstants.getCorrespondingPath(rendition.getPath(), sandboxName)); srcPaths.add(AVMConstants.getCorrespondingPath(rendition.getPath(), sandboxName));
} }
for (NodeRef uploadedFile : uploadedFiles)
{
final String uploadPath = AVMNodeConverter.ToAVMVersionPath(uploadedFile).getSecond();
srcPaths.add(AVMConstants.getCorrespondingPath(uploadPath, sandboxName));
}
srcPaths.add(AVMConstants.getCorrespondingPath(this.formInstanceData.getPath(), sandboxName)); srcPaths.add(AVMConstants.getCorrespondingPath(this.formInstanceData.getPath(), sandboxName));
} }
else else
@@ -358,6 +364,7 @@ public class CreateWebContentWizard extends BaseContentWizard
srcPaths.add(AVMConstants.getCorrespondingPath(this.createdPath, sandboxName)); srcPaths.add(AVMConstants.getCorrespondingPath(this.createdPath, sandboxName));
} }
LOGGER.debug("creating workflow package with " + srcPaths.size() + " files");
final NodeRef packageNodeRef = final NodeRef packageNodeRef =
AVMWorkflowUtil.createWorkflowPackage(srcPaths, AVMWorkflowUtil.createWorkflowPackage(srcPaths,
storeId, storeId,

View File

@@ -29,8 +29,10 @@ import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -46,6 +48,7 @@ import org.alfresco.web.bean.wcm.AVMNode;
import org.alfresco.web.forms.*; import org.alfresco.web.forms.*;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
@@ -97,7 +100,7 @@ public class XFormsBean
private ChibaBean chibaBean; private ChibaBean chibaBean;
private final SchemaFormBuilder schemaFormBuilder; private final SchemaFormBuilder schemaFormBuilder;
private final HashMap<String, NodeRef> uploads = new HashMap<String, NodeRef>(); private final Set<NodeRef> uploads = new HashSet<NodeRef>();
private final List<XMLEvent> eventLog = new LinkedList<XMLEvent>(); private final List<XMLEvent> eventLog = new LinkedList<XMLEvent>();
public XFormsSession(final Document formInstanceData, public XFormsSession(final Document formInstanceData,
@@ -113,9 +116,14 @@ public class XFormsBean
baseUrl); baseUrl);
} }
public void addUpload(final NodeRef nr)
{
this.uploads.add(nr);
}
public NodeRef[] getUploadedFiles() public NodeRef[] getUploadedFiles()
{ {
return (NodeRef[])this.uploads.values().toArray(new NodeRef[0]); return (NodeRef[])this.uploads.toArray(new NodeRef[0]);
} }
public void destroy() public void destroy()
@@ -172,14 +180,6 @@ public class XFormsBean
this.avmBrowseBean = avmBrowseBean; this.avmBrowseBean = avmBrowseBean;
} }
/**
* @param nodeService the nodeService to set.
*/
public void setNodeService(final NodeService nodeService)
{
this.nodeService = nodeService;
}
/** /**
* @param avmService the avmService to set. * @param avmService the avmService to set.
*/ */
@@ -509,15 +509,21 @@ public class XFormsBean
String uploadId = null; String uploadId = null;
String currentPath = null; String currentPath = null;
String filename = null; String filename = null;
String returnPage = null;
InputStream fileInputStream = null; InputStream fileInputStream = null;
for (FileItem item : fileItems) for (FileItem item : fileItems)
{ {
LOGGER.debug("item = " + item); LOGGER.debug("item = " + item);
if (item.isFormField() && item.getFieldName().equals("id")) if (item.isFormField() && item.getFieldName().equals("upload-id"))
{ {
uploadId = item.getString(); uploadId = item.getString();
LOGGER.debug("uploadId is " + uploadId); LOGGER.debug("uploadId is " + uploadId);
} }
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
returnPage = item.getString();
LOGGER.debug("returnPage is " + returnPage);
}
else if (item.isFormField() && item.getFieldName().equals("currentPath")) else if (item.isFormField() && item.getFieldName().equals("currentPath"))
{ {
final String previewStorePath = final String previewStorePath =
@@ -529,39 +535,37 @@ public class XFormsBean
} }
else else
{ {
filename = item.getName(); filename = FilenameUtils.getName(item.getName());
int idx = filename.lastIndexOf('\\');
if (idx == -1)
{
idx = filename.lastIndexOf('/');
}
if (idx != -1)
{
filename = filename.substring(idx + File.separator.length());
}
fileInputStream = item.getInputStream(); fileInputStream = item.getInputStream();
LOGGER.debug("parsed file " + filename); LOGGER.debug("uploading file " + filename);
} }
} }
LOGGER.debug("saving file " + filename + " to " + currentPath); LOGGER.debug("saving file " + filename + " to " + currentPath);
FileCopyUtils.copy(fileInputStream, try
this.avmService.createFile(currentPath, filename)); {
FileCopyUtils.copy(fileInputStream,
this.avmService.createFile(currentPath, filename));
final Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(2, 1.0f);
props.put(ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, filename));
props.put(ContentModel.PROP_DESCRIPTION,
new PropertyValue(DataTypeDefinition.TEXT,
"Uploaded for form " + this.xformsSession.getForm().getName()));
this.avmService.setNodeProperties(currentPath + "/" + filename, props);
this.avmService.addAspect(currentPath + "/" + filename, ContentModel.ASPECT_TITLED);
this.xformsSession.addUpload(AVMNodeConverter.ToNodeRef(-1, currentPath + "/" + filename));
returnPage = returnPage.replace("${_FILE_TYPE_IMAGE}",
Utils.getFileTypeImage(facesContext, filename, true));
}
catch (Exception e)
{
LOGGER.debug(e.getMessage(), e);
returnPage = returnPage.replace("${_UPLOAD_ERROR}", e.getMessage());
}
final NodeRef uploadNodeRef = LOGGER.debug("upload complete. sending response: " + returnPage);
AVMNodeConverter.ToNodeRef(-1, currentPath + "/" + filename);
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(ContentModel.PROP_TITLE, filename);
props.put(ContentModel.PROP_DESCRIPTION,
"Uploaded for form " + this.xformsSession.getForm().getName());
this.nodeService.addAspect(uploadNodeRef,
ContentModel.ASPECT_TITLED,
props);
this.xformsSession.uploads.put(uploadId, uploadNodeRef);
LOGGER.debug("upload complete. sending response");
final Document result = XMLUtil.newDocument(); final Document result = XMLUtil.newDocument();
final Element htmlEl = result.createElement("html"); final Element htmlEl = result.createElement("html");
result.appendChild(htmlEl); result.appendChild(htmlEl);
@@ -571,9 +575,7 @@ public class XFormsBean
final Element scriptEl = result.createElement("script"); final Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl); bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript"); scriptEl.setAttribute("type", "text/javascript");
final Node scriptText = final Node scriptText = result.createTextNode(returnPage);
result.createTextNode("window.parent.FilePickerWidget." +
"_upload_completeHandler('" + uploadId + "');");
scriptEl.appendChild(scriptText); scriptEl.appendChild(scriptText);
final ResponseWriter out = facesContext.getResponseWriter(); final ResponseWriter out = facesContext.getResponseWriter();

View File

@@ -54,7 +54,8 @@ public class XFormsProcessor
"/scripts/ajax/dojo/" + (LOGGER.isDebugEnabled() "/scripts/ajax/dojo/" + (LOGGER.isDebugEnabled()
? "dojo.js.uncompressed.js" ? "dojo.js.uncompressed.js"
: "dojo.js"), : "dojo.js"),
"/scripts/ajax/xforms.js" "/scripts/ajax/xforms.js",
"/scripts/upload_helper.js",
}; };

View File

@@ -3158,10 +3158,6 @@
<property-name>avmService</property-name> <property-name>avmService</property-name>
<value>#{AVMService}</value> <value>#{AVMService}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>nodeService</property-name>
<value>#{NodeService}</value>
</managed-property>
<managed-property> <managed-property>
<property-name>avmBrowseBean</property-name> <property-name>avmBrowseBean</property-name>
<value>#{AVMBrowseBean}</value> <value>#{AVMBrowseBean}</value>

View File

@@ -85,7 +85,6 @@
{ {
padding: 2px; padding: 2px;
border: 1px solid #003366; border: 1px solid #003366;
font-weight: bold;
margin: 2px 5%; margin: 2px 5%;
text-align: center; text-align: center;
text-overflow: ellipsis; text-overflow: ellipsis;

View File

@@ -263,7 +263,8 @@ dojo.declare("alfresco.xforms.FilePicker",
dojo.html.prependClass(this.domNode, "xformsFilePicker"); dojo.html.prependClass(this.domNode, "xformsFilePicker");
attach_point.appendChild(this.domNode); attach_point.appendChild(this.domNode);
//XXXarielb support readonly and disabled //XXXarielb support readonly and disabled
this.widget = new FilePickerWidget(this.domNode, this.widget = new FilePickerWidget(this.id,
this.domNode,
this.getInitialValue(), this.getInitialValue(),
false, false,
this._filePicker_changeHandler, this._filePicker_changeHandler,
@@ -2222,8 +2223,9 @@ if (!Array.prototype.indexOf)
} }
} }
function FilePickerWidget(node, value, readonly, change_callback, resize_callback) function FilePickerWidget(uploadId, node, value, readonly, change_callback, resize_callback)
{ {
this.uploadId = uploadId;
this.node = node; this.node = node;
this.value = value == null || value.length == 0 ? null : value; this.value = value == null || value.length == 0 ? null : value;
this.readonly = readonly || false; this.readonly = readonly || false;
@@ -2234,56 +2236,28 @@ function FilePickerWidget(node, value, readonly, change_callback, resize_callbac
FilePickerWidget._uploads = []; FilePickerWidget._uploads = [];
FilePickerWidget._handleUpload = function(id, fileInput, webappRelativePath, widget) FilePickerWidget._handleUpload = function(id, fileInput, webappRelativePath, widget)
{ {
id = id.substring(0, id.indexOf("-widget"));
var d = fileInput.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[id + "_upload_frame"].name = iframe.name;
FilePickerWidget._uploads[id] = FilePickerWidget._uploads[id] =
{ {
widget:widget, widget:widget,
path: fileInput.value, path: fileInput.value,
webappRelativePath: webappRelativePath, webappRelativePath: webappRelativePath
fileName: fileInput.value.substring(fileInput.value.lastIndexOf("/") + 1)
}; };
var form = document.createElement("form"); handle_upload_helper(fileInput,
form.style.display = "none"; id,
d.body.appendChild(form); FilePickerWidget._upload_completeHandler,
form.id = id + "_upload_form"; alfresco_xforms_constants.WEBAPP_CONTEXT,
form.name = form.id; "/ajax/invoke/XFormsBean.uploadFile",
form.method = "post"; { currentPath: webappRelativePath });
form.encoding = "multipart/form-data";
form.enctype = "multipart/form-data";
form.target = iframe.name;
form.action = alfresco_xforms_constants.WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.uploadFile";
form.appendChild(fileInput.cloneNode(true));
var rp = d.createElement("input");
rp.type = "hidden";
rp.name = "id";
rp.value = id;
form.appendChild(rp);
var rp = d.createElement("input");
rp.name = "currentPath";
rp.value = webappRelativePath;
rp.type = "hidden";
form.appendChild(rp);
form.submit();
} }
FilePickerWidget._upload_completeHandler = function(id) FilePickerWidget._upload_completeHandler = function(id, path, fileName, fileTypeImage, error)
{ {
var upload = FilePickerWidget._uploads[id]; var upload = FilePickerWidget._uploads[id];
upload.widget._upload_completeHandler(upload.fileName, upload.widget._upload_completeHandler(fileName,
upload.webappRelativePath); upload.webappRelativePath,
fileTypeImage,
error);
} }
FilePickerWidget.prototype = { FilePickerWidget.prototype = {
@@ -2317,14 +2291,20 @@ render: function()
{ {
this._showSelectedValue(); this._showSelectedValue();
}, },
_showStatus: function(text) _showStatus: function(text, isError)
{ {
var d = this.node.ownerDocument; var d = this.node.ownerDocument;
if (!this.statusDiv || !this.statusDiv.parentNode) if (!this.statusDiv || !this.statusDiv.parentNode)
{ {
this.statusDiv = d.createElement("div"); this.statusDiv = d.createElement("div");
this.statusDiv.setAttribute("id", this.uploadId + "-status");
this.statusDiv.widget = this;
this.node.insertBefore(this.statusDiv, this.node.firstChild); this.node.insertBefore(this.statusDiv, this.node.firstChild);
dojo.html.setClass(this.statusDiv, "infoText xformsFilePickerStatus"); dojo.html.setClass(this.statusDiv, "infoText xformsFilePickerStatus");
if (isError)
{
dojo.html.addClass(this.statusDiv, "statusErrorText");
}
this.statusDiv.appendChild(d.createTextNode(text)); this.statusDiv.appendChild(d.createTextNode(text));
this.node.style.height = (parseInt(this.node.style.height) + this.node.style.height = (parseInt(this.node.style.height) +
dojo.style.getMarginHeight(this.statusDiv) + dojo.style.getMarginHeight(this.statusDiv) +
@@ -2335,22 +2315,38 @@ _showStatus: function(text)
{ {
this.statusDiv.firstChild.nodeValue = text; this.statusDiv.firstChild.nodeValue = text;
} }
setTimeout("var _status = document.getElementById('" + this.uploadId +
"-status'); if (_status && _status) { _status.widget._hideStatus(); }", 5000);
}, },
_hideStatus: function() _hideStatus: function()
{ {
if (this.statusDiv) if (this.statusDiv)
{ {
this.node.style.height = (parseInt(this.node.style.height) - var anim = dojo.lfx.html.fadeOut(this.statusDiv, 500);
this.statusDiv.offsetHeight) + "px"; var _fp_widget = this;
dojo.dom.removeChildren(this.statusDiv); anim.onEnd = function()
dojo.dom.removeNode(this.statusDiv); {
this.resize_callback(this); if (_fp_widget.statusDiv && _fp_widget.statusDiv.parentNode)
{
_fp_widget.node.style.height = (parseInt(_fp_widget.node.style.height) -
_fp_widget.statusDiv.offsetHeight) + "px";
dojo.dom.removeChildren(_fp_widget.statusDiv);
dojo.dom.removeNode(_fp_widget.statusDiv);
_fp_widget.resize_callback(_fp_widget);
_fp_widget.statusDiv = null;
}
};
anim.play();
} }
}, },
_showSelectedValue: function() _showSelectedValue: function()
{ {
var d = this.node.ownerDocument; var d = this.node.ownerDocument;
dojo.dom.removeChildren(this.node); dojo.dom.removeChildren(this.node);
this.statusDiv = null;
this.contentDiv = null;
this.addContentDiv = null;
this.node.style.height = "20px"; this.node.style.height = "20px";
this.node.style.lineHeight = this.node.style.height; this.node.style.lineHeight = this.node.style.height;
@@ -2418,6 +2414,7 @@ _showPicker: function(data)
parseInt(this.statusDiv.style.marginTop) + parseInt(this.statusDiv.style.marginTop) +
parseInt(this.statusDiv.style.marginBottom)) parseInt(this.statusDiv.style.marginBottom))
: 0) + "px"); : 0) + "px");
this.resize_callback(this); this.resize_callback(this);
var currentPath = data.getElementsByTagName("current-node")[0]; var currentPath = data.getElementsByTagName("current-node")[0];
@@ -2492,8 +2489,15 @@ _showPicker: function(data)
"onclick", "onclick",
function(event) function(event)
{ {
var t = event.target; var w = event.target.filePickerWidget;
t.filePickerWidget._showAddContentPanel(t, t.getAttribute("webappRelativePath")); if (w.addContentDiv)
{
w._hideAddContent();
}
else
{
w._showAddContent(event.target.getAttribute("webappRelativePath"));
}
}); });
var addContentImage = d.createElement("img"); var addContentImage = d.createElement("img");
@@ -2562,12 +2566,11 @@ _showPicker: function(data)
var w = event.target.filePickerWidget; var w = event.target.filePickerWidget;
w._showSelectedValue(); w._showSelectedValue();
}); });
this.contentDiv.style.height = (this.node.offsetHeight - this.contentDiv.style.height = (this.node.offsetHeight -
(this.statusDiv ? this.statusDiv.offsetHeight : 0) - (this.statusDiv ? this.statusDiv.offsetHeight : 0) -
footerDiv.offsetHeight - footerDiv.offsetHeight -
headerDiv.offsetHeight - 10) + "px"; headerDiv.offsetHeight - 10) + "px";
// this.contentDiv.style.overflowY = "auto";
var childNodes = data.getElementsByTagName("child-node"); var childNodes = data.getElementsByTagName("child-node");
for (var i = 0; i < childNodes.length; i++) for (var i = 0; i < childNodes.length; i++)
{ {
@@ -2575,85 +2578,107 @@ _showPicker: function(data)
{ {
continue; continue;
} }
var path = childNodes[i].getAttribute("webappRelativePath"); var webappRelativePath = childNodes[i].getAttribute("webappRelativePath");
var name = path.replace(/.*\/([^/]+)/, "$1"); var fileName = webappRelativePath.replace(/.*\/([^/]+)/, "$1");
var row = this._createRow(fileName,
var row = d.createElement("div"); webappRelativePath,
row.setAttribute("id", name + "-row"); childNodes[i].getAttribute("type") == "directory",
childNodes[i].getAttribute("image"),
"xformsRow" + (i % 2 ? "Even" : "Odd"));
this.contentDiv.appendChild(row); this.contentDiv.appendChild(row);
row.rowIndex = i; }
dojo.html.setClass(row, "xformsFilePickerRow xformsRow" + (row.rowIndex % 2 ? "Even" : "Odd")); },
dojo.event.browser.addListener(row, _createRow: function(fileName, webappRelativePath, isDirectory, fileTypeImage, rowClass)
"mouseover", {
function(event) var d = this.contentDiv.ownerDocument;
{ var result = d.createElement("div");
var prevHover = event.currentTarget.parentNode.hoverNode; result.setAttribute("id", fileName + "-row");
if (prevHover)
{
dojo.html.removeClass(prevHover, "xformsRowHover");
}
event.currentTarget.parentNode.hoverNode = event.currentTarget;
dojo.html.addClass(event.currentTarget, "xformsRowHover")
},
true);
dojo.event.browser.addListener(row,
"mouseout",
function(event)
{
if (event.relatedTarget &&
event.relatedTarget.parentNode == event.currentTarget)
{
return true;
}
dojo.html.removeClass(event.currentTarget, "xformsRowHover");
},
true);
var e = d.createElement("img");
e.align = "absmiddle";
e.style.margin = "0px 4px 0px 4px";
e.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + childNodes[i].getAttribute("image"));
row.appendChild(e);
if (childNodes[i].getAttribute("type") == "directory") dojo.html.setClass(result, "xformsFilePickerRow " + rowClass);
{ dojo.event.browser.addListener(result,
e = d.createElement("a"); "mouseover",
e.filePickerWidget = this; function(event)
e.setAttribute("href", "javascript:void(0)"); {
e.setAttribute("webappRelativePath", path); var prevHover = event.currentTarget.parentNode.hoverNode;
dojo.event.connect(e, "onclick", function(event) if (prevHover)
{ {
var w = event.target.filePickerWidget; dojo.html.removeClass(prevHover, "xformsRowHover");
w._navigateToNode(event.target.getAttribute("webappRelativePath")); }
return true; event.currentTarget.parentNode.hoverNode = event.currentTarget;
}); dojo.html.addClass(event.currentTarget, "xformsRowHover");
e.appendChild(d.createTextNode(name)); },
row.appendChild(e); true);
} dojo.event.browser.addListener(result,
else "mouseout",
{ function(event)
row.appendChild(d.createTextNode(name)); {
} if (event.relatedTarget &&
event.relatedTarget.parentNode == event.currentTarget)
{
return true;
}
dojo.html.removeClass(event.currentTarget, "xformsRowHover");
},
true);
var e = d.createElement("img");
e.align = "absmiddle";
e.style.margin = "0px 4px 0px 4px";
e.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + fileTypeImage);
result.appendChild(e);
e = d.createElement("input"); if (isDirectory)
{
e = d.createElement("a");
e.filePickerWidget = this; e.filePickerWidget = this;
e.type = "button"; e.setAttribute("href", "javascript:void(0)");
e.name = path; e.setAttribute("webappRelativePath", webappRelativePath);
e.value = "Select";
row.appendChild(e);
e.style.position = "absolute";
e.style.right = "10px";
e.style.top = (.5 * row.offsetHeight) - (.5 * e.offsetHeight) + "px";
dojo.event.connect(e, "onclick", function(event) dojo.event.connect(e, "onclick", function(event)
{ {
var w = event.target.filePickerWidget; var w = event.target.filePickerWidget;
w.setValue(event.target.name); w._navigateToNode(event.target.getAttribute("webappRelativePath"));
w._showSelectedValue(); return true;
}); });
e.appendChild(d.createTextNode(fileName));
result.appendChild(e);
}
else
{
result.appendChild(d.createTextNode(fileName));
}
e = d.createElement("input");
e.filePickerWidget = this;
e.type = "button";
e.name = webappRelativePath;
e.value = "Select";
result.appendChild(e);
e.style.position = "absolute";
e.style.right = "10px";
e.style.top = (.5 * result.offsetHeight) - (.5 * e.offsetHeight) + "px";
dojo.event.connect(e, "onclick", function(event)
{
var w = event.target.filePickerWidget;
w.setValue(event.target.name);
w._showSelectedValue();
});
return result;
},
_hideAddContent: function()
{
if (this.addContentDiv)
{
dojo.dom.removeChildren(this.addContentDiv);
dojo.dom.removeNode(this.addContentDiv);
this.addContentDiv = null;
} }
}, },
_showAddContentPanel: function(addContentLink, currentPath) _showAddContent: function(currentPath)
{ {
if (this.addContentDiv)
{
return;
}
var d = this.node.ownerDocument; var d = this.node.ownerDocument;
this.addContentDiv = d.createElement("div"); this.addContentDiv = d.createElement("div");
dojo.html.setClass(this.addContentDiv, "xformsFilePickerAddContent"); dojo.html.setClass(this.addContentDiv, "xformsFilePickerAddContent");
@@ -2676,7 +2701,7 @@ _showAddContentPanel: function(addContentLink, currentPath)
var fileInput = d.createElement("input"); var fileInput = d.createElement("input");
fileInput.type = "file"; fileInput.type = "file";
fileInput.widget = this; fileInput.widget = this;
fileInput.name = this.node.getAttribute("id") + "_file_input"; fileInput.name = this.uploadId + "_file_input";
fileInput.size = "35"; fileInput.size = "35";
fileInput.setAttribute("webappRelativePath", currentPath); fileInput.setAttribute("webappRelativePath", currentPath);
fileInputDiv.appendChild(fileInput); fileInputDiv.appendChild(fileInput);
@@ -2689,22 +2714,53 @@ _showAddContentPanel: function(addContentLink, currentPath)
function(event) function(event)
{ {
var w = event.target.widget; var w = event.target.widget;
FilePickerWidget._handleUpload(w.node.getAttribute("id"), if (w.addContentDiv)
{
var d = w.addContentDiv.ownerDocument;
dojo.dom.removeChildren(w.addContentDiv);
var fileName = event.target.value.replace(/.*[\/\\]([^\/\\]+)/, "$1");
w.addContentDiv.appendChild(d.createTextNode("Upload: " + fileName));
var img = d.createElement("img");
img.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT +
"/images/icons/process_animation.gif");
img.style.position = "absolute";
img.style.right = "10px";
img.style.height = (.5 * w.addContentDiv.offsetHeight) + "px";
img.style.top = (.25 * w.addContentDiv.offsetHeight) + "px";
w.addContentDiv.appendChild(img);
}
FilePickerWidget._handleUpload(w.uploadId,
event.target, event.target,
event.target.getAttribute("webappRelativePath"), event.target.getAttribute("webappRelativePath"),
w); w);
if (w.addContentDiv)
{
dojo.dom.removeChildren(w.addContentDiv);
dojo.dom.removeNode(w.addContentDiv);
w.addContentDiv = null;
}
}); });
}, },
_upload_completeHandler: function(fileName, webappRelativePath) _upload_completeHandler: function(fileName, webappRelativePath, fileTypeImage, error)
{ {
this._showStatus("Successfully uploaded " + fileName + "."); // " into " + webappRelativePath); if (error)
this._navigateToNode(webappRelativePath); {
this._showStatus(error, true);
this._hideAddContent();
this._showAddContent(webappRelativePath);
}
else
{
var nextRow = dojo.dom.nextElement(this.addContentDiv);
var rowClass = (nextRow
? ("xformsRow" + (dojo.html.hasClass(nextRow, "xformsRowEven")
? "Odd"
: "Even"))
: "xformsRowEvent");
var row = this._createRow(fileName,
webappRelativePath == "/" ? "/" + fileName : webappRelativePath + "/" + fileName,
false,
fileTypeImage,
rowClass);
this.contentDiv.replaceChild(row, this.addContentDiv);
this.addContentDiv = null;
}
}, },
_closeParentPathMenu: function() _closeParentPathMenu: function()
{ {
@@ -2796,7 +2852,8 @@ _openParentPathMenu: function(target, path)
parentNodeImage.align = "absmiddle"; parentNodeImage.align = "absmiddle";
parentNodeImage.style.marginRight = "4px"; parentNodeImage.style.marginRight = "4px";
parentNodeDiv.appendChild(parentNodeImage); parentNodeDiv.appendChild(parentNodeImage);
parentNodeImage.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/space_small.gif"); parentNodeImage.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT +
"/images/icons/space_small.gif");
parentNodeDiv.appendChild(parentNodeImage); parentNodeDiv.appendChild(parentNodeImage);
parentNodeDiv.appendChild(d.createTextNode(path)); parentNodeDiv.appendChild(d.createTextNode(path));
dojo.event.connect(parentNodeDiv, dojo.event.connect(parentNodeDiv,

View File

@@ -3,7 +3,9 @@ var _uploads = [];
function handle_upload_helper(fileInputElement, function handle_upload_helper(fileInputElement,
uploadId, uploadId,
callback, callback,
contextPath) contextPath,
actionUrl,
params)
{ {
var id = fileInputElement.getAttribute("name"); var id = fileInputElement.getAttribute("name");
var d = fileInputElement.ownerDocument; var d = fileInputElement.ownerDocument;
@@ -20,12 +22,15 @@ function handle_upload_helper(fileInputElement,
var form = d.createElement("form"); var form = d.createElement("form");
d.body.appendChild(form); d.body.appendChild(form);
form.id = id + "_upload_form";
form.name = form.id;
form.style.display = "none"; form.style.display = "none";
form.method = "post"; form.method = "post";
form.encoding = "multipart/form-data"; form.encoding = "multipart/form-data";
form.enctype = "multipart/form-data"; form.enctype = "multipart/form-data";
form.target = iframe.name; form.target = iframe.name;
form.action = contextPath + "/uploadFileServlet"; actionUrl = actionUrl || "/uploadFileServlet";
form.action = contextPath + actionUrl;
form.appendChild(fileInputElement); form.appendChild(fileInputElement);
var id = document.createElement("input"); var id = document.createElement("input");
@@ -34,17 +39,31 @@ function handle_upload_helper(fileInputElement,
id.name = "upload-id"; id.name = "upload-id";
id.value = uploadId; 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"); var rp = document.createElement("input");
rp.type = "hidden"; rp.type = "hidden";
form.appendChild(rp); form.appendChild(rp);
rp.name = "return-page"; rp.name = "return-page";
rp.value = "javascript:window.parent.upload_complete_helper('" + uploadId + "')"; rp.value = "javascript:window.parent.upload_complete_helper('" + uploadId +
"',{error: '${_UPLOAD_ERROR}', fileTypeImage: '${_FILE_TYPE_IMAGE}'})";
form.submit(); form.submit();
} }
function upload_complete_helper(id) function upload_complete_helper(id, args)
{ {
var upload = _uploads[id]; var upload = _uploads[id];
upload.callback(id, upload.path, upload.path.replace(/.*[\/\\]([^\/\\]+)/, "$1")); upload.callback(id,
upload.path,
upload.path.replace(/.*[\/\\]([^\/\\]+)/, "$1"),
args.fileTypeImage,
args.error != "${_UPLOAD_ERROR}" ? args.error : null);
} }