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