×
Namespaces

Variants
Actions
Revision as of 09:33, 5 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Adding and deleting calendars in Symbian Web Runtime

From Nokia Developer Wiki
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 ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
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.
85 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×