move post

v1.18.x
Baris Soner Usakli 11 years ago
parent 4912b8a893
commit 8e6606fb5a

@ -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",

@ -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');

@ -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">&times;</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">&times;</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">&times;</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>

@ -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) {

@ -638,6 +638,22 @@ websockets.init = function(io) {
});
});
socket.on('api:topic.movePost', function(data, callback) {
if(!uid) {
socket.emit('event:alert', {
title: 'Can&apos;t fork',
message: 'Guests can&apos;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);
});

Loading…
Cancel
Save