7 var Model = function Model() {
11 (function () { // strict mode wrapper
16 * Model module initialisation
18 init: function Model_init(app) {
23 * Creates a TimeDuration object corresponding to the given duration
26 * @param {int} mins Duration in minutes
27 * @return {TimeDuration}
29 getTimeDuration: function Model_getTimeDuration(mins) {
30 return new tizen.TimeDuration(mins, "MINS");
34 * Creates a CalendarAlarm with the given duration
36 * @param {int} minutes Alarm duration in minutes
37 * @returns {CalendarAlarm}
39 getCalendarAlarm: function Model_getCalendarAlarm(minutes, description) {
43 timeDuration = this.getTimeDuration(minutes);
44 calendarAlarm = new tizen.CalendarAlarm(timeDuration, "DISPLAY", description);
50 * Create a new event and add it to the default calendar
52 * @param {Object} calendarItemInit
53 * @config {TZDate} [startDate]
54 * @config {bool} [isAllDay]
55 * @config {TimeDuration} [duration]
56 * @config {string} [summary]
57 * @config {string} [description]
58 * @config {string} [location]
60 addEventToDefaultCalendar: function Model_addEventToDefaultCalendar(calendarItemInit) {
65 calendar = this.getCalendar();
66 event = new tizen.CalendarEvent(calendarItemInit);
70 getCalendar: function Model_getCalendar() {
71 return tizen.calendar.getDefaultCalendar("EVENT"); // get the default calendar
75 * Find all events in the default calendar on the given date
77 * @param {string} date date (in local time)
78 * @param {function} onSuccess success callback
79 * @param {function} onError error callback
81 getEventsFromDefaultCalendar: function Model_getEventsFromDefaultCalendar(date, onSuccess, onError) {
88 * @type {AttributeRangeFilter}
93 calendar = this.getCalendar();
97 filter = this.getStartDateFilter(new Date(date));
100 filter = this.getStartDateFilter(new Date(), true);
103 calendar.find(onSuccess, onError, filter);
107 * Create a startDate attribute range filter for the given day
110 * @param {bool} noEndDate
111 * @returns {AttributeRangeFilter}
113 getStartDateFilter: function Model_getStartDateFilter(date, noEndDate) {
118 // calculate start date for the filter
119 tzDate = new tizen.TZDate(date.getFullYear(), date.getMonth(), date.getDate());
122 endTzDate = undefined;
124 endTzDate = tzDate.addDuration(new tizen.TimeDuration("1", "DAYS")); // calculate end date
126 filter = new tizen.AttributeRangeFilter("startDate", tzDate, endTzDate);
131 * @param {string} event_id
133 deleteEvent: function Model_deleteEvent(event_id) {
134 var myCalendar = this.getCalendar();
135 myCalendar.remove(new tizen.CalendarEventId(event_id));
136 this.app.loadEvents(); // reload the list
140 * @param {string} event_id
142 editEvent: function Model_editEvent (event_id) {
143 var myCalendar = this.getCalendar();
144 return myCalendar.get(new tizen.CalendarEventId(event_id));
148 * @param {string} event_id
149 * @param {Object} new_values
151 updateEvent: function Model_updateEvent(event_id, new_values) {
152 var myCalendar = this.getCalendar(), new_event
153 event = myCalendar.get(new tizen.CalendarEventId(event_id));
155 for (var prop in new_values) {
156 if (new_values.hasOwnProperty(prop)) {
157 event[prop] = new_values[prop]; // copy new values into the event object
161 myCalendar.update(event, false); // save to myCalendar
166 * @returns {TZDate} date with timezone info
168 createTZDateFromDate: function Model_createTZDateFromDate(date) {
169 return new tizen.TZDate(date);
173 * Exit from the application
176 tizen.application.getCurrentApplication().exit();