mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +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,78 +1,36 @@
|
|||||||
<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
|
||||||
|
@@ -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>
|
||||||
}
|
}
|
@@ -31,7 +31,7 @@ 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");
|
||||||
@@ -51,6 +51,38 @@ function update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
||||||
@@ -74,29 +106,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
|
||||||
// the raw content (for editing) whereas the page view needs to display the rendered content.
|
// 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 = update();
|
||||||
//model.result = jsonUtils.toJSONString(result);
|
|
Reference in New Issue
Block a user