v1.18.x
Barış Soner Uşaklı 7 years ago
parent df770aed8e
commit caf43e3025

@ -73,6 +73,7 @@
"thread_tools.lock": "Lock Topic", "thread_tools.lock": "Lock Topic",
"thread_tools.unlock": "Unlock Topic", "thread_tools.unlock": "Unlock Topic",
"thread_tools.move": "Move Topic", "thread_tools.move": "Move Topic",
"thread_tools.move-posts": "Move Posts",
"thread_tools.move_all": "Move All", "thread_tools.move_all": "Move All",
"thread_tools.select_category": "Select Category", "thread_tools.select_category": "Select Category",
"thread_tools.fork": "Fork Topic", "thread_tools.fork": "Fork Topic",
@ -112,6 +113,7 @@
"fork_success": "Successfully forked topic! Click here to go to the forked topic.", "fork_success": "Successfully forked topic! Click here to go to the forked topic.",
"delete_posts_instruction": "Click the posts you want to delete/purge", "delete_posts_instruction": "Click the posts you want to delete/purge",
"merge_topics_instruction": "Click the topics you want to merge", "merge_topics_instruction": "Click the topics you want to merge",
"move_posts_instruction": "Click the posts you want to move",
"composer.title_placeholder": "Enter your topic title here...", "composer.title_placeholder": "Enter your topic title here...",
"composer.handle_placeholder": "Name", "composer.handle_placeholder": "Name",

@ -77,17 +77,11 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
} }
function closeModal() { function closeModal() {
postSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).toggleClass('bg-success', false);
});
if (modal) { if (modal) {
modal.remove(); modal.remove();
modal = null; modal = null;
} }
postSelect.disable();
components.get('topic').off('click', '[data-pid]');
postSelect.enableClicksOnPosts();
} }
return DeletePosts; return DeletePosts;

@ -89,17 +89,12 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
} }
function closeForkModal() { function closeForkModal() {
postSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).toggleClass('bg-success', false);
});
if (forkModal) { if (forkModal) {
forkModal.remove(); forkModal.remove();
forkModal = null; forkModal = null;
} }
components.get('topic').off('click', '[data-pid]'); postSelect.disable();
postSelect.enableClicksOnPosts();
} }
return Fork; return Fork;

@ -1,56 +1,95 @@
'use strict'; 'use strict';
define('forum/topic/move-post', [], function () { define('forum/topic/move-post', ['components', 'postSelect'], function (components, postSelect) {
var MovePost = {}; var MovePost = {};
MovePost.openMovePostModal = function (button) { var moveModal;
var moveCommit;
MovePost.init = function () {
$('.topic').on('click', '[component="topic/move-posts"]', onMovePostsClicked);
$(window).on('action:ajaxify.start', onAjaxifyStart);
};
function onAjaxifyStart() {
closeMoveModal();
$(window).off('action:ajaxify.start', onAjaxifyStart);
}
function onMovePostsClicked() {
MovePost.openMovePostModal();
}
function showPostsSelected() {
if (postSelect.pids.length) {
moveModal.find('#pids').translateHtml('[[topic:fork_pid_count, ' + postSelect.pids.length + ']]');
} else {
moveModal.find('#pids').translateHtml('[[topic:fork_no_pids]]');
}
}
function checkMoveButtonEnable() {
if (moveModal.find('#topicId').val().length && postSelect.pids.length) {
moveCommit.removeAttr('disabled');
} else {
moveCommit.attr('disabled', true);
}
}
MovePost.openMovePostModal = function (postEl) {
app.parseAndTranslate('partials/move_post_modal', {}, function (html) { app.parseAndTranslate('partials/move_post_modal', {}, function (html) {
var dialog = bootbox.dialog({ moveModal = html;
title: '[[topic:move_post]]',
message: html,
show: true,
buttons: {
submit: {
label: '[[topic:confirm_move]]',
className: 'btn-primary submit-btn',
callback: function () {
var topicIdEl = dialog.find('#topicId');
if (!topicIdEl.val()) {
return;
}
movePost(button.parents('[data-pid]'), button.parents('[data-pid]').attr('data-pid'), topicIdEl.val(), function () {
topicIdEl.val('');
});
},
},
},
});
dialog.find('.submit-btn').attr('disabled', true);
dialog.find('#topicId').on('keyup change', function () { moveCommit = moveModal.find('#move_posts_confirm');
dialog.find('.submit-btn').attr('disabled', !dialog.find('#topicId').val());
$(document.body).append(moveModal);
moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal);
moveModal.find('#topicId').on('keyup', checkMoveButtonEnable);
postSelect.init(onPostToggled);
showPostsSelected();
if (postEl) {
postSelect.togglePostSelection(postEl, onPostToggled);
}
moveCommit.on('click', function () {
movePosts();
}); });
}); });
}; };
function movePost(post, pid, tid, callback) { function onPostToggled() {
socket.emit('posts.movePost', { pid: pid, tid: tid }, function (err) { checkMoveButtonEnable();
showPostsSelected();
}
function movePosts() {
var tid = moveModal.find('#topicId').val();
socket.emit('posts.movePosts', { pids: postSelect.pids, tid: tid }, function (err) {
if (err) { if (err) {
app.alertError(err.message); return app.alertError(err.message);
return callback();
} }
postSelect.pids.forEach(function (pid) {
post.fadeOut(500, function () { components.get('post', 'pid', pid).fadeOut(500, function () {
post.remove(); $(this).remove();
});
}); });
app.alertSuccess('[[topic:post_moved]]'); closeMoveModal();
callback();
}); });
} }
function closeMoveModal() {
if (moveModal) {
moveModal.remove();
moveModal = null;
}
postSelect.disable();
}
return MovePost; return MovePost;
}); });

@ -195,7 +195,7 @@ define('forum/topic/postTools', [
}); });
postContainer.on('click', '[component="post/move"]', function () { postContainer.on('click', '[component="post/move"]', function () {
movePost.openMovePostModal($(this)); movePost.openMovePostModal($(this).parents('[data-pid]'));
}); });
postContainer.on('click', '[component="post/ban-ip"]', function () { postContainer.on('click', '[component="post/ban-ip"]', function () {

@ -5,10 +5,11 @@ define('forum/topic/threadTools', [
'forum/topic/fork', 'forum/topic/fork',
'forum/topic/move', 'forum/topic/move',
'forum/topic/delete-posts', 'forum/topic/delete-posts',
'forum/topic/move-post',
'components', 'components',
'translator', 'translator',
'benchpress', 'benchpress',
], function (fork, move, deletePosts, components, translator, Benchpress) { ], function (fork, move, deletePosts, movePosts, components, translator, Benchpress) {
var ThreadTools = {}; var ThreadTools = {};
ThreadTools.init = function (tid) { ThreadTools.init = function (tid) {
@ -80,6 +81,7 @@ define('forum/topic/threadTools', [
deletePosts.init(); deletePosts.init();
fork.init(); fork.init();
movePosts.init();
$('.topic').on('click', '[component="topic/following"]', function () { $('.topic').on('click', '[component="topic/following"]', function () {
changeWatching('follow'); changeWatching('follow');

@ -9,13 +9,20 @@ define('postSelect', ['components'], function (components) {
PostSelect.init = function (onSelect) { PostSelect.init = function (onSelect) {
PostSelect.pids.length = 0; PostSelect.pids.length = 0;
components.get('topic').on('click', '[data-pid]', function () { components.get('topic').on('click', '[data-pid]', function () {
togglePostSelection($(this), onSelect); PostSelect.togglePostSelection($(this), onSelect);
}); });
disableClicksOnPosts(); disableClicksOnPosts();
}; };
PostSelect.disable = function () {
PostSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).toggleClass('bg-success', false);
});
components.get('topic').off('click', '[data-pid]');
enableClicksOnPosts();
};
function togglePostSelection(post, callback) { PostSelect.togglePostSelection = function (post, callback) {
var newPid = post.attr('data-pid'); var newPid = post.attr('data-pid');
if (parseInt(post.attr('data-index'), 10) === 0) { if (parseInt(post.attr('data-index'), 10) === 0) {
@ -37,7 +44,7 @@ define('postSelect', ['components'], function (components) {
} }
callback(); callback();
} }
} };
function disableClicks() { function disableClicks() {
@ -48,7 +55,7 @@ define('postSelect', ['components'], function (components) {
components.get('post').on('click', 'button,a', disableClicks); components.get('post').on('click', 'button,a', disableClicks);
} }
PostSelect.enableClicksOnPosts = function () { function enableClicksOnPosts() {
components.get('post').off('click', 'button,a', disableClicks); components.get('post').off('click', 'button,a', disableClicks);
}; };

@ -7,29 +7,34 @@ var socketHelpers = require('../helpers');
module.exports = function (SocketPosts) { module.exports = function (SocketPosts) {
SocketPosts.movePost = function (socket, data, callback) { SocketPosts.movePost = function (socket, data, callback) {
SocketPosts.movePosts(socket, { pids: [data.pid], tid: data.tid }, callback);
};
SocketPosts.movePosts = function (socket, data, callback) {
if (!socket.uid) { if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]')); return callback(new Error('[[error:not-logged-in]]'));
} }
if (!data || !data.pid || !data.tid) { if (!data || !Array.isArray(data.pids) || !data.tid) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
async.eachSeries(data.pids, function (pid, next) {
async.waterfall([
function (next) {
privileges.posts.canMove(pid, socket.uid, next);
},
function (canMove, next) {
if (!canMove) {
return next(new Error('[[error:no-privileges]]'));
}
async.waterfall([ topics.movePostToTopic(pid, data.tid, next);
function (next) { },
privileges.posts.canMove(data.pid, socket.uid, next); function (next) {
}, socketHelpers.sendNotificationToPostOwner(pid, socket.uid, 'move', 'notifications:moved_your_post');
function (canMove, next) { next();
if (!canMove) { },
return next(new Error('[[error:no-privileges]]')); ], next);
} }, callback);
topics.movePostToTopic(data.pid, data.tid, next);
},
function (next) {
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'move', 'notifications:moved_your_post');
next();
},
], callback);
}; };
}; };

Loading…
Cancel
Save