-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
post-queue.js
95 lines (82 loc) · 2.67 KB
/
post-queue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict';
define('forum/post-queue', ['categorySelector'], function (categorySelector) {
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');
var id = parent.attr('data-id');
var listContainer = parent.get(0).parentNode;
if (!['accept', 'reject'].some(function (valid) {
return action === valid;
})) {
return;
}
socket.emit('posts.' + action, { id: id }, function (err) {
if (err) {
return app.alertError(err.message);
}
parent.remove();
if (listContainer.childElementCount === 0) {
ajaxify.refresh();
}
});
return false;
});
handleContentEdit('.post-content', '.post-content-editable', 'textarea');
handleContentEdit('.topic-title', '.topic-title-editable', 'input');
$('.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;
});
};
function handleContentEdit(displayClass, editableClass, inputSelector) {
$('.posts-list').on('click', displayClass, function () {
var el = $(this);
el.addClass('hidden');
var inputEl = el.parent().find(editableClass);
inputEl.removeClass('hidden').find(inputSelector).focus();
});
$('.posts-list').on('blur', editableClass + ' ' + inputSelector, function () {
var textarea = $(this);
var preview = textarea.parent().parent().find(displayClass);
var id = textarea.parents('[data-id]').attr('data-id');
var 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 app.alertError(err);
}
preview.html(titleEdit ? data.postData.title : data.postData.content);
textarea.parent().addClass('hidden');
preview.removeClass('hidden');
});
});
}
return PostQueue;
});