Initial import of the calendar component for slingshot including a calendar and rss feed dashlet.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9302 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Simon Buckle
2008-05-29 10:21:17 +00:00
parent 6047ef6b5a
commit 93a5bda71a
15 changed files with 263 additions and 119 deletions

View File

@@ -1,4 +1,4 @@
<#assign days = DaysArray>
<#assign days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>
<table id="tabMonthView" bordercolor="#FF00FF" bordercolordark="#FFFFFF" bordercolorlight="#99CCFF" border="1" cellspacing="0" cellpadding="2" width="100%">
<TR>

View File

@@ -1,15 +1,13 @@
var dateString = args.d;
var _currentDateForMonthView= new Date(dateString);
var spaceRef = args.s;
var currentBaseSpace = findNodeByNodeRef(spaceRef);
var currentBaseSpace = search.findNode(args.s);
var eventList = new Array();
function editableObject(obj, iseditable, color) {
this.object = obj;
this.isEditable = iseditable;
this.color = color;
this.color = color;
}
function eventType(datepart, obj) {
@@ -17,85 +15,70 @@ function eventType(datepart, obj) {
this.object = obj;
}
var DaysArray = function() {
var _arr = new Array();
_arr[0] = "Sunday";
_arr[1] = "Monday";
_arr[2] = "Tuesday";
_arr[3] = "Wednesday";
_arr[4] = "Thursday";
_arr[5] = "Friday";
_arr[6] = "Saturday";
return _arr;
}
var MonthsArray = function() {
var _arr = new Array();
_arr[0] = "January";
_arr[1] = "February";
_arr[2] = "March";
_arr[3] = "April";
_arr[4] = "May";
_arr[5] = "June";
_arr[6] = "July";
_arr[7] = "August";
_arr[8] = "September";
_arr[9] = "October";
_arr[10] = "November";
_arr[11] = "December";
return _arr;
}
String.prototype.pad = function(l, s, t) {
return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
+ this + s.substr(0, l - t) : this;
};
// utils.pad(s, length)
var calendarSpaceArray = function() {
var color;
var defaultColor = "#FF0000";
var color;
var defaultColor = "#FF0000";
var c = null;
var x = new Array();
var y = currentBaseSpace.assocs["ia:subscribedCalendarList"];
if (y != null) {
for (i=0; i<y.length; i++) {
c = y[i].childByNamePath("CalEvents");
if (c != null)
if ((color = y[i].properties["ia:colorEventDefault"]) == null) {
color = defaultColor;
}
x[i] = new editableObject(c, 0, color);
}
} else {
logger.log("NOT SUBSCRIBED TO CALENDARS");
}
c = currentBaseSpace.childByNamePath("CalEvents");
if (c != null) {
if ((color = currentBaseSpace.properties["ia:colorEventDefault"]) == null) {
color = defaultColor;
var calendars = new Array();
var assoc = currentBaseSpace.assocs["ia:subscribedCalendarList"];
if (assoc !== null) {
for (i=0; i<assoc.length; i++)
{
c = assoc[i].childByNamePath("CalEvents");
if (c !== null)
{
if ((color = assoc[i].properties["ia:colorEventDefault"]) === null)
{
color = defaultColor;
}
x[x.length] = new editableObject(c, 1, color);
}
calendars[i] = new editableObject(c, 0, color);
}
}
else
{
logger.log("NOT SUBSCRIBED TO CALENDARS");
}
c = currentBaseSpace.childByNamePath("CalEvents");
if (c !== null)
{
if ((color = currentBaseSpace.properties["ia:colorEventDefault"]) === null) {
color = defaultColor;
}
return x;
calendars[calendars.length] = new editableObject(c, 1, color);
}
return calendars;
};
/* A list of the events folders for the current calendar and ALL the calendars the user is subscribed to */
calendarSpaces = calendarSpaceArray();
function getDayEvents(requiredDate) {
var eventsArr = new Array();
var events = "";
var _months = MonthsArray();
if (currentBaseSpace == null)
if (currentBaseSpace === null)
{
return events;
}
for (var j=0; j<calendarSpaces.length; j++)
{
var currentSpace = calendarSpaces[j].object;
logger.log("QNAME PATH: " + currentSpace.qnamePath);
/* Do the Lucene date range query here */
for (var i=0; i<currentSpace.children.length; i++)
{
var child = currentSpace.children[i];
@@ -114,79 +97,50 @@ function getDayEvents(requiredDate) {
}
eventsArr.sort(SortCalendarEvents);
var tempEvents = new Array();
for (var j=0; j<eventsArr.length; j++)
return eventsArr;
}
function getEventsQuery(fromdate, todate)
{
/* Construct the PATH part of Lucene query string */
var query = "";
for (var j=0; j<calendarSpaces.length; j++)
{
var child = eventsArr[j].object;
var fromDate = new Date(child.properties["ia:fromDate"]);
fromDate.setHours(0,0,0,0);
var toDate = new Date(child.properties["ia:toDate"]);
toDate.setHours(11,59,59,0);
var showTimeLine = "";
if (fromDate.toDateString() == requiredDate.toDateString() && toDate.toDateString() == requiredDate.toDateString())
showTimeLine = child.properties["ia:fromDate"].getHours() + ":" + child.properties["ia:fromDate"].getMinutes().toString().pad(2, "0", 1) + " - " + child.properties["ia:toDate"].getHours() + ":" + child.properties["ia:toDate"].getMinutes().toString().pad(2, "0", 1);
else
showTimeLine = child.properties["ia:fromDate"].getDate() + " " + _months[child.properties["ia:fromDate"].getMonth()] + ", " + child.properties["ia:fromDate"].getHours() + ":" + child.properties["ia:fromDate"].getMinutes().toString().pad(2, "0", 1) + " - " + child.properties["ia:toDate"].getDate() + " " + _months[child.properties["ia:toDate"].getMonth()] + ", " + child.properties["ia:toDate"].getHours() + ":" + child.properties["ia:toDate"].getMinutes().toString().pad(2, "0", 1);
tempEvents.push(new editableObject(child, eventsArr[j].isEditable, eventsArr[j].color));
query += "+PATH:\"" + calendarSpaces[j].object.qnamePath + "/*\" ";
}
return tempEvents;
/* Construct the date range */
var from = fromdate.getFullYear() + "\\-" + (fromdate.getMonth() + 1) + "\\-" + fromdate.getDate();
var to = todate.getFullYear() + "\\-" + (todate.getMonth() + 1) + "\\-" + todate.getDate();
query += "+@ia\\:fromDate:[" + from + "T00:00:00 TO " + to + "T00:00:00]";
//var results = search.luceneSearch(query);
//logger.log("RESULTS: " + results.length);
return query;
}
var fromdate = new Date(args.d);
fromdate.setDate(1);
var todate = new Date(args.d);
todate.setDate(31);
logger.log("QUERY: " + getEventsQuery(fromdate, todate));
function SortCalendarEvents(child1, child2)
{
return (child1.object.properties["ia:fromDate"] - child2.object.properties["ia:fromDate"]);
}
function GetMonthName()
{
var _arr = MonthsArray();
return _arr[_currentDateForMonthView.getMonth()];
}
function getGUIDFromNodeRef(nodeRef)
{
var str = "" + nodeRef;
return str.substring(str.lastIndexOf("/")+1);
}
function findNodeByNodeRef(nodeRef)
{
var resultsArray = search.luceneSearch("ID:workspace\\://SpacesStore/" + getGUIDFromNodeRef(nodeRef));
if (resultsArray != null && resultsArray.length > 0)
{
return resultsArray[0];
}
else
{
return null;
}
}
var response;
if (currentBaseSpace == null)
{
response = "Parameters passed:<BR>";
response += "Current Date: " + dateString + "<BR>";
response += "Current Space: " + spaceRef + "<BR>";
response += "<BR>Error: No Space found by this Ref";
}
else
if (currentBaseSpace !== null)
{
calendarSpaces = calendarSpaceArray();
var _arrDay = DaysArray();
var DAYS_IN_WEEK = 7;
var tmpDate;
var i, j;
// Start with the first day of the month and go back if necessary to the previous Sunday.
tmpDate = new Date(Date.parse(_currentDateForMonthView));
tmpDate.setDate(1);
@@ -199,7 +153,7 @@ else
for (i = 2; i <= 7; i++)
{
// Loop through a week.
for (j = 0; j < _arrDay.length; j++)
for (j = 0; j < DAYS_IN_WEEK; j++)
{
if (tmpDate.getMonth() == _currentDateForMonthView.getMonth())
{
@@ -217,5 +171,4 @@ else
}
model.DaysArray = DaysArray();
model.eventList = eventList;

View File

@@ -0,0 +1,16 @@
{
<#list eventList?chunk(7, '-') as row>
<#list row as cell>
<#if cell?exists>
<#if cell.object?exists && cell.object?size &gt; 0>
"${cell.datePart}" : [
<#-- List the events for the current date -->
<#list cell.object as event>
"${event.object.properties["ia:whatEvent"]}"<#if event_has_next>,</#if>
</#list>
],
</#if>
</#if>
</#list>
</#list>
}

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>Event Listing</shortname>
<description>List of all upcoming events</description>
<url>/calendar/events/{nodeId}</url>
<format default="json">extension</format>
<authentication>guest</authentication>
</webscript>

View File

@@ -0,0 +1,13 @@
var calendar = search.findNode("workspace://SpacesStore/" + url.extension);
if (calendar !== null)
{
var eventsFolder = calendar.childByNamePath("CalEvents");
if (eventsFolder !== null)
{
model.events = eventsFolder.children.sort(function(a,b) {
return a.properties["ia:fromDate"] - b.properties["ia:fromDate"];
});
}
}

View File

@@ -0,0 +1,20 @@
{
<#if events?exists && events?size &gt; 0>
<#assign prev = "">
<#list events as event>
<#assign date = event.properties["ia:fromDate"]?string("MM/dd/yyyy")>
<#if date != prev>
<#assign counter = 0>
<#if event_index &gt; 0>],</#if>
"${date}" : [
</#if>
<#if counter &gt; 0>,</#if>
{
"name" : "${event.properties["ia:whatEvent"]}"
}
<#assign counter = counter + 1>
<#if !event_has_next>]</#if>
<#assign prev = date>
</#list>
</#if>
}

View File

@@ -0,0 +1,6 @@
<webscript>
<shortname>Calendar Feed</shortname>
<description>Calendar iCalendar feed</description>
<url>/calendar/feed/{nodeId}</url>
<authentication>guest</authentication>
</webscript>

View File

@@ -0,0 +1,17 @@
<#if events?exists>
<#assign dateFormat = "yyyyMMdd">
<#assign timeFormat = "HHmmss">
BEGIN:VCALENDAR
VERSION:2.0
<#list events as event>
<#assign from = event.properties["ia:fromDate"]>
<#assign to = event.properties["ia:toDate"]>
BEGIN:VEVENT
DTSTART:${from?string(dateFormat)}T${from?string(timeFormat)}Z
DTEND:${to?string(dateFormat)}T${to?string(timeFormat)}Z
SUMMARY:${event.properties["ia:whatEvent"]!""}
DESCRIPTION:${event.properties["ia:descriptionEvent"]!""}
END:VEVENT
</#list>
END:VCALENDAR
</#if>

View File

@@ -0,0 +1,12 @@
var node = search.findNode("workspace://SpacesStore/" + url.extension);
//TODO: add a privacy check. If a calendar is private then don't display it
if (node !== null)
{
var eventsFolder = node.childByNamePath("CalEvents");
if (eventsFolder !== null)
{
model.events = eventsFolder.children;
}
}

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Save Calendar Event</shortname>
<description>Save Calendar Event</description>
<url>/calendar/create?what={whatEvent}&amp;where={whereEvent}&amp;desc={descriptionEvent}&amp;color={colorEvent}&amp;fd={fromDate}&amp;ft={fromTime}&amp;td={toDate}&amp;tt={toTime}&amp;id={nodeId}</url>
<format default="html">extension</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,39 @@
logger.log("DEBUG: create event script called");
logger.log("DEBUG: workspace://SpacesStore/" + args.id);
var node = search.findNode("workspace://SpacesStore/" + args.id);
logger.log("DEBUG: " + node);
if (node !== null)
{
var eventsFolder = node.childByNamePath("CalEvents");
if (eventsFolder === null)
{
eventsFolder = node.createFolder("CalEvents");
}
var timestamp = new Date().getTime();
var event = eventsFolder.createNode(timestamp + ".ics", "ia:calendarEvent");
event.properties["ia:whatEvent"] = args.what;
event.properties["ia:whereEvent"] = args.where;
event.properties["ia:descriptionEvent"] = args.desc;
event.properties["ia:colorEvent"] = args.color;
var fromDate = args.td + " " + args.tt;
var from = new Date(fromDate);
event.properties["ia:fromDate"] = from;
var toDate = args.td + " " + args.tt;
var to = new Date(toDate);
event.properties["ia:toDate"] = to;
event.save();
var msg = "Event saved";
}
else
{
var msg = "SPACE not found with Ref " + args.id;
}
model.msg = msg;

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>Event Listing</shortname>
<description>List of all upcoming events</description>
<url>/calendar/eventList</url>
<format default="json">extension</format>
<authentication>guest</authentication>
</webscript>

View File

@@ -0,0 +1,24 @@
var siteId = args["site"];
model.events = getEvents(siteId);
function getEvents(siteId)
{
var site = siteService.getSite(siteId);
if (site === null)
{
return [];
}
var calendar = site.getContainer("calendar");
if (calendar === null)
{
return [];
}
return calendar.children.sort(function(a,b) {
return a.properties["ia:fromDate"] - b.properties["ia:fromDate"];
});
};

View File

@@ -0,0 +1,20 @@
{
<#if events?exists && events?size &gt; 0>
<#assign prev = "">
<#list events as event>
<#assign date = event.properties["ia:fromDate"]?string("MM/dd/yyyy")>
<#if date != prev>
<#assign counter = 0>
<#if event_index &gt; 0>],</#if>
"${date}" : [
</#if>
<#if counter &gt; 0>,</#if>
{
"name" : "${event.properties["ia:whatEvent"]}"
}
<#assign counter = counter + 1>
<#if !event_has_next>]</#if>
<#assign prev = date>
</#list>
</#if>
}