add dynmic exercsie list, keywords(hardcoded), datafields(hardcoded), adding exercises from exercise list, and show hide for delete button.

This commit is contained in:
2013-01-22 21:09:20 -05:00
parent 30ed56b9ba
commit a5f70ec9d1
7 changed files with 52 additions and 59 deletions

1
app.js
View File

@@ -49,6 +49,7 @@ require('./routes/users')(app);
require('./routes/session')(app);
require('./routes/workouts')(app);
require('./routes/admin')(app);
require('./routes/api')(app);
http.createServer(app).listen(app.get("port"), function(){
console.log ("Server listening on port " + app.get("port"));

View File

@@ -1,29 +0,0 @@
var Schema = require('mongoose').Schema;
var Split = new Schema({
reps: { type: String},
weight: { type: String}
});
var Element = new Schema({
ExerciseID: {type: String} ,
splits: [Split]
});
var workoutSchema = new Schema({
userID: { type: Schema.ObjectId, ref: 'User', required: true },
workoutDate: { type: Date, 'default': Date.now },
workoutTime: { type: Date, 'default': Date.now },
privacySetting: { type: Number},
Notes: { type: String},
templateID: { type: Schema.ObjectId, ref: 'Template'},
circuits: [Number],
elements: [Element]
});
module.exports = workoutSchema;

View File

@@ -8,6 +8,24 @@ $(document).ready(function() {
$('.datepicker').datepicker('setDate', new Date());
//$('.datepicker').datepicker("hide");
jQuery.extend({
getValues: function(url) {
var result = null;
$.ajax({
url: url,
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
result = data;
}
});
return result;
}
});
$("button#addExercise").click(function() {
console.log("click!");
var newElem = $('<li class=ui-state-default ><label for="element">elements[0][exerciseID]<br /></label><input name="elements[][exerciseID]" class="element"><button type="button" class="addSet">Add Set</button><button type="button" class="delete">Delete Exercise</button><ul class="sets"></ul></li>');
@@ -18,8 +36,7 @@ $(document).ready(function() {
});
$(document).on('click', '.addSet',(function() {
console.log("click! set");
var newElem = $('<li><label for="element" name="elements[0][splits][0][reps]">elements[0][splits][0][reps]<br /></label><input name="elements[0][splits][0][reps]" class="element"><label for="element" name="elements[0][splits][0][weight]"><br />elements[0][splits][0][weight]<br /></label><input name="elements[0][splits][0][weight]" class="element"><button type="button" class="delete">Delete Set</button></li>');
var newElem = $('<li class="set"><label for="element" name="elements[0][splits][0][reps]">elements[0][splits][0][reps]<br /></label><input name="elements[0][splits][0][reps]" class="element"><label for="element" name="elements[0][splits][0][weight]"><br />elements[0][splits][0][weight]<br /></label><input name="elements[0][splits][0][weight]" class="element"><button type="button" class="delete">Delete Set</button></li>');
$(this).siblings('ul.sets').append(newElem);
$("button").button();
$("ul.sets").sortable({
@@ -67,7 +84,15 @@ $(document).ready(function() {
newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
$(this).html(newname2);
});
});
if ( $(this).siblings('.set').length > 0 ) {
$(this).children('.delete').show();
console.log(">1 " + $(this).siblings('.set').length);
} else {
$(this).children('.delete').hide();
console.log("=1 " + $(this).siblings('.set').length);
}
});

View File

@@ -9,20 +9,13 @@ a {
ul, menu, dir {
list-style-type: none;
}
#sortable ul {
list-style-type: none;
}
/*#sortable li {
margin: 0 3px 3px 3px;
padding: 0.4em;
padding-left: 1.5em;
height: 24px;
list-style-type: none;
}
*/
label {
margin-left: 5px;
margin-right: 5px;
@@ -32,4 +25,9 @@ label {
border: 1px solid #ccc;
vertical-align: middle;
text-align:center;
}
form {
margin: 5px;
border: 1px solid #ccc;
}

View File

@@ -59,21 +59,6 @@ module.exports = function(app) {
res.render('workouts/new', {title: "New workout"});
});
app.get('/workouts/exerciselist', function(req, res) {
res.contentType('json');
Exercise.find({})
.exec(function(err, exercises) {
if (err) {
return next(err);
}
if (! exercise) {
return res.send(JSON.stringify({ "error": "true" }));
}
res.send(exercises);
});
});
app.get('/workouts/:_id', loadWorkout, function(req, res, next){
console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));

View File

@@ -1,15 +1,26 @@
extends ../layout
block additionalscripts
script(src='/javascripts/workout.js')
block content
h1 New workout
p THis will be a dropdown to select exercises
input#title(name="Exercise")
button#addExercise(type="button") Add Exercise
h3 Exercises (dynamically loaded from database)
ul#exerciselist
div#filters
h3 Filters ( currently just placeholder )
label Free Weights
input#filter1(type="checkbox", value="Free Weights")
//button#addExercise(type="button") Add Exercise
hr
form#newworkout(method="POST", action="/workouts")
ul
li
label(for="title", value="UserID")<br />
label(for="title", value="UserID") UserID
input#title(name="userID", value=session.user._id)
li
label(for="datepicker", value="Date") workoutDate

View File

@@ -1,4 +1,6 @@
extends ../layout
block content
h1= workout.title