2017-08-15 12:59:40 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
2020-08-26 21:56:14 -04:00
|
|
|
define('forum/post-queue', ['categorySelector'], function (categorySelector) {
|
2017-08-15 12:59:40 -04:00
|
|
|
var PostQueue = {};
|
|
|
|
|
|
|
|
|
|
PostQueue.init = function () {
|
2017-10-31 10:53:28 -04:00
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
|
|
|
|
2017-08-15 12:59:40 -04:00
|
|
|
$('.posts-list').on('click', '[data-action]', function () {
|
|
|
|
|
var parent = $(this).parents('[data-id]');
|
|
|
|
|
var action = $(this).attr('data-action');
|
|
|
|
|
var id = parent.attr('data-id');
|
2020-08-27 17:36:58 -04:00
|
|
|
var listContainer = parent.get(0).parentNode;
|
2017-08-15 12:59:40 -04:00
|
|
|
|
2020-08-27 17:36:58 -04:00
|
|
|
if (!['accept', 'reject'].some(function (valid) {
|
|
|
|
|
return action === valid;
|
|
|
|
|
})) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.emit('posts.' + action, { id: id }, function (err) {
|
2017-08-15 12:59:40 -04:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
parent.remove();
|
2020-08-27 17:36:58 -04:00
|
|
|
|
|
|
|
|
if (listContainer.childElementCount === 0) {
|
|
|
|
|
ajaxify.refresh();
|
|
|
|
|
}
|
2017-08-15 12:59:40 -04:00
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2017-10-31 10:53:28 -04:00
|
|
|
|
2020-07-20 21:28:17 -04:00
|
|
|
handleContentEdit('.post-content', '.post-content-editable', 'textarea');
|
|
|
|
|
handleContentEdit('.topic-title', '.topic-title-editable', 'input');
|
2020-07-23 16:43:56 -04:00
|
|
|
|
|
|
|
|
$('.posts-list').on('click', '.topic-category[data-editable]', function () {
|
|
|
|
|
var $this = $(this);
|
|
|
|
|
var id = $this.parents('[data-id]').attr('data-id');
|
|
|
|
|
categorySelector.modal(ajaxify.data.allCategories, function (cid) {
|
|
|
|
|
var category = ajaxify.data.allCategories.find(function (c) {
|
|
|
|
|
return parseInt(c.cid, 10) === parseInt(cid, 10);
|
|
|
|
|
});
|
|
|
|
|
socket.emit('posts.editQueuedContent', {
|
|
|
|
|
id: id,
|
|
|
|
|
cid: cid,
|
|
|
|
|
}, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
app.parseAndTranslate('admin/manage/post-queue', 'posts', {
|
|
|
|
|
posts: [{
|
|
|
|
|
category: category,
|
|
|
|
|
}],
|
|
|
|
|
}, function (html) {
|
|
|
|
|
$this.replaceWith(html.find('.topic-category'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2020-07-20 21:28:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function handleContentEdit(displayClass, editableClass, inputSelector) {
|
|
|
|
|
$('.posts-list').on('click', displayClass, function () {
|
2017-10-31 10:53:28 -04:00
|
|
|
var el = $(this);
|
2018-05-30 14:21:03 -04:00
|
|
|
el.addClass('hidden');
|
2020-07-20 21:28:17 -04:00
|
|
|
var inputEl = el.parent().find(editableClass);
|
|
|
|
|
inputEl.removeClass('hidden').find(inputSelector).focus();
|
2018-05-30 14:21:03 -04:00
|
|
|
});
|
|
|
|
|
|
2020-07-20 21:28:17 -04:00
|
|
|
$('.posts-list').on('blur', editableClass + ' ' + inputSelector, function () {
|
2018-05-30 14:21:03 -04:00
|
|
|
var textarea = $(this);
|
2020-07-20 21:28:17 -04:00
|
|
|
var preview = textarea.parent().parent().find(displayClass);
|
2018-05-30 14:21:03 -04:00
|
|
|
var id = textarea.parents('[data-id]').attr('data-id');
|
2020-07-20 21:28:17 -04:00
|
|
|
var titleEdit = displayClass === '.topic-title';
|
2018-05-30 14:21:03 -04:00
|
|
|
|
2017-10-31 10:53:28 -04:00
|
|
|
socket.emit('posts.editQueuedContent', {
|
2018-05-30 14:21:03 -04:00
|
|
|
id: id,
|
2020-07-20 21:28:17 -04:00
|
|
|
title: titleEdit ? textarea.val() : undefined,
|
|
|
|
|
content: titleEdit ? undefined : textarea.val(),
|
2018-05-30 14:21:03 -04:00
|
|
|
}, function (err, data) {
|
2017-10-31 10:53:28 -04:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err);
|
|
|
|
|
}
|
2020-07-20 21:28:17 -04:00
|
|
|
preview.html(titleEdit ? data.postData.title : data.postData.content);
|
2018-05-30 14:21:03 -04:00
|
|
|
textarea.parent().addClass('hidden');
|
|
|
|
|
preview.removeClass('hidden');
|
2017-10-31 10:53:28 -04:00
|
|
|
});
|
|
|
|
|
});
|
2020-07-20 21:28:17 -04:00
|
|
|
}
|
2017-08-15 12:59:40 -04:00
|
|
|
|
|
|
|
|
return PostQueue;
|
|
|
|
|
});
|