| 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() |
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.
<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();">
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);
}
}
The user can add and delete calendar entries 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_events_in_WRT.zip.
No related wiki articles found