diff --git a/contrib/js/nntpchan/api.js b/contrib/js/nntpchan/api.js index 7186f27..fde0ea0 100644 --- a/contrib/js/nntpchan/api.js +++ b/contrib/js/nntpchan/api.js @@ -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,8 +19,12 @@ function nntpchan_apicall(url, handler, err_handler) { handler(j); } }; - ajax.open("GET", url); - ajax.send(); + var meth = method || "GET"; + ajax.open(meth, url); + if(data) + ajax.send(data); + else + ajax.send(); } // build post from json diff --git a/contrib/js/nntpchan/report.js b/contrib/js/nntpchan/report.js new file mode 100644 index 0000000..74a6faa --- /dev/null +++ b/contrib/js/nntpchan/report.js @@ -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() { + +}); diff --git a/contrib/templates/default/post.mustache b/contrib/templates/default/post.mustache index b349cdc..a6e58f8 100644 --- a/contrib/templates/default/post.mustache +++ b/contrib/templates/default/post.mustache @@ -1,4 +1,4 @@ -
+
+ + +
+
+ [delete] +
+
+
>>{{post.ShortHash}} [{{#i18n.Translations}}{{reply_label}}{{/i18n.Translations}}]
diff --git a/contrib/templates/default/postform.mustache b/contrib/templates/default/postform.mustache index 5c833f6..6250cac 100644 --- a/contrib/templates/default/postform.mustache +++ b/contrib/templates/default/postform.mustache @@ -8,7 +8,7 @@ - files ( bool, do we allow attachments ? ) - csrf ( csrf token ) }} -
+ {{{csrf}}}
@@ -77,17 +77,46 @@ - +
- +