mirror of
https://github.com/bodyrep/DemoApp.git
synced 2025-12-06 06:01:48 +00:00
added basic sortable to workout creation
This commit is contained in:
@@ -10,9 +10,10 @@ $(document).ready(function() {
|
||||
|
||||
$("button#addExercise").click(function() {
|
||||
console.log("click!");
|
||||
var newElem = $('<li><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>');
|
||||
$(newElem).appendTo('#exercises');
|
||||
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>');
|
||||
$(newElem).appendTo('ul#exercises');
|
||||
$("button").button();
|
||||
$( "ul#exercises" ).sortable( "refresh" );
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
});
|
||||
|
||||
@@ -21,6 +22,7 @@ $(document).ready(function() {
|
||||
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>');
|
||||
$(this).siblings('ul.sets').append(newElem);
|
||||
$("button").button();
|
||||
$( "#exercises" ).sortable( "refresh" );
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
}));
|
||||
|
||||
@@ -32,13 +34,12 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
$("#newworkout").bind('sortupdate', function(event, ui) {
|
||||
console.log ('sortupdate');
|
||||
$('#newworkout > ul > li').each(function(){
|
||||
$('#exercises > li').each(function(){
|
||||
var itemindex= $(this).index();
|
||||
var newname = $(this).find('input, select').attr('name').replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||
|
||||
$(this).children('label').html(newname);
|
||||
$(this).children('input').attr('name', newname);
|
||||
$(this).children('input').attr('name', newname);
|
||||
|
||||
$(this).find('ul li').each(function(){
|
||||
var itemindex2= $(this).index();
|
||||
@@ -58,18 +59,21 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
});
|
||||
return false;
|
||||
//return false;
|
||||
});
|
||||
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
|
||||
$("ul#exercises").sortable({
|
||||
items: "> li",
|
||||
cancel: ':input, button' ,
|
||||
placeholder: "ui-state-highlight",
|
||||
revert: true,
|
||||
stop: function(event, ui) {
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
jQuery.validator.addMethod("notEqual", function(value, element, param) {
|
||||
return this.optional(element) || value != param;
|
||||
},"Please select a value");
|
||||
|
||||
//$('#newworkout').trigger('sortupdate');
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -5,4 +5,26 @@ body {
|
||||
|
||||
a {
|
||||
color: #00B7FF;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#sortable li {
|
||||
margin: 0 3px 3px 3px;
|
||||
padding: 0.4em;
|
||||
padding-left: 1.5em;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
label {
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
font-size: 12px;
|
||||
background: #f7f7f7;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #ccc;
|
||||
vertical-align: middle;
|
||||
text-align:center;
|
||||
}
|
||||
Reference in New Issue
Block a user