Skip to content

Node.js based forum software built for the modern web

closes #2309

barisusakli5bc2e7dac2dd
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.json
index 00a2ba412d..12eeb0f660 100644
--- a/public/language/en_GB/modules.json
+++ b/public/language/en_GB/modules.json
@@ -18,5 +18,6 @@
"composer.user_said_in": "%1 said in %2:",
"composer.user_said": "%1 said:",
- "composer.discard": "Are you sure you wish to discard this post?"
+ "composer.discard": "Are you sure you wish to discard this post?",
+ "composer.submit_and_lock": "Submit and Lock"
}
\ No newline at end of file
diff --git a/public/src/client/category.js b/public/src/client/category.js
index cdfb7495f5..2a6a580323 100644
--- a/public/src/client/category.js
+++ b/public/src/client/category.js
@@ -20,12 +20,6 @@ define('forum/category', [
}
});
- $(window).on('action:composer.topics.post', function(ev, data) {
- localStorage.removeItem('category:' + data.data.cid + ':bookmark');
- localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked');
- ajaxify.go('topic/' + data.data.slug);
- });
-
function removeListeners() {
socket.removeListener('event:new_topic', Category.onNewTopic);
categoryTools.removeListeners();
diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index 71706704cb..33fa2ac208 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -43,6 +43,12 @@ define('composer', [
}
});
+ $(window).on('action:composer.topics.post', function(ev, data) {
+ localStorage.removeItem('category:' + data.data.cid + ':bookmark');
+ localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked');
+ ajaxify.go('topic/' + data.data.slug);
+ });
+
// Query server for formatting options
socket.emit('modules.composer.getFormattingOptions', function(err, options) {
composer.formatting = options;
@@ -131,12 +137,18 @@ define('composer', [
};
composer.newTopic = function(cid) {
- push({
- cid: cid,
- title: '',
- body: '',
- modified: false,
- isMain: true
+ socket.emit('categories.isModerator', cid, function(err, isMod) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+ push({
+ cid: cid,
+ title: '',
+ body: '',
+ modified: false,
+ isMain: true,
+ isMod: isMod
+ });
});
};
@@ -166,14 +178,20 @@ define('composer', [
};
composer.newReply = function(tid, pid, title, text) {
- translator.translate(text, config.defaultLang, function(translated) {
- push({
- tid: tid,
- toPid: pid,
- title: title,
- body: translated,
- modified: false,
- isMain: false
+ socket.emit('topics.isModerator', tid, function(err, isMod) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+ translator.translate(text, config.defaultLang, function(translated) {
+ push({
+ tid: tid,
+ toPid: pid,
+ title: title,
+ body: translated,
+ modified: false,
+ isMain: false,
+ isMod: isMod
+ });
});
});
};
@@ -247,11 +265,13 @@ define('composer', [
}
function createNewComposer(post_uuid) {
- var allowTopicsThumbnail = config.allowTopicsThumbnail && composer.posts[post_uuid].isMain && (config.hasImageUploadPlugin || config.allowFileUploads),
- isTopic = composer.posts[post_uuid] ? !!composer.posts[post_uuid].cid : false,
- isMain = composer.posts[post_uuid] ? !!composer.posts[post_uuid].isMain : false,
- isEditing = composer.posts[post_uuid] ? !!composer.posts[post_uuid].pid : false,
- isGuestPost = composer.posts[post_uuid] ? parseInt(composer.posts[post_uuid].uid, 10) === 0 : null;
+ var postData = composer.posts[post_uuid];
+
+ var allowTopicsThumbnail = config.allowTopicsThumbnail && postData.isMain && (config.hasImageUploadPlugin || config.allowFileUploads),
+ isTopic = postData ? !!postData.cid : false,
+ isMain = postData ? !!postData.isMain : false,
+ isEditing = postData ? !!postData.pid : false,
+ isGuestPost = postData ? parseInt(postData.uid, 10) === 0 : false;
composer.bsEnvironment = utils.findBootstrapEnvironment();
@@ -262,9 +282,11 @@ define('composer', [
minimumTagLength: config.minimumTagLength,
maximumTagLength: config.maximumTagLength,
isTopic: isTopic,
- showHandleInput: (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)) && config.allowGuestHandles,
- handle: composer.posts[post_uuid] ? composer.posts[post_uuid].handle || '' : undefined,
- formatting: composer.formatting
+ isEditing: isEditing,
+ showHandleInput: config.allowGuestHandles && (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)),
+ handle: postData ? postData.handle || '' : undefined,
+ formatting: composer.formatting,
+ isAdminOrMod: app.user.isAdmin || postData.isMod
};
parseAndTranslate('composer', data, function(composerTemplate) {
@@ -278,7 +300,6 @@ define('composer', [
$(document.body).append(composerTemplate);
var postContainer = $(composerTemplate[0]),
- postData = composer.posts[post_uuid],
bodyEl = postContainer.find('textarea'),
draft = drafts.getDraft(postData.save_id);
@@ -309,6 +330,11 @@ define('composer', [
post(post_uuid);
});
+ postContainer.on('click', '[data-action="post-lock"]', function() {
+ $(this).attr('disabled', true);
+ post(post_uuid, {lock: true});
+ });
+
postContainer.on('click', '[data-action="discard"]', function() {
if (!composer.posts[post_uuid].modified) {
discard(post_uuid);
@@ -438,7 +464,7 @@ define('composer', [
}
}
- function post(post_uuid) {
+ function post(post_uuid, options) {
var postData = composer.posts[post_uuid],
postContainer = $('#cmp-uuid-' + post_uuid),
handleEl = postContainer.find('.handle'),
@@ -446,6 +472,8 @@ define('composer', [
bodyEl = postContainer.find('textarea'),
thumbEl = postContainer.find('input#topic-thumb-url');
+ options = options || {};
+
titleEl.val(titleEl.val().trim());
bodyEl.val(bodyEl.val().trim());
if (thumbEl.length) {
@@ -471,28 +499,27 @@ define('composer', [
var composerData = {}, action;
if (parseInt(postData.cid, 10) > 0) {
+ action = 'topics.post';
composerData = {
handle: handleEl ? handleEl.val() : undefined,
title: titleEl.val(),
content: bodyEl.val(),
topic_thumb: thumbEl.val() || '',
category_id: postData.cid,
- tags: tags.getTags(post_uuid)
+ tags: tags.getTags(post_uuid),
+ lock: options.lock || false
};
-
- action = 'topics.post';
- socket.emit(action, composerData, done);
} else if (parseInt(postData.tid, 10) > 0) {
+ action = 'posts.reply';
composerData = {
tid: postData.tid,
handle: handleEl ? handleEl.val() : undefined,
content: bodyEl.val(),
- toPid: postData.toPid
+ toPid: postData.toPid,
+ lock: options.lock || false
};
-
- action = 'posts.reply';
- socket.emit(action, composerData, done);
} else if (parseInt(postData.pid, 10) > 0) {
+ action = 'posts.edit';
composerData = {
pid: postData.pid,
handle: handleEl ? handleEl.val() : undefined,
@@ -501,12 +528,9 @@ define('composer', [
topic_thumb: thumbEl.val() || '',
tags: tags.getTags(post_uuid)
};
-
- action = 'posts.edit';
- socket.emit(action, composerData, done);
}
- function done(err, data) {
+ socket.emit(action, composerData, function (err, data) {
$('[data-action="post"]').removeAttr('disabled');
if (err) {
if (err.message === '[[error:email-not-confirmed]]') {
@@ -520,7 +544,7 @@ define('composer', [
drafts.removeDraft(postData.save_id);
$(window).trigger('action:composer.' + action, {composerData: composerData, data: data});
- }
+ });
}
function discard(post_uuid) {
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js
index 9f20697ef9..d98cb0c21f 100644
--- a/src/socket.io/categories.js
+++ b/src/socket.io/categories.js
@@ -118,4 +118,8 @@ SocketCategories.ignore = function(socket, cid, callback) {
});
};
+SocketCategories.isModerator = function(socket, cid, callback) {
+ user.isModerator(socket.uid, cid, callback);
+};
+
module.exports = SocketCategories;
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index e8f5ef9a63..b49e796e7a 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -50,6 +50,10 @@ SocketPosts.reply = function(socket, data, callback) {
socket.emit('event:new_post', result);
SocketPosts.notifyOnlineUsers(socket.uid, result);
+
+ if (data.lock) {
+ socketTopics.doTopicAction('lock', 'event:topic_locked', socket, {tids: [postData.topic.tid], cid: postData.topic.cid});
+ }
});
};
@@ -362,9 +366,9 @@ SocketPosts.purge = function(socket, data, callback) {
});
callback();
- });
+ });
}
-
+
if (!data || !parseInt(data.pid, 10)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -500,7 +504,7 @@ SocketPosts.flag = function(socket, pid, callback) {
}
notifications.push(notification, results.admins.concat(results.moderators), next);
});
- }
+ }
], callback);
};
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index b0f9d3b8c7..c270082953 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -41,6 +41,10 @@ SocketTopics.post = function(socket, data, callback) {
return callback(err);
}
+ if (data.lock) {
+ SocketTopics.doTopicAction('lock', 'event:topic_locked', socket, {tids: [result.topicData.tid], cid: result.topicData.cid});
+ }
+
callback(null, result.topicData);
socket.emit('event:new_post', {posts: [result.postData]});
socket.emit('event:new_topic', result.topicData);
@@ -233,6 +237,7 @@ SocketTopics.unpin = function(socket, data, callback) {
};
SocketTopics.doTopicAction = function(action, event, socket, data, callback) {
+ callback = callback || function() {};
if (!socket.uid) {
return;
}
@@ -550,4 +555,13 @@ SocketTopics.loadMoreTags = function(socket, data, callback) {
});
};
+SocketTopics.isModerator = function(socket, tid, callback) {
+ topics.getTopicField(tid, 'cid', function(err, cid) {
+ if (err) {
+ return callback(err);
+ }
+ user.isModerator(socket.uid, cid, callback);
+ });
+};
+
module.exports = SocketTopics;