v1.18.x
Barış Soner Uşaklı 8 years ago
parent b3227c7742
commit 25cd21fba8

@ -6,5 +6,6 @@
"title": "Title",
"content": "Content",
"posted": "Posted",
"reply-to": "Reply to \"%1\""
"reply-to": "Reply to \"%1\"",
"content-editable": "You can click on individual content to edit before posting."
}

@ -5,6 +5,8 @@ define('admin/manage/post-queue', function () {
var PostQueue = {};
PostQueue.init = function () {
$('[data-toggle="tooltip"]').tooltip();
$('.posts-list').on('click', '[data-action]', function () {
var parent = $(this).parents('[data-id]');
var action = $(this).attr('data-action');
@ -19,6 +21,18 @@ define('admin/manage/post-queue', function () {
});
return false;
});
$('.posts-list').on('input', '[data-id]', function () {
var el = $(this);
socket.emit('posts.editQueuedContent', {
id: el.attr('data-id'),
content: el.find('.post-content').html(),
}, function (err) {
if (err) {
return app.alertError(err);
}
});
});
};
return PostQueue;

@ -70,6 +70,8 @@ module.exports = function (Posts) {
},
function (next) {
next(null, {
id: id,
type: type,
queued: true,
message: '[[success:post-queued]]',
});
@ -178,4 +180,27 @@ module.exports = function (Posts) {
},
], callback);
}
Posts.editQueuedContent = function (uid, id, content, callback) {
async.waterfall([
function (next) {
user.isAdminOrGlobalMod(uid, next);
},
function (isAdminOrGlobalMod, next) {
if (!isAdminOrGlobalMod) {
return callback(new Error('[[error:no-privileges]]'));
}
db.getObject('post:queue:' + id, next);
},
function (data, next) {
try {
data.data = JSON.parse(data.data);
} catch (err) {
return next(err);
}
data.data.content = content;
db.setObjectField('post:queue:' + id, 'data', JSON.stringify(data.data), next);
},
], callback);
};
};

@ -175,6 +175,12 @@ SocketPosts.accept = function (socket, data, callback) {
SocketPosts.reject = function (socket, data, callback) {
acceptOrReject(posts.removeFromQueue, socket, data, callback);
};
SocketPosts.editQueuedContent = function (socket, data, callback) {
if (!data || !data.id || !data.content) {
return callback(new Error('[[error:invalid-data]]'));
}
posts.editQueuedContent(socket.uid, data.id, data.content, callback);
};
function acceptOrReject(method, socket, data, callback) {
async.waterfall([

@ -18,7 +18,7 @@
<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:content]]</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>
</tr>
@ -42,9 +42,7 @@
<!-- ENDIF posts.data.tid -->
{posts.data.title}
</td>
<td class="col-md-5">
{posts.data.content}
</td>
<td class="col-md-5 post-content" contenteditable="true">{posts.data.content}</td>
<td class="col-md-1">
<span class="timeago" title={posts.data.timestampISO}></span>
</td>

@ -761,6 +761,8 @@ describe('Post\'s', function () {
describe('post queue', function () {
var uid;
var queueId;
var jar;
before(function (done) {
meta.config.postQueue = 1;
user.create({ username: 'newuser' }, function (err, _uid) {
@ -780,6 +782,7 @@ describe('Post\'s', function () {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
done();
});
});
@ -789,12 +792,14 @@ describe('Post\'s', function () {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
queueId = result.id;
done();
});
});
it('should load queued posts', function (done) {
helpers.loginUser('globalmod', 'globalmodpwd', function (err, jar) {
helpers.loginUser('globalmod', 'globalmodpwd', function (err, _jar) {
jar = _jar;
assert.ifError(err);
request(nconf.get('url') + '/api/post-queue', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
@ -807,6 +812,25 @@ describe('Post\'s', function () {
});
});
it('should error if data is invalid', function (done) {
socketPosts.editQueuedContent({ uid: globalModUid }, null, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
});
it('should edit post in queue', function (done) {
socketPosts.editQueuedContent({ uid: globalModUid }, { id: queueId, content: 'newContent' }, 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[1].type, 'reply');
assert.equal(body.posts[1].data.content, 'newContent');
done();
});
});
});
it('should accept queued posts submit', function (done) {
var ids;
async.waterfall([

Loading…
Cancel
Save