mirror of
https://github.com/sstent/node.git
synced 2026-01-25 14:42:00 +00:00
added activity blocks
This commit is contained in:
@@ -53,12 +53,21 @@ app.post('/input', store.input_post_handler);
|
|||||||
|
|
||||||
|
|
||||||
app.get('/items', function(req, res) {
|
app.get('/items', function(req, res) {
|
||||||
testcollection.find({}, function(err, result) {
|
// testcollection.find({}, function(err, result) {
|
||||||
result.each(function(err, data) {
|
// if (err) throw err;
|
||||||
console.log(data);
|
// result.each(function(err, data) {
|
||||||
emitdata('populate',data);
|
// if (err) throw err;
|
||||||
});
|
// console.log('This Is What I Got' + JSON.stringify(data));
|
||||||
|
// emitdata('populate',data);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
testcollection.find().toArray(function(err, result) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log('This Is What I Got ' +JSON.stringify(result));
|
||||||
|
emitdata('populate', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof req.session.username == 'undefined') res.redirect('/');
|
if (typeof req.session.username == 'undefined') res.redirect('/');
|
||||||
else res.render('items', { title: 'Ninja Store - Items'});
|
else res.render('items', { title: 'Ninja Store - Items'});
|
||||||
// else res.render('items', { title: 'Ninja Store - Items', username: req.session.username, items:items, keys:keys, fieldkeys:fieldkeys });
|
// else res.render('items', { title: 'Ninja Store - Items', username: req.session.username, items:items, keys:keys, fieldkeys:fieldkeys });
|
||||||
@@ -94,28 +103,28 @@ io.sockets.on('connection', function (socket) {
|
|||||||
var io = require('socket.io');
|
var io = require('socket.io');
|
||||||
io = io.listen(app);
|
io = io.listen(app);
|
||||||
io.configure('development', function(){
|
io.configure('development', function(){
|
||||||
io.set('close timeout', '50');
|
io.set("transports", ["xhr-polling"]);
|
||||||
|
io.set("polling duration", 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
io.sockets.on('connection', function(client) {
|
io.sockets.on('connection', function(socket) {
|
||||||
|
|
||||||
console.log('Client connected');
|
console.log('Client connected');
|
||||||
|
|
||||||
// client add new employee
|
socket.on('data', function(data) {
|
||||||
client.on('add employee', function(data) {
|
|
||||||
console.log("addemployee ")
|
|
||||||
addemployee(data);
|
|
||||||
});
|
|
||||||
client.on('data', function(data) {
|
|
||||||
console.log("data" + JSON.stringify(data))
|
console.log("data" + JSON.stringify(data))
|
||||||
testcollection.insert(data, function(err, result) {
|
testcollection.insert(data, function(err, result) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (result) console.log('Added!');
|
if (result) console.log('Added!' + result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// client add new employee
|
||||||
|
io.sockets.on('add employee', function(data) {
|
||||||
|
console.log("addemployee ")
|
||||||
|
addemployee(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,33 @@
|
|||||||
include userbar
|
include userbar
|
||||||
|
|
||||||
div
|
div
|
||||||
|
input(type='Button', id='AddAct', value='Add Activity')
|
||||||
|
|
||||||
|
|
||||||
|
div(id='Activity',style='display: none')
|
||||||
|
form#myForm
|
||||||
|
input(type='submit', id='save', value='Save')
|
||||||
|
div(Class='ActivityBlock_T', style='display: none')
|
||||||
input(type='button', class='AddNeut', value='Add note Field', data-field='note_area', data-area='note_', data-limit='0', data-jsontag='activity.note')
|
input(type='button', class='AddNeut', value='Add note Field', data-field='note_area', data-area='note_', data-limit='0', data-jsontag='activity.note')
|
||||||
input(type='button', class='AddNeut', value='Add exercise Field', data-field='exercise_area', data-area='exercise_', data-limit='0',data-jsontag='activity.exercise')
|
input(type='button', class='AddNeut', value='Add exercise Field', data-field='exercise_area', data-area='exercise_', data-limit='0',data-jsontag='activity.exercise')
|
||||||
input(type='submit', id='save', value='Save')
|
input(type='button', class='RemNeut', value='Remove note Field', data-field='note_area', data-area='note_', data-limit='0', data-jsontag='activity.note', disabled='disabled')
|
||||||
|
input(type='button', class='RemNeut', value='Remove exercise Field', data-field='exercise_area', data-area='exercise_', data-limit='0',data-jsontag='activity.exercise', disabled='disabled' )
|
||||||
|
ul(class='Activity_area')
|
||||||
form#myForm
|
li(class='exercise_T', style='display: none')
|
||||||
ol(id='note_area')
|
label Activity
|
||||||
|
input(type='text', name='activity.name', value='Name', disabled='disabled')
|
||||||
|
ul(class='note_area')
|
||||||
li(class='note_T', style='display: none')
|
li(class='note_T', style='display: none')
|
||||||
label Note
|
label Note
|
||||||
input(type='text', name='activity.note[]', value='Note', disabled='disabled')
|
input(type='text', name='activity.note[]', value='Note', disabled='disabled')
|
||||||
a(style='cursor:pointer;color:blue;', onclick='this.parentNode.parentNode.removeChild(this.parentNode);') Remove Field
|
ul(class='exercise_area')
|
||||||
ol(id='exercise_area')
|
|
||||||
li(class='exercise_T', style='display: none')
|
li(class='exercise_T', style='display: none')
|
||||||
label Exercise
|
label Exercise
|
||||||
input(type='text', name='activity.exercise[].name', value='Name', disabled='disabled')
|
input(type='text', name='activity.exercise[].name', value='Name', disabled='disabled')
|
||||||
input(type='text', name='activity.exercise[].sets', value='Sets', disabled='disabled', class='numericonly')
|
input(type='text', name='activity.exercise[].sets', value='Sets', disabled='disabled', class='numericonly')
|
||||||
input(type='text', name='activity.exercise[].reps', value='Reps', disabled='disabled')
|
input(type='text', name='activity.exercise[].reps', value='Reps', disabled='disabled')
|
||||||
input(type='text', name='activity.exercise[x].weight', value='Weight', disabled='disabled')
|
input(type='text', name='activity.exercise[].weight', value='Weight', disabled='disabled')
|
||||||
a(style='cursor:pointer;color:blue;', onclick='this.parentNode.parentNode.removeChild(this.parentNode);') Remove Field
|
|
||||||
ul#employees
|
ul#employees
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,36 +9,58 @@ html
|
|||||||
script(src='/form2js/jquery.toObject.js')
|
script(src='/form2js/jquery.toObject.js')
|
||||||
script(src='/form2js/json2.js')
|
script(src='/form2js/json2.js')
|
||||||
script
|
script
|
||||||
//$(document).ready(function() {
|
$(function() {
|
||||||
|
|
||||||
var socket = io.connect('http://localhost:3000');
|
var socket = io.connect('http://localhost:3000');
|
||||||
|
|
||||||
socket.on('populate', function(json) {
|
socket.on('populate', function(json) {
|
||||||
var out = "";
|
var content = "";
|
||||||
for (var n in json) { // Each top-level entry
|
$('#employees').empty();
|
||||||
out += '<li>' + n + '<ul>';
|
//iterate activities
|
||||||
for (var i = 0; i < json[n].length; i++) { // Each sub-entry
|
$.each (json, function (bb) {
|
||||||
out += '<li>' + json[n][i] + '</li>';
|
var activity = json[bb].activity;
|
||||||
};
|
content += '<p>Activity - '+ bb + '</p>';
|
||||||
out += '</ul></li>';
|
$.each (activity.note, function (cc) {
|
||||||
};
|
content += '<p>Note - '+ cc + '</p>';
|
||||||
console.log('out ' + out);
|
});
|
||||||
$('#employees').html(out);
|
$.each (activity.exercise, function (cc) {
|
||||||
|
content += '<p>Exercise '+ cc +' - name:' + activity.exercise[cc].name +'</p>';
|
||||||
|
content += '<p>Exercise '+ cc +' - sets:' + activity.exercise[cc].sets +'</p>';
|
||||||
|
content += '<p>Exercise '+ cc +' - reps:' + activity.exercise[cc].reps +'</p>';
|
||||||
|
content += '<p>Exercise '+ cc +' - weight:' + activity.exercise[cc].weight +'</p>';
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
$(content).appendTo("#employees");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
|
$('#AddAct').click(function() {
|
||||||
|
$('#Activity').attr('style', 'display: block');
|
||||||
|
var last_item = $('.ActivityBlock').length;
|
||||||
|
//if last_item = 0
|
||||||
|
var newElem = $('.ActivityBlock_T').clone().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('data-activity','ActivityBlock' + (last_item + 1));
|
||||||
|
$(newElem).appendTo('form#myForm');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
//Add more fields dynamically.
|
//Add more fields dynamically.
|
||||||
$('.AddNeut').click(function() {
|
$('.AddNeut').click(function() {
|
||||||
var field = $(this).attr('data-field');
|
var field = $(this).attr('data-field');
|
||||||
var area = $(this).attr('data-area');
|
var area = $(this).attr('data-area');
|
||||||
var limit = $(this).attr('data-limit');
|
var limit = $(this).attr('data-limit');
|
||||||
var jsontag = $(this).attr('data-jsontag');
|
var jsontag = $(this).attr('data-jsontag');
|
||||||
|
var actblock = $(this).attr('data-activity');
|
||||||
var last_item = $('.' + area ).length;
|
var last_item = $('.' + area ).length;
|
||||||
console.log('.' + area + ' li')
|
console.log('div#' + actblock + ' ul#' + field + ' li:first')
|
||||||
console.log('LastItem - ',last_item, 'next_Item - ', (last_item + 1) );
|
console.log('LastItem - ',last_item, 'next_Item - ', (last_item + 1) );
|
||||||
// create the new element via clone(), and manipulate it's ID using newNum value
|
// create the new element via clone(), and manipulate it's ID using newNum value
|
||||||
var newElem = $('ol#' + field + ' li:first').clone().attr('style', 'display: block');
|
var newElem = $('div#' + actblock + ' ul.' + field + ' li:first').clone().attr('style', 'display: block');
|
||||||
$(newElem).attr('class', area);
|
$(newElem).attr('class', area);
|
||||||
$(newElem).children('input').attr('disabled',false);
|
$(newElem).children('input').attr('disabled',false);
|
||||||
$(newElem).children('input').each(function(){
|
$(newElem).children('input').each(function(){
|
||||||
@@ -46,10 +68,34 @@ html
|
|||||||
$(this).attr('name', newName);
|
$(this).attr('name', newName);
|
||||||
console.log('name ' + newName);
|
console.log('name ' + newName);
|
||||||
});
|
});
|
||||||
$(newElem).appendTo('ol#' +field);
|
$(newElem).appendTo('ul#' +field);
|
||||||
|
$('#'+ area + 'rem').attr('disabled',false);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.RemNeut').click(function() {
|
||||||
|
var field = $(this).attr('data-field');
|
||||||
|
var area = $(this).attr('data-area');
|
||||||
|
var limit = $(this).attr('data-limit');
|
||||||
|
var last_item = $('.' + area ).length;
|
||||||
|
var actblock = $(this).attr('data-activity');
|
||||||
|
console.log('.' + area + ' li')
|
||||||
|
console.log('LastItem - ',last_item, 'next_Item - ', (last_item - 1) );
|
||||||
|
if (last_item != 0)
|
||||||
|
$('div#' + actblock + ' ul.' + field + ' li:last').remove();
|
||||||
|
|
||||||
|
// enable the "add" button
|
||||||
|
$('.AddNeut#' + area).attr('disabled',false);
|
||||||
|
|
||||||
|
// if only one element remains, disable the "remove" button
|
||||||
|
if ((last_item - 1) == 0)
|
||||||
|
$('#'+ area + 'rem').attr('disabled','disabled');
|
||||||
|
|
||||||
|
console.log('#'+ area + ' .RemNeut')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#save').click(function() {
|
$('#save').click(function() {
|
||||||
var selector= "#myForm"
|
var selector= "#myForm"
|
||||||
//var formDataFirst = $(selector).toObject({mode: 'first'});
|
//var formDataFirst = $(selector).toObject({mode: 'first'});
|
||||||
@@ -58,7 +104,7 @@ html
|
|||||||
|
|
||||||
console.log('All ', JSON.stringify(formDataAll, null, '\t'));
|
console.log('All ', JSON.stringify(formDataAll, null, '\t'));
|
||||||
// to prevent the page from changing
|
// to prevent the page from changing
|
||||||
return false;
|
//return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user