diff --git a/public/src/client/topic/move-post.js b/public/src/client/topic/move-post.js index 029891c8ca..16eb4590fb 100644 --- a/public/src/client/topic/move-post.js +++ b/public/src/client/topic/move-post.js @@ -30,12 +30,18 @@ define('forum/topic/move-post', [ postSelect.togglePostSelection(postEl, postEl.attr('data-pid')); } - $(window).off('action:axajify.end', checkMoveButtonEnable) + $(window).off('action:ajaxify.end', checkMoveButtonEnable) .on('action:ajaxify.end', checkMoveButtonEnable); moveCommit.on('click', function () { + if (!ajaxify.data.template.topic || !ajaxify.data.tid) { + return; + } moveCommit.attr('disabled', true); - + var data = { + pids: postSelect.pids.slice(), + tid: ajaxify.data.tid, + }; alerts.alert({ alert_id: 'pids_move_' + postSelect.pids.join('-'), title: '[[topic:thread_tools.move-posts]]', @@ -43,7 +49,7 @@ define('forum/topic/move-post', [ type: 'success', timeout: 10000, timeoutfn: function () { - movePosts(); + movePosts(data); }, clickfn: function (alert, params) { delete params.timeoutfn; @@ -90,15 +96,15 @@ define('forum/topic/move-post', [ checkMoveButtonEnable(); } - function movePosts() { - if (!ajaxify.data.template.topic || !ajaxify.data.tid) { + function movePosts(data) { + if (!ajaxify.data.template.topic || !data.tid) { return; } - socket.emit('posts.movePosts', { pids: postSelect.pids, tid: ajaxify.data.tid }, function (err) { + socket.emit('posts.movePosts', { pids: data.pids, tid: data.tid }, function (err) { if (err) { return app.alertError(err.message); } - postSelect.pids.forEach(function (pid) { + data.pids.forEach(function (pid) { components.get('post', 'pid', pid).fadeOut(500, function () { $(this).remove(); }); @@ -116,6 +122,5 @@ define('forum/topic/move-post', [ } } - return MovePost; }); diff --git a/public/src/client/topic/move.js b/public/src/client/topic/move.js index 706ca635f8..03c40b56d3 100644 --- a/public/src/client/topic/move.js +++ b/public/src/client/topic/move.js @@ -60,6 +60,12 @@ define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySel } else if (!Move.tids) { message = '[[topic:topic_move_all_success, ' + selectedCategory.name + ']]'; } + var data = { + tids: Move.tids ? Move.tids.slice() : null, + cid: selectedCategory.cid, + currentCid: Move.currentCid, + onComplete: Move.onComplete, + }; alerts.alert({ alert_id: 'tids_move_' + (Move.tids ? Move.tids.join('-') : 'all'), title: '[[topic:thread_tools.move]]', @@ -67,7 +73,7 @@ define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySel type: 'success', timeout: 10000, timeoutfn: function () { - moveTopics(); + moveTopics(data); }, clickfn: function (alert, params) { delete params.timeoutfn; @@ -77,26 +83,19 @@ define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySel } } - function moveTopics() { - var data = { - tids: Move.tids, - cid: selectedCategory.cid, - currentCid: Move.currentCid, - }; - + function moveTopics(data) { $(window).trigger('action:topic.move', data); - socket.emit(Move.moveAll ? 'topics.moveAll' : 'topics.move', data, function (err) { + socket.emit(!data.tids ? 'topics.moveAll' : 'topics.move', data, function (err) { if (err) { return app.alertError(err.message); } - if (typeof Move.onComplete === 'function') { - Move.onComplete(); + if (typeof data.onComplete === 'function') { + data.onComplete(); } }); } - return Move; });