nmbug.js: Stub out a dialog for editing tags
[nmhive.git] / nmbug.js
index 5a8a14142c51b43973fdee754907f08eef1cb4e7..ecf03d894d64a9ea207abb959c96d1cbd6da7347 100644 (file)
--- a/nmbug.js
+++ b/nmbug.js
@@ -2,7 +2,52 @@ var nmbug_server = 'http://localhost:5000';
 
 nmbug = {
        show: function (message_id) {
-               alert(message_id);
+               this._get_tags(message_id, this._edit_tags.bind(this));
+       },
+       _get_tags: function (message_id, callback) {
+               var url = [
+                       nmbug_server,
+                       'mid',
+                       encodeURIComponent(message_id),
+                       ].join('/');
+               console.log('nmbug: get tags from ' + url);
+               var request = new XMLHttpRequest();
+               request.onload = function () {
+                       if (this.status == 200) {
+                               var tags = JSON.parse(this.response);
+                               console.log('nmbug: got tags', tags);
+                               callback(message_id, tags);
+                       } else {
+                               throw 'Error fetching ' + url + ' (status ' + this.status + ')';
+                       }
+               };
+               request.open('get', url, true);
+               request.send();
+       },
+       _edit_tags: function (message_id, tags) {
+               var dialog = document.createElement('dialog');
+
+               var content = document.createElement('p');
+               content.innerHTML = 'Edit tags for ' + message_id;
+               dialog.appendChild(content);
+
+               var ul = document.createElement('ul');
+               dialog.appendChild(ul);
+               for (var i = 0; i < tags.length; i++) {
+                       var li = document.createElement('li');
+                       li.innerHTML = tags[i];
+                       ul.appendChild(li);
+               }
+               var close = document.createElement('button');
+               close.innerHTML = 'Close';
+               close.onclick = function () {
+                       dialog.close();
+               };
+               dialog.appendChild(close);
+
+               document.body.appendChild(dialog);
+
+               dialog.show();
        },
 };
 
@@ -58,7 +103,7 @@ function _check_handler(handler) {
        console.log('nmbug: testing', handler, match);
        if (match) {
                console.log('nmbug: matched', handler);
-               handler.handle(nmbug.show);
+               handler.handle(nmbug.show.bind(nmbug));
        }
        return match;  /* break after the first match */
 }