Skip to content

Node.js based forum software built for the modern web

feat: #8521, allow editing title before posting from queue

Barış Soner Uşaklı2485a5509247
diff --git a/public/src/admin/manage/post-queue.js b/public/src/admin/manage/post-queue.js
index f3a023b5d2..98abbbed32 100644
--- a/public/src/admin/manage/post-queue.js
+++ b/public/src/admin/manage/post-queue.js
@@ -22,31 +22,38 @@ define('admin/manage/post-queue', function () {
return false;
});
- $('.posts-list').on('click', '.post-content', function () {
+ handleContentEdit('.post-content', '.post-content-editable', 'textarea');
+ handleContentEdit('.topic-title', '.topic-title-editable', 'input');
+ };
+
+ function handleContentEdit(displayClass, editableClass, inputSelector) {
+ $('.posts-list').on('click', displayClass, function () {
var el = $(this);
el.addClass('hidden');
- var textareaParent = el.parent().find('.post-content-editable');
- textareaParent.removeClass('hidden').find('textarea').focus();
+ var inputEl = el.parent().find(editableClass);
+ inputEl.removeClass('hidden').find(inputSelector).focus();
});
- $('.posts-list').on('blur', '.post-content-editable textarea', function () {
+ $('.posts-list').on('blur', editableClass + ' ' + inputSelector, function () {
var textarea = $(this);
- var preview = textarea.parent().parent().find('.post-content');
+ var preview = textarea.parent().parent().find(displayClass);
var id = textarea.parents('[data-id]').attr('data-id');
+ var titleEdit = displayClass === '.topic-title';
socket.emit('posts.editQueuedContent', {
id: id,
- content: textarea.val(),
+ title: titleEdit ? textarea.val() : undefined,
+ content: titleEdit ? undefined : textarea.val(),
}, function (err, data) {
if (err) {
return app.alertError(err);
}
- preview.html(data.postData.content);
+ preview.html(titleEdit ? data.postData.title : data.postData.content);
textarea.parent().addClass('hidden');
preview.removeClass('hidden');
});
});
- };
+ }
return PostQueue;
});
diff --git a/src/posts/queue.js b/src/posts/queue.js
index 04753b04e3..006634f557 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -147,7 +147,7 @@ module.exports = function (Posts) {
socketHelpers.notifyNew(data.uid, 'newPost', result);
}
- Posts.editQueuedContent = async function (uid, id, content) {
+ Posts.editQueuedContent = async function (uid, id, content, title) {
const canEditQueue = await Posts.canEditQueue(uid, id);
if (!canEditQueue) {
throw new Error('[[error:no-privileges]]');
@@ -156,7 +156,12 @@ module.exports = function (Posts) {
if (!data) {
return;
}
- data.data.content = content;
+ if (content !== undefined) {
+ data.data.content = content;
+ }
+ if (title !== undefined) {
+ data.data.title = title;
+ }
await db.setObjectField('post:queue:' + id, 'data', JSON.stringify(data.data));
};
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 588ca5b202..e3ea71da0b 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -174,10 +174,10 @@ async function acceptOrReject(method, socket, data) {
}
SocketPosts.editQueuedContent = async function (socket, data) {
- if (!data || !data.id || !data.content) {
+ if (!data || !data.id || (!data.content && !data.title)) {
throw new Error('[[error:invalid-data]]');
}
- await posts.editQueuedContent(socket.uid, data.id, data.content);
+ await posts.editQueuedContent(socket.uid, data.id, data.content, data.title);
return await plugins.fireHook('filter:parse.post', { postData: data });
};
diff --git a/src/views/admin/manage/post-queue.tpl b/src/views/admin/manage/post-queue.tpl
index decf23b657..086f13a7fb 100644
--- a/src/views/admin/manage/post-queue.tpl
+++ b/src/views/admin/manage/post-queue.tpl
@@ -19,7 +19,7 @@
<tr>
<th>[[admin/manage/post-queue:user]]</th>
<th>[[admin/manage/post-queue:category]]</th>
- <th>[[admin/manage/post-queue:title]]</th>
+ <th>[[admin/manage/post-queue:title]] <i class="fa fa-info-circle" data-toggle="tooltip" title="[[admin/manage/post-queue:content-editable]]"></i></th>
<th>[[admin/manage/post-queue:content]] <i class="fa fa-info-circle" data-toggle="tooltip" title="[[admin/manage/post-queue:content-editable]]"></i></th>
<th>[[admin/manage/post-queue:posted]]</th>
<th></th>
@@ -44,9 +44,14 @@
<!-- ENDIF posts.data.tid -->
{posts.data.title}
</td>
+ {{{if !posts.data.tid}}}
+ <td class="col-md-2 topic-title-editable hidden">
+ <input class="form-control" type="text" value="{posts.data.title}"/>
+ </td>
+ {{{end}}}
<td class="col-md-5 post-content">{posts.data.content}</td>
<td class="col-md-5 post-content-editable hidden">
- <textarea>{posts.data.rawContent}</textarea>
+ <textarea class="form-control">{posts.data.rawContent}</textarea>
</td>
<td class="col-md-1">
<span class="timeago" title={posts.data.timestampISO}></span>
diff --git a/test/posts.js b/test/posts.js
index df8b113f89..cf94181492 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -1012,6 +1012,7 @@ describe('Post\'s', function () {
describe('post queue', function () {
var uid;
var queueId;
+ var topicQueueId;
var jar;
before(function (done) {
meta.config.postQueue = 1;
@@ -1033,6 +1034,7 @@ describe('Post\'s', function () {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
+ topicQueueId = result.id;
done();
});
@@ -1082,6 +1084,18 @@ describe('Post\'s', function () {
});
});
+ it('should edit topic title in queue', function (done) {
+ socketPosts.editQueuedContent({ uid: globalModUid }, { id: topicQueueId, title: 'new topic title' }, function (err) {
+ assert.ifError(err);
+ request(nconf.get('url') + '/api/post-queue', { jar: jar, json: true }, function (err, res, body) {
+ assert.ifError(err);
+ assert.equal(body.posts[0].type, 'topic');
+ assert.equal(body.posts[0].data.title, 'new topic title');
+ done();
+ });
+ });
+ });
+
it('should prevent regular users from approving posts', function (done) {
socketPosts.accept({ uid: uid }, { id: queueId }, function (err) {
assert.equal(err.message, '[[error:no-privileges]]');