08-29-2012 12:53 PM
onExampleFileUpload: function DLTB_onExampleFileUpload(e, p_obj)
{
//get the noderef of the current folder
var destination = this.doclistMetadata.parent.nodeRef;
//this url call the upload-content.post.js webscript
var actionUrl = YAHOO.lang.substitute(Alfresco.constants.PROXY_URI + "example/upload-content/{uri}",
{
uri: this.doclistMetadata.parent.nodeRef.replace(":/", "")
});
//make the filedata a mandatory field
var doSetupFormsValidation = function DLTB_oNF_doSetupFormsValidation(p_form)
{
// Validation
// filedata: mandatory value
p_form.addValidation(this.id + "-uploadContent-filedata", Alfresco.forms.validation.mandatory, null, "change");
p_form.setShowSubmitStateDynamically(true, false);
};
this.modules.uploadContent = new Alfresco.module.SimpleDialog(this.id + "-uploadContent").setOptions(
{
width: "30em",
//call the uploadexamplecontent.get.html.ftl webscript wich return the html form
templateUrl: Alfresco.constants.URL_SERVICECONTEXT + "modules/documentlibrary/upload-examplecontent",
actionUrl: actionUrl,
doSetupFormsValidation:
{
fn: doSetupFormsValidation,
scope: this
},
firstFocus: this.id + "-uploadContent-title",
// I need to go in this method
onSuccess:
{
fn: function DLTB_onUploadContent_callback(response)
{
var node = response.json.item;
YAHOO.Bubbling.fire("nodeCreated",
{
name: node.name,
parentNodeRef: destination,
highlightFile: node.name
});
Alfresco.util.PopupManager.displayMessage(
{
text: this.msg("message.new-content.success", node.name)
});
},
scope: this
},
//this one too, but less often
onFailure:
{
fn: function DLTB_onUploadContent_failure(response)
{
Alfresco.util.PopupManager.displayMessage(
{
text: this.msg("message.new-content.failure")
});
},
scope: this
}
});
this.modules.uploadContent.show();
}
<#assign el=args.htmlid?html>
<div id="${el}-dialog" class="upload-content">
<div id="${el}-dialogTitle" class="hd">${msg("title")}</div>
<div class="bd">
<form id="${el}-form" action="" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<div class="yui-g">
<h2 id="${el}-dialogHeader">${msg("header")}</h2>
</div>
<div class="yui-gd">
<div class="yui-u first"><label for="${el}-title">${msg("label.title")}:</label></div>
<div class="yui-u"><input id="${el}-title" type="text" name="title" tabindex="0" /></div>
</div>
<div class="yui-gd">
<div class="yui-u first"><label for="${el}-description">${msg("label.description")}:</label></div>
<div class="yui-u"><textarea id="${el}-description" name="description" rows="3" cols="20" tabindex="0" ></textarea></div>
</div>
<div class="yui-gd">
<div class="yui-u first"><label for="${el}-filedata">${msg("label.filedata")}:</label></div>
<div class="yui-u"><input type="file" id="${el}-filedata" name="filedata" tabindex="0" /></div>
</div>
<div class="bdft">
<input type="submit" id="${el}-ok" value="${msg("button.ok")}" tabindex="0" />
<input type="button" id="${el}-cancel" value="${msg("button.cancel")}" tabindex="0" />
</div>
</form>
</div>
</div>
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/parse-args.lib.js">
function exitUpload(statusCode, statusMsg)
{
status.code = statusCode;
status.message = statusMsg;
status.redirect = true;
formdata.cleanup();
}
function main()
{
try
{
// Use helper function to get the arguments
var parsedArgs = ParseArgs.getParsedArgs();
if (parsedArgs === null)
{
status.setCode(500, msg);
return;
}
parsedArgs.pathNode = ParseArgs.resolveNode(parsedArgs.nodeRef);
var filename = null;
var content = null;
var title = "";
var description = "";
// locate file attributes
for each (field in formdata.fields)
{
if (field.name == "title")
{
title = field.value;
}
else if (field.name == "description")
{
description = field.value;
}
else if (field.name == "filedata" && field.isFile)
{
filename = field.filename;
content = field.content;
}
}
if (filename == undefined || content == undefined)
{
status.code = 400;
status.message = "Uploaded file cannot be located in request";
status.redirect = true;
}
else
{
// create document in company home for uploaded file
upload = parsedArgs.pathNode.createFile("upload" + parsedArgs.pathNode.children.length + "_" + filename) ;
upload.specializeType("example:content");
upload.properties.content.write(content);
upload.properties.content.setEncoding("UTF-8");
upload.properties.content.guessMimetype(filename);
upload.properties.title = title;
upload.properties.description = description;
upload.save();
// setup model for response template
model.newNode = upload;
exitUpload(200, "OK")
}
}
catch (error){
status.setCode(500, msg);
return;
}
}
main();
{
"item":
{
"type": "${newNode.type}",
"name": "${newNode.name!''}",
"fileName": "${newNode.name!''}",
"path": "${newNode.displayPath}",
"nodeRef": "${newNode.nodeRef}"
}
}
08-30-2012 04:29 AM
09-11-2012 03:42 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.