mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
editing of posts
This commit is contained in:
@@ -25,6 +25,12 @@ var socket,
|
|||||||
socket.on('event:consolelog', function(data) {
|
socket.on('event:consolelog', function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('api:posts.getRawPost', function(data) {
|
||||||
|
var contentEl = document.getElementById('post_content');
|
||||||
|
|
||||||
|
contentEl.value = data.post;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async: false
|
async: false
|
||||||
|
|
||||||
@@ -94,7 +100,7 @@ var socket,
|
|||||||
post_content = null;
|
post_content = null;
|
||||||
|
|
||||||
|
|
||||||
app.open_post_window = function(post_mode, id, title) {
|
app.open_post_window = function(post_mode, id, title, pid) {
|
||||||
submit_post_btn = submit_post_btn || document.getElementById('submit_post_btn');
|
submit_post_btn = submit_post_btn || document.getElementById('submit_post_btn');
|
||||||
post_title = post_title || document.getElementById('post_title');
|
post_title = post_title || document.getElementById('post_title');
|
||||||
reply_title = reply_title || document.getElementById('reply_title');
|
reply_title = reply_title || document.getElementById('reply_title');
|
||||||
@@ -112,6 +118,16 @@ var socket,
|
|||||||
submit_post_btn.onclick = function() {
|
submit_post_btn.onclick = function() {
|
||||||
app.post_topic(id);
|
app.post_topic(id);
|
||||||
}
|
}
|
||||||
|
} else if (post_mode === 'edit') {
|
||||||
|
reply_title.innerHTML = 'You are editing "' + title + '"';
|
||||||
|
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);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (post_mode == 'reply') {
|
if (post_mode == 'reply') {
|
||||||
reply_title.innerHTML = 'You are replying to "' + title + '"';
|
reply_title.innerHTML = 'You are replying to "' + title + '"';
|
||||||
@@ -133,7 +149,7 @@ var socket,
|
|||||||
|
|
||||||
|
|
||||||
app.post_reply = function(topic_id) {
|
app.post_reply = function(topic_id) {
|
||||||
var content = document.getElementById('post_content').value;
|
var content = document.getElementById('post_content');
|
||||||
|
|
||||||
if (content.length < 5) {
|
if (content.length < 5) {
|
||||||
app.alert({
|
app.alert({
|
||||||
@@ -148,14 +164,15 @@ var socket,
|
|||||||
|
|
||||||
socket.emit('api:posts.reply', {
|
socket.emit('api:posts.reply', {
|
||||||
'topic_id' : topic_id,
|
'topic_id' : topic_id,
|
||||||
'content' : content
|
'content' : content.value
|
||||||
});
|
});
|
||||||
jQuery(post_window).slideDown(250);
|
jQuery(post_window).slideUp(250);
|
||||||
|
$(document.body).removeClass('composing');
|
||||||
|
content.value = '';
|
||||||
};
|
};
|
||||||
app.post_topic = function(category_id) {
|
app.post_topic = function(category_id) {
|
||||||
var title = document.getElementById('post_title').value,
|
var title = document.getElementById('post_title'),
|
||||||
content = document.getElementById('post_content').value;
|
content = document.getElementById('post_content');
|
||||||
|
|
||||||
if (title.length < 5 || content.length < 5) {
|
if (title.length < 5 || content.length < 5) {
|
||||||
app.alert({
|
app.alert({
|
||||||
@@ -169,16 +186,26 @@ var socket,
|
|||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('api:topics.post', {
|
socket.emit('api:topics.post', {
|
||||||
'title' : title,
|
'title' : title.value,
|
||||||
'content' : content,
|
'content' : content.value,
|
||||||
'category_id' : category_id
|
'category_id' : category_id
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery('#post_title, #post_content').val('');
|
jQuery(post_window).slideUp(250);
|
||||||
jQuery(post_window).slideToggle(250);
|
$(document.body).removeClass('composing');
|
||||||
$(document.body).addClass('composing');
|
title.value = '';
|
||||||
|
content.value = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.edit_post = function(pid) {
|
||||||
|
var content = document.getElementById('post_content');
|
||||||
|
socket.emit('api:posts.edit', { pid: pid, content: content.value });
|
||||||
|
|
||||||
|
jQuery(post_window).slideUp(250);
|
||||||
|
$(document.body).removeClass('composing');
|
||||||
|
content.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
app.current_room = null;
|
app.current_room = null;
|
||||||
app.enter_room = function(room) {
|
app.enter_room = function(room) {
|
||||||
|
|||||||
@@ -72,6 +72,8 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var expose_tools = '{expose_tools}',
|
var expose_tools = '{expose_tools}',
|
||||||
tid = '{topic_id}',
|
tid = '{topic_id}',
|
||||||
|
postListEl = document.getElementById('post-container'),
|
||||||
|
editBtns = document.querySelectorAll('#post-container .post-buttons .edit, #post-container .post-buttons .edit i'),
|
||||||
thread_state = {
|
thread_state = {
|
||||||
locked: '{locked}',
|
locked: '{locked}',
|
||||||
deleted: '{deleted}',
|
deleted: '{deleted}',
|
||||||
@@ -208,8 +210,17 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.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);
|
||||||
|
});
|
||||||
|
|
||||||
ajaxify.register_events(['event:rep_up', 'event:rep_down', 'event:new_post', 'api:get_users_in_room', 'event:topic_deleted']);
|
ajaxify.register_events([
|
||||||
|
'event:rep_up', 'event:rep_down', 'event:new_post', 'api:get_users_in_room',
|
||||||
|
'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',
|
||||||
|
'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned',
|
||||||
|
'event:topic_moved', 'event:post_edited'
|
||||||
|
]);
|
||||||
socket.on('api:get_users_in_room', function(users) {
|
socket.on('api:get_users_in_room', function(users) {
|
||||||
var anonymous = users.anonymous,
|
var anonymous = users.anonymous,
|
||||||
usernames = users.usernames,
|
usernames = users.usernames,
|
||||||
@@ -289,6 +300,14 @@
|
|||||||
if (data && data.tid > 0) ajaxify.go('topic/' + data.tid);
|
if (data && data.tid > 0) ajaxify.go('topic/' + data.tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('event:post_edited', function(data) {
|
||||||
|
var editedPostEl = document.getElementById('content_' + data.pid);
|
||||||
|
$(editedPostEl).fadeOut(250, function() {
|
||||||
|
this.innerHTML = data.content;
|
||||||
|
$(this).fadeIn(250);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function adjust_rep(value, pid, uid) {
|
function adjust_rep(value, pid, uid) {
|
||||||
var post_rep = jQuery('.post_rep_' + pid),
|
var post_rep = jQuery('.post_rep_' + pid),
|
||||||
user_rep = jQuery('.user_rep_' + uid);
|
user_rep = jQuery('.user_rep_' + uid);
|
||||||
|
|||||||
18
src/posts.js
18
src/posts.js
@@ -68,13 +68,11 @@ var RDB = require('./redis.js'),
|
|||||||
pid.push(pids[i]);
|
pid.push(pids[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
|
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
|
||||||
vote_data = fav_data;
|
vote_data = fav_data;
|
||||||
generateThread();
|
generateThread();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
RDB.multi()
|
RDB.multi()
|
||||||
.mget(content)
|
.mget(content)
|
||||||
.mget(uid)
|
.mget(uid)
|
||||||
@@ -182,6 +180,7 @@ var RDB = require('./redis.js'),
|
|||||||
RDB.set('pid:' + pid + ':uid', uid);
|
RDB.set('pid:' + pid + ':uid', uid);
|
||||||
RDB.set('pid:' + pid + ':timestamp', new Date().getTime());
|
RDB.set('pid:' + pid + ':timestamp', new Date().getTime());
|
||||||
RDB.set('pid:' + pid + ':rep', 0);
|
RDB.set('pid:' + pid + ':rep', 0);
|
||||||
|
RDB.set('pid:' + pid + ':tid', tid);
|
||||||
|
|
||||||
RDB.incr('tid:' + tid + ':postcount');
|
RDB.incr('tid:' + tid + ':postcount');
|
||||||
|
|
||||||
@@ -189,7 +188,7 @@ var RDB = require('./redis.js'),
|
|||||||
RDB.lpush('uid:' + uid + ':posts', pid);
|
RDB.lpush('uid:' + uid + ':posts', pid);
|
||||||
|
|
||||||
user.incrementUserFieldBy(uid, 'postcount', 1);
|
user.incrementUserFieldBy(uid, 'postcount', 1);
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
callback(pid);
|
callback(pid);
|
||||||
});
|
});
|
||||||
@@ -262,4 +261,17 @@ var RDB = require('./redis.js'),
|
|||||||
}(pids[i]))
|
}(pids[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Posts.getRawContent = function(pid, socket) {
|
||||||
|
RDB.get('pid:' + pid + ':content', function(err, raw) {
|
||||||
|
socket.emit('api:posts.getRawPost', { post: raw });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.edit = function(pid, content) {
|
||||||
|
RDB.get('pid:' + pid + ':tid', function(err, tid) {
|
||||||
|
RDB.set('pid:' + pid + ':content', content);
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });
|
||||||
|
});
|
||||||
|
}
|
||||||
}(exports));
|
}(exports));
|
||||||
@@ -36,6 +36,7 @@ var config = require('../config.js'),
|
|||||||
|
|
||||||
// a function I feel should be built in user not sure how baris is tackling this so oppa chicken wrapper here
|
// a function I feel should be built in user not sure how baris is tackling this so oppa chicken wrapper here
|
||||||
User.getMultipleUserFields = function(uids, fields, callback) {
|
User.getMultipleUserFields = function(uids, fields, callback) {
|
||||||
|
console.log(uids);
|
||||||
var uuids = uids.filter(function(value, index, self) {
|
var uuids = uids.filter(function(value, index, self) {
|
||||||
return self.indexOf(value) === index;
|
return self.indexOf(value) === index;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -314,6 +314,12 @@ var express = require('express'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.get('/test', function(req, res) {
|
||||||
|
global.modules.posts.getRawContent(11, function(post) {
|
||||||
|
res.send(JSON.stringify(post));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO move user related logic into another file ^^^^^^^^^^^^^^^^^^^^^^^
|
// TODO move user related logic into another file ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
}(WebServer));
|
}(WebServer));
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
socket.on('api:topic.move', function(data) {
|
socket.on('api:topic.move', function(data) {
|
||||||
modules.topics.move(data.tid, data.cid, socket);
|
modules.topics.move(data.tid, data.cid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('api:posts.getRawPost', function(data) {
|
||||||
|
modules.posts.getRawContent(data.pid, socket);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('api:posts.edit', function(data) {
|
||||||
|
modules.posts.edit(data.pid, data.content);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}(SocketIO));
|
}(SocketIO));
|
||||||
|
|||||||
Reference in New Issue
Block a user