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'],
52 * Initialisation function
54 init: function init() {
55 // instantiate the libs
56 this.config = new Config();
57 this.model = new Model();
60 // initialise the modules
61 this.model.init(this);
68 * Application exit from model
70 exit: function exit() {
71 console.log('app.exit()');
77 * @returns {boolean} variable state after the toggle
79 switchFullDay: function switchFullDay() {
80 console.log('switchFullDay()');
81 this.fullDay = !this.fullDay;
86 * Read the radio buttons and set this.alarm and this.alarmN accordingly
88 switchAlarm: function switchAlarm() {
90 duration = this.ui.alarm.getDuration();
93 this.alarmN = this.model.getCalendarAlarm(duration, "EventManager Reminder");
101 * Create a new event in the default calendar,
102 * based on values found in #title, #des, #location
103 * and this.fullDay variable
105 addEvent: function addEvent() {
106 var selectedDate = '',
109 calendarItemInit = null,
112 fullDay = this.fullDay;
113 selectedDate = this.ui.home.getStartDate();
115 duration = this.calculateDuration(
117 this.ui.home.getEndDate(),
121 eventDate = this.createTZDateFromString(selectedDate);
124 startDate: eventDate,
127 summary: this.ui.home.getTitle(),
128 description: this.ui.home.getDescription(),
129 location: this.ui.home.getLocation()
132 this.calendarItemInit = calendarItemInit;
135 calendarItemInit.alarms = [this.alarmN];
141 this.model.addEventToDefaultCalendar(calendarItemInit);
145 this.loadEvents(eventDate);
149 * Calculates time duration
151 * If fullDay, then duration The duration must be n*60*24 minutes for an event lasting n days.
153 * @param {string} startDate
154 * @param {string} endDate
155 * @param {bool=} fullDay 'false' by default
156 * @returns {TimeDuration}
158 calculateDuration: function calculateDuration(startDate, endDate, fullDay) {
161 if (fullDay === undefined) {
165 startDate = new Date(startDate);
166 endDate = new Date(endDate);
168 duration = Math.round((endDate.getTime() - startDate.getTime()) / 60000); // needs duration in minutes;
170 return this.model.getTimeDuration(duration);
174 * Create a TZDate object for the given date string, all assuming
175 * using the local timezone
177 * @param {string} dateString Local date/datetime
179 createTZDateFromString: function (dateString) {
182 date = new Date(dateString);
183 tzDate = this.model.createTZDateFromDate(date);
188 * Load all scheduled events
190 loadEvents: function loadEvents() {
191 console.log("App.loadEvents()");
193 this.model.getEventsFromDefaultCalendar(
194 undefined, // we always load all events now
195 this.ui.home.onEventSearchSuccess.bind(this.ui.home), // Load events into the UI
196 this.ui.home.onEventSearchError.bind(this.ui.home)