53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
var Page = Page || function() {
|
|
this.entry_count = 6; // count of entries (basically workout dates)
|
|
this.entries = []; // entry titles
|
|
this.exercises = []; // exercises
|
|
this.start_weight = 0; // starting weight
|
|
this.end_weight = 50; // ending weight
|
|
this.step_weight = 5; // demarcation steps
|
|
this.input = null; // input element
|
|
this.tab = null; // tab element
|
|
this.element = document.createElement('div'); // bogus element for events
|
|
};
|
|
Page.prototype.loadJSON = function(json) {
|
|
this.entry_count = json.entry_count || this.entry_count;
|
|
this.entries = json.entries || this.entries;
|
|
this.start_weight = json.start_weight || this.start_weight;
|
|
this.end_weight = json.end_weight || this.end_weight;
|
|
this.step_weight = json.step_weight || this.step_weight;
|
|
this.input.value = json.name || 'swolitude';
|
|
if (typeof json.exercises !== 'undefined') {
|
|
for (var i = 0; i < json.exercises.length; i++) {
|
|
var exercise = this.createExercise(json.exercises[i]);
|
|
}
|
|
}
|
|
};
|
|
Page.prototype.getJSON = function() {
|
|
var json = {
|
|
entry_count: this.entry_count,
|
|
entries: this.entries,
|
|
start_weight: this.start_weight,
|
|
end_weight: this.end_weight,
|
|
step_weight: this.step_weight,
|
|
name: this.input.value,
|
|
exercises: []
|
|
};
|
|
for (var i = 0; i < this.exercises.length; i++) {
|
|
json.exercises.push(this.exercises[i].getJSON());
|
|
}
|
|
return json;
|
|
};
|
|
Page.prototype.createExercise = function(json) {
|
|
var exercise = new Exercise(json);
|
|
exercise.parent = this;
|
|
this.exercises.push(exercise);
|
|
return exercise;
|
|
};
|
|
Page.prototype.removeExercise = function(index) {
|
|
if (index instanceof Exercise) {
|
|
index = this.exercises.indexOf(index);
|
|
}
|
|
if (index < 0 || index >= this.exercises.length) return;
|
|
this.exercises.splice(index, 1);
|
|
};
|