Skip to content

Node.js based forum software built for the modern web

half broken editing

Julian Lam061c7a9e66dc
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 8a66546e7d..6052629665 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -162,11 +162,13 @@
var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];
var main = $(this).parents('.main-post');
- if(main.length > 0)
- app.open_post_window('edit', tid, topic_name, pid);
- else
- app.open_post_window('edit', tid, "", pid);
-
+ // if(main.length > 0)
+ // app.open_post_window('edit', tid, topic_name, pid);
+ // else
+ // app.open_post_window('edit', tid, "", pid);
+ require(['composer'], function(cmp) {
+ cmp.push(null, null, pid);
+ });
});
$('.post-container').delegate('.delete', 'click', function(e) {
@@ -448,13 +450,6 @@
}
});
- jQuery(div + ' .edit, ' + div + ' .delete').each(function() {
- var ids = this.id.replace('ids_', '').split('_'),
- pid = ids[0],
- uid = ids[1];
-
- });
-
jQuery(div + ' .favourite').click(function() {
var ids = this.id.replace('favs_', '').split('_'),
pid = ids[0],
diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index c6ae89ae7d..69cfba3350 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -49,8 +49,9 @@ define(function() {
composer.posts[uuid] = {
tid: threadData.tid,
cid: threadData.cid,
+ pid: threadData.pid,
title: threadData.tid ? threadData.title : '',
- body: ''
+ body: threadData.body || ''
};
composer.active++;
composer.update();
@@ -149,10 +150,11 @@ define(function() {
}
}
- composer.push = function(tid, cid) {
+ composer.push = function(tid, cid, pid) {
socket.emit('api:composer.push', {
- tid: tid,
- cid: cid
+ tid: tid, // Replying
+ cid: cid, // Posting
+ pid: pid // Editing
});
}
@@ -167,6 +169,9 @@ define(function() {
if (post_data.tid > 0) {
titleEl.value = 'Replying to: ' + post_data.title;
titleEl.readonly = true;
+ } else if (post_data.pid > 0) {
+ titleEl.value = 'Editing: ' + post_data.title;
+ titleEl.readonly = true;
} else {
titleEl.value = post_data.title;
}
diff --git a/src/posts.js b/src/posts.js
index 58c6b38618..5882f846d6 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -291,9 +291,9 @@ marked.setOptions({
});
}
- Posts.getRawContent = function(pid, socket) {
+ Posts.getRawContent = function(pid, callback) {
RDB.get('pid:' + pid + ':content', function(err, raw) {
- socket.emit('api:posts.getRawPost', { post: raw });
+ callback(raw);
});
}
diff --git a/src/websockets.js b/src/websockets.js
index 9e00d73889..3700a1cc59 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -233,7 +233,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:posts.getRawPost', function(data) {
- posts.getRawContent(data.pid, socket);
+ posts.getRawContent(data.pid, function(raw) {
+ socket.emit('api:posts.getRawPost', { post: raw });
+ });
});
socket.on('api:posts.edit', function(data) {
@@ -306,12 +308,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:composer.push', function(data) {
- if (data.tid > 0) {
+ if (parseInt(data.tid) > 0) {
topics.get_topic(data.tid, uid, function(topicData) {
topicData.tid = data.tid;
socket.emit('api:composer.push', topicData);
});
- } else {
+ } else if (parseInt(data.cid) > 0) {
user.getUserField(uid, 'username', function(username) {
socket.emit('api:composer.push', {
tid: 0,
@@ -320,6 +322,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
title: 'New Topic'
});
});
+ } else if (parseInt(data.pid) > 0) {
+ posts.getRawContent(data.pid, function(raw) {
+ socket.emit('api:composer.push', {
+ title: 'asdf',
+ pid: data.pid,
+ body: raw
+ });
+ });
}
});
});