Skip to content

Node.js based forum software built for the modern web

components

barisusakli9e3b2148baca
diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js
index f47108c7e1..eb64299dde 100644
--- a/public/src/client/topic/events.js
+++ b/public/src/client/topic/events.js
@@ -168,22 +168,16 @@ define('forum/topic/events', [
}
function togglePostFavourite(data) {
- var favBtn = $('[data-pid="' + data.post.pid + '"] .favourite');
+ var favBtn = $('[data-pid="' + data.post.pid + '"] [component="post/favourite"]');
+
if (!favBtn.length) {
return;
}
- favBtn.addClass('btn-warning')
- .attr('data-favourited', data.isFavourited);
+ favBtn.attr('data-favourited', data.isFavourited);
- var icon = favBtn.find('i');
- var className = icon.attr('class');
- if (!className) {
- return;
- }
- if (data.isFavourited ? className.indexOf('-o') !== -1 : className.indexOf('-o') === -1) {
- icon.attr('class', data.isFavourited ? className.replace('-o', '') : className + '-o');
- }
+ favBtn.find('[component="post/favourite/on"]').toggleClass('hidden', !data.isFavourited);
+ favBtn.find('[component="post/favourite/off"]').toggleClass('hidden', data.isFavourited);
}
function togglePostVote(data) {
@@ -192,7 +186,6 @@ define('forum/topic/events', [
post.find('[component="post/downvote"]').toggleClass('downvoted', data.downvote);
}
-
function onNewNotification(data) {
var tid = ajaxify.variables.get('topic_id');
if (data && data.tid && parseInt(data.tid, 10) === parseInt(tid, 10)) {
diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js
index 46a20d19b9..6cf70b112c 100644
--- a/public/src/client/topic/threadTools.js
+++ b/public/src/client/topic/threadTools.js
@@ -9,20 +9,13 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
ThreadTools.init = function(tid, threadState) {
ThreadTools.threadState = threadState;
- if (threadState.locked) {
- ThreadTools.setLockedState({tid: tid, isLocked: true});
- }
-
- if (threadState.deleted) {
- ThreadTools.setDeleteState({tid: tid, isDelete: true});
- }
-
- if (threadState.pinned) {
- ThreadTools.setPinnedState({tid: tid, isPinned: true});
- }
-
components.get('topic/delete').on('click', function() {
- topicCommand(threadState.deleted ? 'restore' : 'delete', tid);
+ topicCommand('delete', tid);
+ return false;
+ });
+
+ components.get('topic/restore').on('click', function() {
+ topicCommand('restore', tid);
return false;
});
@@ -32,19 +25,29 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
});
components.get('topic/lock').on('click', function() {
- socket.emit(threadState.locked ? 'topics.unlock' : 'topics.lock', {tids: [tid], cid: ajaxify.variables.get('category_id')});
+ socket.emit('topics.lock', {tids: [tid], cid: ajaxify.variables.get('category_id')});
+ return false;
+ });
+
+ components.get('topic/unlock').on('click', function() {
+ socket.emit('topics.unlock', {tids: [tid], cid: ajaxify.variables.get('category_id')});
return false;
});
components.get('topic/pin').on('click', function() {
- socket.emit(threadState.pinned ? 'topics.unpin' : 'topics.pin', {tids: [tid], cid: ajaxify.variables.get('category_id')});
+ socket.emit('topics.pin', {tids: [tid], cid: ajaxify.variables.get('category_id')});
+ return false;
+ });
+
+ components.get('topic/unpin').on('click', function() {
+ socket.emit('topics.unpin', {tids: [tid], cid: ajaxify.variables.get('category_id')});
return false;
});
components.get('topic/mark-unread-for-all').on('click', function() {
var btn = $(this);
socket.emit('topics.markAsUnreadForAll', [tid], function(err) {
- if(err) {
+ if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
@@ -60,12 +63,13 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
fork.init();
- components.get('topic').on('click', '[component="topic/follow"]', follow);
+ components.get('topic').on('click', '[component="topic/follow"], [component="topic/unfollow"]', follow);
components.get('topic/follow').off('click').on('click', follow);
+ components.get('topic/unfollow').off('click').on('click', follow);
function follow() {
socket.emit('topics.toggleFollow', tid, function(err, state) {
- if(err) {
+ if (err) {
return app.alert({
type: 'danger',
alert_id: 'topic_follow',
@@ -101,21 +105,20 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
ThreadTools.setLockedState = function(data) {
var threadEl = components.get('topic');
- if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) {
- var isLocked = data.isLocked && !app.user.isAdmin;
+ if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
+ return;
+ }
- components.get('topic/lock').translateHtml('<i class="fa fa-fw fa-' + (data.isLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (data.isLocked ? 'un': '') + 'lock]]');
+ var isLocked = data.isLocked && !app.user.isAdmin;
- translator.translate(isLocked ? '[[topic:locked]]' : '[[topic:reply]]', function(translated) {
- var className = isLocked ? 'fa-lock' : 'fa-reply';
- threadEl.find('[component="post/reply"]').html('<i class="fa ' + className + '"></i> ' + translated).attr('disabled', isLocked);
- $('[component="topic/reply"]').attr('disabled', isLocked).html(isLocked ? '<i class="fa fa-lock"></i> ' + translated : translated);
- });
+ components.get('topic/lock').toggleClass('hidden', data.isLocked);
+ components.get('topic/unlock').toggleClass('hidden', !data.isLocked);
+ components.get('topic/reply').toggleClass('hidden', isLocked);
+ components.get('topic/reply/locked').toggleClass('hidden', !isLocked);
- threadEl.find('[component="post/quote"], [component="post/edit"], [component="post/delete"]').toggleClass('hidden', isLocked);
- $('[component="post/header"] i.fa-lock').toggleClass('hide', !data.isLocked);
- ThreadTools.threadState.locked = data.isLocked;
- }
+ threadEl.find('[component="post/reply"], [component="post/quote"], [component="post/edit"], [component="post/delete"]').toggleClass('hidden', isLocked);
+ $('[component="post/header"] i.fa-lock').toggleClass('hidden', !data.isLocked);
+ ThreadTools.threadState.locked = data.isLocked;
};
ThreadTools.setDeleteState = function(data) {
@@ -124,48 +127,30 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
return;
}
- components.get('topic/delete').translateHtml('<i class="fa fa-fw ' + (data.isDelete ? 'fa-history' : 'fa-trash-o') + '"></i> [[topic:thread_tools.' + (data.isDelete ? 'restore' : 'delete') + ']]');
+ components.get('topic/delete').toggleClass('hidden', data.isDelete);
+ components.get('topic/restore').toggleClass('hidden', !data.isDelete);
+ components.get('topic/purge').toggleClass('hidden', !data.isDelete);
+ components.get('topic/deleted/message').toggleClass('hidden', !data.isDelete);
threadEl.toggleClass('deleted', data.isDelete);
ThreadTools.threadState.deleted = data.isDelete;
-
- components.get('topic/purge').toggleClass('hidden', !data.isDelete);
-
- if (data.isDelete) {
- translator.translate('[[topic:deleted_message]]', function(translated) {
- $('<div id="thread-deleted" class="alert alert-warning">' + translated + '</div>').insertBefore(threadEl);
- });
- } else {
- $('#thread-deleted').remove();
- }
};
ThreadTools.setPinnedState = function(data) {
var threadEl = components.get('topic');
- if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) {
- translator.translate('<i class="fa fa-fw fa-thumb-tack"></i> [[topic:thread_tools.' + (data.isPinned ? 'unpin' : 'pin') + ']]', function(translated) {
- components.get('topic/pin').html(translated);
- ThreadTools.threadState.pinned = data.isPinned;
- });
- $('[component="post/header"] i.fa-thumb-tack').toggleClass('hide', !data.isPinned);
+ if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
+ return;
}
+
+ ThreadTools.threadState.pinned = data.isPinned;
+ components.get('topic/pin').toggleClass('hidden', data.isPinned);
+ components.get('topic/unpin').toggleClass('hidden', !data.isPinned);
+ $('[component="post/header"] i.fa-thumb-tack').toggleClass('hidden', !data.isPinned);
};
function setFollowState(state) {
- var title = state ? '[[topic:unwatch.title]]' : '[[topic:watch.title]]';
- var iconClass = state ? 'fa fa-eye-slash' : 'fa fa-eye';
- var text = state ? '[[topic:unwatch]]' : '[[topic:watch]]';
-
- var followEl = components.get('topic/follow');
-
- translator.translate(title, function(titleTranslated) {
- followEl.attr('title', titleTranslated).find('i').attr('class', iconClass);
- followEl.find('span').text(text);
-
- translator.translate(followEl.html(), function(translated) {
- followEl.html(translated);
- });
- });
+ components.get('topic/follow').toggleClass('hidden', state);
+ components.get('topic/unfollow').toggleClass('hidden', !state);
}
diff --git a/src/privileges/topics.js b/src/privileges/topics.js
index 5820c0e7a6..01bdd6c4f1 100644
--- a/src/privileges/topics.js
+++ b/src/privileges/topics.js
@@ -16,9 +16,11 @@ module.exports = function(privileges) {
privileges.topics = {};
privileges.topics.get = function(tid, uid, callback) {
+ var topic;
async.waterfall([
- async.apply(topics.getTopicFields, tid, ['cid', 'uid']),
- function(topic, next) {
+ async.apply(topics.getTopicFields, tid, ['cid', 'uid', 'locked']),
+ function(_topic, next) {
+ topic = _topic;
async.parallel({
'topics:reply': async.apply(helpers.isUserAllowedTo, 'topics:reply', uid, [topic.cid]),
read: async.apply(helpers.isUserAllowedTo, 'read', uid, [topic.cid]),
@@ -36,12 +38,13 @@ module.exports = function(privileges) {
}
var disabled = parseInt(results.disabled, 10) === 1;
+ var locked = parseInt(topic.locked, 10) === 1;
var isAdminOrMod = results.isAdministrator || results.isModerator;
var editable = isAdminOrMod;
var deletable = isAdminOrMod || results.isOwner;
plugins.fireHook('filter:privileges.topics.get', {
- 'topics:reply': results['topics:reply'][0] || isAdminOrMod,
+ 'topics:reply': (results['topics:reply'][0] && !locked) || isAdminOrMod,
read: results.read[0] || isAdminOrMod,
view_thread_tools: editable || deletable,
editable: editable,
diff --git a/src/threadTools.js b/src/threadTools.js
index 1d13440cad..aa83f99eb7 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -47,6 +47,7 @@ var async = require('async'),
tid: tid,
cid: topicData.cid,
isDelete: isDelete,
+ isLocked: isDelete,
uid: uid
};