| ID | CS001230 | Creation date | January 14, 2009 |
| 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() |
This code snippet demonstrates how to use the Calendar Service API for Web Runtime (introduced in S60 5th Edition) to add and delete calendars.
To obtain access to a service object for the Calendar Service API, the device.getServiceObject("Service.Calendar", "IDataSource") method is used.
<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();">
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);
}
}
The user can add and delete calendars by pressing the Add and Delete buttons.
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.
No related wiki articles found