mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: buttons for post queue content editing
This commit is contained in:
@@ -19,11 +19,63 @@ define('forum/post-queue', [
|
|||||||
|
|
||||||
handleActions();
|
handleActions();
|
||||||
handleBulkActions();
|
handleBulkActions();
|
||||||
handleContentEdit('.post-content', '.post-content-editable', 'textarea');
|
handleContentEdit('[data-action="editContent"]', '.post-content-editable', 'textarea', '.post-content');
|
||||||
handleContentEdit('.topic-title', '.topic-title-editable', 'input');
|
handleContentEdit('[data-action="editTitle"]', '.topic-title-editable', 'input', '.topic-title');
|
||||||
|
|
||||||
$('.posts-list').on('click', '.topic-category[data-editable]', function () {
|
$('.posts-list').on('click', '.topic-category[data-editable]', function (e) {
|
||||||
const $this = $(this);
|
handleCategoryChange(this);
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('[component="post/content"] img:not(.not-responsive)').addClass('img-fluid');
|
||||||
|
};
|
||||||
|
|
||||||
|
function confirmReject(msg) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
bootbox.confirm(msg, resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleContentEdit(triggerClass, editableClass, inputSelector, displayClass) {
|
||||||
|
$('.posts-list').on('click', triggerClass, function () {
|
||||||
|
const el = $(this);
|
||||||
|
const inputEl = el.parents('[data-id]').find(editableClass);
|
||||||
|
const displayEl = el.parents('[data-id]').find(displayClass);
|
||||||
|
if (inputEl.length) {
|
||||||
|
displayEl.addClass('hidden');
|
||||||
|
inputEl.removeClass('hidden').find(inputSelector).focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.posts-list').on('blur', editableClass + ' ' + inputSelector, function () {
|
||||||
|
const textarea = $(this);
|
||||||
|
const preview = textarea.parent().parent().find(displayClass);
|
||||||
|
const id = textarea.parents('[data-id]').attr('data-id');
|
||||||
|
const titleEdit = triggerClass === '[data-action="editTitle"]';
|
||||||
|
|
||||||
|
socket.emit('posts.editQueuedContent', {
|
||||||
|
id: id,
|
||||||
|
title: titleEdit ? textarea.val() : undefined,
|
||||||
|
content: titleEdit ? undefined : textarea.val(),
|
||||||
|
}, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
return alerts.error(err);
|
||||||
|
}
|
||||||
|
if (titleEdit) {
|
||||||
|
preview.find('.title-text').text(data.postData.title);
|
||||||
|
} else {
|
||||||
|
preview.html(data.postData.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea.parent().addClass('hidden');
|
||||||
|
preview.removeClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCategoryChange(categoryEl) {
|
||||||
|
const $this = $(categoryEl);
|
||||||
const id = $this.parents('[data-id]').attr('data-id');
|
const id = $this.parents('[data-id]').attr('data-id');
|
||||||
categorySelector.modal({
|
categorySelector.modal({
|
||||||
onSubmit: function (selectedCategory) {
|
onSubmit: function (selectedCategory) {
|
||||||
@@ -51,56 +103,6 @@ define('forum/post-queue', [
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
|
||||||
|
|
||||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-fluid');
|
|
||||||
};
|
|
||||||
|
|
||||||
function confirmReject(msg) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
bootbox.confirm(msg, resolve);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleContentEdit(displayClass, editableClass, inputSelector) {
|
|
||||||
$('.posts-list').on('click', displayClass, function () {
|
|
||||||
const el = $(this);
|
|
||||||
const inputEl = el.parent().find(editableClass);
|
|
||||||
if (inputEl.length) {
|
|
||||||
el.addClass('hidden');
|
|
||||||
inputEl.removeClass('hidden').find(inputSelector).focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.posts-list').on('blur', editableClass + ' ' + inputSelector, function () {
|
|
||||||
const textarea = $(this);
|
|
||||||
const preview = textarea.parent().parent().find(displayClass);
|
|
||||||
const id = textarea.parents('[data-id]').attr('data-id');
|
|
||||||
const titleEdit = displayClass === '.topic-title';
|
|
||||||
|
|
||||||
socket.emit('posts.editQueuedContent', {
|
|
||||||
id: id,
|
|
||||||
title: titleEdit ? textarea.val() : undefined,
|
|
||||||
content: titleEdit ? undefined : textarea.val(),
|
|
||||||
}, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
return alerts.error(err);
|
|
||||||
}
|
|
||||||
if (titleEdit) {
|
|
||||||
if (preview.find('.title-text').length) {
|
|
||||||
preview.find('.title-text').text(data.postData.title);
|
|
||||||
} else {
|
|
||||||
// for backwards compatibility, remove in 1.16.0
|
|
||||||
preview.html(data.postData.title);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
preview.html(data.postData.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea.parent().addClass('hidden');
|
|
||||||
preview.removeClass('hidden');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleActions() {
|
function handleActions() {
|
||||||
@@ -113,6 +115,12 @@ define('forum/post-queue', [
|
|||||||
const uid = subselector.closest('[data-uid]').getAttribute('data-uid');
|
const uid = subselector.closest('[data-uid]').getAttribute('data-uid');
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case 'editCategory': {
|
||||||
|
const categoryEl = e.target.closest('[data-id]').querySelector('.topic-category');
|
||||||
|
handleCategoryChange(categoryEl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'ban':
|
case 'ban':
|
||||||
AccountModerate.banAccount(uid, ajaxify.refresh);
|
AccountModerate.banAccount(uid, ajaxify.refresh);
|
||||||
break;
|
break;
|
||||||
@@ -151,6 +159,7 @@ define('forum/post-queue', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleQueueActions() {
|
async function handleQueueActions() {
|
||||||
|
// accept, reject, notify
|
||||||
function getMessage() {
|
function getMessage() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const modal = bootbox.dialog({
|
const modal = bootbox.dialog({
|
||||||
|
|||||||
Reference in New Issue
Block a user