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:
Simon Buckle
2008-08-06 09:42:06 +00:00
parent 79801ecac5
commit 93091b6475
3 changed files with 62 additions and 96 deletions

View File

@@ -1,80 +1,38 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js"> <import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js">
/** /**
* Get wiki page properties. * 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 * @method GET
* @param uri {string} /slingshot/wiki/page/{siteid}/{pageTitle} * @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() function main()
{ {
var params = getTemplateParams(); var params = getTemplateArgs(["siteId", "pageTitle"]);
if (params === null) if (params === null)
{ {
return null; return jsonError("No parameters supplied");
} }
// Get the site // Get the site
var site = siteService.getSite(params.siteId); var site = siteService.getSite(params.siteId);
if (site === null) if (site === null)
{ {
return null; return jsonError("Could not find site: " + params.siteId);
} }
var wiki = getWikiContainer(site); var wiki = getWikiContainer(site);
if (wiki === null) if (wiki === null)
{ {
return null; return jsonError("Could not locate wiki");
} }
var page = wiki.childByNamePath(params.pageTitle); var page = wiki.childByNamePath(params.pageTitle);
if (page === null) if (!page)
{ {
page = createWikiPage(params.pageTitle, wiki, { return jsonError(DEFAULT_PAGE_CONTENT);
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 : "")
}
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 // Figure out what (internal) pages this page contains links to
var content = page.content.toString(); var content = page.content.toString();
var re = /\[\[([^\|\]]+)/g; var re = /\[\[([^\|\]]+)/g;

View File

@@ -1,5 +1,5 @@
{ {
<#if result?exists> <#if result.page??>
<#assign page = result.page> <#assign page = result.page>
"title" : "<#if page.properties.title?exists>${page.properties.title}<#else>${page.name?replace("_", " ")}</#if>", "title" : "<#if page.properties.title?exists>${page.properties.title}<#else>${page.name?replace("_", " ")}</#if>",
"pagetext" : '${page.content?js_string}', "pagetext" : '${page.content?js_string}',
@@ -28,6 +28,6 @@
] ]
</#if> </#if>
<#else> <#else>
"error" : "Could not find page" "error" : "${result.error!""}"
</#if> </#if>
} }

View File

@@ -31,26 +31,58 @@ function getTemplateParams()
function update() function update()
{ {
var params = getTemplateParams(); var params = getTemplateArgs(["siteId", "pageTitle"]);
if (params === null) if (params === null)
{ {
return jsonError("No parameters supplied"); return jsonError("No parameters supplied");
} }
// Get the site // Get the site
var site = siteService.getSite(params.siteId); var site = siteService.getSite(params.siteId);
if (site === null) if (site === null)
{ {
return jsonError("Could not find site: " + siteId); return jsonError("Could not find site: " + siteId);
} }
var wiki = getWikiContainer(site); var wiki = getWikiContainer(site);
if (wiki === null) if (wiki === null)
{ {
return jsonError("Could not locate wiki container"); return jsonError("Could not locate wiki container");
} }
var page = wiki.childByNamePath(params.pageTitle); 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")) if (!json.isNull("tags"))
{ {
var tags = Array(json.get("tags")); var tags = Array(json.get("tags"));
@@ -73,29 +105,6 @@ function update()
} }
page.save(); 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 // 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 // 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 = update();
//model.result = jsonUtils.toJSONString(result);