Node.js based forum software built for the modern web
move post
Baris Soner Usakli8e6606fb5af0
diff --git a/public/language/en/topic.json b/public/language/en/topic.jsonindex 51d1563fcf..a6c09c07d1 100644--- a/public/language/en/topic.json+++ b/public/language/en/topic.json@@ -12,6 +12,7 @@"reply": "Reply","edit": "Edit","delete": "Delete",+ "move": "Move","fork": "Fork","banned": "banned","link": "Link",@@ -38,6 +39,7 @@"loading": "Loading","more_posts": "More Posts","move_topic": "Move Topic",+ "move_post": "Move Post","fork_topic": "Fork Topic","topic_will_be_moved_to": "This topic will be moved to the category","fork_topic_instruction": "Click the posts you want to fork",diff --git a/public/src/forum/topic.js b/public/src/forum/topic.jsindex 15eba4d0d4..bfd423fedc 100644--- a/public/src/forum/topic.js+++ b/public/src/forum/topic.js@@ -465,6 +465,50 @@ define(['composer'], function(composer) {}});+ $('#post-container').on('click', '.move', function(e) {+ var moveModal = $('#move-post-modal'),+ moveBtn = moveModal.find('#move_post_commit'),+ topicId = moveModal.find('#topicId'),+ post = $(this),+ pid = $(this).parents('li').attr('data-pid');++ moveModal.removeClass('hide');+ moveModal.css("position", "fixed")+ .css("left", Math.max(0, (($(window).width() - $(moveModal).outerWidth()) / 2) + $(window).scrollLeft()) + "px")+ .css("top", "0px")+ .css("z-index", "2000");++ moveModal.find('.close,#move_post_cancel').on('click', function() {+ moveModal.addClass('hide');+ });++ topicId.on('change', function() {+ if(topicId.val().length) {+ moveBtn.removeAttr('disabled');+ } else {+ moveBtn.attr('disabled', true);+ }+ });++ moveBtn.on('click', function() {+ socket.emit('api:topic.movePost', {pid: pid, tid: topicId.val()}, function(err) {+ if(err) {+ return app.alertError(err.message);+ }++ post.fadeOut(500, function() {+ post.remove();+ });++ moveModal.addClass('hide');+ $('#topicId').val('');++ app.alertSuccess('Post moved!');+ });+ });+ });++$('#post-container').on('click', '.chat', function(e) {var username = $(this).parents('li.row').attr('data-username');var touid = $(this).parents('li.row').attr('data-uid');diff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex 64ee27d852..95201f4d35 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -97,6 +97,9 @@<div class="btn-group post-tools"><button class="btn btn-sm btn-default edit" type="button" title="[[topic:edit]]"><i class="fa fa-pencil"></i></button><button class="btn btn-sm btn-default delete" type="button" title="[[topic:delete]]"><i class="fa fa-trash-o"></i></button>+ <!-- IF !@first -->+ <button class="btn btn-sm btn-default move" type="button" title="[[topic:move]]"><i class="fa fa-arrows"></i></button>+ <!-- ENDIF !@first --></div><!-- ENDIF posts.display_moderator_tools --></div>@@ -209,28 +212,50 @@</div>- <div id="fork-thread-modal" class="hide" tabindex="-1" role="dialog" aria-labelledby="Chat" aria-hidden="true" data-backdrop="none">- <div class="modal-dialog">- <div class="modal-content">- <div class="modal-header">- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>- <h4>[[topic:fork_topic]]</h4>- </div>- <div class="modal-body">- <div class="form-group">- <label for="title">Title</label>- <input id="fork-title" type="text" class="form-control" placeholder="Enter new thread title"><br/>- <label>[[topic:fork_topic_instruction]]</label> <br/>- <span id="fork-pids"></span>+ <div id="fork-thread-modal" class="hide" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true" data-backdrop="none">+ <div class="modal-dialog">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>+ <h4>[[topic:fork_topic]]</h4>+ </div>+ <div class="modal-body">+ <div class="form-group">+ <label for="title">Title</label>+ <input id="fork-title" type="text" class="form-control" placeholder="Enter new thread title"><br/>+ <label>[[topic:fork_topic_instruction]]</label> <br/>+ <span id="fork-pids"></span>+ </div>+ </div>++ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal" id="fork_thread_cancel">[[global:buttons.close]]</button>+ <button type="button" class="btn btn-primary" id="fork_thread_commit" disabled>[[topic:confirm_fork]]</button></div></div>+ </div>+ </div>++ <div id="move-post-modal" class="hide" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true" data-backdrop="none">+ <div class="modal-dialog">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>+ <h4>[[topic:move_post]]</h4>+ </div>+ <div class="modal-body">+ <div class="form-group">+ <label for="topicId">Topic ID</label>+ <input id="topicId" type="text" class="form-control" placeholder="Enter topic ID"><br/>+ </div>+ </div>- <div class="modal-footer">- <button type="button" class="btn btn-default" data-dismiss="modal" id="fork_thread_cancel">[[global:buttons.close]]</button>- <button type="button" class="btn btn-primary" id="fork_thread_commit" disabled>[[topic:confirm_fork]]</button>+ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal" id="move_post_cancel">[[global:buttons.close]]</button>+ <button type="button" class="btn btn-primary" id="move_post_commit" disabled>[[topic:confirm_move]]</button>+ </div></div></div></div>-</div></div>\ No newline at end of filediff --git a/src/topics.js b/src/topics.jsindex b5ed978d98..cb141ccdf4 100644--- a/src/topics.js+++ b/src/topics.js@@ -242,13 +242,7 @@ var async = require('async'),function move(pid, next) {postTools.privileges(pid, uid, function(privileges) {if(privileges.editable) {- posts.getPostField(pid, 'timestamp', function(err, timestamp) {- if(err) {- return next(err);- }-- Topics.movePostToTopic(pid, postData.tid, tid, timestamp, next);- });+ Topics.movePostToTopic(pid, tid, next);} else {next();}@@ -259,13 +253,35 @@ var async = require('async'),});}- Topics.movePostToTopic = function(pid, oldTid, newTid, timestamp, callback) {- Topics.removePostFromTopic(oldTid, pid);- Topics.decreasePostCount(oldTid);+ Topics.movePostToTopic = function(pid, tid, callback) {+ threadTools.exists(tid, function(exists) {+ if(!exists) {+ return callback(new Error('Topic doesn\'t exist'));+ }- posts.setPostField(pid, 'tid', newTid);+ posts.getPostField(pid, 'tid', function(err, oldTid) {+ if(err) {+ return callback(err);+ }++ if(!oldTid) {+ return callback(new Error('Post doesn\'t exist'));+ }- Topics.onNewPostMade(newTid, pid, timestamp, callback);+ Topics.removePostFromTopic(oldTid, pid, function(err) {+ if(err) {+ return callback(err);+ }++ Topics.decreasePostCount(oldTid);++ posts.setPostField(pid, 'tid', tid);++ Topics.increasePostCount(tid);+ Topics.addPostToTopic(tid, pid, callback);+ });+ });+ });}Topics.getTopicData = function(tid, callback) {@@ -1032,8 +1048,8 @@ var async = require('async'),db.listAppend('tid:' + tid + ':posts', pid, callback);}- Topics.removePostFromTopic = function(tid, pid) {- db.listRemoveAll('tid:' + tid + ':posts', pid);+ Topics.removePostFromTopic = function(tid, pid, callback) {+ db.listRemoveAll('tid:' + tid + ':posts', pid, callback);}Topics.getPids = function(tid, callback) {diff --git a/src/websockets.js b/src/websockets.jsindex 8dad9c3c18..38aa771277 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -638,6 +638,22 @@ websockets.init = function(io) {});});+ socket.on('api:topic.movePost', function(data, callback) {+ if(!uid) {+ socket.emit('event:alert', {+ title: 'Can't fork',+ message: 'Guests can't fork topics!',+ type: 'warning',+ timeout: 2000+ });+ return;+ }++ topics.movePostToTopic(data.pid, data.tid, function(err, data) {+ callback(err?{message:err.message}:null, data);+ });+ });+socket.on('api:topic.move', function(data) {threadTools.move(data.tid, data.cid, socket);});