diff --git a/app.js b/app.js index a6391208cd..7fbd6ae288 100644 --- a/app.js +++ b/app.js @@ -2,6 +2,7 @@ var modules = { user: require('./src/user.js'), topics: require('./src/topics.js'), posts: require('./src/posts.js'), + categories: require('./src/categories.js'), templates: require('./src/templates.js'), webserver: require('./src/webserver.js'), websockets: require('./src/websockets.js'), @@ -23,4 +24,36 @@ global.modules = modules; + + //setup scripts to be moved outside of the app in future. + function setup_categories() { + console.log('Checking categories...'); + modules.categories.get(function(data) { + if (data.categories.length === 0) { + console.log('Setting up default categories...'); + + modules.categories.create({ + 'name': 'General', + 'description': 'A place to talk about whateeeever you want' + }); + + + modules.categories.create({ + 'name': 'NodeBB Development', + 'description': 'Bugs? Dont worry, we dont read this thread, so post them here.' + }); + + + modules.categories.create({ + 'name': 'Design Create Play', + 'description': 'In future an example of how a hidden category should look like.' + }); + + } else console.log('Good.'); + }); + } + + + setup_categories(); + }(global.configuration)); \ No newline at end of file diff --git a/public/src/app.js b/public/src/app.js index 90d8c8fbc2..89be5c0a2c 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -98,12 +98,12 @@ var socket, post_window = post_window || document.getElementById('post_window'); jQuery(post_window).slideToggle(250); - if (post_mode == null || post_mode == 'topic') { + if (post_mode == 'topic') { post_title.style.display = "block"; reply_title.style.display = "none"; post_title.focus(); submit_post_btn.onclick = function() { - app.post_topic(); + app.post_topic(id); } } else { if (post_mode == 'reply') { @@ -146,7 +146,7 @@ var socket, jQuery(post_window).slideToggle(250); }; - app.post_topic = function() { + app.post_topic = function(category_id) { var title = document.getElementById('post_title').value, content = document.getElementById('post_content').value; @@ -163,11 +163,11 @@ var socket, socket.emit('api:topics.post', { 'title' : title, - 'content' : content + 'content' : content, + 'category_id' : category_id }); - jQuery('#post_title').val(''); - jQuery('#post_content').val(''); + jQuery('#post_title, #post_content').val(''); jQuery(post_window).slideToggle(250); }; diff --git a/public/src/templates.js b/public/src/templates.js index ee900c66c5..56ceae5c48 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -49,7 +49,7 @@ var templates = {}; function init() { loadTemplates([ - 'header', 'footer', 'register', 'home', 'topic','account', + 'header', 'footer', 'register', 'home', 'topic','account', 'category', 'login', 'reset', 'reset_code', 'account', 'confirm', 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext' @@ -90,9 +90,8 @@ var templates = {}; var template = this.html, regex, block; return (function parse(data, namespace, template) { - if (data.length == 0) { - regex = makeRegex('[^]*'); - template = template.replace(regex, ''); + if (!data || data.length == 0) { + template = ''; } for (var d in data) { @@ -147,6 +146,7 @@ function load_template(callback) { url = (url === '' || url === '/') ? 'home' : url; jQuery.get(API_URL + url, function(data) { + console.log(data) document.getElementById('content').innerHTML = templates[url.split('/')[0]].parse(JSON.parse(data)); if (callback) callback(); }); diff --git a/public/templates/home.tpl b/public/templates/home.tpl index 07b76c15d5..1b9bb49ffa 100644 --- a/public/templates/home.tpl +++ b/public/templates/home.tpl @@ -1,29 +1,9 @@ - +
Posted {topics.relativeTime} ago by {topics.username}. {topics.post_count} posts.
+ +{categories.description}