- '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)
- );
- }
-
- };
-}());
+ '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,
+ /**
+ * @type Integer
+ */
+ eventId: 0,
+
+ /**
+ * 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() {
+ this.model.exit();
+ },
+
+ /**
+ * Toggle this.fullDay
+ * @returns {boolean} variable state after the toggle
+ */
+ switchFullDay: function 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;
+ }
+ app.ui.alarm.updateDurationLabel();
+ },
+
+ /**
+ * Create a new event in the default calendar,
+ * based on values found in #title, #des, #location
+ * and this.fullDay variable
+ */
+ addEvent: function addEvent(e) {
+ 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()
+ };
+
+ this.calendarItemInit = calendarItemInit;
+
+ if (this.alarmN) {
+ calendarItemInit.alarms = [this.alarmN];
+ }
+ try {
+ this.model.addEventToDefaultCalendar(calendarItemInit);
+ } catch (ex) {
+ console.error(ex.message);
+ }
+ this.loadEvents(eventDate);
+ },
+
+ updateEvent: function() {
+ var new_values, selectedDate, duration;
+
+ selectedDate = this.ui.home.getStartDate();
+
+ duration = this.calculateDuration(
+ selectedDate,
+ this.ui.home.getEndDate(),
+ false
+ );
+
+ new_values = {
+ startDate: this.createTZDateFromString(selectedDate),
+ duration: duration,
+ summary: this.ui.home.getTitle(),
+ }
+
+ if (this.alarmN) {
+ // blocked by api issue
+ //new_values.alarms = [this.alarmN];
+ }
+
+ this.model.updateEvent(app.eventId, new_values);
+ this.loadEvents();
+ },
+
+ /**
+ * 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() {
+
+ 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)
+ );
+ }
+
+ };
+}());
\ No newline at end of file