From 5a40d26b44cbea4e1468b2615026f7b915ceb659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 8 Sep 2020 19:22:38 -0400 Subject: [PATCH] feat: #8626, new move posts modal --- public/language/en-GB/topic.json | 7 ++--- public/less/modals.less | 12 +++++++++ public/src/client/topic/move-post.js | 40 +++++++++++++++++++++------- src/meta/css.js | 1 + src/views/modals/move-post.tpl | 20 ++++++++++++++ 5 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 public/less/modals.less create mode 100644 src/views/modals/move-post.tpl diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index b8979e92d03a..10f1f717ff85 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -1,7 +1,5 @@ { "topic": "Topic", - "topic_id": "Topic ID", - "topic_id_placeholder": "Enter topic ID", "no_topics_found": "No topics found!", "no_posts_found": "No posts found!", @@ -116,6 +114,9 @@ "fork_topic": "Fork Topic", "fork_topic_instruction": "Click the posts you want to fork", "fork_no_pids": "No posts selected!", + "no-posts-selected": "No posts selected!", + "x-posts-selected": "%1 post(s) selected", + "x-posts-will-be-moved-to-y": "%1 post(s) will be moved to \"%2\"", "fork_pid_count": "%1 post(s) selected", "fork_success": "Successfully forked topic! Click here to go to the forked topic.", "delete_posts_instruction": "Click the posts you want to delete/purge", @@ -124,7 +125,7 @@ "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", + "move_posts_instruction": "Click the posts you want to move then go to target topic and click move.", "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/less/modals.less b/public/less/modals.less new file mode 100644 index 000000000000..96e47ebb535e --- /dev/null +++ b/public/less/modals.less @@ -0,0 +1,12 @@ +.tool-modal { + position: fixed; + bottom: 10%; + right: 2rem; + z-index: 1; +} + +@media screen and (min-width: @screen-sm-min) { + .tool-modal { + max-width: 33%; + } +} \ No newline at end of file diff --git a/public/src/client/topic/move-post.js b/public/src/client/topic/move-post.js index dd807f0e4f7a..1b9e08bec99b 100644 --- a/public/src/client/topic/move-post.js +++ b/public/src/client/topic/move-post.js @@ -1,17 +1,21 @@ 'use strict'; -define('forum/topic/move-post', ['components', 'postSelect'], function (components, postSelect) { +define('forum/topic/move-post', [ + 'components', 'postSelect', 'translator', +], function (components, postSelect, translator) { var MovePost = {}; var moveModal; var moveCommit; + var fromTid; MovePost.init = function (postEl) { if (moveModal) { return; } - app.parseAndTranslate('partials/move_post_modal', {}, function (html) { + fromTid = ajaxify.data.tid; + app.parseAndTranslate('modals/move-post', {}, function (html) { moveModal = html; moveCommit = moveModal.find('#move_posts_confirm'); @@ -19,7 +23,6 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen $('body').append(moveModal); moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal); - moveModal.find('#topicId').on('keyup', checkMoveButtonEnable); postSelect.init(onPostToggled); showPostsSelected(); @@ -27,6 +30,9 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen postSelect.togglePostSelection(postEl, postEl.attr('data-pid')); } + $(window).off('action:axajify.end', checkMoveButtonEnable) + .on('action:ajaxify.end', checkMoveButtonEnable); + moveCommit.on('click', function () { movePosts(); }); @@ -34,29 +40,45 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen }; function showPostsSelected() { + if (!moveModal) { + return; + } if (postSelect.pids.length) { - moveModal.find('#pids').translateHtml('[[topic:fork_pid_count, ' + 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); + } else { + moveModal.find('#pids').translateHtml('[[topic:x-posts-selected, ' + postSelect.pids.length + ']]'); + } } else { - moveModal.find('#pids').translateHtml('[[topic:fork_no_pids]]'); + moveModal.find('#pids').translateHtml('[[topic:no-posts-selected]]'); } } function checkMoveButtonEnable() { - if (moveModal.find('#topicId').val().length && postSelect.pids.length) { + if (!moveModal) { + return; + } + + if (postSelect.pids.length && ajaxify.data.tid && + ajaxify.data.template.topic && ajaxify.data.tid !== fromTid + ) { moveCommit.removeAttr('disabled'); } else { moveCommit.attr('disabled', true); } + showPostsSelected(); } function onPostToggled() { checkMoveButtonEnable(); - showPostsSelected(); } function movePosts() { - var tid = moveModal.find('#topicId').val(); - socket.emit('posts.movePosts', { pids: postSelect.pids, tid: tid }, function (err) { + if (!ajaxify.data.template.topic || !ajaxify.data.tid) { + return; + } + socket.emit('posts.movePosts', { pids: postSelect.pids, tid: ajaxify.data.tid }, function (err) { if (err) { return app.alertError(err.message); } diff --git a/src/meta/css.js b/src/meta/css.js index 97267497aae3..f0ff59dc120b 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -32,6 +32,7 @@ var buildImports = { '@import "../../public/less/generics.less";', '@import "../../public/less/mixins.less";', '@import "../../public/less/global.less";', + '@import "../../public/less/modals.less";', ].map(function (str) { return str.replace(/\//g, path.sep); }).join('\n'); diff --git a/src/views/modals/move-post.tpl b/src/views/modals/move-post.tpl new file mode 100644 index 000000000000..f24dd9eb64ae --- /dev/null +++ b/src/views/modals/move-post.tpl @@ -0,0 +1,20 @@ +
+
+

[[topic:thread_tools.move-posts]]

+
+
+

+ +

+

+ [[topic:move_posts_instruction]] +

+
+ +
\ No newline at end of file