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,79 +1,37 @@
<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 : "")
}
activities.postActivity("org.alfresco.wiki.page-created", params.siteId, "wiki", jsonUtils.toJSONString(d));
}
catch(e)
{
logger.log(e);
}
}
var page = wiki.childByNamePath(params.pageTitle);
if (!page)
{
return jsonError(DEFAULT_PAGE_CONTENT);
}
// Figure out what (internal) pages this page contains links to
var content = page.content.toString();

View File

@@ -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>
}

View File

@@ -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"));
@@ -74,29 +106,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
// the raw content (for editing) whereas the page view needs to display the rendered content.
@@ -107,4 +116,3 @@ function update()
}
model.result = update();
//model.result = jsonUtils.toJSONString(result);