--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<?xml-stylesheet type="text/xsl" href="description.xsl"?>\r
+<Overview version="1.0">\r
+ <SampleName>EventManager</SampleName>\r
+ <SampleVersion>0.1.1</SampleVersion>\r
+ <Preview>eventmanager-snapshot.png</Preview>\r
+ <Description>\r
+ A sample application demonstrating the tizen device API usage.\r
+ </Description>\r
+</Overview>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ This file provides a functionality to show template's description.xml in the project wizard.
+ Don't delete or move this file.
+ -->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="/">
+ <html>
+ <head>
+ <style type="text/css">
+ html,body {
+ font-family:Arial;
+ margin: 0px;
+ }
+ td
+ {
+ font-size:13px;
+ }
+ .samplename
+ {
+ font-size:16px;
+ color:#ffffff;
+ height:26px;
+ background-color:#6d96ac;
+ }
+ .category
+ {
+ font-size:16px;
+ color:#ffffff;
+ height:30px;
+ background-color:#6d96ac;
+ }
+ .contents
+ {
+ padding: 6px 10px 14px 10px;
+ }
+ table#widgets td
+ {
+ border: solid 1px #6d96ac;
+ border-collapse: collapse;
+ }
+ .widgetname
+ {
+ font-weight: bold;
+ text-align: center;
+ width: 20%;
+ word-break:break-all;
+ }
+ table#references td
+ {
+ width: 100%;
+ border: 0px;
+ border-spacing: 0px;
+ padding: 5px;
+ }
+ .refname
+ {
+ width: 100%;
+ font-weight: bold;
+ }
+ </style>
+ </head>
+ <body>
+ <table width="400px" border="0" cellspacing="0">
+ <tr>
+ <td class="samplename" align="center">
+ <xsl:value-of select="Overview/SampleName"/>
+ <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
+ <!--
+ <xsl:value-of select="Overview/SampleVersion"/>
+ -->
+ </td>
+ </tr>
+ <tr bgcolor="#FFFFFF">
+ <td class="contents">
+ <strong>Type</strong>: JavaScript
+ <p>
+ <xsl:value-of select="Overview/Description"/>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td align="center" bgcolor="#FFFFFF" height="260px">
+ <img>
+ <xsl:attribute name="src">
+ <xsl:value-of select="Overview/Preview"/>
+ </xsl:attribute>
+ </img>
+ </td>
+ </tr>
+ </table>
+ </body>
+ </html>
+ </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>EventManager</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>json.validation.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.jslint.nature.JSLintBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.css.nature.CSSBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.project.builder.WebBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>json.validation.nature</nature>
+ <nature>org.tizen.web.jslint.nature.JSLintNature</nature>
+ <nature>org.tizen.web.css.nature.CSSNature</nature>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.tizen.web.project.builder.WebNature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+Pawel Sierszen <p.sierszen at samsung dot com>
+Tomasz Lukawski <t.lukawski at samsung dot com>
+Piotr Wronski <p.wronski at samsung dot com>
+Artur Kobylinski <a.kobylinski at samsung dot com>
+Tomasz Paciorek <t.paciorek at samsung dot com>
+Karol Surma <k.surma at samsung dot com>
--- /dev/null
+Flora License
+
+Version 1.1, April, 2013
+
+http://floralicense.org/license/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction,
+and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by
+the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and
+all other entities that control, are controlled by, or are
+under common control with that entity. For the purposes of
+this definition, "control" means (i) the power, direct or indirect,
+to cause the direction or management of such entity,
+whether by contract or otherwise, or (ii) ownership of fifty percent (50%)
+or more of the outstanding shares, or (iii) beneficial ownership of
+such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity
+exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications,
+including but not limited to software source code, documentation source,
+and configuration files.
+
+"Object" form shall mean any form resulting from mechanical
+transformation or translation of a Source form, including but
+not limited to compiled object code, generated documentation,
+and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form,
+made available under the License, as indicated by a copyright notice
+that is included in or attached to the work (an example is provided
+in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form,
+that is based on (or derived from) the Work and for which the editorial
+revisions, annotations, elaborations, or other modifications represent,
+as a whole, an original work of authorship. For the purposes of this License,
+Derivative Works shall not include works that remain separable from,
+or merely link (or bind by name) to the interfaces of, the Work and
+Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original
+version of the Work and any modifications or additions to that Work or
+Derivative Works thereof, that is intentionally submitted to Licensor
+for inclusion in the Work by the copyright owner or by an individual or
+Legal Entity authorized to submit on behalf of the copyright owner.
+For the purposes of this definition, "submitted" means any form of
+electronic, verbal, or written communication sent to the Licensor or
+its representatives, including but not limited to communication on
+electronic mailing lists, source code control systems, and issue
+tracking systems that are managed by, or on behalf of, the Licensor
+for the purpose of discussing and improving the Work, but excluding
+communication that is conspicuously marked or otherwise designated
+in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity
+on behalf of whom a Contribution has been received by Licensor and
+subsequently incorporated within the Work.
+
+"Tizen Certified Platform" shall mean a software platform that complies
+with the standards set forth in the Tizen Compliance Specification
+and passes the Tizen Compliance Tests as defined from time to time
+by the Tizen Technical Steering Group and certified by the Tizen
+Association or its designated agent.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the
+Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+(except as stated in this section) patent license to make, have made,
+use, offer to sell, sell, import, and otherwise transfer the Work
+solely as incorporated into a Tizen Certified Platform, where such
+license applies only to those patent claims licensable by such
+Contributor that are necessarily infringed by their Contribution(s)
+alone or by combination of their Contribution(s) with the Work solely
+as incorporated into a Tizen Certified Platform to which such
+Contribution(s) was submitted. If You institute patent litigation
+against any entity (including a cross-claim or counterclaim
+in a lawsuit) alleging that the Work or a Contribution incorporated
+within the Work constitutes direct or contributory patent infringement,
+then any patent licenses granted to You under this License for that
+Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+Work or Derivative Works thereof pursuant to the copyright license
+above, in any medium, with or without modifications, and in Source or
+Object form, provided that You meet the following conditions:
+
+ 1. You must give any other recipients of the Work or Derivative Works
+ a copy of this License; and
+ 2. You must cause any modified files to carry prominent notices stating
+ that You changed the files; and
+ 3. You must retain, in the Source form of any Derivative Works that
+ You distribute, all copyright, patent, trademark, and attribution
+ notices from the Source form of the Work, excluding those notices
+ that do not pertain to any part of the Derivative Works; and
+ 4. If the Work includes a "NOTICE" text file as part of its distribution,
+ then any Derivative Works that You distribute must include a readable
+ copy of the attribution notices contained within such NOTICE file,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works, in at least one of the following places:
+ within a NOTICE text file distributed as part of the Derivative Works;
+ within the Source form or documentation, if provided along with the
+ Derivative Works; or, within a display generated by the Derivative Works,
+ if and wherever such third-party notices normally appear.
+ The contents of the NOTICE file are for informational purposes only
+ and do not modify the License. You may add Your own attribution notices
+ within Derivative Works that You distribute, alongside or as an addendum
+ to the NOTICE text from the Work, provided that such additional attribution
+ notices cannot be construed as modifying the License. You may add Your own
+ copyright statement to Your modifications and may provide additional or
+ different license terms and conditions for use, reproduction, or
+ distribution of Your modifications, or for any such Derivative Works
+ as a whole, provided Your use, reproduction, and distribution of
+ the Work otherwise complies with the conditions stated in this License
+ and your own copyright statement or terms and conditions do not conflict
+ the conditions stated in the License including section 3.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+any Contribution intentionally submitted for inclusion in the Work
+by You to the Licensor shall be under the terms and conditions of
+this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify
+the terms of any separate license agreement you may have executed
+with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+names, trademarks, service marks, or product names of the Licensor,
+except as required for reasonable and customary use in describing the
+origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+agreed to in writing, Licensor provides the Work (and each
+Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied, including, without limitation, any warranties or conditions
+of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+PARTICULAR PURPOSE. You are solely responsible for determining the
+appropriateness of using or redistributing the Work and assume any
+risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+whether in tort (including negligence), contract, or otherwise,
+unless required by applicable law (such as deliberate and grossly
+negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special,
+incidental, or consequential damages of any character arising as a
+result of this License or out of the use or inability to use the
+Work (including but not limited to damages for loss of goodwill,
+work stoppage, computer failure or malfunction, or any and all
+other commercial damages or losses), even if such Contributor
+has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+the Work or Derivative Works thereof, You may choose to offer,
+and charge a fee for, acceptance of support, warranty, indemnity,
+or other liability obligations and/or rights consistent with this
+License. However, in accepting such obligations, You may act only
+on Your own behalf and on Your sole responsibility, not on behalf
+of any other Contributor, and only if You agree to indemnify,
+defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason
+of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Flora License to your work
+
+To apply the Flora License to your work, attach the following
+boilerplate notice, with the fields enclosed by brackets "[]"
+replaced with your own identifying information. (Don't include
+the brackets!) The text should be enclosed in the appropriate
+comment syntax for the file format. We also recommend that a
+file or class name and description of purpose be included on the
+same "printed page" as the copyright notice for easier
+identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
--- /dev/null
+Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.1
+Please, see the LICENSE.Flora file for Flora License, Version 1.1 terms and conditions.
+
--- /dev/null
+<?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>
--- /dev/null
+html.ui-mobile, html {
+ overflow: hidden;
+}
+
+body {
+ overflow: hidden;
+}
+
+#new_event label {
+ font-weight: bold !important;
+ margin-top: .3em !important;
+}
+
+#new_event input {
+ width: 94%;
+}
+
+#events_list {
+ word-wrap: break-word;
+}
+
+li.event {
+ font-size: 0.8rem;
+ height: 60px;
+}
+
+.description {
+ 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;
+}
+
+.green_dot, .red_dot {
+ width: 9px;
+ height: 9px;
+ float: left;
+ margin-right:4px;
+ margin-top:7px;
+}
+
+.deleteEvent,
+.editEvent {
+ display: inline-block;
+ position: absolute;
+ right: 0px;
+ top: 64%;
+}
+
+.editEvent {
+ right: 82px;
+}
+
+.green_dot {
+ background-image: url('/img/green_point.png');
+}
+.red_dot {
+ background-image: url('/img/red_x.gif');
+}
+.ui-btn-icon-top .ui-btn-inner {
+ padding-top: 0 !important; /* overwrite broken tizen-white settings */
+}
+
+.ui-btn.disabled {
+ background: -webkit-linear-gradient(top, #D2D2C8 0%, #F6F8EF 100%);
+}
+
+.ui-listview li.ui-li-divider {
+ height: 1rem;
+}
+/** 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;
+}
+.allDaySwitcherTitle, .allDaySwitcher {
+ display: inline-block;
+}
+.ui-datefield .ui-datefield-month {
+ line-height: 46px;
+}
+
+.ui-btn-back {
+ visibility:hidden;
+}
+
+label.ui-input-text.customDuration,
+input.ui-input-text.customDuration {
+ display: inline;
+ width: 80px;
+}
+
+.ui-datefield .ui-datefield-month {
+ line-height: 24px;
+ height: 24px;
+}
+
+.customDetails {
+ margin-left: 2rem;
+ font-size: smaller;
+}
+
+#alarm {
+ font-size: smaller;
+ margin-left: 0.3em;
+}
+
+#homeDateFilterContainer {
+ text-align: center;
+}
+
+#events_list > ul {
+ margin-top: 0;
+}
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8"/>
+ <meta name="description" content="Event manager"/>
+ <meta name="viewport" content="width=360, user-scalable=no"/>
+
+ <title>Event manager</title>
+
+ <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"/>
+</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">
+ <a href="javascript:void(0)" data-rel="back" data-role="button">Close</a>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
--- /dev/null
+/*global tizen */
+
+/**
+ * @class Config
+ */
+function Config() {
+ 'use strict';
+}
+
+(function () { // strict mode wrapper
+ 'use strict';
+ Config.prototype = {
+
+ properties: {
+ 'systemContactImageDirPath': '/opt/data/contacts-svc/img/',
+ 'defaultAvatarUrl': 'images/default.jpg',
+ 'templateDir': 'templates',
+ 'localstorageConfigKey': 'configData',
+ 'templateExtension': '.tpl',
+ 'convertedPhotoUrl': 'file:///opt/media/Images/output.png'
+ },
+
+ /**
+ * Returns config value
+ */
+ get: function (value, defaultValue) {
+ defaultValue = defaultValue || '';
+
+ if (this.properties.hasOwnProperty(value)) {
+ return this.properties[value];
+ } else {
+ return defaultValue;
+ }
+ }
+ };
+}());
\ No newline at end of file
--- /dev/null
+/*jslint devel:true*/
+/*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
+ */
+ 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
--- /dev/null
+/*jslint devel:true*/
+/*global tizen */
+
+/**
+ * @class Model
+ */
+var Model = function Model() {
+ 'use strict';
+};
+
+(function () { // strict mode wrapper
+ '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();
+ }
+ };
+}());
+
+
--- /dev/null
+/*jslint devel: true*/
+/*global $, app, tizen, TemplateManager */
+
+/**
+ * @class Ui
+ */
+function Ui() {
+ '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").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'});
+ };
+}());
--- /dev/null
+/*global tizen, $, app, ModifierManager */
+/**
+ * @class TemplateManager
+ */
+function TemplateManager() {
+ '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;
+ },
+
+ 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
--- /dev/null
+/*global $*/
+/**
+ * @class ModifierManager
+ */
+function ModifierManager() {
+ 'use strict';
+ this.init();
+}
+
+(function () {
+ 'use strict';
+ ModifierManager.prototype = {
+
+ /**
+ * UI module initialisation
+ */
+ init: function () {
+ },
+
+ /**
+ * @return modifiers object
+ */
+ getAll: function () {
+ return this.modifiers;
+ },
+
+ /**
+ * modifiers definitions
+ */
+ modifiers: {
+ escape: function (str) {
+ return $('<span>').text(str).html();
+ }
+ }
+ };
+}());
\ No newline at end of file
--- /dev/null
+/*
+ * 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 */
+
+/**
+ * This file acts as a loader for the application and its dependencies
+ *
+ * First, the 'app.js' script is loaded .
+ * Then, scripts defined in 'app.requires' are loaded.
+ * Finally, the app is initialised - the app is instantiated ('app = new App()')
+ * and 'app.init()' is called.
+ */
+
+
+var app = null;
+
+(function () { // strict mode wrapper
+ 'use strict';
+
+ ({
+ /**
+ * Loader init - load the App constructor
+ */
+ init: function init() {
+ var self = this;
+ $.getScript('js/app.js')
+ .done(function onAppLoaded() {
+ // once the app is loaded, create the app object
+ // and load the libraries
+ app = new App();
+ self.loadLibs();
+ })
+ .fail(this.onGetScriptError);
+ },
+ /**
+ * Load dependencies
+ */
+ loadLibs: function loadLibs() {
+ var loadedLibs = 0;
+ if ($.isArray(app.requires)) {
+ $.each(app.requires, function onLibLoaded(index, filename) {
+ $.getScript(filename)
+ .done(function () {
+ loadedLibs += 1;
+ if (loadedLibs >= app.requires.length) {
+ // All dependencies are loaded - initialise the app
+ app.init();
+ }
+ })
+ .fail(function (e) {
+ console.error('Loading libs failed');
+ });
+ });
+ }
+ },
+ /**
+ * Handle ajax errors
+ */
+ onGetScriptError: function onGetScriptError(e, jqxhr, setting, exception) {
+ alert('An error occurred: ' + e.message);
+ }
+ }).init(); // run the loader
+
+}());
--- /dev/null
+<!-- 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">
+ <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
--- /dev/null
+<li class="event" data-eventid="%uid%">
+ <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>
--- /dev/null
+<li class="event" data-eventid="%uid%">
+ <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>
--- /dev/null
+ <!-- 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><!-- /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 -->
--- /dev/null
+ <!-- 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 -->
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<tizen-app-template xmlns="http://www.tizen.org/tizen-app-template" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" template-version="" sdk-version="" icon32="tizen_32.png" icon64="tizen_64.png" xsi:schemaLocation="http://www.tizen.org/tizen-app-template tizen-app-template.xsd ">
+ <template-name>EventManager</template-name>
+ <widget-type>TIZEN</widget-type>
+ <build-property key="usedLibraryType" value="WebUIFramework"/>
+ <description-file-name>description.xml</description-file-name>
+ <options>
+ <supportLibraries>
+ <library name="Tizen Web UI Framework"/>
+ </supportLibraries>
+ </options>
+</tizen-app-template>