feat: add back topic id input

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 166d65a1ba
commit 696c489524

@ -142,7 +142,8 @@
"merge-options": "Merge options", "merge-options": "Merge options",
"merge-select-main-topic": "Select the main topic", "merge-select-main-topic": "Select the main topic",
"merge-new-title-for-topic": "New title for 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", "change_owner_instruction": "Click the posts you want to assign to another user",
"composer.title_placeholder": "Enter your topic title here...", "composer.title_placeholder": "Enter your topic title here...",

@ -23,6 +23,7 @@ define('forum/topic/move-post', [
$('body').append(moveModal); $('body').append(moveModal);
moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal); moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal);
moveModal.find('#topicId').on('keyup', utils.debounce(checkMoveButtonEnable, 200));
postSelect.init(onPostToggled); postSelect.init(onPostToggled);
showPostsSelected(); showPostsSelected();
@ -30,17 +31,18 @@ define('forum/topic/move-post', [
postSelect.togglePostSelection(postEl, postEl.attr('data-pid')); postSelect.togglePostSelection(postEl, postEl.attr('data-pid'));
} }
$(window).off('action:ajaxify.end', checkMoveButtonEnable) $(window).off('action:ajaxify.end', onAjaxifyEnd)
.on('action:ajaxify.end', checkMoveButtonEnable); .on('action:ajaxify.end', onAjaxifyEnd);
moveCommit.on('click', function () { moveCommit.on('click', function () {
if (!ajaxify.data.template.topic || !ajaxify.data.tid) { const targetTid = getTargetTid();
if (!targetTid) {
return; return;
} }
moveCommit.attr('disabled', true); moveCommit.attr('disabled', true);
var data = { var data = {
pids: postSelect.pids.slice(), pids: postSelect.pids.slice(),
tid: ajaxify.data.tid, tid: targetTid,
}; };
alerts.alert({ alerts.alert({
alert_id: 'pids_move_' + postSelect.pids.join('-'), 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() { function showPostsSelected() {
if (!moveModal) { if (!moveModal) {
return; return;
} }
var targetTid = getTargetTid();
if (postSelect.pids.length) { if (postSelect.pids.length) {
if (ajaxify.data.template.topic && ajaxify.data.tid && ajaxify.data.tid !== fromTid) { if (targetTid && parseInt(targetTid, 10) !== parseInt(fromTid, 10)) {
var translateStr = translator.compile('topic:x-posts-will-be-moved-to-y', postSelect.pids.length, ajaxify.data.title); api.get('/topics/' + targetTid, {}).then(function (data) {
moveModal.find('#pids').translateHtml(translateStr); 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 { } else {
moveModal.find('#pids').translateHtml('[[topic:x-posts-selected, ' + postSelect.pids.length + ']]'); moveModal.find('#pids').translateHtml('[[topic:x-posts-selected, ' + postSelect.pids.length + ']]');
} }
@ -81,9 +114,9 @@ define('forum/topic/move-post', [
if (!moveModal) { if (!moveModal) {
return; return;
} }
var targetTid = getTargetTid();
if (postSelect.pids.length && ajaxify.data.tid && if (postSelect.pids.length && targetTid &&
ajaxify.data.template.topic && ajaxify.data.tid !== fromTid parseInt(targetTid, 10) !== parseInt(fromTid, 10)
) { ) {
moveCommit.removeAttr('disabled'); moveCommit.removeAttr('disabled');
} else { } else {
@ -97,7 +130,7 @@ define('forum/topic/move-post', [
} }
function movePosts(data) { function movePosts(data) {
if (!ajaxify.data.template.topic || !data.tid) { if (!data.tid) {
return; return;
} }
@ -119,6 +152,7 @@ define('forum/topic/move-post', [
moveModal.remove(); moveModal.remove();
moveModal = null; moveModal = null;
postSelect.disable(); postSelect.disable();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
} }
} }

@ -3,6 +3,10 @@
<h3 class="panel-title">[[topic:thread_tools.move-posts]]</h3> <h3 class="panel-title">[[topic:thread_tools.move-posts]]</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div>
<label for="topicId">[[topic:topic-id]]</label>
<input id="topicId" type="text" class="form-control"><br/>
</div>
<p> <p>
<strong><span id="pids"></span></strong> <strong><span id="pids"></span></strong>
</p> </p>

Loading…
Cancel
Save