diff --git a/public/src/templates.js b/public/src/templates.js index aa1d8a5c23..78cf108802 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -168,7 +168,8 @@ function parse_template() { if (!templates[tpl_url] || !template_data) return; - document.getElementById('content').innerHTML = templates[tpl_url].parse(JSON.parse(template_data)); + //document.getElementById('content').innerHTML = templates[tpl_url].parse(JSON.parse(template_data)); + document.getElementById('content').innerHTML = templates[tpl_url].parse(template_data); jQuery('#content [template-variable]').each(function(index, element) { var value = null; @@ -289,9 +290,6 @@ })(data, "", template); } - - - if ('undefined' !== typeof window) { window.templates = module.exports; templates.init(); diff --git a/src/routes/admin.js b/src/routes/admin.js index 6d6dfe7b61..da238ea80b 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -39,27 +39,26 @@ var user = require('./../user.js'), switch(req.params.method) { case 'users' : if (req.params.tab == 'search') { - res.send(JSON.stringify({search_display: 'block', users: []})) + res.json({search_display: 'block', users: []}); } else { user.getUserList(function(data){ - - res.send(JSON.stringify({search_display: 'none', users:data, yourid:req.user.uid})); + res.json({search_display: 'none', users:data, yourid:req.user.uid}); }); } break; case 'categories': if (req.params.tab == 'disabled') { - res.send(JSON.stringify({categories: []})); + res.json({categories: []}); } else { categories.getAllCategories(function(data) { - res.send(JSON.stringify(data)); + res.json(data); }); } break; case 'topics' : categories.getCategoryById(0, 0, function(data) { - res.send(JSON.stringify(data)); + res.json(data); }); break; case 'redis': @@ -83,11 +82,11 @@ var user = require('./../user.js'), } - res.send(JSON.stringify(finalData)); + res.json(finalData); }); break; default : - res.send('{}'); + res.json({}); } } diff --git a/src/routes/user.js b/src/routes/user.js index 0b7e45932b..19cf0cab4f 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -246,9 +246,7 @@ var user = require('./../user.js'), if (!req.params.section && !req.params.username) { user.getUserList(function(data){ - - res.send(JSON.stringify({users:data})); - + res.json({users:data}); }); } else if(String(req.params.section).toLowerCase() === 'following') { @@ -258,7 +256,7 @@ var user = require('./../user.js'), user.getFollowing(userData.uid, function(followingData){ userData.following = followingData; userData.followingCount = followingData.length; - res.send(JSON.stringify(userData)); + res.json(userData); }); }); } @@ -269,13 +267,13 @@ var user = require('./../user.js'), user.getFollowers(userData.uid, function(followersData){ userData.followers = followersData; userData.followersCount = followersData.length; - res.send(JSON.stringify(userData)); + res.json(userData); }); }); } else if (String(req.params.section).toLowerCase() === 'edit') { getUserDataByUserName(req.params.username, callerUID, function(userData) { - res.send(JSON.stringify(userData)); + res.json(userData); }); } else { getUserDataByUserName(req.params.username, callerUID, function(userData) { @@ -285,7 +283,7 @@ var user = require('./../user.js'), userData.signature = marked(userData.signature || ''); - res.send(JSON.stringify(userData)); + res.json(userData); }); }); diff --git a/src/webserver.js b/src/webserver.js index 13ffa36297..88cd8fd756 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -178,14 +178,14 @@ var express = require('express'), switch(req.params.method) { case 'get_templates_listing' : utils.walk(global.configuration.ROOT_DIRECTORY + '/public/templates', function(err, data) { - res.send(JSON.stringify(data)); + res.json(data); }); break; case 'home' : categories.getAllCategories(function(data) { data.motd_class = (config.show_motd === '1' || config.show_motd === undefined) ? '' : 'none'; data.motd = marked(config.motd || "# NodeBB v0.1\nWelcome to NodeBB, the discussion platform of the future.\n\n Get NodeBB Fork us on Github @dcplabs"); - res.send(JSON.stringify(data)); + res.json(data); }, uid); break; case 'login' : @@ -210,7 +210,7 @@ var express = require('express'), data.token = res.locals.csrf_token; - res.send(JSON.stringify(data)); + res.json(data); break; case 'register' : var data = {}, @@ -234,52 +234,52 @@ var express = require('express'), data.token = res.locals.csrf_token; - res.send(JSON.stringify(data)); + res.json(data); break; case 'topic' : topics.getTopicById(req.params.id, uid, function(data) { - res.send(data ? JSON.stringify(data) : false); + res.json(data); }); break; case 'category' : categories.getCategoryById(req.params.id, uid, function(data) { - res.send(data ? JSON.stringify(data) : false); + res.json(data); }, req.params.id, uid); break; case 'latest' : categories.getLatestTopics(uid, 0, 9, function(data) { - res.send(JSON.stringify(data)); + res.json(data); }); break; case 'popular' : categories.getLatestTopics(uid, 0, 9, function(data) { - res.send(JSON.stringify(data)); + res.json(data); }); break; case 'active' : categories.getLatestTopics(uid, 0, 9, function(data) { - res.send(JSON.stringify(data)); + res.json(data); }); break; case 'confirm': user.email.confirm(req.params.id, function(data) { if (data.status === 'ok') { - res.send(JSON.stringify({ + res.json({ 'alert-class': 'alert-success', title: 'Email Confirmed', text: 'Thank you for vaidating your email. Your account is now fully activated.' - })); + }); } else { - res.send(JSON.stringify({ + res.json({ 'alert-class': 'alert-error', title: 'An error occurred...', text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.' - })); + }); } }); break; default : - res.send('{}'); + res.json({}); break; } }