02-22-2011 03:30 AM
02-22-2011 05:42 PM
var parent = document.getParent();(That parent will be the "fm:topic" object.)var threadTitle = parent.children[0].properties["title"] 02-23-2011 02:31 AM
while ((document.getParent() != null)) {
var parent = document.getParent();
if (parent.typeShort == "st:site") {
//get the ID of the site for use in the reply location URL
siteID = parent.properties["name"];
//get the short name of the site so we can get the group with the members of the site
var siteShortName = parent.getSiteShortName();
//use the site short name to assemble the group name
var siteGroup = people.getGroup("GROUP_site_"+siteShortName);
//get the members of that group
var siteGroupUsers = people.getMembers(siteGroup, true);
//put the emails of the members of the site into a new array for use in sending the notices
var siteUsers = new Array;
for (var i in siteGroupUsers)
{
var name1=siteGroupUsers[i];
siteUsers.push(name1.properties["email"]);
}
break;
}
document = parent;
}
04-26-2011 12:23 PM
05-22-2011 08:00 PM
/*
send-forum-notify.js
version of 22/5/2011
by Ian Crew
A script for Alfresco Community Edition that takes the ownership of anything uploaded to a
directory. It can be used for site quotas or drop box functionality.
This script has only been tested on Alfresco CE 3.4c.
Legalese
This script is copyright 2011 by Ian Crew. No warranties are expressed or implied.
Use at your own risk. This script may be freely distributed and modified
so long as this copyright notice is included in all derivative versions.
*/
var postContentNode = document.properties["content"]; //get the node containing the content of this post
var postContent= postContentNode.getContent(); //get the actual content of the post
var postTitle = document.properties["title"]; //get the title of the post. Unless this is the first post in a new thread, this will be blank, and we'll fill it in below.
var threadID = document.properties["name"]; //get the id of this post, so we can link to the thread in the email that goes out. If this is a reply, this will get overwritten below with the id of the first post in the thread, below.
//Get the human-readable name of the creator of this post for the notification email.
var postCreator = document.properties["creator"]; //get the creator of the post.
var postCreatorPerson=people.getPerson(postCreator);
var postCreatorName=postCreatorPerson.properties["firstName"] + " " + postCreatorPerson.properties["lastName"];
//variables to be filled in below.
var siteTitle = "";
//var threadID = "";
var siteID = "";
//debugging info
//var postProperties = "\n\n\n______________________________________________________________________\nDEBUGGING\n______________________________________________________________________\n";
//postProperties += dumpEntireNode(document);
while ((document.getParent() != null)) {
var parent = document.getParent();
//postProperties += "\nPARENT " + dumpEntireNode(parent);
if ((parent.typeShort == "fm:topic") && (postTitle == "") && (parent.children[0].properties["title"] != null)) {
//get the name of the thread for use in the subject line
postTitle = "Re: " + parent.children[0].properties["title"] ;
//get the ID of the thread for use in the reply location URL
threadID = parent.properties["name"];
}
else if (parent.typeShort == "st:site") {
//Get the name of the site for use in the message subject line
siteTitle = parent.properties["title"];
//get the ID of the site for use in the reply location URL
siteID = parent.properties["name"];
//get the short name of the site so we can get the group with the members of the site
var siteShortName = parent.getSiteShortName();
//postProperties += "Site Short Name:\n\t–\n" + siteShortName +"\n\t–\n";
//use the site short name to assemble the group name
var siteGroup = people.getGroup("GROUP_site_"+siteShortName);
//get the members of that group
var siteGroupUsers = people.getMembers(siteGroup, true);
//put the emails of the members of the site into a new array for use in sending the notices
var siteUsers = new Array;
for (var i in siteGroupUsers)
{
var name1=siteGroupUsers[i];
//siteUsers += dumpEntireNode(name1);
siteUsers.push(name1.properties["email"]);
}
//postProperties += "\nSITE USERS:\n\t–\n" + dump(siteUsers) +"\n\t–\n";
break;
}
document = parent;
}
var replyLocation = "Reply to this post at\n<https://foo.bar.com/share/page/site/'+siteID+'/discussions-topicview?topicId='+threadID+">\n";
if (postContent != "") { //check for null, because some updates seem to generate two messages, one blank.
//error checking
if (postTitle == "") { postTitle = "Unknown post!"; }
if (postContent == "") { postContent = "Unknown content!"; } //this shouldn't ever happen
if (siteTitle == "") { siteTitle = "Unknown site!"; }
//Strip the HTML and clean up the resulting text.
postContent = new String(postContent); //wrap java string in javascript string so we can work with it…..
postContent = postContent.replace(/<br \/>/g, "\n"); //turn BRs into newlines
postContent = postContent.replace(/<.*?>/g, ""); //strip all tags
postContent = postContent.replace(/ /g, " "); //strip nonbreaking spaces
postContent = postContent.replace(/\n+/g, "\n\n"); //clean up consecutive newlines
//assemble the final message, with the reply location listed before and after
//postContent = replyLocation + "———————————————————————-\n" + postContent + "\n———————————————————————-\n" + replyLocation;
postContent = postCreatorName + " writes:\n\n" + postContent + "\n———————————————————————-\n" + replyLocation;
//send email, individually, to each user of the site.
for (var i in siteUsers)
{
var emailAddr=siteUsers[i];
sendMail (emailAddr, "[" + siteTitle + "] " + postTitle, postContent, document); //+postProperties
}
}
//do the change of ownership
//changeOwner();
//logger.log("Done changing owner.");
//logger.log("———————");
//send off the email
function sendMail (recipient, subject, contents, node) {
//send email to the specified recipients
/*
See http://savicprvoslav.blogspot.com/2010/10/send-html-email-from-alfresco-33-with.html to send html email someday
var htmlContents =
'Mime-Version: 1.0\
Content-Type: multipart/alternative; \
boundary="—-=_Part_2665_1854048590.1224718126252"\
\
X-Content-Type-Outer-Envelope: multipart/alternative; boundary=Apple-Mail-1–549697194\
\
\
X-Content-Type-Message-Body: text/plain;\
charset=US-ASCII;\
format=flowed;\
delsp=yes\
\
——=_Part_2665_1854048590.1224718126252\
Content-Type: text/html ; charset=ISO-8859-1\
Content-Transfer-Encoding: quoted-printable\
\
\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\
"http://www.w3.org/TR/html4/loose.dtd">\
<html>\
<head>\
<meta content="text/html;charset=utf-8"\
http-equiv="Content-Type">\
<title>MVP Disk Usage Report</title>\
</head>\
<body bgcolor="#ffffff" text="#000000">\
\
' + contents + '\
\
</body></html>\
\
——=_Part_2665_1854048590.1224718126252–\
\
';
*/
// create mail action
var mail = actions.create("mail");
mail.parameters.to = recipient;
mail.parameters.subject = subject;
mail.parameters.from = "foo@bar.com";
mail.parameters.template = null;
mail.parameters.text = contents;
// execute action against a document
mail.execute(node);
}
//dump the entire node, for debugging
function dumpEntireNode (node) {
var nodeData = "=========================\nNODE DATA\n\n";
nodeData += "node.properties:\n\t–\n"
for (var childProperty in node.properties)
{
logger.log(childProperty +"\t"+node.properties[childProperty]);
nodeData += childProperty +"\t"+node.properties[childProperty] + "\n";
}
nodeData += "\t–\n";
// ARRAY:
nodeData += "node.children:\n\t–\n" + dump (node.children) + "\t–\n";
nodeData += "node.assocs:\n\t–\n" + dump (node.assocs) + "\t–\n";
nodeData += "node.sourceAssocs:\n\t–\n" + dump (node.sourceAssocs) + "\t–\n";
nodeData += "node.childAssocs:\n\t–\n" + dump (node.childAssocs) + "\t–\n";
nodeData += "node.parentAssocs:\n\t–\n" + dump (node.parentAssocs) + "\t–\n";
nodeData += "node.aspects:\n\t–\n" + dump (node.aspects) + "\t–\n";
nodeData += "node.parents:\n\t–\n" + dump (node.parents) + "\t–\n";
nodeData += "node.activeWorkflows:\n\t–\n" + dump (node.activeWorkflows) + "\t–\n";
// BOOLEAN:
nodeData += "isContainer:\t" + node.isContainer + "\n";
nodeData += "isDocument:\t" + node.isDocument + "\n";
nodeData += "isCategory:\t" + node.isCategory + "\n";
//nodeData += "boolean isScriptContent(object obj):\t" + node.boolean isScriptContent(object obj) + "\n";
// STRING
nodeData += "content:\n\t–\n" + node.content + "\n\t–\n";
nodeData += "url:\t" + node.url + "\n";
nodeData += "downloadUrl:\t" + node.downloadUrl + "\n";
nodeData += "webdavUrl:\t" + node.webdavUrl + "\n";
nodeData += "mimetype:\t" + node.mimetype + "\n";
nodeData += "size:\t" + node.size + "\n";
nodeData += "displayPath:\t" + node.displayPath + "\n";
nodeData += "qnamePath:\t" + node.qnamePath + "\n";
nodeData += "icon16:\t" + node.icon16 + "\n";
nodeData += "icon32:\t" + node.icon32 + "\n";
nodeData += "isLocked:\t" + node.isLocked + "\n";
nodeData += "id:\t" + node.id + "\n";
nodeData += "nodeRef:\t" + node.nodeRef + "\n";
nodeData += "name:\t" + node.name + "\n";
nodeData += "type:\t" + node.type + "\n";
nodeData += "typeShort:\t" + node.typeShort + "\n";
nodeData += "parent:\t" + node.parent + "\n";
nodeData += node.getSiteShortName();
nodeData += "=============================\n";
return nodeData;
}
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
* The level - OPTIONAL
* Returns : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
* Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
//if(typeof(value) == 'object') { //If it is an array,
// dumped_text += level_padding + "'" + item + "' …\n";
// dumped_text += dump(value,level+1);
// } else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
//}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
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.