2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 /*global Config, Model, Ui, app, tizen */
22 (function () { // strict mode wrapper
26 * Creates a new application object
30 App = function App() {};
36 requires: ['js/app.config.js', 'js/app.model.js', 'js/app.alarm.js', 'js/app.ui.js',
37 'js/app.ui.templateManager.js', 'js/app.ui.templateManager.modifiers.js'],
53 APP_CONTROL_DATA_KEY: 'http://tizen.org/appcontrol/data/alarm_id',
54 APP_CONTROL_OPERATION_URI: 'http://tizen.org/appcontrol/operation/exercise',
57 * Initialisation function
59 init: function init() {
60 // instantiate the libs
61 this.config = new Config();
62 this.model = new Model();
65 // initialise the modules
66 this.model.init(this);
67 this.ui.init(this, this.getRequestedAppControlData());
73 * Returns this application id
74 * @return {Number} application id
76 getId: function getId() {
77 return tizen.application.getCurrentApplication().appInfo.id;
81 * Parse request AppControl object and retrieve connected exercise info
82 * @return {String} exercise id or undefined
84 getRequestedAppControlData: function getRequestedAppControlData() {
85 var reqAppControl = tizen
87 .getCurrentApplication()
88 .getRequestedAppControl(),
94 data = reqAppControl.appControl.data;
95 len = data.length - 1;
98 if (data[len].key === this.APP_CONTROL_DATA_KEY) {
99 exerciseId = data[len].value[0];
110 * Application exit from model
112 exit: function exit() {
113 tizen.application.getCurrentApplication().exit();
117 * Adds exercise to storage
118 * @param {Object} exercise
119 * @param {Function} success callback
120 * @param {Function} failure callback
122 addExercise: function addExercise(exercise, success, failure) {
123 // if add was successful
124 if (this.model.add(exercise)) {
125 if (success instanceof Function) {
128 } else { // if add fail
129 console.log('problem with adding');
130 if (failure instanceof Function) {
137 * Gets all stored exercises
138 * @return {Array} list of exercises
140 getAllExercises: function getAllExercises() {
141 return this.model.getAll();
145 * Single exercise which match value in corresponding key
146 * @param {String} attr name
148 * @return {Object|undefined} exercise object
150 getExercise: function getExercise(attr, value) {
151 return this.model.find(attr, value)[0];
155 * Adds exercise to storage
156 * @param {String} exerciseId
157 * @param {Function} success callback
158 * @param {Function} failure callback
160 removeExercise: function removeExercise(exerciseId, success, failure) {
161 // if removed was successfully completed
162 if (this.model.remove(exerciseId)) {
163 if (success instanceof Function) {
166 } else { // if there was problem with removing exercise
167 console.log('problem with removing');
168 if (failure instanceof Function) {