From 93091b6475e67630788ccbb4b07e59fdaefa68f6 Mon Sep 17 00:00:00 2001 From: Simon Buckle Date: Wed, 6 Aug 2008 09:42:06 +0000 Subject: [PATCH] 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 --- .../org/alfresco/slingshot/wiki/page.get.js | 64 +++---------- .../alfresco/slingshot/wiki/page.get.json.ftl | 4 +- .../org/alfresco/slingshot/wiki/page.put.js | 90 ++++++++++--------- 3 files changed, 62 insertions(+), 96 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.js index 817737083f..5e857a688c 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.js @@ -1,80 +1,38 @@ - /** * 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; diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.json.ftl index c683a649eb..6e4da50fd0 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.get.json.ftl @@ -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("_", " ")}", "pagetext" : '${page.content?js_string}', @@ -28,6 +28,6 @@ ] <#else> - "error" : "Could not find page" + "error" : "${result.error!""}" } \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.js index 34db2faa49..4716d37b7c 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.js @@ -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); \ No newline at end of file +model.result = update(); \ No newline at end of file