From: W. Trevor King Date: Sat, 20 Sep 2014 21:17:55 +0000 (-0700) Subject: nmbug.js: Fill in the tag-fetching portion of nmbug.show X-Git-Tag: v0.1.0~31 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=540b3e0484f22955636ec9bbb0f6daac0456d3cb;p=nmhive.git nmbug.js: Fill in the tag-fetching portion of nmbug.show Ask nmhive for the tags associated with the given Message-ID. I've also used bind [1] so that the nmbug.show callback get's called with this pointing to the nmbug object. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind --- diff --git a/nmbug.js b/nmbug.js index 5a8a141..3321729 100644 --- a/nmbug.js +++ b/nmbug.js @@ -2,7 +2,30 @@ 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) { + alert('edit ' + tags + ' for ' + message_id); }, }; @@ -58,7 +81,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 */ }