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

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 8ddc8dd10f
commit 2485a55092

@ -22,31 +22,38 @@ define('admin/manage/post-queue', function () {
return false; 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); var el = $(this);
el.addClass('hidden'); el.addClass('hidden');
var textareaParent = el.parent().find('.post-content-editable'); var inputEl = el.parent().find(editableClass);
textareaParent.removeClass('hidden').find('textarea').focus(); 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 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 id = textarea.parents('[data-id]').attr('data-id');
var titleEdit = displayClass === '.topic-title';
socket.emit('posts.editQueuedContent', { socket.emit('posts.editQueuedContent', {
id: id, id: id,
content: textarea.val(), title: titleEdit ? textarea.val() : undefined,
content: titleEdit ? undefined : textarea.val(),
}, function (err, data) { }, function (err, data) {
if (err) { if (err) {
return app.alertError(err); return app.alertError(err);
} }
preview.html(data.postData.content); preview.html(titleEdit ? data.postData.title : data.postData.content);
textarea.parent().addClass('hidden'); textarea.parent().addClass('hidden');
preview.removeClass('hidden'); preview.removeClass('hidden');
}); });
}); });
}; }
return PostQueue; return PostQueue;
}); });

@ -147,7 +147,7 @@ module.exports = function (Posts) {
socketHelpers.notifyNew(data.uid, 'newPost', result); 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); const canEditQueue = await Posts.canEditQueue(uid, id);
if (!canEditQueue) { if (!canEditQueue) {
throw new Error('[[error:no-privileges]]'); throw new Error('[[error:no-privileges]]');
@ -156,7 +156,12 @@ module.exports = function (Posts) {
if (!data) { if (!data) {
return; 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)); 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) { 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]]'); 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 }); return await plugins.fireHook('filter:parse.post', { postData: data });
}; };

@ -19,7 +19,7 @@
<tr> <tr>
<th>[[admin/manage/post-queue:user]]</th> <th>[[admin/manage/post-queue:user]]</th>
<th>[[admin/manage/post-queue:category]]</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: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>[[admin/manage/post-queue:posted]]</th>
<th></th> <th></th>
@ -44,9 +44,14 @@
<!-- ENDIF posts.data.tid --> <!-- ENDIF posts.data.tid -->
{posts.data.title} {posts.data.title}
</td> </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">{posts.data.content}</td>
<td class="col-md-5 post-content-editable hidden"> <td class="col-md-5 post-content-editable hidden">
<textarea>{posts.data.rawContent}</textarea> <textarea class="form-control">{posts.data.rawContent}</textarea>
</td> </td>
<td class="col-md-1"> <td class="col-md-1">
<span class="timeago" title={posts.data.timestampISO}></span> <span class="timeago" title={posts.data.timestampISO}></span>

@ -1012,6 +1012,7 @@ describe('Post\'s', function () {
describe('post queue', function () { describe('post queue', function () {
var uid; var uid;
var queueId; var queueId;
var topicQueueId;
var jar; var jar;
before(function (done) { before(function (done) {
meta.config.postQueue = 1; meta.config.postQueue = 1;
@ -1033,6 +1034,7 @@ describe('Post\'s', function () {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(result.queued, true); assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]'); assert.equal(result.message, '[[success:post-queued]]');
topicQueueId = result.id;
done(); 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) { it('should prevent regular users from approving posts', function (done) {
socketPosts.accept({ uid: uid }, { id: queueId }, function (err) { socketPosts.accept({ uid: uid }, { id: queueId }, function (err) {
assert.equal(err.message, '[[error:no-privileges]]'); assert.equal(err.message, '[[error:no-privileges]]');

Loading…
Cancel
Save