//
// Licensed to Jasig under one or more contributor license
// agreements. See the NOTICE file distributed with this work
// for additional information regarding copyright ownership.
// Jasig licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a
// copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// Insert Bedework calendar events from a json feed
var bwJsWidgetOptions = {
title: 'Upcoming Events',
showTitle: true,
displayDescription: false,
calendarServer: 'http://events.albany.edu',
calSuiteContext: '/cal',
listMode: 'byTitle', // values: 'byDate' or 'byTitle' - highlights the date or title first (sort is always by date)
displayEndDateInList: true,
displayTimeInList: true,
displayLocationInList: false,
displayEventDetailsInline: false,
displayContactInDetails: true,
displayCostInDetails: true,
displayTagsInDetails: true,
displayTimezoneInDetails: true,
limitList: false,
limit: 5
};
// Insert Bedework calendar events from a json feed
function insertBwEvents(outputContainerID) {
var outputContainer = document.getElementById(outputContainerID);
var output = "";
var eventlist = new Array();
var eventIndex = 0;
var xprops = new Array();
var xpropsIndex = 0;
var image = "";
if ((bwObject.bwEventList != undefined) &&
(bwObject.bwEventList.events != undefined) &&
(bwObject.bwEventList.events.length > 0)) {
// get events
for (i = 0; i < bwObject.bwEventList.events.length; i++) {
eventlist[eventIndex] = i;
eventIndex++;
}
// GENERATE OUTPUT
// This is where you may wish to customize the output. To see what
// fields are available for events, look at the json source file included
// by the widget code. The core formatting is done in formatDateTime()
// and formatSummary()
// The title is included because you may wish to hide it when
// no events are present.
if (bwJsWidgetOptions.showTitle) {
output += "
" + bwJsWidgetOptions.title + "
";
}
// Output the list
output += "";
// Now, iterate over the events:
for(i in eventlist){
// stop if we've reached a limit on the number of events
if(bwJsWidgetOptions.limitList && bwJsWidgetOptions.limit == i) {
break;
}
// provide a shorthand reference to the event:
var event = bwObject.bwEventList.events[eventlist[i]];
// create the list item:
output += "- ";
if (bwJsWidgetOptions.listMode == 'byDate') {
//loop through each event's xproperties array of each event to find the X-BEDEWORK-IMAGE object that holds the image URL
for (k=0; k < event.xproperties.length; k++) {
xprops[xpropsIndex] = event.xproperties[k];
//check to see if each element in the xproperties array is the X-BEDWORK-IMAGE object
tempcheck = Object.prototype.toString.call(xprops[xpropsIndex]["X-BEDEWORK-IMAGE"]);
if (tempcheck == "[object Object]") {
//if this is the X-BEDWORK-IMAGE Object get the text value
image = xprops[xpropsIndex]["X-BEDEWORK-IMAGE"].values.text;
}
xpropsIndex++;
}
//if there is image information available add it to the list item being worked on by the function and the reset the image information to an empty string
if (image !== "") {
var testlink = image.substr(0,4);
if (testlink == "http"){
output += " ";
image = "";
}
}
output += formatBwDateTime(event);
output += "
"
output += formatBwSummary(event,outputContainerID,i);
} else {
//loop through each event's xproperties array of each event to find the X-BEDEWORK-IMAGE object that holds the image URL
for (l = 0; l < event.xproperties.length; l++) {
xprops[xpropsIndex] = event.xproperties[l];
//check to see if each element in the xproperties array is the X-BEDWORK-IMAGE object
tempcheck = Object.prototype.toString.call(xprops[xpropsIndex]["X-BEDEWORK-IMAGE"]);
if (tempcheck == "[object Object]") {
//if this is the X-BEDWORK-IMAGE Object append an absolute URL path to the text value
image = xprops[xpropsIndex]["X-BEDEWORK-IMAGE"].values.text;
}
xpropsIndex++;
}
//if there is image information available add it to the list item being worked on by the function and the reset the image information to an empty string
if (image !== "") {
var testlink = image.substr(0,4);
if (testlink == "http"){
output += " ";
image = "";
}}
output += formatBwSummary(event,outputContainerID,i);
output += "
"
output += formatBwDateTime(event);
}
if (bwJsWidgetOptions.displayLocationInList) {
output += "
" + event.location.address + "";
}
if (bwJsWidgetOptions.displayDescription) {
output += "";
output += event.description.replace(/\n/g,'
');
output += "
";
output += "
";
}
output += " ";
}
output += "
";
// Finally, send the output to the container:
outputContainer.innerHTML = output;
}
}
function formatBwDateTime(event) {
var output = "";
output += "";
if (bwJsWidgetOptions.listMode == 'byDate') {
output +="";
}
// would much prefer to pass in a date/time format string, but can't do so
// in an internationalized way.
output += event.start.longdate;
if ((event.start.allday == 'false') && bwJsWidgetOptions.displayTimeInList) {
output += " " + event.start.time;
}
if (bwJsWidgetOptions.displayEndDateInList) {
if (event.start.shortdate != event.end.shortdate) {
output += " - ";
output += event.end.longdate;
if ((event.start.allday == 'false') && bwJsWidgetOptions.displayTimeInList) {
output += " " + event.end.time;
}
} else if ((event.start.allday == 'false') &&
bwJsWidgetOptions.displayTimeInList &&
(event.start.time != event.end.time)) {
// same date, different times
output += " - " + event.end.time;
}
}
if (bwJsWidgetOptions.listMode == 'byDate') {
output +="";
}
output += "";
return output;
}
function formatBwSummary(event,outputContainerID,i) {
var output = "";
output += "";
if (bwJsWidgetOptions.listMode == 'byTitle') {
output +="";
}
if (bwJsWidgetOptions.displayEventDetailsInline) {
// don't link back to the calendar - display event details in the widget
output += "" + event.summary + "";
} else {
// link back to the calendar
// Include the urlPrefix for links back to events in the calendar.
var urlPrefix = bwJsWidgetOptions.calendarServer + bwJsWidgetOptions.calSuiteContext + "/event/eventView.do";
// generate the query string parameters that get us back to the
// event in the calendar:
var eventQueryString = "?subid=" + event.subscriptionId;
eventQueryString += "&calPath=" + event.calPath;
eventQueryString += "&guid=" + event.guid;
eventQueryString += "&recurrenceId=" + event.recurrenceId;
output += "" + event.summary + "";
}
if (bwJsWidgetOptions.listMode == 'byTitle') {
output +="";
}
output += "";
return output;
}
function showBwEvent(outputContainerID, eventId) {
// Style further with CSS
var outputContainer = document.getElementById(outputContainerID);
var output = "";
var xprops = new Array();
var xpropsIndex = 0;
var image = "";
// provide a shorthand reference to the event:
var event = bwObject.bwEventList.events[eventId];
for (l = 0; l < event.xproperties.length; l++) {
xprops[xpropsIndex] = event.xproperties[l];
//check to see if each element in the xproperties array is the X-BEDWORK-IMAGE object
tempcheck = Object.prototype.toString.call(xprops[xpropsIndex]["X-BEDEWORK-IMAGE"]);
if (tempcheck == "[object Object]") {
//if this is the X-BEDWORK-IMAGE Object append an absolute URL path to the text value
image = xprops[xpropsIndex]["X-BEDEWORK-IMAGE"].values.text;
}
xpropsIndex++;
}
//if there is image information available add it to the list item being worked on by the function and the reset the image information to an empty string
if (image !== "") {
var testlink = image.substr(0,4);
if (testlink == "http"){
output += "";
image = "";
}}
// create the event
output += "" + event.summary + "
";
output += "";
// output date/time
output += "
";
output += event.start.longdate;
if ((event.start.allday == 'false') && bwJsWidgetOptions.displayTimeInList) {
output += " " + event.start.time;
if ((event.start.timezone != event.end.timezone) &&
bwJsWidgetOptions.displayTimezoneInDetails) {
output += " " + event.start.timezone;
}
}
if (event.start.shortdate != event.end.shortdate) {
output += " - ";
output += event.end.longdate;
if (event.start.allday == 'false') {
output += " " + event.end.time;
if (bwJsWidgetOptions.displayTimezoneInDetails) {
output += " " + event.end.timezone;
}
}
} else if ((event.start.allday == 'false') &&
(event.start.time != event.end.time)) {
// same date, different times
output += " - " + event.end.time;
if (bwJsWidgetOptions.displayTimezoneInDetails) {
output += " " + event.end.timezone;
}
}
output += "
";
// output location
output += "
";
// output description
output += "
";
output += event.description.replace(/\n/g,'
');
output += "
";
// output contact
if (bwJsWidgetOptions.displayContactInDetails) {
output += "
";
}
// output cost
if (event.cost != "" && bwJsWidgetOptions.displayCostInDetails) {
output += "
";
output += "Cost: " + event.cost;
output += "
";
}
// output tags (categories)
if (event.categories != "" && bwJsWidgetOptions.displayTagsInDetails) {
output += "
";
output += "Tags: " + event.categories;
output += "
";
}
// output link
if (event.link != "") {
output += "
";
}
output += "
";
// create a link back to the main view
output += " Return ";
// Send the output to the container:
outputContainer.innerHTML = output;
}