diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index 91e1a97f14..069088dc4f 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -142,7 +142,8 @@ "merge-options": "Merge options", "merge-select-main-topic": "Select the main topic", "merge-new-title-for-topic": "New title for topic", - "move_posts_instruction": "Click the posts you want to move then go to target topic and click move.", + "topic-id": "Topic ID", + "move_posts_instruction": "Click the posts you want to move then enter a topic ID or go to the target topic", "change_owner_instruction": "Click the posts you want to assign to another user", "composer.title_placeholder": "Enter your topic title here...", diff --git a/public/src/client/topic/move-post.js b/public/src/client/topic/move-post.js index 8a5e68fe32..bcd02582ac 100644 --- a/public/src/client/topic/move-post.js +++ b/public/src/client/topic/move-post.js @@ -23,6 +23,7 @@ define('forum/topic/move-post', [ $('body').append(moveModal); moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal); + moveModal.find('#topicId').on('keyup', utils.debounce(checkMoveButtonEnable, 200)); postSelect.init(onPostToggled); showPostsSelected(); @@ -30,17 +31,18 @@ define('forum/topic/move-post', [ postSelect.togglePostSelection(postEl, postEl.attr('data-pid')); } - $(window).off('action:ajaxify.end', checkMoveButtonEnable) - .on('action:ajaxify.end', checkMoveButtonEnable); + $(window).off('action:ajaxify.end', onAjaxifyEnd) + .on('action:ajaxify.end', onAjaxifyEnd); moveCommit.on('click', function () { - if (!ajaxify.data.template.topic || !ajaxify.data.tid) { + const targetTid = getTargetTid(); + if (!targetTid) { return; } moveCommit.attr('disabled', true); var data = { pids: postSelect.pids.slice(), - tid: ajaxify.data.tid, + tid: targetTid, }; alerts.alert({ alert_id: 'pids_move_' + postSelect.pids.join('-'), @@ -61,14 +63,45 @@ define('forum/topic/move-post', [ }); }; + function onAjaxifyEnd() { + if (!moveModal) { + return; + } + var tidInput = moveModal.find('#topicId'); + var targetTid = null; + if (ajaxify.data.template.topic && ajaxify.data.tid && + parseInt(ajaxify.data.tid, 10) !== fromTid + ) { + targetTid = ajaxify.data.tid; + } + if (targetTid && !tidInput.val()) { + tidInput.val(targetTid); + } + checkMoveButtonEnable(); + } + + function getTargetTid() { + var tidInput = moveModal.find('#topicId'); + if (tidInput.length && tidInput.val()) { + return tidInput.val(); + } + return ajaxify.data.template.topic && ajaxify.data.tid; + } + function showPostsSelected() { if (!moveModal) { return; } + var targetTid = getTargetTid(); if (postSelect.pids.length) { - if (ajaxify.data.template.topic && ajaxify.data.tid && ajaxify.data.tid !== fromTid) { - var translateStr = translator.compile('topic:x-posts-will-be-moved-to-y', postSelect.pids.length, ajaxify.data.title); - moveModal.find('#pids').translateHtml(translateStr); + if (targetTid && parseInt(targetTid, 10) !== parseInt(fromTid, 10)) { + api.get('/topics/' + targetTid, {}).then(function (data) { + if (!data || !data.tid) { + return app.alertError('[[error:no-topic]]'); + } + var translateStr = translator.compile('topic:x-posts-will-be-moved-to-y', postSelect.pids.length, data.title); + moveModal.find('#pids').translateHtml(translateStr); + }); } else { moveModal.find('#pids').translateHtml('[[topic:x-posts-selected, ' + postSelect.pids.length + ']]'); } @@ -81,9 +114,9 @@ define('forum/topic/move-post', [ if (!moveModal) { return; } - - if (postSelect.pids.length && ajaxify.data.tid && - ajaxify.data.template.topic && ajaxify.data.tid !== fromTid + var targetTid = getTargetTid(); + if (postSelect.pids.length && targetTid && + parseInt(targetTid, 10) !== parseInt(fromTid, 10) ) { moveCommit.removeAttr('disabled'); } else { @@ -97,7 +130,7 @@ define('forum/topic/move-post', [ } function movePosts(data) { - if (!ajaxify.data.template.topic || !data.tid) { + if (!data.tid) { return; } @@ -119,6 +152,7 @@ define('forum/topic/move-post', [ moveModal.remove(); moveModal = null; postSelect.disable(); + $(window).off('action:ajaxify.end', onAjaxifyEnd); } } diff --git a/src/views/modals/move-post.tpl b/src/views/modals/move-post.tpl index e1b2884617..7583157798 100644 --- a/src/views/modals/move-post.tpl +++ b/src/views/modals/move-post.tpl @@ -3,6 +3,10 @@