Namespaces
Variants
Actions

Adding and deleting calendars in Symbian Web Runtime

Jump to: navigation, search

Contents

Overview

This code example demonstrates how to add and delete calendars on Symbian Web Runtime, using the Calendar Service API (introduced in S60 5th Edition).

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

Article Metadata

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

Compatibility
Platform(s): S60 5th Edition

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

Source: Relevant HTML components

<label for="calendarList">Calendars:</label><br />
<select size="2" id="calendarList" onclick="showEvents();"></select><br />
 
<input type="button" value="Add" id="add" onclick="addCalendar();">
<input type="button" value="Delete" id="delete" onclick="deleteCalendar();">

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;
}
 
listCalendars();
}
 
function listCalendars() {
// Listing calendars is omitted here for brevity. Refer to the See also
// section for the code snippet that provides you with more information.
// ...
}
 
function addCalendar() {
var calName = prompt("Please enter the calendar name", "C:NewCalendar");
if (calName == "" || calName == null) {
return;
}
var criteria = new Object();
criteria.Type = "Calendar";
 
var item = new Object();
item.CalendarName = calName;
criteria.Item = item;
 
try {
var result = serviceObj.IDataSource.Add(criteria);
if (result.ErrorCode != 0){
alert("Error in adding a new calendar");
}
listCalendars();
} catch (ex) {
alert("Error in adding a new calendar: " + ex);
}
}
 
function deleteCalendar() {
var calendarList = document.getElementById("calendarList");
var calName = "";
for (var i = 0; i < calendarList.options.length; i++) {
if (calendarList.options[i].selected) {
calName = calendarList.options[i].value;
}
}
if (calName == "" || calName == null) {
return;
}
var criteria = new Object();
criteria.Type = "Calendar";
 
var delData = new Object();
delData.CalendarName = calName;
criteria.Data = delData;
 
try {
var result = serviceObj.IDataSource.Delete(criteria);
if (result.ErrorCode != 0){
alert("Error in deleting the calendar");
}
listCalendars();
} catch (ex) {
alert("Error in deleting the calendar: " + ex);
}
}

Postconditions

The user can add and delete calendars 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 in WRT.zip.

See also

Listing calendars in Symbian Web Runtime

This page was last modified on 5 October 2012, at 09:33.
143 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