Revert "Updated application sources" 09/22409/1 master
authorPiotr Wronski <p.wronski@samsung.com>
Tue, 3 Jun 2014 06:17:07 +0000 (23:17 -0700)
committerPiotr Wronski <p.wronski@samsung.com>
Tue, 3 Jun 2014 06:17:07 +0000 (23:17 -0700)
This reverts commit de7a03a9784458cccdf7e34a889bcf52af295a75.

Change-Id: Icb3398bad634374ec3f0a34fe8049ccc4c40e2a1

15 files changed:
project/config.xml
project/css/style.css
project/index.html
project/js/app.config.js
project/js/app.js
project/js/app.model.js
project/js/app.ui.js
project/js/app.ui.templateManager.js
project/js/app.ui.templateManager.modifiers.js
project/js/main.js
project/templates/alarm.tpl
project/templates/all_day_event.tpl
project/templates/event.tpl
project/templates/home.tpl
project/templates/new_event.tpl

index 912c467..0d21b61 100644 (file)
@@ -1,34 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<widget
-
-    xmlns="http://www.w3.org/ns/widgets"
-    xmlns:tizen="http://tizen.org/ns/widgets"
-    id="http://sample-web-application.tizen.org/EventManager"
-    version="2.2.0"
-    viewmodes="maximized">
-
-    <tizen:application
-        id="VJTVhzmnwf.EventManager"
-        package="VJTVhzmnwf" required_version="2.2" />
-
-    <content src="index.html" />
-
-    <icon src="icon.png" />
-
-    <name>Event Manager</name>
-
-    <feature name="http://tizen.org/feature/screen.size.normal.720.1280"/>
-
-    <tizen:privilege name="http://tizen.org/privilege/application.launch" />
-    <tizen:privilege name="http://tizen.org/privilege/calendar.read" />
-    <tizen:privilege name="http://tizen.org/privilege/calendar.write" />
-    <tizen:privilege name="http://tizen.org/privilege/time" />
-
-    <tizen:setting
-        screen-orientation="portrait"
-        context-menu="disable"
-        background-support="disable"
-        encryption="disable"
-        install-location="auto" />
-
+<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets"
+       id="http://sample-web-application.tizen.org/EventManager" version="2.2.0"
+       viewmodes="maximized">
+       <tizen:application id="VJTVhzmnwf.EventManager"
+               package="VJTVhzmnwf" required_version="2.2" />
+       <content src="index.html" />
+       <icon src="icon.png" />
+       <name>Event Manager</name>
+       <feature name="http://tizen.org/feature/screen.size.normal.720.1280"/>
+       <tizen:privilege name="http://tizen.org/privilege/application.launch" />
+       <tizen:privilege name="http://tizen.org/privilege/calendar.read" />
+       <tizen:privilege name="http://tizen.org/privilege/calendar.write" />
+       <tizen:privilege name="http://tizen.org/privilege/time" />
+       <tizen:setting screen-orientation="portrait"
+               context-menu="disable" background-support="disable" encryption="disable"
+               install-location="auto" />
 </widget>
index 90bb15c..e19fadf 100644 (file)
 html.ui-mobile, html {
-    overflow: hidden;
+       overflow: hidden;
 }
 
 body {
-    overflow: hidden;
-    -webkit-user-select: none;
+       overflow: hidden;
 }
 
 #new_event label {
-    font-weight: bold !important;
-    margin-top: .3em !important;
+       font-weight: bold !important;
+       margin-top: .3em !important;
 }
 
 #new_event input {
-    width: 94%;
+       width: 94%;
 }
 
 #events_list {
-    word-wrap: break-word;
+       word-wrap: break-word;
 }
 
 li.event {
-    font-size: 0.8rem;
-    height: 60px;
+       font-size: 0.8rem;
+       height: 60px;
 }
 
 .description {
-    display: block;
-    overflow: hidden;
-    white-space: pre;
-    text-overflow: ellipsis;
-    width: 14rem;
-    font-weight: bold;
-    margin-left: 14px;
-    height:22px;
-    white-space: nowrap;
-    text-overflow: ellipsis;
+       display: inline-block;
+       overflow: hidden;
+       white-space: nowrap;
+       text-overflow: ellipsis;
+       width: 14rem;
+       font-weight: bold;
+       margin-left: 14px;
 }
 
 li.event .ui-li-aside {
-    margin-right: 10px;
-    font-size: 0.8rem;
-    float: left;
+       margin-right: 10px;
+       font-size: 0.8rem;
+       float: left;
 }
 
 .green_dot, .red_dot {
-    width: 9px;
-    height: 9px;
-    float: left;
-    margin-right:4px;
-    margin-top:7px;
+       width: 9px;
+       height: 9px;
+       float: left;
+       margin-right:4px;
+       margin-top:7px;
 }
 
 .deleteEvent,
 .editEvent {
-    display: inline-block;
-    position: absolute;
-    right: 0px;
-    top: 64%;
+       display: inline-block;
+       position: absolute;
+       right: 0px;
+       top: 64%;
 }
 
 .editEvent {
-    right: 82px;
+       right: 82px;
 }
 
 .green_dot {
-    background-image: url('/img/green_point.png');
+       background-image: url('/img/green_point.png');
 }
 .red_dot {
-    background-image: url('/img/red_x.gif');
+       background-image: url('/img/red_x.gif');
 }
 .ui-btn-icon-top .ui-btn-inner {
-    padding-top: 0 !important; /* overwrite broken tizen-white settings */
+       padding-top: 0 !important; /* overwrite broken tizen-white settings */
 }
 
 .ui-btn.disabled {
-    background: -webkit-linear-gradient(top, #D2D2C8 0%, #F6F8EF 100%);
+       background: -webkit-linear-gradient(top, #D2D2C8 0%, #F6F8EF 100%);
 }
 
 .ui-listview li.ui-li-divider {
-    height: 1rem;
+       height: 1rem;
 }
-/** workaround to prevent hiding footer caused by broken softkeyboardupdate
-    event**/
-[data-role='footer'] {
-    display: block !important;
+/** workaround to prevent hiding footer caused by broken softkeyboardupdate event**/
+[data-role="footer"] {
+       display: block !important;
 }
-.ui-tabbar:not(.ui-tabbar-persist) a.ui-btn-active .ui-btn-text,
-    .ui-tabbar:not(.ui-tabbar-persist) .ui-btn-show-style .ui-btn-text {
-    border: none;
+.ui-tabbar:not(.ui-tabbar-persist) a.ui-btn-active .ui-btn-text, .ui-tabbar:not(.ui-tabbar-persist) .ui-btn-show-style .ui-btn-text {
+       border:none;
 }
 .allDaySwitcherTitle, .allDaySwitcher {
-    display: inline-block;
+       display: inline-block;
 }
 .ui-datefield .ui-datefield-month {
-    line-height: 46px;
+       line-height: 46px;
 }
 
 .ui-btn-back {
-    visibility: hidden;
+       visibility:hidden;
 }
 
 label.ui-input-text.customDuration,
 input.ui-input-text.customDuration {
-    display: inline;
-    width: 80px;
+       display: inline;
+       width: 80px;
 }
 
 .ui-datefield .ui-datefield-month {
-    line-height: 24px;
-    height: 24px;
+       line-height: 24px;
+       height: 24px;
 }
 
 .customDetails {
-    margin-left: 2rem;
-    font-size: smaller;
+       margin-left: 2rem;
+       font-size: smaller;
 }
 
 #alarm {
-    font-size: smaller;
-    margin-left: 0.3em;
+       font-size: smaller;
+       margin-left: 0.3em;
 }
 
 #homeDateFilterContainer {
-    text-align: center;
+       text-align: center;
 }
 
 #events_list > ul {
-    margin-top: 0;
-}
-
-#homeDateFilterContainer {
-    padding-bottom: 8px;
-}
-
-#homeDateFilterContainer .ui-btn-box-s.ui-btn-up-s {
-    background: -webkit-linear-gradient(top, #F7F5ED, #ECEAE2) !important;
-    border: 1px #85837E solid !important;
-    box-shadow: .5px 1px 1px #85837E !important;
-}
-
-#homeDateFilterContainer .ui-btn-box-s.ui-btn-down-s {
-    border: 1px transparent solid !important;
+       margin-top: 0;
 }
index 51e2934..374d001 100644 (file)
@@ -1,31 +1,31 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <meta charset="utf-8" />
-    <meta name="description" content="Event manager" />
-    <meta name="viewport" content="width=360, user-scalable=no" />
+       <meta charset="utf-8"/>
+       <meta name="description" content="Event manager"/>
+       <meta name="viewport" content="width=360, user-scalable=no"/>
 
-    <title>Event manager</title>
+       <title>Event manager</title>
 
-    <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.min.js"></script>
-    <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js">
-        </script>
-    <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js"
-        data-framework-theme="tizen-white"></script>
+       <script src="tizen-web-ui-fw/latest/js/jquery.min.js"></script>
+       <script src="tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script>
+       <script src="tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js"
+               data-framework-theme="tizen-white"></script>
 
-    <script type="text/javascript" src="js/main.js"></script>
-    <link rel="stylesheet" type="text/css" href="css/style.css" />
+       <script type="text/javascript" src="js/main.js"></script>
+       <link rel="stylesheet" type="text/css" href="css/style.css"/>
 </head>
 <body>
-    <div data-role="page" id="mock" data-title="mock" data-add-back-btn="false">
-        </div>
-    <div data-role="page" id="popup_page" data-add-back-btn="false">
-        <div data-role="popup" id="popup">
-            <div class="ui-popup-text">
-                <p></p>
-            </div>
-            <div class="ui-popup-button-bg"></div>
-        </div>
-    </div>
+       <div data-role="page" id="mock" data-title="mock" data-add-back-btn="false"></div>
+       <div data-role="page" id="popup_page" data-add-back-btn="false">
+               <div data-role="popup" id="popup">
+                       <div class="ui-popup-text">
+                               <p></p>
+                       </div>
+                       <div class="ui-popup-button-bg">
+                               <a href="javascript:void(0)" data-rel="back" data-role="button">Close</a>
+                       </div>
+               </div>
+       </div>
 </body>
 </html>
index e2757c1..6003509 100644 (file)
@@ -1,19 +1,3 @@
-/*
- *      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.
- */
-
 /*global tizen  */
 
 /**
index 548d427..a4f42ce 100644 (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 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
index d0a3b97..e391b5c 100644 (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();
+               }
+       };
 }());
 
 
index 3a3a458..57a5475 100644 (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 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'});
+       };
 }());
index c880c5e..c1db140 100644 (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.
-*/
-
 /*global tizen, $, app, ModifierManager */
-
 /**
-* @class TemplateManager
-*/
+ * @class TemplateManager
+ */
 function TemplateManager() {
-    'use strict';
-    this.init();
+       'use strict';
+       this.init();
 }
 
 (function () { // strict mode wrapper
-    'use strict';
-
-    TemplateManager.prototype = {
-
-        /**
-        * Template cache
-        */
-        cache: {},
-
-        /**
-        * UI module initialisation
-        */
-        init: function init() {
-            this.modifiers = new ModifierManager().getAll();
-        },
-
-        /**
-        * Returns template html (from cache)
-        * @param {string} tplName
-        * @param {string} tplParams
-        */
-        get: function TemplateManager_get(tplName, tplParams) {
-            if (this.cache[tplName] !== undefined) {
-                return this.getCompleted(this.cache[tplName], tplParams);
-            }
-            return '';
-        },
-
-        /**
-        * Load templates to cache
-        * @param {string} tplNames
-        * @param {function} onSuccess
-        */
-        loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
-            var self = this,
-                cachedTemplates = 0,
-                tplName,
-                tplPath;
-
-            if ($.isArray(tplNames)) {
-
-                // for each template
-                $.each(tplNames, function (index, fileName) {
-
-                    // cache template html
-                    if (self.cache[fileName] === undefined) {
-                        tplName = [
-                            fileName,
-                            app.config.get('templateExtension')
-                        ].join('');
-                        tplPath = [
-                            app.config.get('templateDir'),
-                            tplName
-                        ].join('/');
-
-                        $.ajax({
-                            url: tplPath,
-                            cache: true,
-                            dataType: 'html',
-                            async: true,
-                            success: function (data) {
-                                // increase counter
-                                cachedTemplates += 1;
-
-                                // save to cache
-                                self.cache[fileName] = data;
-
-                                // if all templates are cached launch callback
-                                if (
-                                    cachedTemplates >= tplNames.length &&
-                                        typeof onSuccess === 'function'
-                                ) {
-                                    onSuccess();
-                                }
-                            },
-                            error: function (jqXHR, textStatus, errorThrown) {
-                                console.error(
-                                    'templateManagerError: ' +
-                                        errorThrown
-                                );
-                            }
-                        });
-                    } else {
-                        // template is already cached
-                        cachedTemplates += 1;
-                        // if all templates are cached launch callback
-                        if (
-                            cachedTemplates >= tplNames.length &&
-                                typeof onSuccess === 'function'
-                        ) {
-                            onSuccess();
-                        }
-                    }
-                });
-
-            }
-        },
-
-        /**
-        * Returns template completed by specified params
-        * @param {string} tplHtml
-        * @param {string} tplParams
-        */
-        getCompleted: function TemplateManager_getCompleted(
-            tplHtml,
-            tplParams
-        ) {
-            var tplParam;
-
-            for (tplParam in tplParams) {
-                if (tplParams.hasOwnProperty(tplParam)) {
-                    tplHtml = this.passThruModifiers(
-                        tplHtml,
-                        tplParam,
-                        tplParams[tplParam]
-                    );
-                }
-            }
-
-            return tplHtml;
-        },
-
-        /**
-         * Returns template completed by specified params
-         * including modifiers
-         * @param {string} tplHtml
-         * @param {string} tplParams
-         * @param {string} content
-         */
-        passThruModifiers: function (tplHtml, tplParam, content) {
-            var regModOn = new RegExp('%' + tplParam + '(\\|(.+?)){1,}%', 'g'),
-                regModOff = new RegExp(['%', tplParam, '%'].join(''), 'g'),
-                regModGet = new RegExp('%' + tplParam + '\\|(.+?)%'),
-                regModPut = new RegExp('%' + tplParam + '\\|(.+?)%', 'g'),
-                specRegExp = new RegExp('\\$', 'g'),
-                modifiers,
-                i;
-
-            if (content && (typeof content === 'string')) {
-                content = content.replace(specRegExp, '$$$$');
-            }
-
-            if (regModOn.test(tplHtml)) {
-                modifiers = tplHtml.match(regModGet)[1].split('|');
-                for (i in modifiers) {
-                    if (this.modifiers[modifiers[i]] instanceof Function) {
-                        content = this.modifiers[modifiers[i]](content);
-                    } else {
-                        console.error('unknown modifier: ' + modifiers[i]);
-                    }
-                }
-                tplHtml = tplHtml.replace(regModPut, content);
-            }
-            tplHtml = tplHtml.replace(regModOff, content);
-
-            return tplHtml;
-        }
-    };
-
-}());
+       'use strict';
+       TemplateManager.prototype = {
+
+               /**
+                * Template cache
+                */
+               cache: {},
+
+               /**
+                * UI module initialisation
+                */
+               init: function init() {
+                       this.modifiers = new ModifierManager().getAll();
+               },
+
+               /**
+                * Returns template html (from cache)
+                * @param {string} tplName
+                * @param {string} tplParams
+                */
+               get: function TemplateManager_get(tplName, tplParams) {
+                       if (this.cache[tplName] !== undefined) {
+                               return this.getCompleted(this.cache[tplName], tplParams);
+                       }
+                       return '';
+               },
+
+               /**
+                * Load templates to cache
+                * @param {string} tplNames
+                * @param {function} onSuccess
+                */
+               loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
+                       var self = this,
+                               cachedTemplates = 0,
+                               tplName,
+                               tplPath;
+
+                       if ($.isArray(tplNames)) {
+
+                               // for each template
+                               $.each(tplNames, function (index, fileName) {
+
+                                       // cache template html
+                                       if (self.cache[fileName] === undefined) {
+                                               tplName = [fileName, app.config.get('templateExtension')].join('');
+                                               tplPath = [app.config.get('templateDir'), tplName].join('/');
+
+                                               $.ajax({
+                                                       url: tplPath,
+                                                       cache: true,
+                                                       dataType: 'html',
+                                                       async: true,
+                                                       success: function (data) {
+                                                               // increase counter
+                                                               cachedTemplates += 1;
+
+                                                               // save to cache
+                                                               self.cache[fileName] = data;
+
+                                                               // if all templates are cached launch callback
+                                                               if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+                                                                       onSuccess();
+                                                               }
+                                                       },
+                                                       error: function (jqXHR, textStatus, errorThrown) {
+                                                               console.error('templateManagerError: ' + errorThrown);
+                                                       }
+                                               });
+                                       } else {
+                                               // template is already cached
+                                               cachedTemplates += 1;
+                                               // if all templates are cached launch callback
+                                               if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+                                                       onSuccess();
+                                               }
+                                       }
+                               });
+
+                       }
+               },
+
+               /**
+                * Returns template completed by specified params
+               * @param {string} tplHtml
+               * @param {string} tplParams
+                */
+               getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
+                       var tplParam;
+
+                       for (tplParam in tplParams) {
+                               if (tplParams.hasOwnProperty(tplParam)) {
+                                       tplHtml = this.passThruModifiers(tplHtml, tplParam, tplParams[tplParam]);
+                               }
+                       }
+
+                       return tplHtml;
+               },
+
+               passThruModifiers: function (tplHtml, tplParam, content) {
+                       var regModOn = new RegExp('%' + tplParam + '\\|([a-zA-Z]){1,}%', 'g'),
+                               regModOff = new RegExp(['%', tplParam, '%'].join(''), 'g'),
+                               regModGet = new RegExp('%' + tplParam + '\\|(.+?)%'),
+                               modifier;
+
+                       if (regModOn.test(tplHtml)) {
+                               modifier = tplHtml.match(regModGet)[1];
+                               try {
+                                       content = this.modifiers[modifier](content);
+                               } catch (error) {
+                                       console.error('unknown modifier: ' + modifier);
+                               }
+                               tplHtml = tplHtml.replace(regModOn, content);
+                       } else {
+                               tplHtml = tplHtml.replace(regModOff, content);
+                       }
+
+                       return tplHtml;
+               }
+       };
+
+}());
\ No newline at end of file
index e182164..483faa7 100644 (file)
@@ -1,52 +1,36 @@
-/*
- *      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.
- */
-
 /*global $*/
 /**
  * @class ModifierManager
  */
 function ModifierManager() {
-    'use strict';
-    this.init();
+       'use strict';
+       this.init();
 }
 
 (function () {
-    'use strict';
-    ModifierManager.prototype = {
+       'use strict';
+       ModifierManager.prototype = {
 
-        /**
-         * UI module initialisation
-         */
-        init: function () {
-        },
+               /**
+                * UI module initialisation
+                */
+               init: function () {
+               },
 
-        /**
-         * @return modifiers object
-         */
-        getAll: function () {
-            return this.modifiers;
-        },
+               /**
+                * @return modifiers object
+                */
+               getAll: function () {
+                       return this.modifiers;
+               },
 
-        /**
-         * modifiers definitions
-         */
-        modifiers: {
-            escape: function (str) {
-                return $('<span>').text(str).html();
-            }
-        }
-    };
+               /**
+                * modifiers definitions
+                */
+               modifiers: {
+                       escape: function (str) {
+                               return $('<span>').text(str).html();
+                       }
+               }
+       };
 }());
\ No newline at end of file
index 2ef4c63..d7f4013 100644 (file)
@@ -58,8 +58,7 @@ var app = null;
                         .done(function () {
                             loadedLibs += 1;
                             if (loadedLibs >= app.requires.length) {
-                                // All dependencies are loaded
-                                // - initialise the app
+                                // All dependencies are loaded - initialise the app
                                 app.init();
                             }
                         })
@@ -72,8 +71,7 @@ var app = null;
         /**
          * Handle ajax errors
          */
-        onGetScriptError:
-            function onGetScriptError(e, jqxhr, setting, exception) {
+        onGetScriptError: function onGetScriptError(e, jqxhr, setting, exception) {
             alert('An error occurred: ' + e.message);
         }
     }).init(); // run the loader
index 2603847..d6ed429 100644 (file)
@@ -1,50 +1,49 @@
 <!-- Start of second page: #alarm -->
 <div data-role="page" id="new_alarm" data-add-back-btn="false">
 
-    <div data-role="header" data-position="fixed">
-        <h1>Set alarm</h1>
-    </div><!-- /header -->
-
-    <div data-role="content">
-        <input type="radio" name="radio-choice" id="radio-choice-0" value="-1" />
-        <label for="radio-choice-0">Off</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-1" value="0" checked />
-        <label for="radio-choice-1">On time</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-2" value="5" />
-        <label for="radio-choice-2">5 minutes before</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-3" value="15" />
-        <label for="radio-choice-3">15 minutes before</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-4" value="60" />
-        <label for="radio-choice-4">1 hour before</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-5" value="1440" />
-        <label for="radio-choice-5">1 day before</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-6" value="2880" />
-        <label for="radio-choice-6">2 days before</label>
-
-        <input type="radio" name="radio-choice" id="radio-choice-7" value="10080" />
-        <label for="radio-choice-7">1 week before</label>
-
-        <input type="radio" class="customDuration" name="radio-choice" id="yes_1" value="Yes" >
-        <label for="yes_1">custom time:</label>
-        <span class="customDetails">
-            <!-- max = 99 weeks (9*7*24*60 minutes) -->
-            <input placeholder="0" class="customDuration" type="number" name="radio-choice" min="0" max="997920" id="customDuration" />
-            minutes before
-        </span>
-    </div><!-- /content -->
-
-    <div data-role="footer" data-position ="fixed">
-        <div data-role="tabbar" data-style="tabbar" >
-            <ul>
-                <li><a  id="add-alarm">Save alarm</a></li>
-            </ul>
-        </div>
-    </div><!-- /footer -->
+       <div data-role="header" data-position="fixed">
+               <h1>Set alarm</h1>
+       </div><!-- /header -->
+
+       <div data-role="content">
+               <input type="radio" name="radio-choice" id="radio-choice-0" value="-1" />
+               <label for="radio-choice-0">Off</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-1" value="0" checked />
+               <label for="radio-choice-1">On time</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-2" value="5" />
+               <label for="radio-choice-2">5 minutes before</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-3" value="15" />
+               <label for="radio-choice-3">15 minutes before</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-4" value="60" />
+               <label for="radio-choice-4">1 hour before</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-5" value="1440" />
+               <label for="radio-choice-5">1 day before</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-6" value="2880" />
+               <label for="radio-choice-6">2 days before</label>
+
+               <input type="radio" name="radio-choice" id="radio-choice-7" value="10080" />
+               <label for="radio-choice-7">1 week before</label>
+
+               <input type="radio" class="customDuration" name="radio-choice" id="yes_1" value="Yes" >
+               <label for="yes_1">custom time:</label>
+               <span class="customDetails">
+                       <input placeholder="0" class="customDuration" type="number" name="radio-choice" min="0" id="customDuration"/>
+                       minutes before
+               </span>
+       </div><!-- /content -->
+
+       <div data-role="footer" data-position ="fixed">
+               <div data-role="tabbar" data-style="tabbar" >
+                       <ul>
+                               <li><a href="#new_event" id="add-alarm">Save alarm</a></li>
+                       </ul>
+               </div>
+       </div><!-- /footer -->
 
 </div><!-- /page alarm -->
\ No newline at end of file
index 6a2cabb..0eae0be 100644 (file)
@@ -1,9 +1,9 @@
 <li class="event" data-eventid="%uid%">
-    <div class="ui-li-aside ui-li-desc">
-        <span class="description">%summary|escape% (all day)</span>
-        <div class="green_dot"></div><small>%startDate%</small><br />
-        <div class="red_dot"></div><small>%endDate%</small><br />
-    </div>
-    <div class="editEvent"><form><input type="button" class="edit_event_btn" data-inline="true" value="edit" /></form></div>
-    <div class="deleteEvent"><form><input type="button" class="remove_event_btn" data-inline="true" value="delete" /></form></div>
+       <div class="ui-li-aside ui-li-desc">
+               <span class="description">%summary|escape%</span><br/>
+               <div class="green_dot"></div><small>%startDate%</small><br/>
+               <div class="red_dot"></div><small>all day</small><br/>
+       </div>
+       <div class="editEvent"><form><input type="button" class="edit_event_btn" data-inline="true" value="edit"/></form></div>
+       <div class="deleteEvent"><form><input type="button" class="remove_event_btn" data-inline="true" value="delete"/></form></div>
 </li>
index 248112b..e360971 100644 (file)
@@ -1,9 +1,9 @@
 <li class="event" data-eventid="%uid%">
-    <div class="ui-li-aside ui-li-desc">
-        <div class="description">%summary|escape%</div>
-        <div class="green_dot"></div><small>%startDateTime%</small><br />
-        <div class="red_dot"></div><small>%endDateTime%</small><br />
-    </div>
-    <div class="editEvent"><form><input type="button" class="edit_event_btn" data-inline="true" value="edit" /></form></div>
-    <div class="deleteEvent"><form><input type="button" class="remove_event_btn" data-inline="true" value="delete" /></form></div>
+       <div class="ui-li-aside ui-li-desc">
+               <span class="description">%summary|escape%</span><br/>
+               <div class="green_dot"></div><small>%startDateTime%</small><br/>
+               <div class="red_dot"></div><small>%endDateTime%</small><br/>
+       </div>
+       <div class="editEvent"><form><input type="button" class="edit_event_btn" data-inline="true" value="edit"/></form></div>
+       <div class="deleteEvent"><form><input type="button" class="remove_event_btn" data-inline="true" value="delete"/></form></div>
 </li>
index fff60d8..96b5ac4 100644 (file)
@@ -1,26 +1,26 @@
-<!-- Start of first page: #home -->
-<div data-role="page" id="home" data-add-back-btn="false">
-    <div data-role="header">
-        <h1>Event manager</h1>
-        <div id="homeDateFilterContainer" data-position="fixed">
-            <input type="date" id="homeDateFilter" />
-        </div>
-    </div>
-    <div data-role="content">
+       <!-- Start of first page: #home -->
+       <div data-role="page" id="home" data-add-back-btn="false">
+               <div data-role="header">
+                       <h1>Event manager</h1>
+               </div>
+               <div id="homeDateFilterContainer">
+                       <input type="date" id="homeDateFilter"/>
+               </div>
+               <div data-role="content">
 
-        <div id="events_list">
-            <ul data-role="listview" data-inset="true">
-            </ul>
-        </div>
+                       <div id="events_list">
+                               <ul data-role="listview" data-inset="true">
+                               </ul>
+                       </div>
 
-    </div><!-- /content -->
+               </div><!-- /content -->
 
-    <div data-role="footer" data-position="fixed">
-        <div data-role="tabbar" data-style="tabbar">
-            <ul>
-                <li><a href="#new_event" id="newEventBtn">Add New Event</a></li>
-                <li><a href="javascript:void(0)" id="exit_btn">Exit</a></li>
-            </ul>
-        </div>
-    </div><!-- /footer -->
-</div><!-- /home -->
+               <div data-role="footer" data-position="fixed">
+                       <div data-role="tabbar" data-style="tabbar" >
+                               <ul>
+                                       <li><a href="#new_event" id="newEventBtn">Add New Event</a></li>
+                                       <li><a href="javascript:void(0)" id="exit_btn">Exit</a></li>
+                               </ul>
+                       </div>
+               </div><!-- /footer -->
+       </div><!-- /home -->
index 46d0d1a..f253c97 100644 (file)
@@ -1,55 +1,55 @@
-<!-- Start of the new event form: #new_event -->
-<div data-role="page" id="new_event">
-
-    <div data-role="header" data-position="fixed">
-        <h1>New event</h1>
-    </div><!-- /header -->
-
-    <div data-role="content">
-
-        <fieldset>
-            <label for="title">Title</label>
-            <div><input type="text" name="summary" id="title" /></div>
-
-            <label for="dataAllDay">Type</label>
-            <div id="dataAllDay" data-role="dataAllDay">
-                <span class="allDaySwitcher">
-                <select id="allDay" data-role="slider">
-                    <option value="1">All day</option>
-                    <option value="0">Period</option>
-                </select>
-            </div>
-
-            <label for="demo-date-1">Start</label>
-            <div id="date-1">
-                <span class="ui-li-text-main">
-                    <input type="datetime" name="startDate" id="demo-date-1" data-format="MMM dd yyyy HH:mm" />
-                </span>
-            </div>
-
-            <label for="demo-date-2">End</label>
-            <div id="date-2">
-                <span class="ui-li-text-main">
-                    <input type="datetime" name="endDate" id="demo-date-2" data-format="MMM dd yyyy HH:mm" />
-                </span>
-            </div>
-
-            <label for="alarm">Alarm</label>
-            <div>
-                <a id="set-alarm" data-inline="true" data-role="button">Set</a>
-                <span id="alarm">0 minutes before</span>
-            </div>
-
-        </fieldset>
-
-    </div><!-- /content -->
-
-    <div data-role="footer" data-position="fixed">
-        <div data-role="tabbar" data-style="tabbar">
-            <ul>
-                <li><a id="add-event-cancel-btn" data-inline="true">Cancel</a></li>
-                <li><a id="add-event-btn" data-inline="true">Save</a></li>
-            </ul>
-        </div><!-- /controlbar -->
-    </div><!-- /footer -->
-</div><!-- /new_event -->
+       <!-- Start of the new event form: #new_event -->
+       <div data-role="page" id="new_event">
+
+               <div data-role="header" data-position="fixed">
+                       <h1>New event</h1>
+               </div><!-- /header -->
+
+               <div data-role="content">
+
+                       <fieldset>
+                               <label for="title">Title</label>
+                               <div><input type="text" name="summary" id="title" /></div>
+
+                               <label for="dataAllDay">Type</label>
+                               <div id="dataAllDay" data-role="dataAllDay">
+                                       <span class="allDaySwitcher">
+                                       <select id="allDay" data-role="slider">
+                                               <option value="1">All day</option>
+                                               <option value="0">Period</option>
+                                       </select>
+                               </div>
+
+                               <label for="demo-date-1">Start</label>
+                               <div id="date-1">
+                                       <span class="ui-li-text-main">
+                                               <input type="datetime" name="startDate" id="demo-date-1" data-format="MMM dd yyyy HH:mm"/>
+                                       </span>
+                               </div>
+
+                               <label for="demo-date-2">End</label>
+                               <div id="date-2">
+                                       <span class="ui-li-text-main">
+                                               <input type="datetime" name="endDate" id="demo-date-2" data-format="MMM dd yyyy HH:mm"/>
+                                       </span>
+                               </div>
+
+                               <label for="alarm">Alarm</label>
+                               <div>
+                                       <a id="add_alarm" data-inline="true" data-role="button">Set</a>
+                                       <span id="alarm">0 minutes before</span>
+                               </div>
+
+                       </fieldset>
+
+               </div><!-- /content -->
+
+               <div data-role="footer" data-position="fixed">
+                       <div data-role="tabbar" data-style="tabbar">
+                               <ul>
+                                       <li><a id="add-event-cancel-btn" data-inline="true">Cancel</a></li>
+                                       <li><a id="add-event-btn" data-inline="true">Save</a></li>
+                               </ul>
+                       </div><!-- /controlbar -->
+               </div><!-- /footer -->
+       </div><!-- /new_event -->