2 /*global Config, Model, Ui*/
6 (function () { // strict mode wrapper
10 * Creates a new application object
14 App = function App() {};
20 requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js'],
55 * Initialisation function
57 init: function init() {
58 // instantiate the libs
59 this.config = new Config();
60 this.model = new Model();
63 // initialise the modules
64 this.model.init(this);
71 * Application exit from model
73 exit: function exit() {
79 * @returns {boolean} variable state after the toggle
81 switchFullDay: function switchFullDay() {
82 this.fullDay = !this.fullDay;
87 * Read the radio buttons and set this.alarm and this.alarmN accordingly
89 switchAlarm: function switchAlarm() {
91 duration = this.ui.alarm.getDuration();
94 this.alarmN = this.model.getCalendarAlarm(duration, "EventManager Reminder");
99 app.ui.alarm.updateDurationLabel();
103 * Create a new event in the default calendar,
104 * based on values found in #title, #des, #location
105 * and this.fullDay variable
107 addEvent: function addEvent(e) {
108 var selectedDate = '',
111 calendarItemInit = null,
114 fullDay = this.fullDay;
115 selectedDate = this.ui.home.getStartDate();
117 duration = this.calculateDuration(
119 this.ui.home.getEndDate(),
123 eventDate = this.createTZDateFromString(selectedDate);
126 startDate: eventDate,
129 summary: this.ui.home.getTitle()
132 this.calendarItemInit = calendarItemInit;
135 calendarItemInit.alarms = [this.alarmN];
138 this.model.addEventToDefaultCalendar(calendarItemInit);
140 console.error(ex.message);
142 this.loadEvents(eventDate);
145 updateEvent: function() {
146 var new_values, selectedDate, duration;
148 selectedDate = this.ui.home.getStartDate();
150 duration = this.calculateDuration(
152 this.ui.home.getEndDate(),
157 startDate: this.createTZDateFromString(selectedDate),
159 summary: this.ui.home.getTitle(),
163 // blocked by api issue
164 //new_values.alarms = [this.alarmN];
167 this.model.updateEvent(app.eventId, new_values);
172 * Calculates time duration
174 * If fullDay, then duration The duration must be n*60*24 minutes for an event lasting n days.
176 * @param {string} startDate
177 * @param {string} endDate
178 * @param {bool=} fullDay 'false' by default
179 * @returns {TimeDuration}
181 calculateDuration: function calculateDuration(startDate, endDate, fullDay) {
184 if (fullDay === undefined) {
188 startDate = new Date(startDate);
189 endDate = new Date(endDate);
191 duration = Math.round((endDate.getTime() - startDate.getTime()) / 60000); // needs duration in minutes;
193 return this.model.getTimeDuration(duration);
197 * Create a TZDate object for the given date string, all assuming
198 * using the local timezone
200 * @param {string} dateString Local date/datetime
202 createTZDateFromString: function (dateString) {
205 date = new Date(dateString);
206 tzDate = this.model.createTZDateFromDate(date);
211 * Load all scheduled events
213 loadEvents: function loadEvents() {
215 this.model.getEventsFromDefaultCalendar(
216 undefined, // we always load all events now
217 this.ui.home.onEventSearchSuccess.bind(this.ui.home), // Load events into the UI
218 this.ui.home.onEventSearchError.bind(this.ui.home)