[ExercisePlanner]Updated Private -> RSA
[samples/web/ExercisePlanner.git] / js / app.js
index 46f0697..d66e17f 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -1,4 +1,4 @@
-/*jslint browser: true, devel: true */
+/*jslint devel:true*/
 /*global tizen, $, app, localStorage, Audio, document, unlockScreen, UI */
 var ExercisePlanner = function () {
        "use strict";
@@ -125,7 +125,6 @@ var ExercisePlanner = function () {
         * (use localStorage)
         */
        ExercisePlanner.prototype.loadConfig = function () {
-               console.log('ExercisePlanner_loadConfig');
                var configStr = localStorage.getItem('config');
                if (configStr) {
                        this.config = JSON.parse(configStr);
@@ -140,18 +139,15 @@ var ExercisePlanner = function () {
         * (use localStorage)
         */
        ExercisePlanner.prototype.saveConfig = function () {
-               console.log('ExercisePlanner_saveConfig');
                localStorage.setItem('config', JSON.stringify(this.config));
        };
 
        ExercisePlanner.prototype.stopTraining = function () {
-               console.log('ExercisePlanner_stopTraining');
                this.removeAllAlarms();
                this.ui.setStatusRun(this.config.trainingEnabled);
        };
 
        ExercisePlanner.prototype.startTraining = function () {
-               console.log('ExercisePlanner_startTraining');
                this.ui.setStatusRun(this.config.trainingEnabled);
                this.startAlarms();
        };
@@ -160,7 +156,6 @@ var ExercisePlanner = function () {
         * Toggle start/stop alarms for workouts
         */
        ExercisePlanner.prototype.appStartStop = function () {
-               console.log('ExercisePlanner_appStartStop');
                this.config.trainingEnabled = !this.config.trainingEnabled;
                if (this.config.trainingEnabled) {
                        this.startTraining();
@@ -174,7 +169,6 @@ var ExercisePlanner = function () {
         * Closing application with the configuration data saving
         */
        ExercisePlanner.prototype.exit = function () {
-               console.log('ExercisePlanner_exit');
                this.saveConfig();
                this.stopMusic();
                tizen.application.getCurrentApplication().exit();
@@ -185,7 +179,6 @@ var ExercisePlanner = function () {
         * @param value
         */
        ExercisePlanner.prototype.setFrequency = function (value) {
-               console.log('ExercisePlanner_setFrequency', value);
                this.config.frequency[this.config.currentTypeOfPeriods] = parseInt(value, 10);
 
                this.saveConfig();
@@ -199,7 +192,6 @@ var ExercisePlanner = function () {
         * @param value
         */
        ExercisePlanner.prototype.setStrength = function (value) {
-               console.log('ExercisePlanner_setStrength', value);
                this.config.strength[this.config.currentTypeOfPeriods] = parseInt(value, 10);
                this.saveConfig();
        };
@@ -208,7 +200,6 @@ var ExercisePlanner = function () {
         * Sending array of exercises to UI for update
         */
        ExercisePlanner.prototype.updateExercises = function () {
-               console.log('ExercisePlanner_updateExercises');
                this.ui.fillExercises(this.config.exercises);
        };
 
@@ -217,7 +208,6 @@ var ExercisePlanner = function () {
         * & update graph schedule
         */
        ExercisePlanner.prototype.updateTimesRanges = function () {
-               console.log('ExercisePlanner_updateTimesRanges');
 
                this.ui.fillTimesRanges(this.config.timesRanges);
                this.ui.graphSchedule.updateTimeRanges();
@@ -228,7 +218,6 @@ var ExercisePlanner = function () {
         * @param newData
         */
        ExercisePlanner.prototype.saveExercises = function (newData) {
-               console.log('ExercisePlanner_saveExercises', newData);
                var i, l;
 
                if (newData) {
@@ -245,7 +234,6 @@ var ExercisePlanner = function () {
         * and show in UI
         */
        ExercisePlanner.prototype.showNextAlarm = function showNextAlarm() {
-               console.log('ExercisePlanner_showNextAlarm');
                var alarms,
                        currentDate = new Date();
 
@@ -260,7 +248,6 @@ var ExercisePlanner = function () {
                }).sort(function (a, b) {
                        return a.date - b.date;
                });
-               console.log(alarms);
 
                if (this.config.nearestExercise > -1) {
                        this.ui.showAlarmInMonitor({
@@ -291,17 +278,16 @@ var ExercisePlanner = function () {
         * @returns
         */
        ExercisePlanner.prototype.checkExerciseName = function (name) {
-               console.log('ExercisePlanner_checkExerciseName', name);
                var i, l;
+               name = $.trim(name);
 
-               if (name) {
-                       for (i = 0, l = this.config.exercises.length; i < l; i += 1) {
-                               if (this.config.exercises[i].name === name) {
-                                       return i;
-                               }
+               for (i = 0, l = this.config.exercises.length; i < l; i += 1) {
+                       if (this.config.exercises[i].name === name) {
+                               return false;
                        }
-                       return -1;
                }
+
+               return true;
        };
 
        /**
@@ -310,8 +296,7 @@ var ExercisePlanner = function () {
         * @returns {Boolean}
         */
        ExercisePlanner.prototype.addExercise = function (name) {
-               console.log('ExercisePlanner_addExercise', name);
-               if (this.checkExerciseName(name) < 0) {
+               if (this.checkExerciseName(name) === true) {
                        this.config.exercises.push({
                                name: name,
                                enabled: false
@@ -320,7 +305,8 @@ var ExercisePlanner = function () {
                        this.ui.fillExercises(this.config.exercises);
                        return true;
                }
-               this.ui.showErrors({name: 'Element exists!'});
+
+               this.ui.showErrors([{name: 'Given exercise already exists!'}]);
                return false;
        };
 
@@ -330,7 +316,6 @@ var ExercisePlanner = function () {
         * @returns {number}
         */
        ExercisePlanner.prototype.getNumberOfWorkoutsByFrequency = function getNumberOfWorkoutsByFrequency(value) {
-               console.log('ExercisePlanner_frequencyMap', value);
                var iMap = [1, 2, 4, 8, 16, 24, 150],
                        // -- times per 24h; proportion to set periods of available time;
                        numberOfWorkouts = iMap[value];
@@ -345,7 +330,6 @@ var ExercisePlanner = function () {
         * @returns {number}
         */
        ExercisePlanner.prototype.getStrength = function strengthMap(value, count) {
-               console.log('ExercisePlanner_strengthMap', value, count);
                var sMap = [1, 1, 2, 4, 10, 20],
                        base = sMap[value] || 2;
 
@@ -357,7 +341,6 @@ var ExercisePlanner = function () {
         * Generate name of exercise for nearest workout
         */
        ExercisePlanner.prototype.generateNearestExercise = function () {
-               console.log('ExercisePlanner_generateNearestExercise');
                var tmp = this.config.exercises.filter(function (item) {
                        return item.enabled;
                });
@@ -393,7 +376,6 @@ var ExercisePlanner = function () {
         * @param {String} typeOfPeriods ['workday'|'weekend']
         */
        ExercisePlanner.prototype.updateGraph = function updateGraph(typeOfPeriods) {
-               console.log('updateGraph');
                var alarms;
                if (!this.ui.graphSchedule) {
                        throw {
@@ -402,7 +384,6 @@ var ExercisePlanner = function () {
                }
 
                typeOfPeriods = typeOfPeriods || ((this.todayIsWorkday()) ? 'workday' : 'weekend');
-               console.log('typeOfPeriods: ', typeOfPeriods);
 
                if (typeOfPeriods === 'workday') {
                        alarms = this.alarms.workday;
@@ -449,14 +430,12 @@ var ExercisePlanner = function () {
        // Initialize function
        ExercisePlanner.prototype.init = function init() {
                var onUiInitialize = function onUiInitialize() {
-                       console.log('onUiInitialize');
                        // register watcher on visibility change;
                        document.addEventListener('webkitvisibilitychange', this.onVisibilityChange.bind(this));
                        this.showNextAlarm();
                        this.onVisibilityChange();
                }.bind(this);
 
-               console.log('ExercisePlanner..init');
                this.selfId = tizen.application.getAppContext().appId;
                this.ui = new UI();
                this.ui.app = this;
@@ -465,7 +444,6 @@ var ExercisePlanner = function () {
                this.config.currentTypeOfPeriods = (this.todayIsWorkday()) ? 'workday' : 'weekend';
 
                this.generateAlarms();
-
                this.ui.initialize(onUiInitialize);
        };
 }());