You Are Here:

Community: Wiki

This page was last modified on 20 January 2009, at 08:20.

CS001244 - Listing calendar entries in WRT

From Forum Nokia Wiki



ID CS001244 Creation date December 18, 2008
Platform S60 5th Edition Tested on devices Nokia 5800 XpressMusic
Category Web Runtime (WRT) Subcategory PIM


Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.Calendar.GetList()

Overview

This code snippet shows how to list calendar entries by using the Calendar Platform Service for S60 Web Runtime introduced in S60 5th Edition.

The device.getServiceObject("Service.Calendar", "IDataSource") method is used to obtain access to the service object for the Calendar Service API.

Source: Relevant HTML components

<input type="radio" name="eventType" id="meeting" checked
onclick="showEntries();">
<label for="meeting">Meetings</label><br />
 
<input type="radio" name="eventType" id="anniversary"
onclick="showEntries();">
<label for="anniversary">Anniversaries</label><br />
 
<input type="radio" name="eventType" id="dayEvent"
onclick="showEntries();">
<label for="dayEvent">Day Events</label><br />
 
<input type="radio" name="eventType" id="reminder"
onclick="showEntries();">
<label for="reminder">Reminders</label><br />
 
<input type="radio" name="eventType" id="toDo"
onclick="showEntries();">
<label for="toDo">ToDos</label><br />
 
<label for="entriesList">Entries:</label><br />
<select size="2" id="entriesList"></select><br />

Source: JavaScript file

var serviceObj = null;
 
window.onload = init;
 
// Initializes the widget
function init() {
// Obtain the service object
try {
serviceObj = device.getServiceObject("Service.Calendar",
"IDataSource");
} catch (ex) {
alert("Service object cannot be found.");
return;
}
}
 
function showEntries() {
var criteria = new Object();
var filter = new Object();
if (document.getElementById("meeting").checked) {
filter.Type = "Meeting";
} else if (document.getElementById("anniversary").checked) {
filter.Type = "Anniversary";
} else if (document.getElementById("dayEvent").checked) {
filter.Type = "DayEvent";
} else if (document.getElementById("reminder").checked) {
filter.Type = "Reminder";
} else if (document.getElementById("toDo").checked) {
filter.Type = "ToDo";
}
criteria.Filter = filter;
criteria.Type = "CalendarEntry";
 
// Get the list of entries
try {
var result = serviceObj.IDataSource.GetList(criteria);
if (result.ErrorCode == 0) {
displayEntries(result.ReturnValue);
} else {
alert("Error in getting calendar entries.");
}
} catch(exception) {
alert("Error in getting calendar entries: " + result.ErrorMessage);
}
}
 
function displayEntries(iterator) {
var entriesList = document.getElementById("entriesList");
 
// Empty the entries list
while (entriesList.length != 0) {
entriesList.remove(0);
}
 
// Set the pointer to the first element
iterator.reset();
 
var item;
while ((item = iterator.getNext()) != undefined) {
var msg = "";
msg = msg + "Type: " + item['Type'];
msg = msg + "Summary: " + item['Summary'];
// The commented code shows available fields that can be retrieved
//msg = msg + "StartTime: " + item['StartTime'];
//msg = msg + "EndTime: " + item['EndTime'];
//msg = msg + "Id: " + item['Id'];
//msg = msg + "LocalId: " + item['LocalId'];
var node = document.createElement("option");
node.value = item['LocalId'];
node.appendChild(document.createTextNode(msg));
entriesList.appendChild(node);
}
}

Postconditions

Available calendar entries are displayed.

Supplementary material

You can view the source file and executable application in the attached ZIP archive. The archive is available for download at Media:Listing_calendars_and_events_in_WRT.zip.

See also

CS001278 - Listing calendars in WRT

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia