From 7d7f3da1ebd2d7d259ff4f5bf9af27289bfc2038 Mon Sep 17 00:00:00 2001 From: andela-gnyenyeshi Date: Thu, 28 Apr 2016 23:33:22 +0300 Subject: [PATCH] [#118543823] Styles dashboard, modifies models and controllers --- public/css/style.css | 10 +++++- public/index.html | 1 + public/js/script.js | 68 ++++++++++++++++++++++++++---------- server/controllers/member.js | 16 +++++++-- server/models/member.js | 4 +++ 5 files changed, 77 insertions(+), 22 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index 62d072e..4cee774 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -52,5 +52,13 @@ nav .brand-logo { .row { margin-left: 40px; - /*border: 20px solid red;*/ +} + +.delete { + cursor: pointer; +} + +#get-button { + margin-bottom: 30px; + left: 45%; } diff --git a/public/index.html b/public/index.html index 414573e..c5b9bb9 100644 --- a/public/index.html +++ b/public/index.html @@ -8,6 +8,7 @@ + Tech In Pink diff --git a/public/js/script.js b/public/js/script.js index 7f37fb1..82e1061 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1,26 +1,56 @@ $(function () { // GET function - $('#get-button').on('click', function() { + $(document).on('click', '#get-button', function() { $.ajax({ url: '/api/view', contentType: 'application/json', success: function(response) { - console.log('Tulifika', response); + var data = response.members; + // Clear the tbody + $('tbody').html(''); + // Loop and append + data.forEach(function print(member) { + $('tbody').append( + '' + + "' + member.name +'" + + 'Andela' + + 'Saturday' + + "delete" + + '' + ); + }); } }); }); // POST function - $('#post-button').on('click', function() { - $.ajax({ - url: '/api/save', - method: 'POST', - contentType: 'application/json', - data: JSON.stringify({name: 'Gertrude Nyenyeshi'}), - success: function(response) { - console.log('Watuuuu', response); - } - }); + $(document).on('click', '#post-button', function() { + // Get the value from form + var attendee = $('#attendee').val(); + // If user has not filled form + if (!attendee) { + Materialize.toast('Please fill with a name :)', 4000); + } else { + // Post value if user has filled name + $.ajax({ + url: '/api/save', + method: 'POST', + contentType: 'application/json', + data: JSON.stringify({name: attendee}), + success: function(response) { + $('#get-button').trigger('click'); + Materialize.toast('Successfully added new user', 4000); + } + }); + } + }); + + // DELETE Button + $(document).on('click', '.delete', function() { + var del = $(this).closest('tr'); + var id = del.find('.name').text(); + console.log(del); + console.log(id); }); // GET STARTED button function @@ -28,14 +58,14 @@ $(function () { document.getElementById('o').innerHTML = "

Enter Attendee:

" + "
" + "

"; - var b; + " Add" + + " View all
" + + "
" + + "" + + "
NameVenueDay
GertrudeAndelaSaturday" + + "delete
"; + $('#get-started').text(''); // this.id = "go-back"; }); - - // $(document).on('click', '#go-back', function() { - // document.getElementById("o").innerHTML = "

OoFJHFDF

"; - // console.log('Ola'); - // }); }); diff --git a/server/controllers/member.js b/server/controllers/member.js index fbc1cb2..4c5e183 100644 --- a/server/controllers/member.js +++ b/server/controllers/member.js @@ -26,9 +26,21 @@ // Assignment. Learn how to do this }, - delete: function() {}, + delete: function() { + Member.find(); + }, find: function(req, res) { - res.send({name: 'Gerty', age: 21}); + Member.find(function(err, members) { + if (err) { + return res.status(500).json({ + err: err || err.errmessage + }); + } else { + return res.status(200).json({ + members: members + }); + } + }); } }; })(); diff --git a/server/models/member.js b/server/models/member.js index d347589..6efe7e5 100644 --- a/server/models/member.js +++ b/server/models/member.js @@ -8,6 +8,10 @@ name: { type: String, required: true + }, + email: { + type: String, + required: true } });