-/*jslint browser: true, devel: true */
+/*jslint devel:true*/
/*global tizen, $, app, localStorage, Audio, document, unlockScreen, UI */
var ExercisePlanner = function () {
"use strict";
* (use localStorage)
*/
ExercisePlanner.prototype.loadConfig = function () {
- console.log('ExercisePlanner_loadConfig');
var configStr = localStorage.getItem('config');
if (configStr) {
this.config = JSON.parse(configStr);
* (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();
};
* 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();
* Closing application with the configuration data saving
*/
ExercisePlanner.prototype.exit = function () {
- console.log('ExercisePlanner_exit');
this.saveConfig();
this.stopMusic();
tizen.application.getCurrentApplication().exit();
* @param value
*/
ExercisePlanner.prototype.setFrequency = function (value) {
- console.log('ExercisePlanner_setFrequency', value);
this.config.frequency[this.config.currentTypeOfPeriods] = parseInt(value, 10);
this.saveConfig();
* @param value
*/
ExercisePlanner.prototype.setStrength = function (value) {
- console.log('ExercisePlanner_setStrength', value);
this.config.strength[this.config.currentTypeOfPeriods] = parseInt(value, 10);
this.saveConfig();
};
* Sending array of exercises to UI for update
*/
ExercisePlanner.prototype.updateExercises = function () {
- console.log('ExercisePlanner_updateExercises');
this.ui.fillExercises(this.config.exercises);
};
* & update graph schedule
*/
ExercisePlanner.prototype.updateTimesRanges = function () {
- console.log('ExercisePlanner_updateTimesRanges');
this.ui.fillTimesRanges(this.config.timesRanges);
this.ui.graphSchedule.updateTimeRanges();
* @param newData
*/
ExercisePlanner.prototype.saveExercises = function (newData) {
- console.log('ExercisePlanner_saveExercises', newData);
var i, l;
if (newData) {
* and show in UI
*/
ExercisePlanner.prototype.showNextAlarm = function showNextAlarm() {
- console.log('ExercisePlanner_showNextAlarm');
var alarms,
currentDate = new Date();
}).sort(function (a, b) {
return a.date - b.date;
});
- console.log(alarms);
if (this.config.nearestExercise > -1) {
this.ui.showAlarmInMonitor({
* @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;
};
/**
* @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
this.ui.fillExercises(this.config.exercises);
return true;
}
- this.ui.showErrors({name: 'Element exists!'});
+
+ this.ui.showErrors([{name: 'Given exercise already exists!'}]);
return false;
};
* @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];
* @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;
* 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;
});
* @param {String} typeOfPeriods ['workday'|'weekend']
*/
ExercisePlanner.prototype.updateGraph = function updateGraph(typeOfPeriods) {
- console.log('updateGraph');
var alarms;
if (!this.ui.graphSchedule) {
throw {
}
typeOfPeriods = typeOfPeriods || ((this.todayIsWorkday()) ? 'workday' : 'weekend');
- console.log('typeOfPeriods: ', typeOfPeriods);
if (typeOfPeriods === 'workday') {
alarms = this.alarms.workday;
// 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;
this.config.currentTypeOfPeriods = (this.todayIsWorkday()) ? 'workday' : 'weekend';
this.generateAlarms();
-
this.ui.initialize(onUiInitialize);
};
}());