You Are Here:

Community: Wiki

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

CS001233 - Adding and deleting calendar events in WRT

From Forum Nokia Wiki



ID CS001233 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.Add(), Service.Calendar.Delete()

Overview

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

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

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 />
 
<input type="button" value="Add" id="add" onclick="addEntry();">
<input type="button" value="Delete" id="delete" onclick="deleteEntry();">

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() {
// Showing calendar entries is omitted here for brevity. Refer to the See
// also section of the snippet for more information.
// ...
}
 
function addEntry() {
var item = new Object();
item.Type = "Meeting";
 
var startDate = new Date("January 6, 2009 19:05:00");
var endDate = new Date("January 7, 2009 20:05:00");
item.StartTime = startDate;
item.EndTime = endDate;
 
var criteria = new Object();
criteria.Type = "CalendarEntry";
criteria.Item = item;
try {
var result = serviceObj.IDataSource.Add(criteria);
if (result.ErrorCode == 0) {
showEntries();
} else {
alert("Error in adding calendar entry");
}
} catch (ex) {
alert("Error in adding calendar entry: " + ex);
}
}
 
function deleteEntry() {
// Get the selected calendar entry
var entriesList = document.getElementById("entriesList");
var entryId = "";
for (var i = 0; i < entriesList.options.length; i++) {
if (entriesList.options[i].selected) {
entryId = entriesList.options[i].value;
break;
}
}
var criteria = new Object();
criteria.Type = "CalendarEntry";
criteria.Data = new Object();
criteria.Data.LocalIdList = new Array();
criteria.Data.LocalIdList[0] = entryId;
try {
var result = serviceObj.IDataSource.Delete(criteria);
if(result.ErrorCode == 0) {
showEntries();
} else {
alert("Error in deleting calendar entry");
}
} catch (ex) {
alert("Error in deleting calendar entry: " + ex);
}
}

Postconditions

The user can add and delete calendar entries by pressing the Add and Delete buttons.

Supplementary material

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

See also

CS001244 - Listing calendar entries 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