components

This commit is contained in:
barisusakli
2015-04-02 22:06:18 -04:00
parent 04f536854c
commit 9e3b2148ba
4 changed files with 60 additions and 78 deletions

View File

@@ -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;
components.get('topic/lock').translateHtml('<i class="fa fa-fw fa-' + (data.isLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (data.isLocked ? 'un': '') + 'lock]]');
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);
});
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;
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
return;
}
var isLocked = data.isLocked && !app.user.isAdmin;
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/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);
}