From: W. Trevor King Date: Sun, 21 Sep 2014 13:41:39 +0000 (-0700) Subject: nmbug.js: Fill in the POST /mid/ handling X-Git-Tag: v0.1.0~21 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f6bb68b5e9462511d93f184fa7bb937bbd00bfec;p=nmhive.git nmbug.js: Fill in the POST /mid/ handling This is currently only (un)setting one tag per request. If we want, a later optimization could queue changes and push them all at once (e.g. after a user pushes a submit button). It would also be nice to update the UI based on the list of returned tags, so we hear about changes made by parallel parties. --- diff --git a/nmbug.js b/nmbug.js index 669272d..4281cdb 100644 --- a/nmbug.js +++ b/nmbug.js @@ -115,7 +115,33 @@ nmbug = { dialog.show(); }, _toggle_tag: function (message_id, tag, li) { - alert('toggle ' + tag + ' for ' + message_id); + var prefix; + if (li.style.backgroundColor == 'lime') { + prefix = '-'; /* unset */ + li.style.backgroundColor = null; + } else { + prefix = '+'; /* set */ + li.style.backgroundColor = 'lime'; + } + var url = [ + nmbug_server, + 'mid', + encodeURIComponent(message_id), + ].join('/'); + console.log('nmbug: alter tags via ' + url); + var request = new XMLHttpRequest(); + request.onload = function () { + if (this.status == 200) { + var tags = JSON.parse(this.response); + console.log('nmbug: got tags', tags); + } else { + throw 'Error posting to ' + url + ' (status ' + this.status + ')'; + } + }; + request.open('post', url, true); + request.setRequestHeader( + 'Content-Type', 'application/json; charset=UTF-8'); + request.send(JSON.stringify([prefix + tag])); }, };