fix: buttons for post queue content editing

This commit is contained in:
Julian Lam
2023-03-24 16:34:41 -04:00
parent 6947e60b47
commit 33ad5a724a

View File

@@ -19,11 +19,63 @@ define('forum/post-queue', [
handleActions();
handleBulkActions();
handleContentEdit('.post-content', '.post-content-editable', 'textarea');
handleContentEdit('.topic-title', '.topic-title-editable', 'input');
handleContentEdit('[data-action="editContent"]', '.post-content-editable', 'textarea', '.post-content');
handleContentEdit('[data-action="editTitle"]', '.topic-title-editable', 'input', '.topic-title');
$('.posts-list').on('click', '.topic-category[data-editable]', function () {
const $this = $(this);
$('.posts-list').on('click', '.topic-category[data-editable]', function (e) {
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');
categorySelector.modal({
onSubmit: function (selectedCategory) {
@@ -51,56 +103,6 @@ define('forum/post-queue', [
},
});
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() {
@@ -113,6 +115,12 @@ define('forum/post-queue', [
const uid = subselector.closest('[data-uid]').getAttribute('data-uid');
switch (action) {
case 'editCategory': {
const categoryEl = e.target.closest('[data-id]').querySelector('.topic-category');
handleCategoryChange(categoryEl);
break;
}
case 'ban':
AccountModerate.banAccount(uid, ajaxify.refresh);
break;
@@ -151,6 +159,7 @@ define('forum/post-queue', [
}
async function handleQueueActions() {
// accept, reject, notify
function getMessage() {
return new Promise((resolve) => {
const modal = bootbox.dialog({