Node.js based forum software built for the modern web
replies are up
psychobunnye658531a676e
diff --git a/public/src/app.js b/public/src/app.jsindex 64dd8378ff..20732a2b5a 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -79,17 +79,57 @@ var socket,}var post_window = null,- mode = 'topic',- topic_id = null;+ submit_post_btn = null,+ post_title = null,+ post_content = null;++app.open_post_window = function(post_mode, id) {+ submit_post_btn = submit_post_btn || document.getElementById('submit_post_btn');+ post_title = post_title || document.getElementById('post_title');+ post_content = post_content || document.getElementById('post_content');++post_window = post_window || document.getElementById('post_window');jQuery(post_window).slideToggle(250);- document.getElementById('post_title').focus();- mode = (post_mode == null) ? 'topic' : mode;- topic_id = (mode == 'reply') ? topic_id : null;+ if (post_mode == null || post_mode == 'topic') {+ post_title.style.display = 'block';+ post_title.focus();+ submit_post_btn.onclick = function() {+ app.post_topic();+ }+ } else {+ post_title.style.display = 'none';+ post_content.focus();+ submit_post_btn.onclick = function() {+ app.post_reply(id)+ }+ }+};+ app.post_reply = function(topic_id) {+ var content = document.getElementById('post_content').value;++ if (content.length < 5) {+ app.alert({+ title: 'Reply Failure',+ message: 'You need to write more dude.',+ type: 'error',+ timeout: 2000+ });++ return;+ }++ socket.emit('api:posts.reply', {+ 'topic_id' : topic_id,+ 'content' : content+ });+ jQuery(post_window).slideToggle(250);++ };app.post_topic = function() {var title = document.getElementById('post_title').value,content = document.getElementById('post_content').value;@@ -99,10 +139,7 @@ var socket,title: 'Topic Post Failure',message: 'You need to write more dude.',type: 'error',- timeout: 2000,- clickfn: function() {- ajaxify.go('register');- }+ timeout: 2000});return;diff --git a/public/templates/header.tpl b/public/templates/header.tplindex d18ac06159..3f0ac6af5a 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -90,10 +90,10 @@border: 1px solid #eee;margin-top: 50px;}- .topic-container li.topic-row:nth-child(odd) {+ .topic-container a:nth-child(odd) li.topic-row {background-color:#fdfdfd;}- .topic-container li.topic-row:nth-child(even) {+ .topic-container a:nth-child(even) li.topic-row {background-color:#fff;}.topic-container li.topic-row {@@ -161,7 +161,7 @@<a class="btn btn-link" href="#" tabindex="-1"><i class="icon-list"></i></a></div><div class="btn-group" style="float: right; margin-right: -12px">- <a class="btn" onclick="app.post_topic()"><i class="icon-ok"></i> Submit</a>+ <a id="submit_post_btn" class="btn" onclick="app.post_topic()"><i class="icon-ok"></i> Submit</a><a class="btn" onclick="jQuery(post_window).slideToggle(250);"><i class="icon-remove"></i> Discard</a></div></div>diff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex b5e32b08c4..fa901d285c 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -13,4 +13,4 @@ var post_reply = document.getElementById('post_reply');post_reply.onclick = function() {app.open_post_window('reply', {TOPIC_ID});}-</script>+</script>diff --git a/src/posts.js b/src/posts.jsindex 4c51b92ea5..b3117b3286 100644--- a/src/posts.js+++ b/src/posts.js@@ -48,7 +48,7 @@ var RDB = require('./redis.js'),});}- callback({'posts': posts, 'TOPIC_ID': tid});+ callback({'TOPIC_ID': tid, 'posts': posts});});} else {callback({});@@ -60,8 +60,17 @@ var RDB = require('./redis.js'),}- Posts.reply = function() {+ Posts.reply = function(tid, uid, content) {+ Posts.create(uid, content, function(pid) {+ RDB.rpush('tid:' + tid + ':posts', pid);+ global.socket.emit('event:alert', {+ title: 'Reply Successful',+ message: 'You have successfully replied. Click here to view your reply.',+ type: 'notify',+ timeout: 2000+ });+ });};Posts.create = function(uid, content, callback) {diff --git a/src/redis.js b/src/redis.jsindex 0a6e633272..a71cc1e3d5 100644--- a/src/redis.js+++ b/src/redis.js@@ -76,6 +76,10 @@db.lpush(key, item);}+ RedisDB.rpush = function(key, item) {+ db.rpush(key, item);+ }+RedisDB.lrange = function(key, start, end, callback, error_handler) {db.lrange(key, start, end, function(error, data) {return_handler(error, data, callback, error_handler);diff --git a/src/templates.js b/src/templates.jsindex c74aba7934..8fb384a2e6 100644--- a/src/templates.js+++ b/src/templates.js@@ -93,7 +93,7 @@ var fs = require('fs');block = parse(data[d], namespace, block);template = setBlock(regex, block, template);- } else {+ } else {template = replace(namespace + d, data[d], template);}}diff --git a/src/websockets.js b/src/websockets.jsindex ba6786fc80..aa8fb58ac1 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -93,6 +93,10 @@ var SocketIO = require('socket.io').listen(global.server),modules.topics.post(uid, data.title, data.content);});+ socket.on('api:posts.reply', function(data) {+ modules.posts.reply(data.topic_id, uid, data.content);+ });+socket.on('api:user.active.get', function() {modules.user.active.get();});