2014-10-08 15:36:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-02-17 21:55:19 -07:00
|
|
|
|
2015-12-24 12:08:10 +02:00
|
|
|
define('forum/topic/threadTools', [
|
|
|
|
|
'components',
|
2017-02-17 19:31:21 -07:00
|
|
|
'translator',
|
2018-11-17 20:50:07 -05:00
|
|
|
], function (components, translator) {
|
2014-10-08 15:36:47 -04:00
|
|
|
var ThreadTools = {};
|
|
|
|
|
|
2020-09-15 16:05:45 -04:00
|
|
|
ThreadTools.init = function (tid, topicContainer) {
|
|
|
|
|
renderMenu(topicContainer);
|
2015-10-24 21:29:20 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/delete"]', function () {
|
2015-04-02 22:06:18 -04:00
|
|
|
topicCommand('delete', tid);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/restore"]', function () {
|
2015-04-02 22:06:18 -04:00
|
|
|
topicCommand('restore', tid);
|
2014-10-08 15:36:47 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/purge"]', function () {
|
2014-10-08 15:36:47 -04:00
|
|
|
topicCommand('purge', tid);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/lock"]', function () {
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.lock', { tids: [tid], cid: ajaxify.data.cid });
|
2015-04-02 22:06:18 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/unlock"]', function () {
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.unlock', { tids: [tid], cid: ajaxify.data.cid });
|
2014-10-08 15:36:47 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/pin"]', function () {
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.pin', { tids: [tid], cid: ajaxify.data.cid });
|
2015-04-02 22:06:18 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/unpin"]', function () {
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.unpin', { tids: [tid], cid: ajaxify.data.cid });
|
2014-10-08 15:36:47 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/mark-unread"]', function () {
|
|
|
|
|
socket.emit('topics.markUnread', tid, function (err) {
|
2016-02-01 19:52:26 +02:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err);
|
|
|
|
|
}
|
|
|
|
|
app.alertSuccess('[[topic:mark_unread.success]]');
|
|
|
|
|
});
|
2016-01-04 11:22:35 +02:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/mark-unread-for-all"]', function () {
|
2014-10-08 15:36:47 -04:00
|
|
|
var btn = $(this);
|
2016-10-13 11:43:39 +02:00
|
|
|
socket.emit('topics.markAsUnreadForAll', [tid], function (err) {
|
2015-04-02 22:06:18 -04:00
|
|
|
if (err) {
|
2014-10-08 15:36:47 -04:00
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
|
|
|
|
|
btn.parents('.thread-tools.open').find('.dropdown-toggle').trigger('click');
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
topicContainer.on('click', '[component="topic/move"]', function () {
|
2018-11-17 20:50:07 -05:00
|
|
|
require(['forum/topic/move'], function (move) {
|
|
|
|
|
move.init([tid], ajaxify.data.cid);
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-17 20:50:07 -05:00
|
|
|
topicContainer.on('click', '[component="topic/delete/posts"]', function () {
|
|
|
|
|
require(['forum/topic/delete-posts'], function (deletePosts) {
|
|
|
|
|
deletePosts.init();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topicContainer.on('click', '[component="topic/fork"]', function () {
|
|
|
|
|
require(['forum/topic/fork'], function (fork) {
|
|
|
|
|
fork.init();
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2018-11-17 20:50:07 -05:00
|
|
|
topicContainer.on('click', '[component="topic/move-posts"]', function () {
|
|
|
|
|
require(['forum/topic/move-post'], function (movePosts) {
|
|
|
|
|
movePosts.init();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topicContainer.on('click', '[component="topic/following"]', function () {
|
2016-05-19 14:20:34 +03:00
|
|
|
changeWatching('follow');
|
2016-05-18 19:02:43 +03:00
|
|
|
});
|
2018-11-17 20:50:07 -05:00
|
|
|
topicContainer.on('click', '[component="topic/not-following"]', function () {
|
2016-05-19 14:20:34 +03:00
|
|
|
changeWatching('unfollow');
|
2016-05-18 19:02:43 +03:00
|
|
|
});
|
2018-11-17 20:50:07 -05:00
|
|
|
topicContainer.on('click', '[component="topic/ignoring"]', function () {
|
2016-05-19 14:20:34 +03:00
|
|
|
changeWatching('ignore');
|
2016-05-18 19:02:43 +03:00
|
|
|
});
|
2015-03-23 14:42:17 -04:00
|
|
|
|
2016-05-19 14:20:34 +03:00
|
|
|
function changeWatching(type) {
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.changeWatching', { tid: tid, type: type }, function (err) {
|
2015-04-02 22:06:18 -04:00
|
|
|
if (err) {
|
2014-10-08 15:36:47 -04:00
|
|
|
return app.alert({
|
|
|
|
|
type: 'danger',
|
|
|
|
|
alert_id: 'topic_follow',
|
|
|
|
|
title: '[[global:please_log_in]]',
|
|
|
|
|
message: '[[topic:login_to_subscribe]]',
|
2017-02-17 19:31:21 -07:00
|
|
|
timeout: 5000,
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
}
|
2016-05-18 19:02:43 +03:00
|
|
|
var message = '';
|
|
|
|
|
if (type === 'follow') {
|
|
|
|
|
message = '[[topic:following_topic.message]]';
|
|
|
|
|
} else if (type === 'unfollow') {
|
|
|
|
|
message = '[[topic:not_following_topic.message]]';
|
|
|
|
|
} else if (type === 'ignore') {
|
|
|
|
|
message = '[[topic:ignoring_topic.message]]';
|
|
|
|
|
}
|
|
|
|
|
setFollowState(type);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'follow_thread',
|
2016-05-18 19:02:43 +03:00
|
|
|
message: message,
|
2014-10-08 15:36:47 -04:00
|
|
|
type: 'success',
|
2017-02-17 19:31:21 -07:00
|
|
|
timeout: 5000,
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
2016-06-02 04:18:24 -04:00
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
$(window).trigger('action:topics.changeWatching', { tid: tid, type: type });
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-03-23 14:42:17 -04:00
|
|
|
}
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2020-09-15 16:05:45 -04:00
|
|
|
function renderMenu(container) {
|
|
|
|
|
container.on('show.bs.dropdown', '.thread-tools', function () {
|
2015-10-24 21:29:20 -04:00
|
|
|
var $this = $(this);
|
|
|
|
|
var dropdownMenu = $this.find('.dropdown-menu');
|
|
|
|
|
if (dropdownMenu.html()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.loadTopicTools', { tid: ajaxify.data.tid, cid: ajaxify.data.cid }, function (err, data) {
|
2015-10-24 21:29:20 -04:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err);
|
|
|
|
|
}
|
2018-11-17 20:50:07 -05:00
|
|
|
app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {
|
|
|
|
|
dropdownMenu.html(html);
|
2020-03-13 10:30:43 -04:00
|
|
|
$(window).trigger('action:topic.tools.load', {
|
|
|
|
|
element: dropdownMenu,
|
|
|
|
|
});
|
2015-10-24 21:29:20 -04:00
|
|
|
});
|
|
|
|
|
});
|
2015-10-24 22:29:22 -04:00
|
|
|
});
|
2015-10-24 21:29:20 -04:00
|
|
|
}
|
|
|
|
|
|
2014-10-08 15:36:47 -04:00
|
|
|
function topicCommand(command, tid) {
|
2016-10-13 11:43:39 +02:00
|
|
|
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function (msg) {
|
|
|
|
|
bootbox.confirm(msg, function (confirm) {
|
2015-09-16 08:35:40 -04:00
|
|
|
if (!confirm) {
|
|
|
|
|
return;
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
2015-09-16 08:35:40 -04:00
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('topics.' + command, { tids: [tid], cid: ajaxify.data.cid }, function (err) {
|
2015-09-16 08:35:40 -04:00
|
|
|
if (err) {
|
|
|
|
|
app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
ThreadTools.setLockedState = function (data) {
|
2015-03-17 13:38:18 -04:00
|
|
|
var threadEl = components.get('topic');
|
2015-04-02 22:06:18 -04:00
|
|
|
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-08-12 12:57:23 +03:00
|
|
|
var isLocked = data.isLocked && !ajaxify.data.privileges.isAdminOrMod;
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2018-12-19 12:09:36 -05:00
|
|
|
components.get('topic/lock').toggleClass('hidden', data.isLocked).parent().attr('hidden', data.isLocked ? '' : null);
|
|
|
|
|
components.get('topic/unlock').toggleClass('hidden', !data.isLocked).parent().attr('hidden', !data.isLocked ? '' : null);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2020-09-21 22:03:51 -04:00
|
|
|
var hideReply = !!((data.isLocked || ajaxify.data.deleted) && !ajaxify.data.privileges.isAdminOrMod);
|
2016-08-12 12:57:23 +03:00
|
|
|
|
|
|
|
|
components.get('topic/reply/container').toggleClass('hidden', hideReply);
|
|
|
|
|
components.get('topic/reply/locked').toggleClass('hidden', ajaxify.data.privileges.isAdminOrMod || !data.isLocked || ajaxify.data.deleted);
|
|
|
|
|
|
|
|
|
|
threadEl.find('[component="post"]:not(.deleted) [component="post/reply"], [component="post"]:not(.deleted) [component="post/quote"]').toggleClass('hidden', hideReply);
|
|
|
|
|
threadEl.find('[component="post/edit"], [component="post/delete"]').toggleClass('hidden', isLocked);
|
|
|
|
|
|
2016-10-13 11:42:29 +02:00
|
|
|
threadEl.find('[component="post"][data-uid="' + app.user.uid + '"].deleted [component="post/tools"]').toggleClass('hidden', isLocked);
|
2016-08-12 12:57:23 +03:00
|
|
|
|
2020-09-09 16:40:03 -04:00
|
|
|
$('[component="post/header"] [component="topic/locked"]').toggleClass('hidden', !data.isLocked);
|
2016-08-12 12:57:23 +03:00
|
|
|
$('[component="post/tools"] .dropdown-menu').html('');
|
|
|
|
|
ajaxify.data.locked = data.isLocked;
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
ThreadTools.setDeleteState = function (data) {
|
2015-03-17 13:38:18 -04:00
|
|
|
var threadEl = components.get('topic');
|
2014-10-08 15:36:47 -04:00
|
|
|
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-19 12:09:36 -05:00
|
|
|
components.get('topic/delete').toggleClass('hidden', data.isDelete).parent().attr('hidden', data.isDelete ? '' : null);
|
|
|
|
|
components.get('topic/restore').toggleClass('hidden', !data.isDelete).parent().attr('hidden', !data.isDelete ? '' : null);
|
|
|
|
|
components.get('topic/purge').toggleClass('hidden', !data.isDelete).parent().attr('hidden', !data.isDelete ? '' : null);
|
2015-04-02 22:06:18 -04:00
|
|
|
components.get('topic/deleted/message').toggleClass('hidden', !data.isDelete);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2019-02-06 11:29:18 -05:00
|
|
|
if (data.isDelete) {
|
|
|
|
|
app.parseAndTranslate('partials/topic/deleted-message', {
|
|
|
|
|
deleter: data.user,
|
|
|
|
|
deleted: true,
|
|
|
|
|
deletedTimestampISO: utils.toISOString(Date.now()),
|
|
|
|
|
}, function (html) {
|
|
|
|
|
components.get('topic/deleted/message').replaceWith(html);
|
|
|
|
|
html.find('.timeago').timeago();
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-08-12 12:57:23 +03:00
|
|
|
var hideReply = data.isDelete && !ajaxify.data.privileges.isAdminOrMod;
|
|
|
|
|
|
|
|
|
|
components.get('topic/reply/container').toggleClass('hidden', hideReply);
|
|
|
|
|
components.get('topic/reply/locked').toggleClass('hidden', ajaxify.data.privileges.isAdminOrMod || !ajaxify.data.locked || data.isDelete);
|
|
|
|
|
threadEl.find('[component="post"]:not(.deleted) [component="post/reply"], [component="post"]:not(.deleted) [component="post/quote"]').toggleClass('hidden', hideReply);
|
|
|
|
|
|
2014-10-08 15:36:47 -04:00
|
|
|
threadEl.toggleClass('deleted', data.isDelete);
|
2016-08-12 12:57:23 +03:00
|
|
|
ajaxify.data.deleted = data.isDelete;
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2016-08-12 12:57:23 +03:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
ThreadTools.setPinnedState = function (data) {
|
2015-03-17 13:38:18 -04:00
|
|
|
var threadEl = components.get('topic');
|
2015-04-02 22:06:18 -04:00
|
|
|
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
|
|
|
|
|
return;
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
2015-04-02 22:06:18 -04:00
|
|
|
|
2018-12-19 12:09:36 -05:00
|
|
|
components.get('topic/pin').toggleClass('hidden', data.isPinned).parent().attr('hidden', data.isPinned ? '' : null);
|
|
|
|
|
components.get('topic/unpin').toggleClass('hidden', !data.isPinned).parent().attr('hidden', !data.isPinned ? '' : null);
|
2020-09-09 16:40:03 -04:00
|
|
|
$('[component="post/header"] [component="topic/pinned"]').toggleClass('hidden', !data.isPinned);
|
2016-08-12 12:57:23 +03:00
|
|
|
ajaxify.data.pinned = data.isPinned;
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function setFollowState(state) {
|
2016-05-18 19:02:43 +03:00
|
|
|
var menu = components.get('topic/following/menu');
|
|
|
|
|
menu.toggleClass('hidden', state !== 'follow');
|
|
|
|
|
components.get('topic/following/check').toggleClass('fa-check', state === 'follow');
|
|
|
|
|
|
2016-05-19 14:20:34 +03:00
|
|
|
menu = components.get('topic/not-following/menu');
|
2016-05-18 19:02:43 +03:00
|
|
|
menu.toggleClass('hidden', state !== 'unfollow');
|
2016-05-19 14:20:34 +03:00
|
|
|
components.get('topic/not-following/check').toggleClass('fa-check', state === 'unfollow');
|
2016-05-18 19:02:43 +03:00
|
|
|
|
|
|
|
|
menu = components.get('topic/ignoring/menu');
|
2017-02-18 01:21:34 -07:00
|
|
|
menu.toggleClass('hidden', state !== 'ignore');
|
2016-05-18 19:02:43 +03:00
|
|
|
components.get('topic/ignoring/check').toggleClass('fa-check', state === 'ignore');
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ThreadTools;
|
|
|
|
|
});
|