Namespaces
Variants
Actions

Adding and deleting calendar events in Symbian Web Runtime

Jump to: navigation, search

This code example shows how to add and delete calendar entries on Symbian Web Runtime.

Article Metadata

Code Example
Tested with
Devices(s): Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 5th Edition

Article
Keywords: device.getServiceObject(), Service.Calendar.Add(), Service.Calendar.Delete()
Created: ivruban (10 Dec 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

Overview

The example uses the Calendar Platform Service, 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

Listing calendar entries in Symbian Web Runtime

This page was last modified on 5 October 2012, at 09:49.
364 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved