Archived
1
0

add censortools to postform

This commit is contained in:
Jeff Becker 2017-01-12 09:24:51 -05:00
parent 25ae491ddc
commit 0e394ae25e
4 changed files with 140 additions and 11 deletions

View File

@ -1,13 +1,13 @@
// call an api method
// handler(json_object) on success
// handler(null) on fail
function nntpchan_apicall(url, handler, err_handler) {
function nntpchan_apicall(url, handler, err_handler, method, data) {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == XMLHttpRequest.DONE ) {
var status = ajax.status;
var j = null;
if (status == 200) {
if (status == 200 || status == 201) {
// found
try {
j = JSON.parse(ajax.responseText);
@ -19,7 +19,11 @@ function nntpchan_apicall(url, handler, err_handler) {
handler(j);
}
};
ajax.open("GET", url);
var meth = method || "GET";
ajax.open(meth, url);
if(data)
ajax.send(data);
else
ajax.send();
}

View File

@ -0,0 +1,87 @@
/** censor tools */
function show_censortools() {
var e = document.getElementById("censor-tools");
if(e) e.checked = true;
}
function nntpchan_report_thread(posthash) {
var thread = document.getElementById(posthash);
if (!thread) return;
var posts = thread.getElementsByClassName("post");
for (var idx = 0; idx < posts.length; idx ++ ) {
var post = posts[idx];
nntpchan_report(post.dataset.msgid);
}
}
function nntpchan_report(msgid) {
var e = document.getElementById("modactions");
if (!e) return;
e.value += "delete "+msgid+"\n";
show_censortools();
}
function nntpchan_submit_censor(form, regular_url) {
var result = document.getElementById("nntpchan_censor_result");
var show_result = function(msg) {
result.innerHTML = document.createTextNode(msg);
}
var handle_result = function(j) {
var err = j.error;
if(err) {
show_result("error: "+err);
return;
}
var msgid = j.message_id;
if(msgid) {
show_result("submitted report as "+msgid);
}
}
// build url to ctl
var parts = regular_url.split('/');
parts[parts.length-1] = 'ctl';
var url = parts.join('/');
url += '?json';
var captcha = form.captcha.value;
if(!captcha) {
show_result("no captcha solution provided");
return;
}
var secret = document.getElementById("nntpchan_censor_secret").value;
if(!secret) {
show_result("no mod key provided");
return;
}
var actions = document.getElementById("nntpchan_censor_actions").value;
if(!actions) {
show_result("no mod actions provided");
}
var msg = "";
var lines = actions.split("\n");
for (var idx = 0; idx < lines.length; idx ++ ) {
var line = lines[idx].trim();
if(!line) continue;
msg += line + "\n";
}
if(!msg) {
show_result("no mod actions given");
return;
}
var formdata = new FormData();
formdata.append("name", "mod#"+secret);
formdata.append("subject", "censor");
formdata.append("message", msg);
formdata.append("captcha", captcha);
formdata.append("reference", "");
nntpchan_apicall(url, handle_result, null, "POST", formdata);
}
onready(function() {
});

View File

@ -1,4 +1,4 @@
<div id="{{post.PostHash}}" class="{{post.CSSClass}}"
<div id="{{post.PostHash}}" class="{{post.CSSClass}} post"
data-frontend="{{post.Frontend}}"
data-newsgroup="{{post.Board}}"
data-msgid="{{post.MessageID}}"
@ -31,6 +31,15 @@
{{/post.IsClearnet}}
</span>
<div class="postreply">
<div class="postreport">
<label for="report_{{post.PostHash}}">[x]</label>
<input type="checkbox" id="report_{{post.PostHash}}">
<div style="display: none;" onclick="nntpchan_report('{{post.MessageID}}', '{{post.Reference}}')">
<div class="mod-delete">
[delete]
</div>
</div>
</div>
<a class="postno" onclick="nntpchan_reply(this, '{{post.ShortHash}}');" root="{{post.Reference}}" boardname="{{post.Board}}">&gt;&gt;{{post.ShortHash}}</a>
<a href="{{post.PostURL}}">[{{#i18n.Translations}}{{reply_label}}{{/i18n.Translations}}]</a>
</div>

View File

@ -8,7 +8,7 @@
- files ( bool, do we allow attachments ? )
- csrf ( csrf token )
}}
<form action="{{post_url}}" enctype="multipart/form-data" name="post" method="post">
<form action="{{post_url}}" enctype="multipart/form-data" name="post" method="post" id="postform">
{{{csrf}}}
<input type="hidden" name="reference" value="{{reference}}" id="postform_reference"/>
<div id="postform-outer">
@ -77,14 +77,43 @@
<input type="text" name="captcha" autocomplete="off" id="captcha_solution" height="175" width="350"/>
</td>
</tr>
<!-- <tr>
<tr>
<th>
{{#i18n.Translations}}{{cuckoo_pow}}{{/i18n.Translations}}
<label id="censor-toggle" for="censor-tools">[censor tools]</label>
</th>
<td>
<input type="text" name="pow" autocomplete="off" id="miner_result" /><input id="start_miner" class="button" type="button" value="{{#i18n.Translations}}{{start_mining}}{{/i18n.Translations}}"/>
<input type="checkbox" id="censor-tools"><div style="display: none;">
<table>
<tbody>
<tr>
<th>
Actions:
</th>
<td>
<textarea cols=85 id="nntpchan_censor_actions"></textarea>
</td>
</tr> -->
</tr>
<tr>
<th>
Secret:
</th>
<td>
<input type="password" id="nntp_censor_secret"></input>
</td>
</tr>
<tr>
<th>
<button onclick="nntpchan_submit_censor(document.getElementById('postform'), '{{post_url}}')">report</button>
</th>
<td>
<div id="nntpchan_censor_result"></div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>