Skip to content

Node.js based forum software built for the modern web

topic titles can be edited now

Baris Usaklia4fd54a0c3e7
diff --git a/public/src/app.js b/public/src/app.js
index c04a423114..b9da953aeb 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -194,11 +194,17 @@ var socket,
app.post_topic(id);
}
} else if (post_mode === 'edit') {
- reply_title.innerHTML = 'You are editing "' + title + '"';
+
+ if(title === "") {
+ post_title.style.display = "none";
+ }
+ else {
+ post_title.style.display = "block";
+ post_title.value = title;
+ }
+ reply_title.style.display = "none";
socket.emit('api:posts.getRawPost', { pid: pid });
-
- post_title.style.display = "none";
- reply_title.style.display = "block";
+
post_content.focus();
submit_post_btn.onclick = function() {
app.edit_post(pid);
@@ -307,9 +313,10 @@ var socket,
};
app.edit_post = function(pid) {
- var content = $('#post_content');
+ var title = $('#post_title'),
+ content = $('#post_content');
- if (content.val().length < 5) {
+ if (title.val().length < 5 || content.val().length < 5) {
app.alert({
title: 'Topic Post Failure',
message: 'You need to write more dude.',
@@ -320,7 +327,7 @@ var socket,
return;
}
- socket.emit('api:posts.edit', { pid: pid, content: content.val() });
+ socket.emit('api:posts.edit', { pid: pid, content: content.val(), title: title.val() });
app.close_post_window();
content.val('');
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 5d9b8f17c5..365bb7eb7f 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -23,7 +23,7 @@
<i class="icon-pencil"></i><span class="user_posts_{main_posts.uid}">8</span>
</div>
</a>
- <h3><p class="topic-title">{topic_name}</p>
+ <h3><p id="topic_title_{main_posts.pid}" class="topic-title">{topic_name}</p>
<div class="pull-right hidden-phone" style="margin-right: 10px;">
<button id="ids_{main_posts.pid}_{main_posts.uid}" class="btn edit {main_posts.display_moderator_tools}" type="button"><i class="icon-pencil"></i></button>
<button id="ids_{main_posts.pid}_{main_posts.uid}" class="btn delete {main_posts.display_moderator_tools}" type="button"><i class="icon-trash"></i></button>
@@ -277,7 +277,13 @@
$('.post-container').delegate('.edit', 'click', function(e) {
var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];
- app.open_post_window('edit', "{topic_id}", "{topic_name}", pid);
+
+ var main = $(this).parents('.main-post');
+ if(main.length > 0)
+ app.open_post_window('edit', "{topic_id}", "{topic_name}", pid);
+ else
+ app.open_post_window('edit', "{topic_id}", "", pid);
+
});
$('.post-container').delegate('.delete', 'click', function(e) {
@@ -490,6 +496,16 @@
socket.on('event:post_edited', function(data) {
var editedPostEl = document.getElementById('content_' + data.pid);
+
+ var editedPostTitle = $('#topic_title_'+data.pid);
+
+ if(editedPostTitle.length > 0) {
+ editedPostTitle.fadeOut(250, function() {
+ editedPostTitle.html(data.title);
+ editedPostTitle.fadeIn(250);
+ });
+ }
+
$(editedPostEl).fadeOut(250, function() {
this.innerHTML = data.content;
$(this).fadeIn(250);
diff --git a/src/postTools.js b/src/postTools.js
index 00adbfc86d..682ae1d51d 100644
--- a/src/postTools.js
+++ b/src/postTools.js
@@ -47,15 +47,18 @@ marked.setOptions({
});
}
- PostTools.edit = function(uid, pid, content) {
+ PostTools.edit = function(uid, pid, title, content) {
var success = function() {
+
RDB.set('pid:' + pid + ':content', content);
RDB.set('pid:' + pid + ':edited', new Date().getTime());
RDB.set('pid:' + pid + ':editor', uid);
posts.get_tid_by_pid(pid, function(tid) {
+ RDB.set('tid:' + tid + ':title', title);
io.sockets.in('topic_' + tid).emit('event:post_edited', {
pid: pid,
+ title: title,
content: marked(content || '')
});
});
diff --git a/src/websockets.js b/src/websockets.js
index 0a3c15d826..aecec118dd 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -236,7 +236,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:posts.edit', function(data) {
- postTools.edit(uid, data.pid, data.content);
+ postTools.edit(uid, data.pid, data.title, data.content);
});
socket.on('api:posts.delete', function(data) {