!!!
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='/javascripts/jquery-1.7.2.min.js')
script(src='/javascripts/jquery-ui-1.8.20.custom.min.js')
script(src='/javascripts/jsrender.js')
script(src='/socket.io/socket.io.js')
script(src='/form2js/form2js.js')
script(src='/form2js/jquery.toObject.js')
script(src='/form2js/json2.js')
link(rel='stylesheet', href="stylesheets/smoothness/jquery-ui-1.8.20.custom.css")
script#movieTemplate1(type="text/x-jsrender").
Delete |
{{:activity.name}} |
{{:date}} |
{{if activity.note}}
{{for activity.note}}
{{:name}}
{{/for}}
{{/if}}
|
{{if activity.exercise}}
{{for activity.exercise}}
{{:name}}{{:sets}}{{:reps}}{{:weight}}
{{/for}}
{{/if}}
|
script
$(function() {
//$( "#datepicker" ).datepicker();
var socket = io.connect();
socket.on('populate', function(json) {
console.log('#poulate recieved');
var content = "";
$('#employees').empty();
$( "#employees" ).html(
$( "#movieTemplate1" ).render( json )
);
});
$('#AddAct').click(function() {
$('#Activity').attr('style', 'display: block');
var last_item = $('.ActivityBlock').length;
//if last_item = 0
var newElem = $('.ActivityBlock_T').clone(true, true).attr('style', 'display: block');
$(newElem).attr('class', 'ActivityBlock');
$(newElem).attr('id', 'ActivityBlock' + (last_item + 1) );
//$(newElem).children('.AddNeut').attr('data-activity','ActivityBlock_' + (last_item + 1));
//$(newElem).children('.RemNeut').attr('data-activity','ActivityBlock_' + (last_item + 1));
$(newElem).children('.AddNeut').attr('disabled',false);
//$(newElem).children('.RemNeut').attr('disabled',false);
$(newElem).find('ul.activity li').children('input').attr('disabled',false);
$(newElem).find('ul.activity li').attr('style', 'display: block');
$(newElem).find('input.datefield').datepicker()
$(newElem).find('input.datefield').datepicker('setDate', new Date())
$(newElem).appendTo('form#myForm');
});
//Add more fields dynamically.
$('input.AddNeut').click(function() {
var field = $(this).attr('data-field');
var area = $(this).attr('data-area');
var limit = $(this).attr('data-limit');
var actblock = $(this).closest('div').attr('id');
var last_item = $('#' + actblock + ' .' + area ).length;
console.log($(this).closest('div').attr('id'))
console.log('#' + actblock + ' ul.' + field + ' li:first - LastItem - ',last_item, 'next_Item - ', (last_item + 1) );
// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#' + actblock + ' ul.' + area + ' li:first').clone().attr('style', 'display: block');
$(newElem).attr('class', area);
$(newElem).children('input').attr('disabled',false);
$(newElem).children('input').each(function(){
var newName = $(this).attr('name').replace('[i]','[' +(last_item) + ']');
console.log('name ' + newName);
$(this).attr('name', newName);
});
$(newElem).appendTo('div#' + actblock + ' ul.' +area);
console.log('enable #' + actblock + ' .'+ area + 'rem');
$('#' + actblock + ' .'+ area + 'rem').attr('disabled',false);
});
$('input.RemNeut').click(function() {
var field = $(this).attr('data-field');
var area = $(this).attr('data-area');
var limit = $(this).attr('data-limit');
var actblock = $(this).closest('div').attr('id');
var last_item = $('#' + actblock + ' .' + area ).length;
console.log('.' + area + ' li')
console.log('LastItem - ',last_item, 'next_Item - ', (last_item - 1) );
if (last_item != 1) {
$('#' + actblock + ' ul.' + area + ' li:last').remove();
};
// enable the "add" button
$('.AddNeut#' + area).attr('disabled',false);
// if only one element remains, disable the "remove" button
if (last_item == 2)
$('#' + actblock + ' .'+ area + 'rem').attr('disabled','disabled');
console.log('#'+ area + ' .RemNeut')
});
$('#save').click(function() {
var selector= ".ActivityBlock"
//var formDataFirst = $(selector).toObject({mode: 'first'});
var formDataAll = $(selector).toObject({mode: 'all'});
socket.emit('data', formDataAll);
console.log('All ', JSON.stringify(formDataAll, null, '\t'));
// to prevent the page from changing
$('.ActivityBlock').remove();
$('#Activity').attr('style', 'display: none');
return false;
});
$('#cancel').click(function() {
$('.ActivityBlock').remove();
$('#Activity').attr('style', 'display: none');
return false;
});
});
body!= body