Skip to content

Commit

Permalink
feat: add back topic id input
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 8, 2021
1 parent 166d65a commit 696c489
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
3 changes: 2 additions & 1 deletion public/language/en-GB/topic.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down
56 changes: 45 additions & 11 deletions public/src/client/topic/move-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ 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();

if (postEl) {
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('-'),
Expand All @@ -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 + ']]');
}
Expand All @@ -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 {
Expand All @@ -97,7 +130,7 @@ define('forum/topic/move-post', [
}

function movePosts(data) {
if (!ajaxify.data.template.topic || !data.tid) {
if (!data.tid) {
return;
}

Expand All @@ -119,6 +152,7 @@ define('forum/topic/move-post', [
moveModal.remove();
moveModal = null;
postSelect.disable();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/views/modals/move-post.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 696c489

Please sign in to comment.