First cut of single- and multi-file Move To. Thumbnail generation in file upload

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9959 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mike Hatfield
2008-07-21 15:28:41 +00:00
parent 3e3f90ee77
commit e0821f2751
6 changed files with 124 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ var content = null;
var mimetype = null;
var siteId = null;
var containerId = null;
var thumbnailName = null;
// Upload specific
var uploadDirectory = null;
@@ -73,6 +74,10 @@ for each (field in formdata.fields)
case "overwrite":
overwrite = field.value == "true";
break;
case "thumbnail":
thumbnailName = field.value;
break;
}
}
@@ -107,21 +112,21 @@ else
status.message = "Component container (" + containerId + ") not found.";
status.redirect = true;
}
if(updateNodeRef !== null && uploadDirectory === null)
if (updateNodeRef !== null && uploadDirectory === null)
{
// Update mode, since updateNodeRef was used
var workingCopy = search.findNode(updateNodeRef);
if(workingCopy.isLocked)
if (workingCopy.isLocked)
{
// Its not a working copy, should have been the working copy, throw error
// It's not a working copy, should have been the working copy, throw error
status.code = 404;
status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead.";
status.redirect = true;
}
else if(!workingCopy.hasAspect("cm:workingcopy"))
else if (!workingCopy.hasAspect("cm:workingcopy"))
{
// Its not a working copy, do a check out to get the working copy
// It's not a working copy, do a check out to get the working copy
workingCopy = workingCopy.checkout();
}
// Update the working copy
@@ -130,7 +135,7 @@ else
workingCopy = workingCopy.checkin(description, majorVersion);
model.document = workingCopy;
}
else if(uploadDirectory !== null && updateNodeRef === null)
else if (uploadDirectory !== null && updateNodeRef === null)
{
var destNode = container;
if (uploadDirectory != "")
@@ -149,7 +154,7 @@ else
if (existingFile !== null)
{
// File already exists, decide what to do
if(overwrite)
if (overwrite)
{
// Upload component was configured to overwrite files if name clashes
existingFile.properties.content.write(content);
@@ -173,7 +178,7 @@ else
}
// save the new file (original or renamed file) as long as an overwrite hasn't been performed
if(!overwritten)
if (!overwritten)
{
var newFile = destNode.createFile(filename);
newFile.properties.contentType = contentType;
@@ -187,6 +192,11 @@ else
newFile.addAspect("cm:versionable");
// Save new file
newFile.save();
// Create thumbnail?
if (thumbnailName && thumbnailService.isThumbnailNameRegistered(thumbnailName))
{
newFile.createThumbnail(thumbnailName, true);
}
model.document = newFile;
}
}

View File

@@ -0,0 +1,9 @@
<webscript>
<shortname>files</shortname>
<description>Document List Action - Move multiple files</description>
<url>/slingshot/doclib/action/move-to/site/{site}/{container}/{path}</url>
<url>/slingshot/doclib/action/move-to/node/{store_type}/{store_id}/{id}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,76 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">
/**
* Move multiple files action
* @method POST
*/
/**
* Entrypoint required by action.lib.js
*
* @method runAction
* @param p_params {object} Object literal containing files array
* @return {object|null} object representation of action results
*/
function runAction(p_params)
{
var results = [];
var files = p_params.files;
var file, fileNode, result, nodeRef;
// Find destination node
var destNode = p_params.node || getAssetNode(p_params.rootNode, p_params.filePath);
// Must have destNode by this point
if (typeof assetNode == "string")
{
status.setCode(status.STATUS_NOT_FOUND, "Not found: " + p_params.filePath);
return;
}
// Must have array of files
if (!files || files.length == 0)
{
status.setCode(status.STATUS_BAD_REQUEST, "No files.");
return;
}
for (file in files)
{
nodeRef = files[file];
result =
{
nodeRef: nodeRef,
action: "moveFile",
success: false
}
try
{
fileNode = search.findNode(nodeRef);
if (fileNode === null)
{
result.id = file;
result.nodeRef = nodeRef;
result.success = false;
}
else
{
result.id = fileNode.name;
result.type = fileNode.isContainer ? "folder" : "document";
// move the node
result.success = fileNode.move(destNode);
}
}
catch (e)
{
result.id = file;
result.nodeRef = nodeRef;
result.success = false;
}
results.push(result);
}
return results;
}

View File

@@ -0,0 +1,2 @@
<#import "action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />

View File

@@ -2,6 +2,8 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js">
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/parse-args.lib.js">
var THUMBNAIL_NAME = "doclib";
/**
* Document List Component: doclist
*/
@@ -12,6 +14,9 @@ function getDocList(filter)
{
var items = new Array();
var assets;
// Is our thumbnail tpe registered?
var haveThumbnails = thumbnailService.isThumbnailNameRegistered(THUMBNAIL_NAME);
// Use helper function to get the arguments
var parsedArgs = getParsedArgs();
@@ -44,9 +49,7 @@ function getDocList(filter)
}
// Locked/working copy status defines action set
var itemStatus;
var itemOwner;
var actionSet;
var itemStatus, itemOwner, actionSet, thumbnail;
for each(asset in assets)
{
@@ -71,6 +74,17 @@ function getDocList(filter)
itemStatus.push("lockedBySelf");
}
// Make sure we have a thumbnail
if (haveThumbnails)
{
thumbnail = asset.getThumbnail(THUMBNAIL_NAME);
if (thumbnail === null)
{
// No thumbnail, so queue creation
asset.createThumbnail(THUMBNAIL_NAME, true);
}
}
// Get relevant actions set
actionSet = getActionSet(asset,
{

View File

@@ -30,6 +30,7 @@ function getFilterQuery(filter, obj)
filterQuery = "+PATH:\"" + obj.rootNode.qnamePath + "//*\" ";
filterQuery += "+@cm\\:" + dateField + ":[" + fromQuery + "T00\\:00\\:00 TO " + toQuery + "T23\\:59\\:59] ";
filterQuery += "-ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\"";
filterQuery += "-TYPE:\"{http://www.alfresco.org/model/content/1.0}thumbnail\"";
break;
case "editingMe":