Files
NodeBB/public/src/forum/topic/threadTools.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

'use strict';
/* globals define, app, translator, ajaxify, socket, bootbox */
define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {
var ThreadTools = {};
ThreadTools.init = function(tid, threadState) {
if (ajaxify.variables.get('expose_tools') === '1') {
2014-03-18 16:46:07 -04:00
$('.thread-tools').removeClass('hide');
2014-03-18 16:46:07 -04:00
$('.delete_thread').on('click', function(e) {
var command = threadState.deleted !== '1' ? 'delete' : 'restore';
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
bootbox.confirm(msg, function(confirm) {
if (confirm) {
socket.emit('topics.' + command, [tid]);
}
});
2014-03-18 16:46:07 -04:00
});
2014-03-18 16:46:07 -04:00
return false;
});
2014-03-18 16:46:07 -04:00
$('.lock_thread').on('click', function(e) {
socket.emit(threadState.locked !== '1' ? 'topics.lock' : 'topics.unlock', [tid]);
2014-03-18 16:46:07 -04:00
return false;
});
2014-03-18 16:46:07 -04:00
$('.pin_thread').on('click', function(e) {
socket.emit(threadState.pinned !== '1' ? 'topics.pin' : 'topics.unpin', [tid]);
2014-03-18 16:46:07 -04:00
return false;
});
$('.markAsUnreadForAll').on('click', function() {
var btn = $(this);
socket.emit('topics.markAsUnreadForAll', [tid], function(err) {
2014-03-18 16:46:07 -04:00
if(err) {
return app.alertError(err.message);
}
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
btn.parents('.thread-tools.open').find('.dropdown-toggle').trigger('click');
});
return false;
});
$('.move_thread').on('click', function(e) {
move.init([tid], ajaxify.variables.get('category_id'));
return false;
});
2014-03-18 16:46:07 -04:00
fork.init();
}
socket.emit('topics.followCheck', tid, function(err, state) {
setFollowState(state, false);
});
2014-03-18 16:46:07 -04:00
$('.posts').on('click', '.follow', function() {
socket.emit('topics.follow', tid, function(err, state) {
if(err) {
2014-03-18 16:46:07 -04:00
return app.alert({
type: 'danger',
alert_id: 'topic_follow',
title: '[[global:please_log_in]]',
message: '[[topic:login_to_subscribe]]',
timeout: 5000
});
}
2014-03-18 16:46:07 -04:00
setFollowState(state, true);
});
2014-03-18 16:46:07 -04:00
return false;
});
};
2014-03-18 16:46:07 -04:00
function setFollowState(state, alert) {
$('.posts .follow').toggleClass('btn-success', state).attr('title', state ? 'You are currently receiving updates to this topic' : 'Be notified of new replies in this topic');
if(alert) {
2014-04-19 12:02:33 +01:00
app.alertSuccess(state ? '[[topic:following_topic.message]]' : '[[topic:not_following_topic.message]]');
2014-03-18 16:46:07 -04:00
}
}
return ThreadTools;
2014-04-10 20:31:57 +01:00
});