From f6bb68b5e9462511d93f184fa7bb937bbd00bfec Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 21 Sep 2014 06:41:39 -0700 Subject: [PATCH] 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. --- nmbug.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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])); }, }; -- 2.26.2