var Exercise = Exercise || function(json) { this.name = json.name || ''; this.color = json.color || [255, 128, 255]; //this.color_string = 'rgba('+this.color[0]+','+this.color[1]+','+this.color[2]+')'; this.color_string = '#'+(this.color[0].toString(16))+(this.color[1].toString(16))+(this.color[2].toString(16)); this.sets = []; this.parent = null; // Page this owns this if (typeof json.sets !== 'undefined') { for (var i = 0; i < json.sets.length; i++) { this.createSet(json.sets[i]); } } else { this.createSet({}); } }; Exercise.prototype.getJSON = function() { var json = { name: this.name, color: this.color, sets: [] }; for (var i = 0; i < this.sets.length; i++) { json.sets.push(this.sets[i].getJSON()); } return json; }; Exercise.prototype.createSet = function(json) { var set = new ESet(json); set.parent = this; this.sets.push(set); return set; }; Exercise.prototype.removeSet = function(index) { if (index < 0 || index >= this.sets.length) return; this.sets.splice(index, 1); };