-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint devel:true*/
-/*global Config, Model, Ui, app, $, tizen */
+/*global Config, Model, Ui, app*/
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',
- 'js/app.ui.templateManager.modifiers.js'],
- /**
- * @type Config
- */
- config: null,
- /**
- * @type Model
- */
- model: null,
- /**
- * @type Ui
- */
- ui: null,
- /**
- * @type bool
- */
- allDay: false,
- /**
- * @type bool
- */
- alarm: false,
- /**
- * @type CalendarAlarm
- */
- alarmN: null,
- /**
- * @type Date
- */
- lastDateLoaded: null,
- /**
- * @type Integer
- */
- eventId: 0,
-
- homeDateFilter: new Date(),
-
- /**
- * 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.allDay
- * @returns {boolean} variable state after the toggle
- */
- switchAllDay: function switchAllDay() {
- this.allDay = !this.allDay;
- return this.allDay;
- },
-
- /**
- * read initial alarm setting
- */
- setAlarm: function setAlarm(duration) {
- if (duration !== -1) {
- this.alarmN = this.model.getCalendarAlarm(duration,
- 'EventManager Reminder');
- this.alarm = true;
- } else {
- this.alarmN = [];
- this.alarm = false;
- }
- },
-
- /**
- * Read the radio buttons and set this.alarm and this.alarmN accordingly
- */
- switchAlarm: function switchAlarm() {
- var duration = -1;
- duration = this.ui.alarm.getValue();
- this.setAlarm(duration);
- app.ui.alarm.updateDurationLabel();
- $.mobile.changePage('#new_event');
- },
-
- retrieveTimeDurationInMinutes: function (duration) {
- switch (duration.unit) {
- case 'MSECS':
- return (duration.length / (60 * 1000));
- case 'SECS':
- return (duration.length / 60);
- case 'MINS':
- return duration.length;
- case 'HOURS':
- return (duration.length * 60);
- case 'DAYS':
- return (duration.length * 60 * 24);
- }
- return duration.length;
- },
-
- /**
- * Create a new event in the default calendar,
- * based on values found in #title, #des, #location
- * and this.allDay variable
- */
- addEvent: function addEvent(e, callback) {
- var startDateString = '',
- endDateString = '',
- startDate = null,
- allDay = false,
- duration = 0,
- calendarItemInit = null;
-
- startDateString = this.ui.home.getStartDate();
- endDateString = this.ui.home.getEndDate();
- allDay = this.ui.home.getAllDayInfo();
- if (allDay) {
- startDateString = startDateString
- .replace(/[0-9]+:[0-9]+:[0-9]+/, '00:00:00');
- endDateString = endDateString
- .replace(/[0-9]+:[0-9]+:[0-9]+/, '00:00:00');
- }
-
- duration = this.calculateDuration(
- startDateString,
- endDateString,
- allDay
- );
-
- startDate = this.createTZDateFromString(startDateString);
- startDate.setSeconds(0);
-
- calendarItemInit = {
- startDate: startDate,
- isAllDay: allDay,
- duration: duration,
- summary: this.ui.home.getTitle(),
- status: 'TENTATIVE',
- priority: 'MEDIUM'
- };
- this.calendarItemInit = calendarItemInit;
-
- if (this.alarmN) {
- calendarItemInit.alarms = [this.alarmN];
- }
- try {
- this.model.addEventToDefaultCalendar(calendarItemInit);
- } catch (ex) {
- console.error(ex.message);
- }
-
- this.changeHomeDateFilter(new Date(startDateString));
- this.loadEvents(startDate);
- if (typeof callback === 'function') {
- callback();
- }
- },
-
- updateEvent: function (e, callback) {
- var new_values, selectedDate, duration, allDay;
-
- selectedDate = this.ui.home.getStartDate();
- allDay = this.ui.home.getAllDayInfo();
-
- duration = this.calculateDuration(
- selectedDate,
- this.ui.home.getEndDate(),
- allDay
- );
-
- new_values = {
- startDate: this.createTZDateFromString(selectedDate),
- duration: duration,
- summary: this.ui.home.getTitle(),
- isAllDay: allDay,
- alarms: []
- };
-
- if (this.alarmN) {
- new_values.alarms = [this.alarmN];
- }
- this.model.updateEvent(app.eventId, new_values);
-
- this.changeHomeDateFilter(new Date(selectedDate));
- this.loadEvents();
- if (typeof callback === 'function') {
- callback();
- }
- },
-
- changeHomeDateFilter: function (date) {
- this.homeDateFilter = date;
- app.ui.home.updateHomeDateFilter();
- },
-
- /**
- * Calculates time duration.
- *
- * @param {string} startDate
- * @param {string} endDate
- * @param {bool=} allDay 'false' by default
- * @returns {TimeDuration}
- */
- calculateDuration: function calculateDuration(
- startDate,
- endDate,
- allDay
- ) {
- var minutes;
- startDate = new Date(startDate);
- endDate = new Date(endDate);
- // duration in minutes
- minutes = Math.round(
- (endDate.getTime() - startDate.getTime()) / 60000
- );
- if (allDay) {
- // round up to full days
- minutes = Math.ceil(minutes / (60 * 24) + 1) * (60 * 24);
- }
- return this.model.getTimeDuration(minutes);
- },
-
- /**
- * 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
- // Load events into the UI
- this.ui.home.onEventSearchSuccess.bind(this.ui.home),
- this.ui.home.onEventSearchError.bind(this.ui.home)
- );
- },
-
- /**
- * Check, if delete popup is active and if 'yes' check it could be
- * active
- */
- checkDeletePopup: function checkDeletePopup() {
- if ($.mobile.popup.active) {
- this.model.isEventExists(app.eventId, null, function () {
- $('#popup').popup('close');
- app.eventId = 0;
- });
- }
- }
- };
+ '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', 'js/app.ui.templateManager.modifiers.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,
+
+ homeDateFilter: new Date(),
+
+ /**
+ * 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 initial alarm setting
+ */
+ setAlarm: function setAlarm(duration) {
+ if (duration != -1) {
+ this.alarmN = this.model.getCalendarAlarm(duration, "EventManager Reminder");
+ this.alarm = true;
+ } else {
+ this.alarmN = [];
+ this.alarm = false;
+ }
+ },
+
+ /**
+ * Read the radio buttons and set this.alarm and this.alarmN accordingly
+ */
+ switchAlarm: function switchAlarm() {
+ var duration = -1;
+ duration = this.ui.alarm.getValue();
+ this.setAlarm(duration);
+ app.ui.alarm.updateDurationLabel();
+ },
+
+ retrieveTimeDurationInMinutes: function(duration) {
+ switch (duration.unit) {
+ case "MSECS":
+ return (duration.length / (60 * 1000));
+ case "SECS":
+ return (duration.length / 60);
+ case "MINS":
+ return duration.length;
+ case "HOURS":
+ return (duration.length * 60);
+ case "DAYS":
+ return (duration.length * 60 * 24);
+ }
+ return duration.length;
+ },
+
+ /**
+ * Create a new event in the default calendar,
+ * based on values found in #title, #des, #location
+ * and this.fullDay variable
+ */
+ addEvent: function addEvent(e, callback) {
+ var selectedDate = '',
+ eventDate = null,
+ duration = 0,
+ calendarItemInit = null,
+ fullDay = false;
+
+ fullDay = this.ui.home.getAllDayInfo();
+ 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.changeHomeDateFilter(new Date(selectedDate));
+ this.loadEvents(eventDate);
+ if (typeof callback === 'function'){
+ callback();
+ }
+ },
+
+ updateEvent: function (e, callback) {
+ var new_values, selectedDate, duration, fullDay;
+
+ selectedDate = this.ui.home.getStartDate();
+ fullDay = this.ui.home.getAllDayInfo();
+
+ duration = this.calculateDuration(
+ selectedDate,
+ this.ui.home.getEndDate(),
+ fullDay
+ );
+
+ new_values = {
+ startDate: this.createTZDateFromString(selectedDate),
+ duration: duration,
+ summary: this.ui.home.getTitle(),
+ isAllDay: fullDay,
+ alarms: []
+ };
+
+ if (this.alarmN) {
+ new_values.alarms = [this.alarmN];
+ }
+ this.model.updateEvent(app.eventId, new_values);
+
+ this.changeHomeDateFilter(new Date(selectedDate));
+ this.loadEvents();
+ if (typeof callback === 'function'){
+ callback();
+ }
+ },
+
+ changeHomeDateFilter: function (date) {
+ this.homeDateFilter = date;
+ app.ui.home.updateHomeDateFilter();
+ },
+
+ /**
+ * 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) {
+ if (fullDay) {
+ return new tizen.TimeDuration(24*60-1, "MINUTES");
+ }
+ startDate = new Date(startDate);
+ endDate = new Date(endDate);
+ // duration in minutes
+ return this.model.getTimeDuration(
+ Math.round((endDate.getTime() - startDate.getTime()) / 60000)
+ );
+ },
+
+ /**
+ * 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
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint devel:true*/
-/*global tizen, app */
+/*global tizen */
/**
* @class Model
*/
var Model = function Model() {
- 'use strict';
+ 'use strict';
};
(function () { // strict mode wrapper
- 'use strict';
- Model.prototype = {
-
- /**
- * @type Long
- */
- listenerId: 0,
- /**
- * Model module initialisation
- */
- init: function Model_init(app) {
- this.app = app;
- this.addEventListener();
- },
-
- /**
- * Creates a TimeDuration object corresponding to the given duration
- * in minutes
- *
- * @param {int} minutes Duration in minutes
- * @return {TimeDuration}
- */
- getTimeDuration: function Model_getTimeDuration(minutes) {
- if (minutes === 0) {
- return new tizen.TimeDuration(minutes, 'MINS');
- }
- if (minutes % 1440 === 0) {
- return new tizen.TimeDuration(minutes / 1440, 'DAYS');
- }
- if (minutes % 60 === 0) {
- return new tizen.TimeDuration(minutes / 60, 'HOURS');
- }
- return new tizen.TimeDuration(minutes, 'MINS');
- },
-
- /**
- * Creates a CalendarAlarm with the given duration
- *
- * @param {int} minutes Alarm duration in minutes
- * @returns {CalendarAlarm}
- */
- getCalendarAlarm:
- function Model_getCalendarAlarm(minutes, description) {
- var timeDuration,
- calendarAlarm;
-
- timeDuration = this.getTimeDuration(minutes);
- calendarAlarm = new tizen.CalendarAlarm(timeDuration, 'DISPLAY',
- description);
- return calendarAlarm;
- },
-
- /**
- * Create a new event and add it to the default calendar
- *
- * @param {Object} calendarItemInit
- * @config {TZDate} [startDate]
- * @config {bool} [isAllDay]
- * @config {TimeDuration} [duration]
- * @config {string} [summary]
- * @config {string} [description]
- * @config {string} [location]
- */
- addEventToDefaultCalendar:
- function Model_addEventToDefaultCalendar(calendarItemInit) {
- var calendar = null,
- event = null;
- calendar = this.getCalendar();
- event = new tizen.CalendarEvent(calendarItemInit);
- calendar.add(event);
- },
-
- getCalendar: function Model_getCalendar() {
- // get the default calendar
- return tizen.calendar.getDefaultCalendar('EVENT');
- },
-
- /**
- * Find all events in the default calendar on the given date
- *
- * @param {string} date date (in local time)
- * @param {function} onSuccess success callback
- * @param {function} onError error callback
- */
- getEventsFromDefaultCalendar:
- function Model_getEventsFromDefaultCalendar(date, onSuccess,
- onError) {
- var calendar = null, filter = null;
-
- calendar = this.getCalendar();
-
- // show all events
- filter = this.getStartDateFilter(app.homeDateFilter);
-
- calendar.find(onSuccess, onError, filter);
- },
-
- /**
- * Create a startDate attribute range filter for the given day
- *
- * @param {Date} date
- * @returns {AttributeRangeFilter}
- */
- getStartDateFilter: function Model_getStartDateFilter(date) {
- var beginOfToday = new tizen.TZDate(date.getFullYear(),
- date.getMonth(),
- date.getDate(),
- 0, 0, 0, 0
- ),
- endOfToday = new tizen.TZDate(date.getFullYear(),
- date.getMonth(),
- date.getDate(),
- 23, 59, 59, 999
- ),
- endOfTomorrow = new tizen.TZDate(date.getFullYear(),
- date.getMonth(),
- date.getDate() + 1,
- 23, 59, 59, 999
- );
- return new tizen.CompositeFilter(
- 'UNION',
- [
- new tizen.CompositeFilter(
- 'INTERSECTION',
- [
- new tizen.AttributeFilter(
- 'isAllDay',
- 'EXACTLY',
- false
- ),
- new tizen.AttributeRangeFilter(
- 'startDate',
- null,
- endOfToday
- ),
- new tizen.AttributeRangeFilter(
- 'endDate',
- beginOfToday,
- null
- )
- ]
- ),
- new tizen.CompositeFilter(
- 'INTERSECTION',
- [
- new tizen.AttributeFilter(
- 'isAllDay',
- 'EXACTLY',
- true
- ),
- new tizen.AttributeRangeFilter(
- 'startDate',
- null,
- endOfToday
- ),
- new tizen.AttributeRangeFilter(
- 'endDate',
- endOfTomorrow,
- null
- )
- ]
- )
- ]
- );
- },
-
- isEventExists: function (event_id, success, error) {
- var myCalendar = this.getCalendar();
- error = error || new Function();
- success = success || new Function();
- try {
- myCalendar.get(new tizen.CalendarEventId(event_id));
- success();
- } catch (e) {
- error(e);
- }
- },
-
- /**
- * @param {string} event_id
- */
- deleteEvent: function Model_deleteEvent(event_id) {
- var myCalendar = this.getCalendar();
- myCalendar.remove(new tizen.CalendarEventId(event_id));
- this.app.loadEvents(); // reload the list
- },
-
- /**
- * @param {string} event_id
- */
- editEvent: function Model_editEvent(event_id) {
- var myCalendar = this.getCalendar();
- return myCalendar.get(new tizen.CalendarEventId(event_id));
- },
-
- /**
- * @param {string} event_id
- * @param {Object} new_values
- */
- updateEvent: function Model_updateEvent(event_id, new_values) {
- var myCalendar = this.getCalendar(), new_event, prop,
- event = myCalendar.get(new tizen.CalendarEventId(event_id));
-
- for (prop in new_values) {
- if (new_values.hasOwnProperty(prop)) {
- // copy new values into the event object
- event[prop] = new_values[prop];
- }
- }
-
- myCalendar.update(event, false); // save to myCalendar
- },
-
- /**
- * @param {Date} date
- * @returns {TZDate} date with timezone info
- */
- createTZDateFromDate: function Model_createTZDateFromDate(date) {
- return new tizen.TZDate(date);
- },
-
- /**
- * Add event change listener
- */
- addEventListener: function Model_addEventListener() {
- var myCalendar = this.getCalendar(),
- listener = {
- onitemsadded: function (items) {
- this.app.loadEvents(); // reload the list
- },
- onitemsupdated: function (items) {
- this.app.loadEvents(); // reload the list
- },
- onitemsremoved: function (ids) {
- this.app.loadEvents(); // reload the list
- this.app.checkDeletePopup();
- }
- };
- this.listenerId = myCalendar.addChangeListener(listener);
- },
- /**
- * Exit from the application
- */
- exit: function () {
- var myCalendar = this.getCalendar();
-
- tizen.application.getCurrentApplication().exit();
- myCalendar.removeChangeListener(this.listenerId);
- }
- };
+ 'use strict';
+ Model.prototype = {
+
+ /**
+ * Model module initialisation
+ */
+ init: function Model_init(app) {
+ this.app = app;
+ },
+
+ /**
+ * Creates a TimeDuration object corresponding to the given duration
+ * in minutes
+ *
+ * @param {int} minutes Duration in minutes
+ * @return {TimeDuration}
+ */
+ getTimeDuration: function Model_getTimeDuration(minutes) {
+ if (minutes === 0) {
+ return new tizen.TimeDuration(minutes, "MINS");
+ }
+ if (minutes % 1440 === 0) {
+ return new tizen.TimeDuration(minutes / 1440, "DAYS");
+ }
+ if (minutes % 60 === 0) {
+ return new tizen.TimeDuration(minutes / 60, "HOURS");
+ }
+ return new tizen.TimeDuration(minutes, "MINS");
+ },
+
+ /**
+ * Creates a CalendarAlarm with the given duration
+ *
+ * @param {int} minutes Alarm duration in minutes
+ * @returns {CalendarAlarm}
+ */
+ getCalendarAlarm: function Model_getCalendarAlarm(minutes, description) {
+ var timeDuration,
+ calendarAlarm;
+
+ timeDuration = this.getTimeDuration(minutes);
+ calendarAlarm = new tizen.CalendarAlarm(timeDuration, "DISPLAY", description);
+ return calendarAlarm;
+ },
+
+ /**
+ * Create a new event and add it to the default calendar
+ *
+ * @param {Object} calendarItemInit
+ * @config {TZDate} [startDate]
+ * @config {bool} [isAllDay]
+ * @config {TimeDuration} [duration]
+ * @config {string} [summary]
+ * @config {string} [description]
+ * @config {string} [location]
+ */
+ addEventToDefaultCalendar: function Model_addEventToDefaultCalendar(calendarItemInit) {
+ var calendar = null,
+ event = null;
+
+
+ calendar = this.getCalendar();
+ event = new tizen.CalendarEvent(calendarItemInit);
+ calendar.add(event);
+ },
+
+ getCalendar: function Model_getCalendar() {
+ return tizen.calendar.getDefaultCalendar("EVENT"); // get the default calendar
+ },
+
+ /**
+ * Find all events in the default calendar on the given date
+ *
+ * @param {string} date date (in local time)
+ * @param {function} onSuccess success callback
+ * @param {function} onError error callback
+ */
+ getEventsFromDefaultCalendar: function Model_getEventsFromDefaultCalendar(date, onSuccess, onError) {
+ var calendar = null, filter = null;
+
+ calendar = this.getCalendar();
+
+ // show all events
+ filter = this.getStartDateFilter(app.homeDateFilter);
+
+ calendar.find(onSuccess, onError, filter);
+ },
+
+ /**
+ * Create a startDate attribute range filter for the given day
+ *
+ * @param {Date} date
+ * @returns {AttributeRangeFilter}
+ */
+ getStartDateFilter: function Model_getStartDateFilter(date) {
+ var today = new tizen.TZDate(date.getFullYear(), date.getMonth(), date.getDate()),
+ tomorrow = new tizen.TZDate(date.getFullYear(), date.getMonth(), date.getDate()+1);
+ return new tizen.CompositeFilter(
+ "UNION",
+ [
+ new tizen.CompositeFilter(
+ "INTERSECTION",
+ [
+ new tizen.AttributeFilter("isAllDay", "EXACTLY", false),
+ new tizen.AttributeRangeFilter("startDate", null, tomorrow),
+ new tizen.AttributeRangeFilter("endDate", today, null)
+ ]
+ ),
+ new tizen.CompositeFilter(
+ "INTERSECTION",
+ [
+ new tizen.AttributeFilter("isAllDay", "EXACTLY", true),
+ new tizen.AttributeRangeFilter("startDate", tomorrow, tomorrow),
+ ]
+ )
+ ]
+ );
+ },
+
+ isEventExists: function(event_id, success, error) {
+ var myCalendar = this.getCalendar();
+ error = error || new Function;
+ success = success || new Function;
+ try {
+ myCalendar.get(new tizen.CalendarEventId(event_id));
+ success();
+ } catch(e) {
+ error(e);
+ }
+ },
+
+ /**
+ * @param {string} event_id
+ */
+ deleteEvent: function Model_deleteEvent(event_id) {
+ var myCalendar = this.getCalendar();
+ myCalendar.remove(new tizen.CalendarEventId(event_id));
+ this.app.loadEvents(); // reload the list
+ },
+
+ /**
+ * @param {string} event_id
+ */
+ editEvent: function Model_editEvent(event_id) {
+ var myCalendar = this.getCalendar();
+ return myCalendar.get(new tizen.CalendarEventId(event_id));
+ },
+
+ /**
+ * @param {string} event_id
+ * @param {Object} new_values
+ */
+ updateEvent: function Model_updateEvent(event_id, new_values) {
+ var myCalendar = this.getCalendar(), new_event, prop,
+ event = myCalendar.get(new tizen.CalendarEventId(event_id));
+
+ for (prop in new_values) {
+ if (new_values.hasOwnProperty(prop)) {
+ event[prop] = new_values[prop]; // copy new values into the event object
+ }
+ }
+
+ myCalendar.update(event, false); // save to myCalendar
+ },
+
+ /**
+ * @param {Date} date
+ * @returns {TZDate} date with timezone info
+ */
+ createTZDateFromDate: function Model_createTZDateFromDate(date) {
+ return new tizen.TZDate(date);
+ },
+
+ /**
+ * Exit from the application
+ */
+ exit: function () {
+ tizen.application.getCurrentApplication().exit();
+ }
+ };
}());
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint devel: true*/
-/*global window */
-
/*global $, app, tizen, TemplateManager */
/**
* @class Ui
*/
function Ui() {
- 'use strict';
+ 'use strict';
}
(function () { // strict mode wrapper
- 'use strict';
- Ui.prototype = {
-
- templateManager: null,
-
- monthNames: ([
- 'January', 'February', 'March', 'April', 'May', 'June',
- 'July', 'August', 'September', 'October', 'November', 'December'
- ]),
- /**
- * UI module initialisation
- */
- init: function UI_init(app) {
- this.app = app;
- this.templateManager = new TemplateManager();
- $(document).ready(this.domInit.bind(this));
-
- // init inner objects
- this.home.context = this;
- this.alarm.context = this;
- this.new_event.context = this;
- },
-
- /**
- * When DOM is ready, initialise it
- */
- domInit: function UI_domInit() {
- this.templateManager.loadToCache(['home', 'alarm', 'new_event',
- 'event', 'all_day_event'], this.initPages.bind(this));
- // Disable text selection
- $.mobile.tizen.disableSelection(document);
- },
-
- /**
- * Append pages to body and initialise them
- */
- initPages: function UI_initPages() {
- var pages = [];
-
- pages.push(this.templateManager.get('home'));
- pages.push(this.templateManager.get('alarm'));
- pages.push(this.templateManager.get('new_event'));
-
- $('body').append(pages.join(''));
- this.fixContentHeight();
-
- this.home.init();
- this.alarm.init();
-
- if (!app.ui.new_event.initialized) {
- app.ui.new_event.init();
- }
-
- $(':jqmData(role="tabbar")').first().delegate('a', 'vmouseup',
- function (event) {
- $(this).removeClass($.mobile.activeBtnClass);
- });
-
- $('#new_event').on('pagebeforeshow', function () {
- app.ui.new_event.updateDateFormat();
- app.ui.new_event.setStartDate();
- app.ui.new_event.setEndDate();
- $('#add-event-btn').removeClass('disabled');
- // workaround for N_SE-43733
- $('.ui-datefield-selected')
- .removeClass('ui-datefield-selected');
- $('.ui-popupwindow').hide();
- });
-
- $(document).ready(function () {
- if ($('input[type=radio]:checked').val() !== 'Yes') {
- $('#customDuration')
- .val('')
- .addClass('ui-disabled')
- .prop('disabled', true)
- .data('placeholder', '0');
- }
-
- $('input[type=radio]').change(function () {
- if ($(this).val() === 'Yes') {
- $('#customDuration').removeClass('ui-disabled');
- $('#customDuration').prop('disabled', false);
- $('#customDuration').focus();
- } else {
- $('#customDuration').blur();
- $('#customDuration').addClass('ui-disabled')
- .data('placeholder', '0');
- $('#customDuration').prop('disabled', true);
- }
- });
-
- $('#customDuration').on('blur', function () {
- if ($('input[type=radio]:checked').val() === 'Yes') {
- var value = Math.abs(parseInt($(this).val(), 10));
- if (isNaN(value)) {
- value = 0;
- }
- $(this).val(value);
- }
- $('input[type=radio]').checkboxradio('refresh');
- });
- });
-
- $('.customDuration, #customDuration').on('click change',
- function (e) {
- if ($(this).attr('checked')) {
- $('#yes_1').attr('checked', true)
- .checkboxradio('refresh');
- $.each($('#new_alarm input:radio'), function () {
- $(this).attr('checked', $(this).val() === 'Yes')
- .checkboxradio('refresh');
- });
- $('#customDuration')
- .removeClass('ui-disabled')
- .prop('disabled', false)
- .trigger('focus');
- }
- });
-
- $(window).resize(function (event) {
- if ($.mobile.activePage.attr('id') === 'new_alarm') {
- var content = $('#new_alarm [data-role=content]'),
- customDuration = $('#customDuration'),
- size = customDuration.position().top
- + customDuration.outerHeight();
- content.scrollview('scrollTo', 0, -1 * size, 0);
- }
- });
-
- document.addEventListener('webkitvisibilitychange',
- function (event) {
- var dateTimePicker1 = $('#demo-date-1'),
- dateTimePicker2 = $('#demo-date-2'),
- startDate = dateTimePicker1.attr('data-date'),
- endDate = dateTimePicker2.attr('data-date'),
- clearDateGMT = function (dateString) {
- return new Date(dateString.substring(0,
- dateString.indexOf('GMT')));
- };
-
- app.ui.new_event.updateDateFormat(true);
- if (document.webkitVisibilityState === 'visible') {
- if ($.mobile.activePage.attr('id') === 'new_event'
- || $.mobile.activePage.attr('id')
- === 'new_alarm') {
- if (app.eventId !== 0) {
- app.model.isEventExists(app.eventId, null,
- function () {
- $.mobile.changePage('#home');
- });
- }
- }
- //workaround for making datePicker value independent from
- //timezone change in the background
- if ($.mobile.activePage.attr('id') === 'new_event') {
- dateTimePicker1.datetimepicker('value',
- clearDateGMT(startDate));
- dateTimePicker2.datetimepicker('value',
- clearDateGMT(endDate));
- }
- }
- });
-
- $('input#customDuration').on('keypress', function (e) {
- if ((e.keyCode < 48) || (e.keyCode > 57)) {
- e.stopImmediatePropagation();
- e.preventDefault();
- e.stopPropagation();
- }
- });
-
- $('input#customDuration').on('input keyup', function (e) {
- var val = parseInt($(this).val(), 10),
- max = parseInt($(this).attr('max'), 10),
- min = 0;
-
- if (val > max) {
- $(this).val(max);
- } else if (val < min) {
- $(this).val(min);
- }
- });
-
- $('input#customDuration').on('keydown', function (e) {
- if (e.keyCode === 13) {
- $('input#customDuration').blur();
- }
- });
-
- window.addEventListener('tizenhwkey', function (e) {
- if (e.keyName === 'back') {
- if ($.mobile.activePage.attr('id') === 'home') {
- tizen.application.getCurrentApplication().exit();
- } else if ($.mobile.activePage.attr('id') === 'new_event') {
- $.mobile.changePage('#home');
- } else {
- history.back();
- $('#customDuration').blur();
- }
- }
- });
-
- $.mobile.changePage('#home', 'pop', false, true);
- },
-
- /**
- * Contains methods related to the #home page
- * @namespace
- */
- home: {
- init: function UI_home_init() {
- var app = this.context.app, self = this,
- alarm = this.context.alarm;
-
- $('#demo-date-1, #demo-date-2').datetimepicker();
- $('#allDay').slider();
-
- $('#exit_btn').on('click', app.exit.bind(app));
- $('input:radio').checkboxradio();
- alarm.setValue(-1);
- alarm.updateDurationLabel();
-
- // buttons in the events list
- $('#events_list').on('click', '.remove_event_btn', function () {
- var eventId = $(this).parents('.event').data('eventid');
- app.eventId = eventId;
- app.ui.popup('Are you sure?', {
- 'No': function () {
- $('#popup').popup('close');
- },
- 'Yes': function () {
- app.model.isEventExists(eventId, function () {
- try {
- app.model.deleteEvent(eventId);
- $('#popup').popup('close');
- } catch (e) {
- app.ui.popup(e);
- }
- }, function () {
- app.ui.popup('Selected event does not exist.');
- });
- }
- });
- });
-
- $('#events_list').on('click', '.edit_event_btn', function () {
- var eventId = $(this).parents('.event').data('eventid'),
- event = app.model.editEvent(eventId),
- field,
- date,
- duration,
- key,
- properties = ['summary', 'startDate', 'endDate'];
-
- $('#demo-date-1').datetimepicker();
- $('#demo-date-2').datetimepicker();
- app.eventId = eventId;
- properties.forEach(function (element) {
- if (event.hasOwnProperty(element)) {
- field = $('#new_event input[name="' + element
- + '"]');
-
- if (field.length !== 0) {
- if (field.attr('type') === 'datetime') {
- date = self.TZD2Date(event[element]);
- field.datetimepicker('value', date);
- } else {
- field.val(event[element]);
- }
- }
- }
- });
-
- $('#new_event h1').text('Edit event');
-
- if (event.alarms.length !== 0) {
- if (event.alarms[0].before !== null) {
- duration = app
- .retrieveTimeDurationInMinutes(event.alarms[0]
- .before);
- } else {
- duration = 0;
- }
- }
-
- if (duration === undefined) {
- duration = -1;
- }
- alarm.setValue(duration);
- alarm.updateDurationLabel();
-
- $.mobile.changePage('#new_event');
- // set select allDay property
- app.ui.new_event.setSelectAllDay(event.isAllDay);
- app.ui.new_event.updateDateFormat();
- });
-
- $('#newEventBtn').on('click', function () {
- app.eventId = 0;
- $('#demo-date-1').datetimepicker('value', new Date());
- $('#demo-date-2').datetimepicker('value', new Date());
- // workaround - if just initied once again,
- // datepickers remembers the date
- $('#new_event h1').text('New event');
- $('#title').val('');
- app.ui.new_event.setSelectAllDay(false);
- app.ui.new_event.updateDateFormat();
- alarm.setValue(0);
- alarm.updateDurationLabel();
- });
-
- $('#homeDateFilter').change(function () {
- $('#exit_btn').blur();
- app.homeDateFilter =
- app.ui.new_event.getDateFromPicker($(this));
- app.loadEvents();
- });
-
- this.loadEvents();
- },
-
- TZD2Date: function (tzdate) {
- return new Date(
- tzdate.getFullYear(),
- tzdate.getMonth(),
- tzdate.getDate(),
- tzdate.getHours(),
- tzdate.getMinutes(),
- tzdate.getSeconds(),
- tzdate.getMilliseconds()
- );
- },
-
- /**
- * Get start date value from the form (#demo-date-1 field)
- *
- * @returns {string}
- */
- getStartDate: function UI_home_getStartDate() {
- var startDate = $('#demo-date-1').attr('data-date');
- return startDate;
- },
-
- /**
- * Get info if event is allDay event
- *
- * @returns {boolean}
- */
- getAllDayInfo: function UI_home_getAllDayInfo() {
- var isAllDay = $('select#allDay').val() === '1' ? true : false;
- return isAllDay;
- },
- /**
- * Get end date value from the form (#demo-date-2 field)
- *
- * @returns {string}
- */
- getEndDate: function UI_home_getEndDate() {
- var endDate = $('#demo-date-2').attr('data-date');
- return endDate;
- },
- /**
- * Get the title from the form (#title field)
- *
- * @returns {string}
- */
- getTitle: function UI_home_getTitle() {
- return $('#title').val();
- },
- /**
- * Get the description from the form (#des field)
- *
- * @returns {string}
- */
- getDescription: function UI_home_getDescription() {
- return $('#des').val();
- },
- /**
- * Get the location from the form (#location field)
- *
- * @returns {string}
- */
- getLocation: function UI_home_getLocation() {
- return $('#location').val();
- },
- /**
- * Wrapper for app.loadEvents
- * @param {Object} e event
- * @param {Date} date selected date
- */
- loadEvents: function UI_home_loadEvents(e, date) {
- this.context.app.loadEvents(date);
- },
-
- /**
- * Returns text for separating list items with events
- * Skips repeated values
- *
- * @param {Object} event
- * @returns {string}
- */
- getSeparatorText: function UI_home_getSeparatorText(event) {
- var previous = '';
-
- // redefine itself
- this.getSeparatorText = function (event) {
- if (event === undefined) {
- previous = '';
- return undefined;
- }
-
- var startDate = event.startDate,
- str = this.formatLongDate(startDate);
-
- if (previous === str) {
- return ''; // skip it - already returned
- }
- // store in the closure for future comparison
- previous = str;
-
- return str;
- };
-
- return this.getSeparatorText(event);
- },
-
- /**
- * Format long date (D. MMMM YYYY)
- * @param {TZDate} date
- * @returns {string}
- */
- formatLongDate: function UI_home_formatLongDate(date) {
- return date.getDate() + ' ' + app.ui.monthNames[date.getMonth()]
- + ' ' + date.getFullYear();
- },
-
- /**
- * Format short date (YYYY/MM/DD)
- * @param {TZDate} date
- * @returns {string}
- */
- formatDate: function UI_home_formatDate(date) {
- return date.getFullYear() + '/' + this.pad(date.getMonth() + 1)
- + '/' + this.pad(date.getDate());
- },
-
- /**
- * Format date and time (YYYY/MM/DD hh:mm)
- * @param {TZDate} date
- * @returns {string}
- */
- formatDateTime: function UI_home_formatDateTime(date) {
- return date.getFullYear() + '/' + this.pad(date.getMonth() + 1)
- + '/' + this.pad(date.getDate()) + ' '
- + this.pad(date.getHours()) + ':'
- + this.pad(date.getMinutes());
- },
-
- /**
- * Zero-pads a positive number to 2 digits
- */
- pad: function UI_home_pad(number) {
- return number < 10 ? '0' + number : number;
- },
-
- /**
- * Creates HTML representing the given array of alarms
- *
- * @param {Alarm[]} alarms
- * @returns {string}
- */
- getAlarmsHtml: function UI_home_getAlarmsHtml(alarms) {
- var alarm = '', j, len;
-
- len = alarms.length;
-
- if (len) {
- alarm += '<p class="ui-li-aside ui-li-desc">'
- + '<img src="img/clock.png"/>';
-
- for (j = 0; j < len; j += 1) {
- if (alarms[j].before !== null) {
- alarm += alarms[j].before.length;
- alarm += ' ' + alarms[j].before.unit;
- }
- }
- alarm += '</p>';
- }
- return alarm;
- },
-
- /**
- * Load the events into the #event_popup.
- *
- * Callback function for app.loadEvents.
- * @param {Array} events
- */
- onEventSearchSuccess:
- function UI_home_onEventSearchSuccess(events) {
- var i = 0, j = 0,
- str = '',
- event,
- alarm = '',
- dividerText = '',
- templateParameters = {},
- tmplName,
- compareTZDates = function (a, b) {
- if (a.getFullYear() !== b.getFullYear()) {
- return a.getFullYear() < b.getFullYear() ? 1 : -1;
- }
- if (a.getMonth() !== b.getMonth()) {
- return a.getMonth() < b.getMonth() ? 1 : -1;
- }
- if (a.getDate() !== b.getDate()) {
- return a.getDate() < b.getDate() ? 1 : -1;
- }
- return 0;
- },
- compareTZTimes = function (a, b) {
- if (a.getHours() !== b.getHours()) {
- return a.getMinutes() < b.getMinutes() ? -1 : 1;
- }
- return a.getHours() < b.getHours() ? -1 : 1;
- },
- endDate2;
-
- events = events.sort(
- function (a, b) {
- var result;
- result = compareTZDates(a.startDate, b.startDate);
- if (result !== 0) {
- return result;
- }
- if (a.isAllDay !== b.isAllDay) {
- return a.isAllDay ? 1 : -1;
- }
- result = compareTZTimes(a.startDate, b.startDate);
- if (result !== 0) {
- return result;
- }
- result = compareTZDates(a.endDate, b.endDate);
- if (result !== 0) {
- return result;
- }
- result = compareTZTimes(a.endDate, b.endDate);
- if (result !== 0) {
- return result;
- }
- if (a.name !== b.name) {
- return a.name < b.name ? -1 : 1;
- }
- return 0;
- }
- );
-
- // content
- str = '';
- if (events.length !== 0) {
- for (i = 0; i < events.length; i += 1) {
- event = events[i];
-
- dividerText = this.getSeparatorText(event);
-
- if (dividerText) {
- str += '<li data-role="list-divider">'
- + dividerText + '</li>';
- }
-
- alarm = this.getAlarmsHtml(event.alarms);
-
- endDate2 = new tizen.TZDate(event.endDate.getFullYear(),
- event.endDate.getMonth(),
- event.endDate.getDate() - 1,
- 0, 0, 0, 0
- );
-
- templateParameters = {
- uid: event.id.uid,
- startDateTime: this.formatDateTime(event.startDate),
- endDateTime: this.formatDateTime(event.endDate),
- startDate: this.formatDate(event.startDate),
- endDate: this.formatDate(endDate2),
- summary: event.summary || '[ no title ]',
- location: event.location,
- description: event.description,
- alarm: alarm
- };
-
- tmplName = event.isAllDay ? 'all_day_event' : 'event';
- str += this.context.templateManager.get(tmplName,
- templateParameters);
- }
- } else {
- dividerText = this.getSeparatorText({
- startDate: app.homeDateFilter
- });
-
- if (dividerText) {
- str += '<li data-role="list-divider">'
- + dividerText + '</li>';
- }
-
- str += '<li>No events found</li>';
- }
- this.getSeparatorText(); // clear the separator state
-
- $('#events_list ul').html(str);
- $('#events_list ul').listview();
- $('#events_list ul').listview('refresh');
- $('#events_list ul input.edit_event_btn').button();
- $('#events_list ul input.remove_event_btn').button();
-
- // scroll to top
- $('#home [data-role=content]')
- .scrollview('scrollTo', 100, 0, 0);
- },
-
- /**
- * Error handler for event search
- */
- onEventSearchError: function UI_home_onEventSearchError() {
- console.error('event search error');
- },
-
- updateHomeDateFilter: function () {
- $('#homeDateFilter')
- .datetimepicker('value', app.homeDateFilter);
- }
- },
-
- /**
- * Contains methods related to the #alarm page
- * @namespace
- */
- alarm: {
- init: function UI_alarm_init() {
- $('#customDuration').val('').data('placeholder', '0');
- },
-
- setValue: function (duration) {
- if (duration === undefined) {
- duration = 0;
- }
-
- app.setAlarm(duration);
-
- $.each($('#new_alarm input:radio'), function () {
- $(this).attr('checked',
- parseInt($(this).val(), 10) === duration)
- .checkboxradio('refresh');
- });
-
- if (!$('#new_alarm input[type=radio]:checked').val()) {
- $('#yes_1').attr('checked', true).checkboxradio('refresh');
- $('#customDuration').val(duration);
- $('#customDuration')
- .removeClass('ui-disabled').prop('disabled', false)
- .trigger('focus');
- } else {
- $('#customDuration')
- .val('')
- .addClass('ui-disabled')
- .data('placeholder', '0');
- }
- return duration;
- },
-
- getValue: function () {
- var value = parseInt($('#new_alarm input[type=radio]:checked')
- .val(), 10);
- if (isNaN(value)) {
- value = Math.abs(parseInt($('#customDuration').val(), 10));
- if (isNaN(value)) {
- value = '';
- }
- } else {
- this.disableCustomDuration();
- }
- return value;
- },
-
- disableCustomDuration: function () {
- $('#customDuration').val('').addClass('ui-disabled')
- .data('placeholder', '0');
- },
-
- getStoredValue: function () {
- return parseInt($('#alarm').attr('data-minutes'), 10);
- },
-
- /**
- * Reads and sets alarm duration label
- */
- updateDurationLabel: function (eventAndAlarm) {
- var value = this.getValue(), unit, label;
- app.ui.alarm.setValue(value === 0 ? 0 : (value || -1));
- $('#alarm').attr('data-minutes', value);
- if (value === -1) {
- label = 'Off';
- } else if (value === 0) {
- label = 'On time';
- } else {
- unit = 'minute';
- if (value % 10080 === 0) {
- value /= 10080;
- unit = 'week';
- } else if (value % 1440 === 0) {
- value /= 1440;
- unit = 'day';
- } else if (value % 60 === 0) {
- value /= 60;
- unit = 'hour';
- }
- label = value + ' ' + unit + (value > 1 ? 's' : '')
- + ' before';
- }
- $('#alarm').text(label);
- }
- },
-
- /**
- * Contains methods related to the new event page
- * @namespace
- */
- new_event: {
- initialized: false,
- animateStatus: false,
-
- init: function () {
- this.assignFields();
- this.updateDateFormat();
- this.setStartDate();
- this.setEndDate();
- this.addEvents();
- this.initialized = true;
- },
-
- addEvents: function () {
- var self = this, alarm;
-
- this.allday.change(this.updateDateFormat.bind(this));
- this.start.change(this.validStart.bind(this));
- this.end.change(this.validEnd.bind(this));
-
- $('#new_event').on('pageshow', function () {
- self.animateStatusChange.bind(self)();
- });
-
- /* old events */
- $('#add-event-btn').on('click', this.addEvent.bind(this));
- $('#add-event-cancel-btn').on('click', this.cancel.bind(this));
- //alarm selection confirm
- $('#add-alarm').on('click', app.switchAlarm.bind(app));
- // go to alarm selection
- $('#set-alarm').on('click', function (e) {
- app.ui.alarm.setValue(app.ui.alarm.getStoredValue());
- $.mobile.changePage('#new_alarm');
- });
-
- $(window).resize(function (event) {
- if ($.mobile.activePage.attr('id') === 'new_alarm') {
- setTimeout(function () {
- var content = $('#new_alarm [data-role=content]'),
- customDuration = $('#customDuration'),
- size = customDuration.position().top
- + customDuration.outerHeight();
- content.scrollview('scrollTo', 0, -1 * size, 0);
- }, 260);
- }
- });
- },
-
- animateStatusChange: function () {
- var self = this;
- this.end.next().find('span').not('.ui-datefield-seperator')
- .off('click')
- .on('click', function (e) {
- self.animateStatus =
- $(e.target).hasClass('ui-btn-picker');
- });
- },
-
- validStart: function () {
- this.setStartDate();
- if (this.startDate > this.endDate) {
- this.end.datetimepicker('value', this.startDate);
- this.setEndDate();
- }
- },
-
- validEnd: function () {
- if (this.startDate > this.getDateFromPicker(this.end)) {
- this.setDateValue(this.end, this.endDate);
- this.showWarning(
- 'End date cannot be earlier than initial date.',
- function () {
- $('#demo-date-2').datetimepicker();
- }
- );
- } else {
- this.setEndDate();
- }
- },
-
- validAll: function () {
- this.validStart();
- this.validEnd();
- },
-
- showWarning: function (text, successCallback) {
- if (successCallback instanceof Function) {
- $('#popup').one('popupafterclose', successCallback);
- }
- this.lockTabKey();
- app.ui.popup(text, {
- 'OK': function () {
- $('#popup').popup('close');
- }
- });
- this.popup.one('popupafterclose', function () {
- $(document).off('keydown');
- });
- },
-
- lockTabKey: function () {
- $(document).on('keydown', function (event) {
- if (event.keyCode === 9) {
- event.preventDefault();
- }
- });
- },
-
- assignFields: function () {
- this.allday = $('#allDay');
- this.start = $('#demo-date-1');
- this.end = $('#demo-date-2');
- this.popup = $('#popup');
- },
-
- updateDateFormat: function (fast) {
- var date = tizen.time.getDateFormat(true),
- time = tizen.time.getTimeFormat();
- if (this.allday.val() === '1') {
- this.format = 'MMM dd yyyy';
- } else {
- if (time === 'h:m:s') {
- this.format = 'MMM dd yyyy HH:mm';
- } else {
- this.format = 'MMM dd yyyy hh:mm tt';
- }
- }
- if (fast) {
- this.start.datetimepicker('option', 'format', this.format);
- this.end.datetimepicker('option', 'format', this.format);
- } else {
- $('#title').blur();
- this.start.datetimepicker('option', 'format', this.format)
- .datetimepicker();
- this.end.datetimepicker('option', 'format', this.format)
- .datetimepicker();
- }
- $('#demo-date-1').datetimepicker();
- $('#demo-date-2').datetimepicker();
- },
-
- setDateValue: function (field, date) {
- var sp = field.next().find('span')
- .not('.ui-datefield-seperator');
- field.datetimepicker('value', date);
- if (this.animateStatus) {
- sp.animationComplete(function () {
- setTimeout(function () {
- field.datetimepicker('value', date);
- }, 700);
- sp.off('webkitAnimationEnd');
- sp.off('animationend');
- });
- }
- },
-
- setStartDate: function () {
- this.startDate = this.getDateFromPicker(this.start);
- },
-
- setEndDate: function () {
- this.endDate = this.getDateFromPicker(this.end);
- },
-
- getDateFromPicker: function (field) {
- return field.data('datetimepicker').options.date;
- },
-
- /* methods before new event refactor */
-
- setSelectAllDay: function (value) {
- value = value ? 1 : 0;
- app.ui.new_event.allday.find('option')
- .attr('selected', false);
- app.ui.new_event.allday.find('option[value="' + value + '"]')
- .attr('selected', true);
- app.ui.new_event.allday.slider('refresh');
- },
-
- addEvent: function Ui_newEvent_addEvent(e) {
- e.preventDefault();
- e.stopPropagation();
- var button = $('#add-event-btn');
- if (!button.hasClass('disabled')) {
- button.addClass('disabled');
- if (app.eventId === 0) {
- this.context.app.addEvent(e, function () {
- $.mobile.changePage('#home');
- });
- } else {
- this.context.app.updateEvent(e, function () {
- $.mobile.changePage('#home');
- });
- }
- }
- },
-
- cancel: function Ui_newEvent_cancel(e) {
- e.preventDefault();
- e.stopPropagation();
- $.mobile.changePage('#home');
- }
- },
-
- fixContentHeight: function Ui_fixContentHeight() {
- var contentHeight = screen.availHeight
- - $('div[data-role="header"]').outerHeight()
- - $('div[data-role="footer"]').outerHeight();
- $('div[data-role="content"]').css('height', contentHeight);
- }
- };
-
- Ui.prototype.popup = function (text, buttons) {
- var i, popup = $('#popup');
-
- if (!popup.hasClass('ui-popup')) {
- popup.popup();
- }
-
- if (!buttons) {
- buttons = {
- 'OK': function () {
- $('#popup').popup('close');
- }
- };
- }
-
- $('.ui-popup-button-bg', popup).empty();
-
- popup[0].className = popup[0].className
- .replace(/\bcenter_basic.*?\b/g, '');
- popup.addClass('center_basic_' + Object.keys(buttons).length + 'btn');
-
- for (i in buttons) {
- if (buttons.hasOwnProperty(i)) {
- if (buttons[i]) {
- $('<a/>')
- .text(i)
- .attr({'data-role': 'button', 'data-inline': 'true'})
- .bind('click', buttons[i])
- .appendTo($('.ui-popup-button-bg', popup));
- }
- }
- }
- $('.ui-popup-text p', popup).text(text);
-
- popup.trigger('create');
- popup.popup('open', {positionTo: 'window'});
- };
+ 'use strict';
+ Ui.prototype = {
+
+ templateManager: null,
+
+ monthNames: ([
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"
+ ]),
+
+ /**
+ * UI module initialisation
+ */
+ init: function UI_init(app) {
+ this.app = app;
+ this.templateManager = new TemplateManager();
+ $(document).ready(this.domInit.bind(this));
+
+ // init inner objects
+ this.home.context = this;
+ this.alarm.context = this;
+ this.new_event.context = this;
+ },
+
+ /**
+ * When DOM is ready, initialise it
+ */
+ domInit: function UI_domInit() {
+ this.templateManager.loadToCache(['home', 'alarm', 'new_event', 'event', 'all_day_event'], this.initPages.bind(this));
+ // Disable text selection
+ $.mobile.tizen.disableSelection(document);
+ },
+
+ /**
+ * Append pages to body and initialise them
+ */
+ initPages: function UI_initPages() {
+ var pages = [];
+
+ pages.push(this.templateManager.get('home'));
+ pages.push(this.templateManager.get('alarm'));
+ pages.push(this.templateManager.get('new_event'));
+
+ $('body').append(pages.join(''));
+ this.fixContentHeight();
+
+ this.home.init();
+ this.alarm.init();
+
+ if (!app.ui.new_event.initialized) {
+ app.ui.new_event.init();
+ }
+
+ $(":jqmData(role='tabbar')").first().delegate( "a", "vmouseup", function ( event ) {
+ $(this).removeClass( $.mobile.activeBtnClass );
+ });
+
+ $("#new_event").on('pagebeforeshow', function () {
+ app.ui.new_event.updateDateFormat();
+ app.ui.new_event.setStartDate();
+ app.ui.new_event.setEndDate();
+ $('#add-event-btn').removeClass('disabled');
+ // workaround for N_SE-43733
+ $(".ui-datefield-selected").removeClass('ui-datefield-selected');
+ $(".ui-popupwindow").hide();
+ });
+
+ $(document).ready(function () {
+ if ($('input[type=radio]:checked').val() !== 'Yes') {
+ $("#customDuration").addClass('ui-disabled');
+ }
+
+ $('input[type=radio]').change( function () {
+ if ($(this).val() === 'Yes') {
+ $("#customDuration").removeClass('ui-disabled');
+ $("#customDuration").prop('disabled', false);
+ $("#customDuration").focus();
+ } else {
+ $("#customDuration").blur();
+ $("#customDuration").addClass('ui-disabled');
+ $("#customDuration").prop('disabled', true);
+ }
+ });
+
+ $('#customDuration').on('blur', function () {
+ var value = Math.abs(parseInt($(this).val()));
+ if (isNaN(value)) {
+ value = 0;
+ }
+ $(this).val(value);
+ });
+ });
+ $(".customDuration, #customDuration").on("click change", function (e) {
+ if ($(this).attr("checked")) {
+ $("#yes_1").attr('checked', true).checkboxradio('refresh');
+ $.each($('#new_alarm input:radio'), function () {
+ $(this).attr('checked', $(this).val() === 'Yes')
+ .checkboxradio('refresh');
+ });
+ $("#customDuration")
+ .removeClass('ui-disabled')
+ .prop('disabled', false)
+ .trigger("focus");
+ }
+ });
+
+ document.addEventListener('webkitvisibilitychange', function (event) {
+ app.ui.new_event.updateDateFormat(true);
+ if (document.webkitVisibilityState === 'visible') {
+ app.loadEvents();
+ if ($.mobile.activePage.attr('id') === "new_event"
+ || $.mobile.activePage.attr('id') === "new_alarm" ) {
+ if (app.eventId !== 0) {
+ app.model.isEventExists(app.eventId, null, function () {
+ $.mobile.changePage('#home');
+ });
+ }
+ }
+ }
+ });
+
+ $("input#customDuration").on("keypress",function (e) {
+ if(/[^0-9]/.test(String.fromCharCode(e.keyCode))) {
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ });
+ $("input#customDuration").on("input keyup", function (e) {
+ var val = parseInt($(this).val(), 10),
+ max = parseInt($(this).attr("max"), 10),
+ min = 0;
+
+ if (val > max){
+ $(this).val(max);
+ } else if (val < min) {
+ $(this).val(min);
+ }
+ });
+
+ window.onkeydown= function(e){
+ if ($.mobile.activePage.attr('id') === 'new_alarm' && e.keyCode === 9) {
+ e.preventDefault();
+ }
+ };
+
+ window.addEventListener('tizenhwkey', function(e) {
+ if (e.keyName == "back") {
+ if ($.mobile.activePage.attr('id') === 'home') {
+ tizen.application.getCurrentApplication().exit();
+ } else if ($.mobile.activePage.attr('id') === 'new_event') {
+ $.mobile.changePage("#home");
+ } else {
+ history.back();
+ }
+ }
+ });
+
+ $.mobile.changePage('#home', 'pop', false, true);
+ },
+
+ /**
+ * Contains methods related to the #home page
+ * @namespace
+ */
+ home: {
+ init: function UI_home_init() {
+ var app = this.context.app, self = this, alarm = this.context.alarm;
+
+ $("#demo-date-1, #demo-date-2").datetimepicker();
+ $("#allDay").slider();
+
+ $('#exit_btn').on('click', app.exit.bind(app));
+ $("input:radio").checkboxradio();
+ alarm.setValue(-1);
+ alarm.updateDurationLabel();
+
+ // buttons in the events list
+ $('#events_list').on('click', '.remove_event_btn', function () {
+ var eventId = $(this).parents('.event').data('eventid');
+ app.ui.popup('Are you sure?', {
+ 'No': function () {
+ $("#popup").popup('close');
+ },
+ 'Yes': function () {
+ app.model.isEventExists(eventId, function () {
+ app.model.deleteEvent(eventId);
+ $("#popup").popup('close');
+ }, function () {
+ app.ui.popup("Selected event does not exist.");
+ });
+ }
+ });
+ });
+
+ $('#events_list').on('click', '.edit_event_btn', function () {
+ var eventId = $(this).parents('.event').data('eventid'),
+ event = app.model.editEvent(eventId),
+ field,
+ date,
+ duration,
+ key,
+ properties = ['summary', 'startDate', 'endDate'];
+
+ $("#demo-date-1").datetimepicker();
+ $("#demo-date-2").datetimepicker();
+ app.eventId = eventId;
+ properties.forEach(function(element){
+ if (event.hasOwnProperty(element)) {
+ field = $('#new_event input[name="' + element + '"]');
+
+ if (field.length !== 0) {
+ if (field.attr('type') === 'datetime') {
+ date = self.TZD2Date(event[element]);
+ field.datetimepicker('value', date);
+ } else {
+ field.val(event[element]);
+ }
+ }
+ }
+ });
+
+ $('#new_event h1').text('Edit event');
+
+ if (event.alarms.length !== 0) {
+ duration = app.retrieveTimeDurationInMinutes(event.alarms[0].before);
+ }
+
+ if(typeof duration == "undefined") {
+ duration = -1;
+ }
+ alarm.setValue(duration);
+ alarm.updateDurationLabel();
+
+ $.mobile.changePage("#new_event");
+ // set select allDay property
+ app.ui.new_event.setSelectAllDay(event.isAllDay);
+ app.ui.new_event.updateDateFormat();
+ });
+
+ $('#newEventBtn').on('click', function () {
+ app.eventId = 0;
+ $("#demo-date-1").datetimepicker("value", new Date());
+ $("#demo-date-2").datetimepicker("value", new Date());
+ // workaround - if just initied once again, datepickers remembers the date
+ $('#new_event h1').text('New event');
+ $('#title').val('');
+ app.ui.new_event.setSelectAllDay(false);
+ app.ui.new_event.updateDateFormat();
+ alarm.setValue(0);
+ alarm.updateDurationLabel();
+ });
+
+ $("#homeDateFilter").change(function () {
+ $("#exit_btn").blur();
+ app.homeDateFilter =
+ app.ui.new_event.getDateFromPicker($(this));
+ app.loadEvents();
+ });
+
+ this.loadEvents();
+ },
+
+ TZD2Date: function (tzdate) {
+ return new Date(
+ tzdate.getFullYear(),
+ tzdate.getMonth(),
+ tzdate.getDate(),
+ tzdate.getHours(),
+ tzdate.getMinutes(),
+ tzdate.getSeconds(),
+ tzdate.getMilliseconds()
+ );
+ },
+
+ /**
+ * Get start date value from the form (#demo-date-1 field)
+ *
+ * @returns {string}
+ */
+ getStartDate: function UI_home_getStartDate() {
+ var startDate = $('#demo-date-1').attr('data-date');
+ return startDate;
+ },
+
+ /**
+ * Get info if event is allDay event
+ *
+ * @returns {boolean}
+ */
+ getAllDayInfo: function UI_home_getAllDayInfo() {
+ var isAllDay = $('select#allDay').val() == '1' ? true : false;
+ return isAllDay;
+ },
+ /**
+ * Get end date value from the form (#demo-date-2 field)
+ *
+ * @returns {string}
+ */
+ getEndDate: function UI_home_getEndDate() {
+ var endDate = $('#demo-date-2').attr('data-date');
+ return endDate;
+ },
+ /**
+ * Get the title from the form (#title field)
+ *
+ * @returns {string}
+ */
+ getTitle: function UI_home_getTitle() {
+ return $('#title').val();
+ },
+ /**
+ * Get the description from the form (#des field)
+ *
+ * @returns {string}
+ */
+ getDescription: function UI_home_getDescription() {
+ return $('#des').val();
+ },
+ /**
+ * Get the location from the form (#location field)
+ *
+ * @returns {string}
+ */
+ getLocation: function UI_home_getLocation() {
+ return $('#location').val();
+ },
+ /**
+ * Wrapper for app.loadEvents
+ * @param {Object} e event
+ * @param {Date} date selected date
+ */
+ loadEvents: function UI_home_loadEvents(e, date) {
+ this.context.app.loadEvents(date);
+ },
+
+ /**
+ * Returns text for separating list items with events
+ * Skips repeated values
+ *
+ * @param {Object} event
+ * @returns {string}
+ */
+ getSeparatorText: function UI_home_getSeparatorText(event) {
+ var previous = '';
+
+ // redefine itself
+ this.getSeparatorText = function (event) {
+ if (event === undefined) {
+ previous = '';
+ return undefined;
+ }
+
+ var startDate = event.startDate,
+ str = this.formatLongDate(startDate);
+
+ if (previous === str) {
+ return ''; // skip it - already returned
+ }
+ previous = str; // store in the closure for future comparison
+
+ return str;
+ };
+
+ return this.getSeparatorText(event);
+ },
+
+ /**
+ * Format long date (D. MMMM YYYY)
+ * @param {TZDate} date
+ * @returns {string}
+ */
+ formatLongDate: function UI_home_formatLongDate(date) {
+ return date.getDate() + " " + app.ui.monthNames[date.getMonth()] + " " + date.getFullYear();
+ },
+
+ /**
+ * Format short date (YYYY/MM/DD)
+ * @param {TZDate} date
+ * @returns {string}
+ */
+ formatDate: function UI_home_formatDate(date) {
+ return date.getFullYear() + '/' + this.pad(date.getMonth()+1) + '/' + this.pad(date.getDate());
+ },
+
+ /**
+ * Format date and time (YYYY/MM/DD hh:mm)
+ * @param {TZDate} date
+ * @returns {string}
+ */
+ formatDateTime: function UI_home_formatDateTime(date) {
+ return date.getFullYear() + '/' + this.pad(date.getMonth()+1) + '/' + this.pad(date.getDate()) +
+ ' ' + this.pad(date.getHours()) + ':' + this.pad(date.getMinutes());
+ },
+
+ /**
+ * Zero-pads a positive number to 2 digits
+ */
+ pad: function UI_home_pad(number) {
+ return number < 10 ? '0' + number : number;
+ },
+
+ /**
+ * Creates HTML representing the given array of alarms
+ *
+ * @param {Alarm[]} alarms
+ * @returns {string}
+ */
+ getAlarmsHtml: function UI_home_getAlarmsHtml(alarms) {
+ var alarm = '', j, len;
+
+ len = alarms.length;
+
+ if (len) {
+ alarm += '<p class="ui-li-aside ui-li-desc"><img src="img/clock.png"/>';
+
+ for (j = 0; j < len; j += 1) {
+ alarm += alarms[j].before.length;
+ alarm += ' ' + alarms[j].before.unit;
+ }
+ alarm += '</p>';
+ }
+ return alarm;
+ },
+
+ /**
+ * Load the events into the #event_popup.
+ *
+ * Callback function for app.loadEvents.
+ * @param {Array} events
+ */
+ onEventSearchSuccess: function UI_home_onEventSearchSuccess(events) {
+ var i = 0, j = 0,
+ str = "",
+ event,
+ alarm = '',
+ dividerText = '',
+ templateParameters = {},
+ tmplName;
+
+ var compareTZDates = function(a, b) {
+ if (a.getFullYear() !== b.getFullYear())
+ return a.getFullYear() < b.getFullYear() ? 1 : -1;
+ if (a.getMonth() !== b.getMonth())
+ return a.getMonth() < b.getMonth() ? 1 : -1;
+ if (a.getDate() !== b.getDate())
+ return a.getDate() < b.getDate() ? 1 : -1;
+ return 0;
+ };
+
+ var compareTZTimes = function(a, b) {
+ return a.getHours() < b.getHours() ? -1 : 1;
+ if (a.getMinutes() !== b.getMinutes())
+ return a.getMinutes() < b.getMinutes() ? -1 : 1;
+ return 0;
+ };
+
+ events = events.sort(
+ function(a, b) {
+ var result;
+ result = compareTZDates(a.startDate, b.startDate);
+ if (result !== 0) {
+ return result;
+ }
+ if (a.isAllDay !== b.isAllDay) {
+ return a.isAllDay ? 1 : -1;
+ }
+ var result = compareTZTimes(a.startDate, b.startDate);
+ if (result !== 0) {
+ return result;
+ }
+ var result = compareTZDates(a.endDate, b.endDate);
+ if (result !== 0) {
+ return result;
+ }
+ var result = compareTZTimes(a.endDate, b.endDate);
+ if (result !== 0) {
+ return result;
+ }
+ if (a.name !== b.name)
+ return a.name < b.name ? -1 : 1;
+ return 0;
+ }
+ );
+
+ // content
+ str = '';
+ if (events.length !== 0) {
+ for (i = 0; i < events.length; i += 1) {
+ event = events[i];
+
+ dividerText = this.getSeparatorText(event);
+
+ if (dividerText) {
+ str += '<li data-role="list-divider">'
+ + dividerText + '</li>';
+ }
+
+ alarm = this.getAlarmsHtml(event.alarms);
+
+ templateParameters = {
+ uid: event.id.uid,
+ startDate: this.formatDate(event.startDate),
+ startDateTime: this.formatDateTime(event.startDate),
+ endDateTime: this.formatDateTime(event.endDate),
+ summary: event.summary || '[ no title ]',
+ location: event.location,
+ description: event.description,
+ alarm: alarm
+ };
+
+ tmplName = event.isAllDay ? 'all_day_event' : 'event';
+ str += this.context.templateManager.get(tmplName,
+ templateParameters);
+ }
+ } else {
+ dividerText = this.getSeparatorText({
+ startDate: app.homeDateFilter
+ });
+
+ if (dividerText) {
+ str += '<li data-role="list-divider">'
+ + dividerText + '</li>';
+ }
+
+ str += '<li>No events found</li>';
+ }
+ this.getSeparatorText(); // clear the separator state
+
+ $('#events_list ul').html(str);
+ $('#events_list ul').listview();
+ $('#events_list ul').data('listview').refresh();
+ $('#events_list ul input.edit_event_btn').button();
+ $('#events_list ul input.remove_event_btn').button();
+ },
+
+ /**
+ * Error handler for event search
+ */
+ onEventSearchError: function UI_home_onEventSearchError() {
+ console.error("event search error");
+ },
+
+ updateHomeDateFilter: function () {
+ $("#homeDateFilter")
+ .datetimepicker("value", app.homeDateFilter);
+ }
+ },
+
+ /**
+ * Contains methods related to the #alarm page
+ * @namespace
+ */
+ alarm: {
+ init: function UI_alarm_init() {
+ $("#customDuration").val("");
+ },
+
+ setValue: function (duration) {
+ if(typeof duration == "undefined") {
+ duration = 0;
+ }
+
+ app.setAlarm(duration);
+
+ $.each($('#new_alarm input:radio'), function () {
+ $(this).attr('checked', parseInt($(this).val(), 10) === duration)
+ .checkboxradio('refresh');
+ });
+
+ if (!$("#new_alarm input[type=radio]:checked").val()) {
+ $('#yes_1').attr('checked', true).checkboxradio('refresh');
+ $("#customDuration").val(duration).removeClass('ui-disabled');
+ } else {
+ $("#customDuration").val(0).addClass('ui-disabled');
+ }
+ return duration;
+ },
+
+ getValue: function () {
+ var value = parseInt($("#new_alarm input[type=radio]:checked").val(), 10);
+ if(isNaN(value))
+ {
+ value = Math.abs(parseInt($("#customDuration").val()));
+ if (isNaN(value)) {
+ value = 0;
+ }
+ } else {
+ this.disableCustomDuration();
+ }
+ return value;
+ },
+
+ disableCustomDuration: function () {
+ $("#customDuration").val("").addClass('ui-disabled');
+ },
+
+ /**
+ * Reads and sets alarm duration label
+ */
+ updateDurationLabel: function (eventAndAlarm) {
+ var value = this.getValue(), unit, label;
+ app.ui.alarm.setValue(value === 0 ? 0 : (value || -1));
+ if (value === -1) {
+ label = 'Off';
+ } else if (value === 0) {
+ label = 'On time';
+ } else {
+ unit = 'minute';
+ if (value % 10080 === 0) {
+ value /= 10080;
+ unit = 'week';
+ } else if (value % 1440 === 0) {
+ value /= 1440;
+ unit = 'day';
+ } else if (value % 60 === 0) {
+ value /= 60;
+ unit = 'hour';
+ }
+ label = value + ' ' + unit + (value > 1 ? 's' : '') + ' before';
+ }
+ $('#alarm').text(label);
+ }
+ },
+
+ /**
+ * Contains methods related to the new event page
+ * @namespace
+ */
+ new_event: {
+ initialized: false,
+ animateStatus: false,
+
+ init: function () {
+ this.assignFields();
+ this.updateDateFormat();
+ this.setStartDate();
+ this.setEndDate();
+ this.addEvents();
+ this.initialized = true;
+ },
+
+ addEvents: function () {
+ var self = this, alarm;
+
+ this.allday.change(this.updateDateFormat.bind(this));
+ this.start.change(this.validStart.bind(this));
+ this.end.change(this.validEnd.bind(this));
+
+ $("#new_event").on('pageshow', function () {
+ self.animateStatusChange.bind(self)();
+ });
+
+ /* old events */
+ $('#add-event-btn').on('click', this.addEvent.bind(this));
+ $('#add-event-cancel-btn').on('click', this.cancel.bind(this));
+ //alarm selection confirm
+ $('#add-alarm').on('click', app.switchAlarm.bind(app));
+ // go to alarm selection
+ $('#add_alarm').on('click', function (e) {
+ $.mobile.changePage('#new_alarm');
+ });
+ },
+
+ animateStatusChange: function () {
+ var self = this;
+ this.end.next().find('span').not('.ui-datefield-seperator')
+ .off('click')
+ .on('click', function (e) {
+ self.animateStatus =
+ $(e.target).hasClass('ui-btn-picker');
+ });
+ },
+
+ validStart: function () {
+ this.setStartDate();
+ if (this.startDate > this.endDate) {
+ this.end.datetimepicker("value", this.startDate);
+ this.setEndDate();
+ }
+ },
+
+ validEnd: function () {
+ if (this.startDate > this.getDateFromPicker(this.end)) {
+ this.setDateValue(this.end, this.endDate)
+ this.showWarning(
+ 'End date cannot be earlier than initial date',
+ function () {$("#demo-date-2").datetimepicker()}
+ );
+ } else {
+ this.setEndDate();
+ }
+ },
+
+ validAll: function () {
+ this.validStart();
+ this.validEnd();
+ },
+
+ showWarning: function (text, successCallback) {
+ this.lockTabKey();
+ app.ui.popup(text, {
+ 'OK': function () {
+ $("#popup").popup('close');
+ if (successCallback instanceof Function) {
+ successCallback();
+ }
+ }
+ });
+ this.popup.one("popupafterclose", function () {
+ $(document).off('keydown');
+ });
+ },
+
+ lockTabKey: function () {
+ $(document).on('keydown', function(event) {
+ if (event.keyCode === 9) {
+ event.preventDefault();
+ }
+ });
+ },
+
+ assignFields: function () {
+ this.allday = $("#allDay");
+ this.start = $("#demo-date-1");
+ this.end = $("#demo-date-2");
+ this.popup = $("#popup");
+ },
+
+ updateDateFormat: function (fast) {
+ var date = tizen.time.getDateFormat(true),
+ time = tizen.time.getTimeFormat();
+ if (this.allday.val() === '1') {
+ this.format = "MMM dd yyyy";
+ this.end.parent().parent().hide();
+ this.end.parent().parent().prev().hide();
+ } else {
+ if (time === "h:m:s") {
+ this.format = "MMM dd yyyy HH:mm";
+ } else {
+ this.format = "MMM dd yyyy hh:mm tt";
+ }
+ this.end.parent().parent().show();
+ this.end.parent().parent().prev().show();
+ }
+ if (fast) {
+ this.start.datetimepicker("option", "format", this.format);
+ this.end.datetimepicker("option", "format", this.format);
+ } else {
+ $("#title").blur();
+ this.start.datetimepicker("option", "format", this.format)
+ .datetimepicker();
+ this.end.datetimepicker("option", "format", this.format)
+ .datetimepicker();
+ }
+ $("#demo-date-1").datetimepicker();
+ $("#demo-date-2").datetimepicker();
+ },
+
+ setDateValue: function (field, date) {
+ var sp = field.next().find('span').not('.ui-datefield-seperator');
+ field.datetimepicker("value", date);
+ if (this.animateStatus) {
+ sp.animationComplete(function () {
+ setTimeout(function () {
+ field.datetimepicker("value", date);
+ }, 700);
+ sp.off('webkitAnimationEnd');
+ sp.off('animationend');
+ });
+ }
+ },
+
+ setStartDate: function () {
+ this.startDate = this.getDateFromPicker(this.start);
+ },
+
+ setEndDate: function () {
+ this.endDate = this.getDateFromPicker(this.end);
+ },
+
+ getDateFromPicker: function (field) {
+ return field.data('datetimepicker').options.date;
+ },
+
+ /* methods before new event refactor */
+
+ setSelectAllDay: function (value) {
+ value = value ? 1 : 0;
+ app.ui.new_event.allday.find("option")
+ .attr('selected', false);
+ app.ui.new_event.allday.find("option[value='" + value + "']")
+ .attr('selected', true);
+ app.ui.new_event.allday.slider("refresh");
+ },
+
+ addEvent: function Ui_newEvent_addEvent(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ var button = $('#add-event-btn');
+ if (!button.hasClass('disabled')) {
+ button.addClass('disabled');
+ if (app.eventId === 0) {
+ this.context.app.addEvent(e, function(){
+ $.mobile.changePage('#home');
+ });
+ } else {
+ this.context.app.updateEvent(e, function(){
+ $.mobile.changePage('#home');
+ });
+ }
+ }
+ },
+
+ cancel: function Ui_newEvent_cancel(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ $.mobile.changePage('#home');
+ }
+ },
+
+ fixContentHeight: function Ui_fixContentHeight() {
+ var contentHeight = screen.availHeight - $('div[data-role="header"]').outerHeight() - $('div[data-role="footer"]').outerHeight();
+ $('div[data-role="content"]').css('height', contentHeight);
+ }
+ };
+
+ Ui.prototype.popup = function (text, buttons) {
+ var i, popup = $("#popup");
+
+ if(!popup.hasClass('ui-popup')) {
+ popup.popup();
+ }
+
+ if (!buttons) {
+ buttons = {'OK': function () { $("#popup").popup('close') }};
+ }
+
+ $(".ui-popup-button-bg", popup).empty();
+ for (i in buttons) {
+ if (buttons.hasOwnProperty(i)) {
+ if (buttons[i]) {
+ $('<a/>')
+ .text(i)
+ .attr({'data-role': 'button', 'data-inline': 'true'})
+ .bind('click', buttons[i])
+ .appendTo($(".ui-popup-button-bg", popup));
+ }
+ }
+ }
+ $(".ui-popup-text p", popup).text(text);
+
+ popup.trigger("create");
+ popup.popup('open', {positionTo: 'window'});
+ };
}());