-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
move-post.js
105 lines (86 loc) · 2.39 KB
/
move-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
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;
}
fromTid = ajaxify.data.tid;
app.parseAndTranslate('modals/move-post', {}, function (html) {
moveModal = html;
moveCommit = moveModal.find('#move_posts_confirm');
$('body').append(moveModal);
moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal);
postSelect.init(onPostToggled);
showPostsSelected();
if (postEl) {
postSelect.togglePostSelection(postEl, postEl.attr('data-pid'));
}
$(window).off('action:axajify.end', checkMoveButtonEnable)
.on('action:ajaxify.end', checkMoveButtonEnable);
moveCommit.on('click', function () {
movePosts();
});
});
};
function showPostsSelected() {
if (!moveModal) {
return;
}
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);
} else {
moveModal.find('#pids').translateHtml('[[topic:x-posts-selected, ' + postSelect.pids.length + ']]');
}
} else {
moveModal.find('#pids').translateHtml('[[topic:no-posts-selected]]');
}
}
function checkMoveButtonEnable() {
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();
}
function movePosts() {
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);
}
postSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).fadeOut(500, function () {
$(this).remove();
});
});
closeMoveModal();
});
}
function closeMoveModal() {
if (moveModal) {
moveModal.remove();
moveModal = null;
postSelect.disable();
}
}
return MovePost;
});