Skip to content
Snippets Groups Projects
Commit 0b2a0778 authored by echicken's avatar echicken :chicken:
Browse files

Cleanup

parent 20ce2df0
Branches
Tags
No related merge requests found
...@@ -12,8 +12,8 @@ function login(evt) { ...@@ -12,8 +12,8 @@ function login(evt) {
{ 'url' : './api/auth.ssjs', { 'url' : './api/auth.ssjs',
'method' : 'POST', 'method' : 'POST',
'data' : { 'data' : {
'username' : $('#input-username').val(), username : $('#input-username').val(),
'password' : $('#input-password').val() password : $('#input-password').val()
} }
} }
).done( ).done(
......
// Add a parameter to the query string // Add a parameter to the query string
var insertParam = function(key, value) { function insertParam(key, value) {
key = encodeURIComponent(key); key = encodeURIComponent(key);
value = encodeURIComponent(value); value = encodeURIComponent(value);
var kvp = window.location.search.substr(1).split('&'); var kvp = window.location.search.substr(1).split('&');
var i = kvp.length, x; var i = kvp.length, x;
while(i--) { while (i--) {
x = kvp[i].split('='); x = kvp[i].split('=');
if (x[0]==key) { if (x[0] == key) {
x[1] = value; x[1] = value;
kvp[i] = x.join('='); kvp[i] = x.join('=');
break; break;
} }
} }
if(i<0) if (i<0) kvp[kvp.length] = [key,value].join('=');
kvp[kvp.length] = [key,value].join('=');
window.location.search = kvp.join('&'); window.location.search = kvp.join('&');
} }
// For now we'll just remove nested quotes from the parent post // For now we'll just remove nested quotes from the parent post
var quotify = function(id) { function quotify(id) {
$('#quote-' + id).attr("disabled", true); $('#quote-' + id).attr('disabled', true);
var html = $('#message-' + id).clone(); var html = $('#message-' + id).clone();
html.find('blockquote').remove(); html.find('blockquote').remove();
$('#replytext-' + id).val( $('#replytext-' + id).val(
html.text().replace(/\n\s*\n\s*\n/g, '\n\n').split(/\r?\n/).map( html.text().replace(/\n\s*\n\s*\n/g, '\n\n').split(/\r?\n/).map(
function(line) { return ("> " + line); } function (line) { return ("> " + line); }
).join("\n") + ).join('\n') +
$('#replytext-' +id).val() $('#replytext-' +id).val()
); );
} }
// (Try to) post a new message to 'sub' via the web API // (Try to) post a new message to 'sub' via the web API
var postNew = function(sub) { function postNew(sub) {
$('#newmessage-button').attr("disabled", true); $('#newmessage-button').attr('disabled', true);
var to = $('#newmessage-to').val(); var to = $('#newmessage-to').val();
var subject = $('#newmessage-subject').val(); var subject = $('#newmessage-subject').val();
var body = $('#newmessage-body').val(); var body = $('#newmessage-body').val();
$.ajax( $.ajax(
{ 'url' : "./api/forum.ssjs", { url : './api/forum.ssjs',
'method' : "POST", method : 'POST',
'data' : { data : {
'call' : "post", call : 'post',
'sub' : sub, sub : sub,
'to' : to, to : to,
'subject' : subject, subject : subject,
'body' : body body : body
} }
} }
).done( ).done(
function(data) { function (data) {
if(data.success) { if (data.success) {
$('#newmessage').remove(); $('#newmessage').remove();
insertParam("notice", "Your message has been posted."); insertParam('notice', 'Your message has been posted.');
} }
$('#newmessage-button').attr("disabled", false); $('#newmessage-button').attr('disabled', false);
} }
); );
} }
// (Try to) post a reply to message number 'id' of 'sub' via the web API // (Try to) post a reply to message number 'id' of 'sub' via the web API
var postReply = function(sub, id) { function postReply(sub, id) {
$('#reply-button-' + id).attr("disabled", true); $('#reply-button-' + id).attr('disabled', true);
var body = $('#replytext-' + id).val(); var body = $('#replytext-' + id).val();
$.ajax( $.ajax(
{ 'url' : "./api/forum.ssjs", { url : './api/forum.ssjs',
'method' : "POST", method : 'POST',
'data' : { data : {
'call' : "post-reply", call : 'post-reply',
'sub' : sub, sub : sub,
'body' : $('#replytext-' + id).val(), body : $('#replytext-' + id).val(),
'pid' : id pid : id
} }
} }
).done( ).done(
function(data) { function (data) {
if(data.success) { if (data.success) {
$('#quote-' + id).attr("disabled", false); $('#quote-' + id).attr('disabled', false);
$('#replybox-' + id).remove(); $('#replybox-' + id).remove();
insertParam("notice", "Your message has been posted."); insertParam('notice', 'Your message has been posted.');
} else { } else {
$('#reply-button-' + id).attr("disabled", false); $('#reply-button-' + id).attr('disabled', false);
} }
} }
); );
} }
// (Try to) delete a message via the web API // (Try to) delete a message via the web API
var deleteMessage = function(sub, id) { function deleteMessage(sub, id) {
$.getJSON( $.getJSON(
'./api/forum.ssjs?call=delete-message&sub=' + sub + '&number=' + id, './api/forum.ssjs?call=delete-message&sub=' + sub + '&number=' + id,
function(data) { function (data) {
console.log(data); console.log(data);
if(data.success) { if (data.success) {
$('#li-' + id).remove(); $('#li-' + id).remove();
insertParam("notice", "Message deleted."); insertParam('notice', 'Message deleted.');
} }
} }
); );
} }
// Add a new message input form to the element with id 'forum-list-container' for sub 'sub' // Add a new message input form to the element with id 'forum-list-container' for sub 'sub'
var addNew = function(sub) { function addNew(sub) {
if($('#newmessage').length > 0) if ($('#newmessage').length > 0) return;
return;
$('#forum-list-container').append( $('#forum-list-container').append(
'<li id="newmessage" class="list-group-item">' + '<li id="newmessage" class="list-group-item">' +
'<input id="newmessage-to" class="form-control" type="text" placeholder="To"><br>' + '<input id="newmessage-to" class="form-control" type="text" placeholder="To"><br>' +
...@@ -113,17 +111,18 @@ var addNew = function(sub) { ...@@ -113,17 +111,18 @@ var addNew = function(sub) {
); );
$.getJSON( $.getJSON(
'./api/forum.ssjs?call=get-signature', './api/forum.ssjs?call=get-signature',
function(data) { function (data) {
$('#newmessage-body').val($('#newmessage-body').val() + "\r\n" + data.signature); $('#newmessage-body').val(
$('#newmessage-body').val() + '\r\n' + data.signature
);
} }
); );
window.location.hash = "#newmessage"; window.location.hash = '#newmessage';
} }
// Add a reply input form to the page for message with number 'id' in sub 'sub' // Add a reply input form to the page for message with number 'id' in sub 'sub'
var addReply = function(sub, id) { function addReply(sub, id) {
if($('#replybox-' + id).length > 0) if ($('#replybox-' + id).length > 0) return;
return;
$('#li-' + id).append( $('#li-' + id).append(
'<div class="reply" id="replybox-' + id + '">' + '<div class="reply" id="replybox-' + id + '">' +
'<strong>Reply</strong>' + '<strong>Reply</strong>' +
...@@ -134,37 +133,48 @@ var addReply = function(sub, id) { ...@@ -134,37 +133,48 @@ var addReply = function(sub, id) {
); );
$.getJSON( $.getJSON(
'./api/forum.ssjs?call=get-signature', './api/forum.ssjs?call=get-signature',
function(data) { function (data) {
$('#replytext-' + id).val($('#replytext-' + id).val() + "\r\n" + data.signature); $('#replytext-' + id).val(
$('#replytext-' + id).val() + '\r\n' + data.signature
);
} }
); );
} }
// 'sub' can be a single sub code, or a string of <sub1>&sub=<sub2>&sub=<sub3>... // 'sub' can be a single sub code, or a string of <sub1>&sub=<sub2>&sub=<sub3>...
var getSubUnreadCount = function(sub) { function getSubUnreadCount(sub) {
$.getJSON( $.getJSON(
"./api/forum.ssjs?call=get-sub-unread-count&sub=" + sub, './api/forum.ssjs?call=get-sub-unread-count&sub=' + sub,
function(data) { function(data) {
for(sub in data) { for (sub in data) {
if(data[sub].scanned > 0) if (data[sub].scanned > 0) {
$('#badge-' + sub).text(data[sub].total); $('#badge-' + sub).text(data[sub].total);
else if(data[sub].total > 0) } else if (data[sub].total > 0) {
$('#badge-' + sub).text(data[sub].total); $('#badge-' + sub).text(data[sub].total);
else } else {
$('#badge-' + sub).text(""); $('#badge-' + sub).text('');
}
} }
} }
); );
} }
// 'group' can be a single group index, or a string of 0&group=1&group=2... // 'group' can be a single group index, or a string of 0&group=1&group=2...
var getGroupUnreadCount = function(group) { function getGroupUnreadCount(group) {
$.getJSON( $.getJSON(
"./api/forum.ssjs?call=get-group-unread-count&group=" + group, './api/forum.ssjs?call=get-group-unread-count&group=' + group,
function(data) { function (data) {
for(group in data) { for (group in data) {
$('#badge-scanned-' + group).text((data[group].scanned == 0 ? "" : data[group].scanned)); $('#badge-scanned-' + group).text(
$('#badge-ignored-' + group).text((data[group].total == 0 || data[group].total == data[group].scanned ? "" : (data[group].total - data[group].scanned))); (data[group].scanned == 0 ? "" : data[group].scanned)
);
$('#badge-ignored-' + group).text(
( data[group].total == 0 ||
data[group].total == data[group].scanned
? ''
: (data[group].total - data[group].scanned)
)
);
} }
} }
); );
...@@ -172,20 +182,26 @@ var getGroupUnreadCount = function(group) { ...@@ -172,20 +182,26 @@ var getGroupUnreadCount = function(group) {
/* Fetch a private mail message's body (with links to attachments) where 'id' /* Fetch a private mail message's body (with links to attachments) where 'id'
is the message number. Output it to an element with id 'message-<id>'. */ is the message number. Output it to an element with id 'message-<id>'. */
var getMailBody = function(id) { function getMailBody(id) {
if(!$('#message-' + id).attr('hidden')) { if (!$('#message-' + id).attr('hidden')) {
$('#message-' + id).attr('hidden', true); $('#message-' + id).attr('hidden', true);
} else if($('#message-' + id).html() != "") { } else if ($('#message-' + id).html() != '') {
$('#message-' + id).attr('hidden', false); $('#message-' + id).attr('hidden', false);
} else { } else {
$.getJSON( $.getJSON(
"./api/forum.ssjs?call=get-mail-body&number=" + id, './api/forum.ssjs?call=get-mail-body&number=' + id,
function(data) { function (data) {
var str = data.body; var str = data.body;
if(data.inlines.length > 0) if (data.inlines.length > 0) {
str += "<br>Inline attachments: " + data.inlines.join("<br>") + "<br>"; str +=
if(data.attachments.length > 0) '<br>Inline attachments: ' +
str += "<br>Attachments: " + data.attachments.join("<br>") + "<br>"; data.inlines.join('<br>') + '<br>';
}
if (data.attachments.length > 0) {
str +=
'<br>Attachments: ' +
data.attachments.join('<br>') + '<br>';
}
str += str +=
'<button class="btn btn-default icon" ' + '<button class="btn btn-default icon" ' +
'aria-label="Reply to this message" ' + 'aria-label="Reply to this message" ' +
...@@ -205,19 +221,18 @@ var getMailBody = function(id) { ...@@ -205,19 +221,18 @@ var getMailBody = function(id) {
} }
} }
var setScanCfg = function(sub, cfg) { function setScanCfg(sub, cfg) {
var opts = [ var opts = [
"scan-cfg-off", 'scan-cfg-off',
"scan-cfg-new", 'scan-cfg-new',
"scan-cfg-youonly" 'scan-cfg-youonly'
]; ];
$.getJSON( $.getJSON(
"./api/forum.ssjs?call=set-scan-cfg&sub=" + sub + "&cfg=" + cfg, './api/forum.ssjs?call=set-scan-cfg&sub=' + sub + '&cfg=' + cfg,
function(data) { function (data) {
if(!data.success) if (!data.success) return;
return;
opts.forEach( opts.forEach(
function(opt, index) { function (opt, index) {
$('#' + opt).toggleClass('btn-primary', (cfg == index)); $('#' + opt).toggleClass('btn-primary', (cfg == index));
$('#' + opt).toggleClass('btn-default', (cfg != index)); $('#' + opt).toggleClass('btn-default', (cfg != index));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment