Skip to content

Commit

Permalink
fix: buttons for post queue content editing
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Mar 24, 2023
1 parent 6947e60 commit 33ad5a7
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions public/src/client/post-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,13 @@ define('forum/post-queue', [

handleActions();
handleBulkActions();
handleContentEdit('.post-content', '.post-content-editable', 'textarea');
handleContentEdit('.topic-title', '.topic-title-editable', 'input');

$('.posts-list').on('click', '.topic-category[data-editable]', function () {
const $this = $(this);
const id = $this.parents('[data-id]').attr('data-id');
categorySelector.modal({
onSubmit: function (selectedCategory) {
Promise.all([
api.get(`/categories/${selectedCategory.cid}`, {}),
socket.emit('posts.editQueuedContent', {
id: id,
cid: selectedCategory.cid,
}),
]).then(function (result) {
const category = result[0];
app.parseAndTranslate('post-queue', 'posts', {
posts: [{
category: category,
}],
}, function (html) {
if ($this.find('.category-text').length) {
$this.find('.category-text').text(html.find('.topic-category .category-text').text());
} else {
// for backwards compatibility, remove in 1.16.0
$this.replaceWith(html.find('.topic-category'));
}
});
}).catch(alerts.error);
},
});
return false;
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 (e) {
handleCategoryChange(this);
e.stopPropagation();
e.preventDefault();
});

$('[component="post/content"] img:not(.not-responsive)').addClass('img-fluid');
Expand All @@ -62,12 +37,13 @@ define('forum/post-queue', [
});
}

function handleContentEdit(displayClass, editableClass, inputSelector) {
$('.posts-list').on('click', displayClass, function () {
function handleContentEdit(triggerClass, editableClass, inputSelector, displayClass) {
$('.posts-list').on('click', triggerClass, function () {
const el = $(this);
const inputEl = el.parent().find(editableClass);
const inputEl = el.parents('[data-id]').find(editableClass);
const displayEl = el.parents('[data-id]').find(displayClass);
if (inputEl.length) {
el.addClass('hidden');
displayEl.addClass('hidden');
inputEl.removeClass('hidden').find(inputSelector).focus();
}
});
Expand All @@ -76,7 +52,7 @@ define('forum/post-queue', [
const textarea = $(this);
const preview = textarea.parent().parent().find(displayClass);
const id = textarea.parents('[data-id]').attr('data-id');
const titleEdit = displayClass === '.topic-title';
const titleEdit = triggerClass === '[data-action="editTitle"]';

socket.emit('posts.editQueuedContent', {
id: id,
Expand All @@ -87,12 +63,7 @@ define('forum/post-queue', [
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);
}
preview.find('.title-text').text(data.postData.title);
} else {
preview.html(data.postData.content);
}
Expand All @@ -103,6 +74,37 @@ define('forum/post-queue', [
});
}

function handleCategoryChange(categoryEl) {
const $this = $(categoryEl);
const id = $this.parents('[data-id]').attr('data-id');
categorySelector.modal({
onSubmit: function (selectedCategory) {
Promise.all([
api.get(`/categories/${selectedCategory.cid}`, {}),
socket.emit('posts.editQueuedContent', {
id: id,
cid: selectedCategory.cid,
}),
]).then(function (result) {
const category = result[0];
app.parseAndTranslate('post-queue', 'posts', {
posts: [{
category: category,
}],
}, function (html) {
if ($this.find('.category-text').length) {
$this.find('.category-text').text(html.find('.topic-category .category-text').text());
} else {
// for backwards compatibility, remove in 1.16.0
$this.replaceWith(html.find('.topic-category'));
}
});
}).catch(alerts.error);
},
});
return false;
}

function handleActions() {
const listEl = document.querySelector('.posts-list');
if (listEl) {
Expand All @@ -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;
Expand Down Expand Up @@ -151,6 +159,7 @@ define('forum/post-queue', [
}

async function handleQueueActions() {
// accept, reject, notify
function getMessage() {
return new Promise((resolve) => {
const modal = bootbox.dialog({
Expand Down

0 comments on commit 33ad5a7

Please sign in to comment.