mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Modified how wiki pages are created.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10267 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,80 +1,38 @@
|
||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js">
|
||||
|
||||
/**
|
||||
* Get wiki page properties.
|
||||
* Creates a page if the specified one doesn't exist.
|
||||
* Returns an error message if the specified page cannot be found.
|
||||
*
|
||||
* @method GET
|
||||
* @param uri {string} /slingshot/wiki/page/{siteid}/{pageTitle}
|
||||
*/
|
||||
|
||||
function getTemplateParams()
|
||||
{
|
||||
// Grab the URI parameters
|
||||
var siteId = "" + url.templateArgs.siteId;
|
||||
var pageTitle = "" + url.templateArgs.pageTitle;
|
||||
|
||||
if (siteId === null || siteId.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pageTitle === null || pageTitle.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
"siteId": siteId,
|
||||
"pageTitle": pageTitle
|
||||
};
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
var params = getTemplateParams();
|
||||
var params = getTemplateArgs(["siteId", "pageTitle"]);
|
||||
if (params === null)
|
||||
{
|
||||
return null;
|
||||
return jsonError("No parameters supplied");
|
||||
}
|
||||
|
||||
// Get the site
|
||||
var site = siteService.getSite(params.siteId);
|
||||
if (site === null)
|
||||
{
|
||||
return null;
|
||||
return jsonError("Could not find site: " + params.siteId);
|
||||
}
|
||||
|
||||
var wiki = getWikiContainer(site);
|
||||
if (wiki === null)
|
||||
{
|
||||
return null;
|
||||
return jsonError("Could not locate wiki");
|
||||
}
|
||||
|
||||
var page = wiki.childByNamePath(params.pageTitle);
|
||||
if (page === null)
|
||||
{
|
||||
page = createWikiPage(params.pageTitle, wiki, {
|
||||
content: DEFAULT_PAGE_CONTENT,
|
||||
versionable: true
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
// Log page create to activity service
|
||||
var d = {
|
||||
pageName: params.pageTitle.replace(/_/g, " "),
|
||||
pageContext: (args.context ? args.context : "")
|
||||
}
|
||||
|
||||
var page = wiki.childByNamePath(params.pageTitle);
|
||||
if (!page)
|
||||
{
|
||||
return jsonError(DEFAULT_PAGE_CONTENT);
|
||||
}
|
||||
|
||||
activities.postActivity("org.alfresco.wiki.page-created", params.siteId, "wiki", jsonUtils.toJSONString(d));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
logger.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out what (internal) pages this page contains links to
|
||||
var content = page.content.toString();
|
||||
var re = /\[\[([^\|\]]+)/g;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
<#if result?exists>
|
||||
<#if result.page??>
|
||||
<#assign page = result.page>
|
||||
"title" : "<#if page.properties.title?exists>${page.properties.title}<#else>${page.name?replace("_", " ")}</#if>",
|
||||
"pagetext" : '${page.content?js_string}',
|
||||
@@ -28,6 +28,6 @@
|
||||
]
|
||||
</#if>
|
||||
<#else>
|
||||
"error" : "Could not find page"
|
||||
"error" : "${result.error!""}"
|
||||
</#if>
|
||||
}
|
@@ -31,26 +31,58 @@ function getTemplateParams()
|
||||
|
||||
function update()
|
||||
{
|
||||
var params = getTemplateParams();
|
||||
if (params === null)
|
||||
{
|
||||
return jsonError("No parameters supplied");
|
||||
}
|
||||
var params = getTemplateArgs(["siteId", "pageTitle"]);
|
||||
if (params === null)
|
||||
{
|
||||
return jsonError("No parameters supplied");
|
||||
}
|
||||
|
||||
// Get the site
|
||||
var site = siteService.getSite(params.siteId);
|
||||
if (site === null)
|
||||
{
|
||||
return jsonError("Could not find site: " + siteId);
|
||||
}
|
||||
// Get the site
|
||||
var site = siteService.getSite(params.siteId);
|
||||
if (site === null)
|
||||
{
|
||||
return jsonError("Could not find site: " + siteId);
|
||||
}
|
||||
|
||||
var wiki = getWikiContainer(site);
|
||||
if (wiki === null)
|
||||
{
|
||||
return jsonError("Could not locate wiki container");
|
||||
}
|
||||
var wiki = getWikiContainer(site);
|
||||
if (wiki === null)
|
||||
{
|
||||
return jsonError("Could not locate wiki container");
|
||||
}
|
||||
|
||||
var page = wiki.childByNamePath(params.pageTitle);
|
||||
// Create the page if it doesn't exist
|
||||
if (page === null)
|
||||
{
|
||||
page = createWikiPage(params.pageTitle, wiki, {
|
||||
content: json.get("pagecontent"),
|
||||
versionable: true
|
||||
});
|
||||
|
||||
// Log page create to activity service
|
||||
var d = {
|
||||
pageName: params.pageTitle.replace(/_/g, " "),
|
||||
pageContext: (args.context ? args.context : "")
|
||||
}
|
||||
|
||||
activities.postActivity("org.alfresco.wiki.page-created", params.siteId, "wiki", jsonUtils.toJSONString(d));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a new revision of the page
|
||||
var workingCopy = page.checkout();
|
||||
workingCopy.content = json.get("pagecontent");
|
||||
workingCopy.checkin();
|
||||
|
||||
// Log page update to activity service
|
||||
var d = {
|
||||
pageName: params.pageTitle.replace(/_/g, " "),
|
||||
pageContext: (args.context ? unescape(args.context) : "")
|
||||
}
|
||||
|
||||
activities.postActivity("org.alfresco.wiki.page-edited", params.siteId, "wiki", jsonUtils.toJSONString(d));
|
||||
}
|
||||
|
||||
if (!json.isNull("tags"))
|
||||
{
|
||||
var tags = Array(json.get("tags"));
|
||||
@@ -73,29 +105,6 @@ function update()
|
||||
}
|
||||
page.save();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Create a new revision of the page
|
||||
var workingCopy = page.checkout();
|
||||
workingCopy.content = json.get("pagecontent");
|
||||
workingCopy.checkin();
|
||||
|
||||
// Log page update to activity service
|
||||
var d = {
|
||||
pageName: params.pageTitle.replace(/_/g, " "),
|
||||
pageContext: (args.context ? unescape(args.context) : "")
|
||||
}
|
||||
|
||||
activities.postActivity("org.alfresco.wiki.page-edited", params.siteId, "wiki", jsonUtils.toJSONString(d));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: for now we return the raw page content and do the transformation
|
||||
// of any wiki markup on the client. This is because the edit view needs to display
|
||||
@@ -106,5 +115,4 @@ function update()
|
||||
}
|
||||
}
|
||||
|
||||
model.result = update();
|
||||
//model.result = jsonUtils.toJSONString(result);
|
||||
model.result = update();
|
Reference in New Issue
Block a user