mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -3,6 +3,7 @@ var content = null;
|
|||||||
var mimetype = null;
|
var mimetype = null;
|
||||||
var siteId = null;
|
var siteId = null;
|
||||||
var containerId = null;
|
var containerId = null;
|
||||||
|
var thumbnailName = null;
|
||||||
|
|
||||||
// Upload specific
|
// Upload specific
|
||||||
var uploadDirectory = null;
|
var uploadDirectory = null;
|
||||||
@@ -73,6 +74,10 @@ for each (field in formdata.fields)
|
|||||||
case "overwrite":
|
case "overwrite":
|
||||||
overwrite = field.value == "true";
|
overwrite = field.value == "true";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "thumbnail":
|
||||||
|
thumbnailName = field.value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,21 +112,21 @@ else
|
|||||||
status.message = "Component container (" + containerId + ") not found.";
|
status.message = "Component container (" + containerId + ") not found.";
|
||||||
status.redirect = true;
|
status.redirect = true;
|
||||||
}
|
}
|
||||||
if(updateNodeRef !== null && uploadDirectory === null)
|
|
||||||
|
if (updateNodeRef !== null && uploadDirectory === null)
|
||||||
{
|
{
|
||||||
// Update mode, since updateNodeRef was used
|
// Update mode, since updateNodeRef was used
|
||||||
|
|
||||||
var workingCopy = search.findNode(updateNodeRef);
|
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.code = 404;
|
||||||
status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead.";
|
status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead.";
|
||||||
status.redirect = true;
|
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();
|
workingCopy = workingCopy.checkout();
|
||||||
}
|
}
|
||||||
// Update the working copy
|
// Update the working copy
|
||||||
@@ -130,7 +135,7 @@ else
|
|||||||
workingCopy = workingCopy.checkin(description, majorVersion);
|
workingCopy = workingCopy.checkin(description, majorVersion);
|
||||||
model.document = workingCopy;
|
model.document = workingCopy;
|
||||||
}
|
}
|
||||||
else if(uploadDirectory !== null && updateNodeRef === null)
|
else if (uploadDirectory !== null && updateNodeRef === null)
|
||||||
{
|
{
|
||||||
var destNode = container;
|
var destNode = container;
|
||||||
if (uploadDirectory != "")
|
if (uploadDirectory != "")
|
||||||
@@ -149,7 +154,7 @@ else
|
|||||||
if (existingFile !== null)
|
if (existingFile !== null)
|
||||||
{
|
{
|
||||||
// File already exists, decide what to do
|
// File already exists, decide what to do
|
||||||
if(overwrite)
|
if (overwrite)
|
||||||
{
|
{
|
||||||
// Upload component was configured to overwrite files if name clashes
|
// Upload component was configured to overwrite files if name clashes
|
||||||
existingFile.properties.content.write(content);
|
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
|
// 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);
|
var newFile = destNode.createFile(filename);
|
||||||
newFile.properties.contentType = contentType;
|
newFile.properties.contentType = contentType;
|
||||||
@@ -187,6 +192,11 @@ else
|
|||||||
newFile.addAspect("cm:versionable");
|
newFile.addAspect("cm:versionable");
|
||||||
// Save new file
|
// Save new file
|
||||||
newFile.save();
|
newFile.save();
|
||||||
|
// Create thumbnail?
|
||||||
|
if (thumbnailName && thumbnailService.isThumbnailNameRegistered(thumbnailName))
|
||||||
|
{
|
||||||
|
newFile.createThumbnail(thumbnailName, true);
|
||||||
|
}
|
||||||
model.document = newFile;
|
model.document = newFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
@@ -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;
|
||||||
|
}
|
@@ -0,0 +1,2 @@
|
|||||||
|
<#import "action.lib.ftl" as actionLib />
|
||||||
|
<@actionLib.resultsJSON results=results />
|
@@ -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/filters.lib.js">
|
||||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/parse-args.lib.js">
|
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/parse-args.lib.js">
|
||||||
|
|
||||||
|
var THUMBNAIL_NAME = "doclib";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document List Component: doclist
|
* Document List Component: doclist
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +14,9 @@ function getDocList(filter)
|
|||||||
{
|
{
|
||||||
var items = new Array();
|
var items = new Array();
|
||||||
var assets;
|
var assets;
|
||||||
|
|
||||||
|
// Is our thumbnail tpe registered?
|
||||||
|
var haveThumbnails = thumbnailService.isThumbnailNameRegistered(THUMBNAIL_NAME);
|
||||||
|
|
||||||
// Use helper function to get the arguments
|
// Use helper function to get the arguments
|
||||||
var parsedArgs = getParsedArgs();
|
var parsedArgs = getParsedArgs();
|
||||||
@@ -44,9 +49,7 @@ function getDocList(filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Locked/working copy status defines action set
|
// Locked/working copy status defines action set
|
||||||
var itemStatus;
|
var itemStatus, itemOwner, actionSet, thumbnail;
|
||||||
var itemOwner;
|
|
||||||
var actionSet;
|
|
||||||
|
|
||||||
for each(asset in assets)
|
for each(asset in assets)
|
||||||
{
|
{
|
||||||
@@ -71,6 +74,17 @@ function getDocList(filter)
|
|||||||
itemStatus.push("lockedBySelf");
|
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
|
// Get relevant actions set
|
||||||
actionSet = getActionSet(asset,
|
actionSet = getActionSet(asset,
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ function getFilterQuery(filter, obj)
|
|||||||
filterQuery = "+PATH:\"" + obj.rootNode.qnamePath + "//*\" ";
|
filterQuery = "+PATH:\"" + obj.rootNode.qnamePath + "//*\" ";
|
||||||
filterQuery += "+@cm\\:" + dateField + ":[" + fromQuery + "T00\\:00\\:00 TO " + toQuery + "T23\\:59\\:59] ";
|
filterQuery += "+@cm\\:" + dateField + ":[" + fromQuery + "T00\\:00\\:00 TO " + toQuery + "T23\\:59\\:59] ";
|
||||||
filterQuery += "-ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\"";
|
filterQuery += "-ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\"";
|
||||||
|
filterQuery += "-TYPE:\"{http://www.alfresco.org/model/content/1.0}thumbnail\"";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "editingMe":
|
case "editingMe":
|
||||||
|
Reference in New Issue
Block a user