diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 02:12:54 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 02:12:54 +0900 |
commit | d943eef4f484d9042e7bf254f97cde04d9f22b3a (patch) | |
tree | 373270bf305792c53d0dbb4ba94bba51daa4b11b /js/app.js | |
parent | 01efacd0e3742615d24e6a76b22c11f6a6955ddf (diff) | |
download | EventManager-d943eef4f484d9042e7bf254f97cde04d9f22b3a.tar.gz EventManager-d943eef4f484d9042e7bf254f97cde04d9f22b3a.tar.bz2 EventManager-d943eef4f484d9042e7bf254f97cde04d9f22b3a.zip |
Tizen 2.1 base
Diffstat (limited to 'js/app.js')
-rw-r--r-- | js/app.js | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..49612a5 --- /dev/null +++ b/js/app.js @@ -0,0 +1,201 @@ +/*jslint devel: true*/ +/*global Config, Model, Ui*/ + +var App = null; + +(function () { // strict mode wrapper + 'use strict'; + + /** + * Creates a new application object + * + * @class Application + */ + App = function App() {}; + + App.prototype = { + /** + * @type Array + */ + requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js'], + /** + * @type Config + */ + config: null, + /** + * @type Model + */ + model: null, + /** + * @type Ui + */ + ui: null, + /** + * @type bool + */ + fullDay: false, + /** + * @type bool + */ + alarm: false, + /** + * @type CalendarAlarm + */ + alarmN: null, + + /** + * @type Date + */ + lastDateLoaded: null, + + /** + * Initialisation function + */ + init: function init() { + // instantiate the libs + this.config = new Config(); + this.model = new Model(); + this.ui = new Ui(); + + // initialise the modules + this.model.init(this); + this.ui.init(this); + + return this; + }, + + /** + * Application exit from model + */ + exit: function exit() { + console.log('app.exit()'); + this.model.exit(); + }, + + /** + * Toggle this.fullDay + * @returns {boolean} variable state after the toggle + */ + switchFullDay: function switchFullDay() { + console.log('switchFullDay()'); + this.fullDay = !this.fullDay; + return this.fullDay; + }, + + /** + * Read the radio buttons and set this.alarm and this.alarmN accordingly + */ + switchAlarm: function switchAlarm() { + var duration = 0; + duration = this.ui.alarm.getDuration(); + + if (duration) { + this.alarmN = this.model.getCalendarAlarm(duration, "EventManager Reminder"); + this.alarm = true; + } else { + this.alarm = false; + } + }, + + /** + * Create a new event in the default calendar, + * based on values found in #title, #des, #location + * and this.fullDay variable + */ + addEvent: function addEvent() { + var selectedDate = '', + eventDate = null, + duration = 0, + calendarItemInit = null, + fullDay = false; + + fullDay = this.fullDay; + selectedDate = this.ui.home.getStartDate(); + + duration = this.calculateDuration( + selectedDate, + this.ui.home.getEndDate(), + fullDay + ); + + eventDate = this.createTZDateFromString(selectedDate); + + calendarItemInit = { + startDate: eventDate, + isAllDay: fullDay, + duration: duration, + summary: this.ui.home.getTitle(), + description: this.ui.home.getDescription(), + location: this.ui.home.getLocation() + }; + + this.calendarItemInit = calendarItemInit; + + if (this.alarmN) { + calendarItemInit.alarms = [this.alarmN]; + }/* + else{ + ev.alarms = null; + }*/ + try { + this.model.addEventToDefaultCalendar(calendarItemInit); + } catch (e) { + console.error(e); + } + this.loadEvents(eventDate); + }, + + /** + * Calculates time duration + * + * If fullDay, then duration The duration must be n*60*24 minutes for an event lasting n days. + * + * @param {string} startDate + * @param {string} endDate + * @param {bool=} fullDay 'false' by default + * @returns {TimeDuration} + */ + calculateDuration: function calculateDuration(startDate, endDate, fullDay) { + var duration = 0; + + if (fullDay === undefined) { + fullDay = false; + } + + startDate = new Date(startDate); + endDate = new Date(endDate); + + duration = Math.round((endDate.getTime() - startDate.getTime()) / 60000); // needs duration in minutes; + + return this.model.getTimeDuration(duration); + }, + + /** + * Create a TZDate object for the given date string, all assuming + * using the local timezone + * + * @param {string} dateString Local date/datetime + */ + createTZDateFromString: function (dateString) { + var date = null, + tzDate = null; + date = new Date(dateString); + tzDate = this.model.createTZDateFromDate(date); + return tzDate; + }, + + /** + * Load all scheduled events + */ + loadEvents: function loadEvents() { + console.log("App.loadEvents()"); + + this.model.getEventsFromDefaultCalendar( + undefined, // we always load all events now + this.ui.home.onEventSearchSuccess.bind(this.ui.home), // Load events into the UI + this.ui.home.onEventSearchError.bind(this.ui.home) + ); + } + + }; +}()); |