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

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

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

Loading…
Cancel
Save