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) {
|
||||
testcollection.find({}, function(err, result) {
|
||||
result.each(function(err, data) {
|
||||
console.log(data);
|
||||
emitdata('populate',data);
|
||||
});
|
||||
// testcollection.find({}, function(err, result) {
|
||||
// if (err) throw err;
|
||||
// result.each(function(err, 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('/');
|
||||
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 });
|
||||
@@ -94,28 +103,28 @@ io.sockets.on('connection', function (socket) {
|
||||
var io = require('socket.io');
|
||||
io = io.listen(app);
|
||||
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');
|
||||
|
||||
// client add new employee
|
||||
client.on('add employee', function(data) {
|
||||
console.log("addemployee ")
|
||||
addemployee(data);
|
||||
});
|
||||
client.on('data', function(data) {
|
||||
socket.on('data', function(data) {
|
||||
console.log("data" + JSON.stringify(data))
|
||||
testcollection.insert(data, function(err, result) {
|
||||
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
|
||||
|
||||
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 exercise Field', data-field='exercise_area', data-area='exercise_', data-limit='0',data-jsontag='activity.exercise')
|
||||
input(type='submit', id='save', value='Save')
|
||||
|
||||
|
||||
form#myForm
|
||||
ol(id='note_area')
|
||||
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')
|
||||
li(class='exercise_T', style='display: none')
|
||||
label Activity
|
||||
input(type='text', name='activity.name', value='Name', disabled='disabled')
|
||||
ul(class='note_area')
|
||||
li(class='note_T', style='display: none')
|
||||
label Note
|
||||
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
|
||||
ol(id='exercise_area')
|
||||
ul(class='exercise_area')
|
||||
li(class='exercise_T', style='display: none')
|
||||
label Exercise
|
||||
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[].reps', value='Reps', disabled='disabled')
|
||||
input(type='text', name='activity.exercise[x].weight', value='Weight', disabled='disabled')
|
||||
a(style='cursor:pointer;color:blue;', onclick='this.parentNode.parentNode.removeChild(this.parentNode);') Remove Field
|
||||
input(type='text', name='activity.exercise[].weight', value='Weight', disabled='disabled')
|
||||
|
||||
ul#employees
|
||||
|
||||
|
||||
|
||||
@@ -9,36 +9,58 @@ html
|
||||
script(src='/form2js/jquery.toObject.js')
|
||||
script(src='/form2js/json2.js')
|
||||
script
|
||||
//$(document).ready(function() {
|
||||
|
||||
$(function() {
|
||||
var socket = io.connect('http://localhost:3000');
|
||||
|
||||
socket.on('populate', function(json) {
|
||||
var out = "";
|
||||
for (var n in json) { // Each top-level entry
|
||||
out += '<li>' + n + '<ul>';
|
||||
for (var i = 0; i < json[n].length; i++) { // Each sub-entry
|
||||
out += '<li>' + json[n][i] + '</li>';
|
||||
};
|
||||
out += '</ul></li>';
|
||||
};
|
||||
console.log('out ' + out);
|
||||
$('#employees').html(out);
|
||||
var content = "";
|
||||
$('#employees').empty();
|
||||
//iterate activities
|
||||
$.each (json, function (bb) {
|
||||
var activity = json[bb].activity;
|
||||
content += '<p>Activity - '+ bb + '</p>';
|
||||
$.each (activity.note, function (cc) {
|
||||
content += '<p>Note - '+ cc + '</p>';
|
||||
});
|
||||
$.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.
|
||||
$('.AddNeut').click(function() {
|
||||
var field = $(this).attr('data-field');
|
||||
var area = $(this).attr('data-area');
|
||||
var limit = $(this).attr('data-limit');
|
||||
var jsontag = $(this).attr('data-jsontag');
|
||||
var actblock = $(this).attr('data-activity');
|
||||
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) );
|
||||
// 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).children('input').attr('disabled',false);
|
||||
$(newElem).children('input').each(function(){
|
||||
@@ -46,10 +68,34 @@ html
|
||||
$(this).attr('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() {
|
||||
var selector= "#myForm"
|
||||
//var formDataFirst = $(selector).toObject({mode: 'first'});
|
||||
@@ -58,7 +104,7 @@ html
|
||||
|
||||
console.log('All ', JSON.stringify(formDataAll, null, '\t'));
|
||||
// to prevent the page from changing
|
||||
return false;
|
||||
//return false;
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user