mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Initial version of scripts for updating and deleting an event.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>deleteevent</shortname>
|
||||
<description>Event Action - Delete event</description>
|
||||
<url>/calendar/delete/{siteid}/{eventname}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Delete event action
|
||||
* @method DELETE
|
||||
* @param uri {string} /{siteid}/{eventname}
|
||||
*/
|
||||
var result = deleteEvent();
|
||||
status.code = result;
|
||||
|
||||
function deleteEvent()
|
||||
{
|
||||
var params = getTemplateParams();
|
||||
if (params === null)
|
||||
{
|
||||
return status.STATUS_BAD_REQUEST;
|
||||
}
|
||||
|
||||
var site = siteService.getSite(params.siteid);
|
||||
if (site === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
var eventsFolder = site.getContainer("calendar");
|
||||
if (eventsFolder === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
var event = eventsFolder.childByNamePath(params.eventname);
|
||||
if (event === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (!event.remove())
|
||||
{
|
||||
return status.STATUS_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
// Success
|
||||
return status.STATUS_NO_CONTENT;
|
||||
}
|
||||
|
||||
function getTemplateParams()
|
||||
{
|
||||
// Grab the URI parameters
|
||||
var siteid = "" + url.templateArgs.siteid;
|
||||
var eventname = "" + url.templateArgs.eventname;
|
||||
|
||||
if (siteid === null || siteid.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (eventname === null || eventname.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
"siteid": siteid,
|
||||
"eventname": eventname
|
||||
};
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>updateevent</shortname>
|
||||
<description>Event Action - Update event</description>
|
||||
<url>/calendar/event/{siteid}/{eventname}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Update event properties
|
||||
* @method PUT
|
||||
* @param uri {string} /calendar/event/{siteid}/{eventname}
|
||||
*/
|
||||
function getTemplateParams()
|
||||
{
|
||||
// Grab the URI parameters
|
||||
var siteid = "" + url.templateArgs.siteid;
|
||||
var eventname = "" + url.templateArgs.eventname;
|
||||
|
||||
if (siteid === null || siteid.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (eventname === null || eventname.length === 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
"siteid": siteid,
|
||||
"eventname": eventname
|
||||
};
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
var params = getTemplateParams();
|
||||
if (params === null)
|
||||
{
|
||||
return status.STATUS_BAD_REQUEST;
|
||||
}
|
||||
|
||||
// Get the site
|
||||
var site = siteService.getSite(params.siteid);
|
||||
if (site === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
var eventsFolder = site.getContainer("calendar");
|
||||
if (eventsFolder === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
var event = eventsFolder.childByNamePath(params.eventname);
|
||||
if (event === null)
|
||||
{
|
||||
return status.STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
var props = [
|
||||
"ia:whatEvent",
|
||||
"ia:descriptionEvent",
|
||||
"ia:whereEvent"
|
||||
];
|
||||
|
||||
for (var i=0; i < props.length; i++)
|
||||
{
|
||||
var prop = props[i];
|
||||
try
|
||||
{
|
||||
var value = json.get(prop);
|
||||
// TODO: deal with formatting date strings correctly
|
||||
if (value)
|
||||
{
|
||||
event.properties[prop] = value;
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
// Couldn't find the property in the JSON data
|
||||
}
|
||||
}
|
||||
|
||||
event.save();
|
||||
return status.STATUS_NO_CONTENT;
|
||||
}
|
||||
|
||||
var response = main();
|
||||
status.code = response;
|
Reference in New Issue
Block a user