mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: #8521, allow editing title before posting from queue
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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));
|
||||
};
|
||||
|
||||
|
||||
@@ -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 });
|
||||
};
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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]]');
|
||||
|
||||
Reference in New Issue
Block a user