From a197e99b1e294e0077469d462b360e79206312eb Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Sun, 22 Feb 2015 16:27:38 +0900 Subject: [PATCH] Starting bonfires view partial, ajax call works, need to work into view --- app.js | 4 ++++ controllers/bonfire.js | 14 +++++++++++--- views/partials/bonfires.jade | 25 +++++++++++++++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index bbc0e6192a..9ed01a4f1e 100644 --- a/app.js +++ b/app.js @@ -301,6 +301,8 @@ app.get('/api/trello', resourcesController.trelloCalls); /** * Bonfire related routes */ +app.get('/bonfires/pooproute', bonfireController.poopRoute); +app.get('/bonfires/getBonfireList', bonfireController.showAllBonfires); app.get('/playground', bonfireController.index); app.get('/bonfires', bonfireController.returnNextBonfire); app.get('/bonfire-json-generator', bonfireController.returnGenerator); @@ -315,6 +317,8 @@ app.get('/bonfire', function(req, res) { res.redirect(301, '/playground'); }); + + app.post('/completed-bonfire/', bonfireController.completedBonfire); /** diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 83431a390d..d18ca1a8bd 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -8,11 +8,19 @@ var _ = require('lodash'), * Bonfire controller */ -exports.bonfireNames = function(req, res) { - res.render('bonfires/showList', { - bonfireList: resources.allBonfireNames() +exports.showAllBonfires = function(req, res) { + var completedBonfires = req.user.completedBonfires.map(function(elem) { + return elem._id; }); + var data = {}; + data.bonfireList = resources.allBonfireNames(); + //data.completedList = completedBonfires; + res.send(data); }; +// FIXME: remove this +exports.poopRoute = function(req, res) { + res.render('partials/bonfires.jade'); +} exports.index = function(req, res) { res.render('bonfire/show.jade', { diff --git a/views/partials/bonfires.jade b/views/partials/bonfires.jade index cabd9ecf93..c856ea9bf6 100644 --- a/views/partials/bonfires.jade +++ b/views/partials/bonfires.jade @@ -1,7 +1,20 @@ h3 - ol(start='0') - for bonfire in bonfires - li - a(href="/bonfires/#{bonfire.bonfireNumber}", class="#{ (cc && cc[bonfire.bonfireNumber] > 0) ? 'strikethrough' : '' }") #{bonfire.name} - |   (Level #{bonfire.difficulty}) -a.btn.btn-lg.btn-primary.btn-block(href="/done-with-first-100-hours", class="#{ ((cc && cc[53] === 0) || (!cc)) ? 'disabled' : '' }") I'm done with all the challenges! \ No newline at end of file + ol#bonfireList + script. + var getLinkedName = function getLinkedName(name) { + return name.toLowerCase().replace(/\s/g, '-'); + } + $.ajax({ + url: '/bonfires/getBonfireList', + type: 'GET' + }) + .success( + function(data) { + for (var i = 0; i < data.bonfireList.length; i++) { + var li = document.createElement('li'); + var linkedName = getLinkedName(data.bonfireList[i]); + $(li) + .html("" + data.bonfireList[i] + ""); + $(li).appendTo($('#bonfireList')); + } + });