diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-05-24 22:57:13 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-07-04 23:18:45 -0700 |
commit | 6eb99ceb647cf35c39dc97292f00040fbb821170 (patch) | |
tree | 1db97cb18370f6b25902bb06b2e01a74aae169e2 /htdocs/nfc/nfc-binding.js | |
parent | f9e5259d74c8cf521921a96377c64691b5b3c3ae (diff) |
binding: nfc: new initial binding
Slight rewrite to use libnfc initially for getting tag uid's for
user settings.
Bug-AGL: SPEC-1554
Change-Id: I7b8c30102b82e86a92c89909bcbfba9ab7164c1f
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'htdocs/nfc/nfc-binding.js')
-rw-r--r-- | htdocs/nfc/nfc-binding.js | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/htdocs/nfc/nfc-binding.js b/htdocs/nfc/nfc-binding.js deleted file mode 100644 index 4241c26..0000000 --- a/htdocs/nfc/nfc-binding.js +++ /dev/null @@ -1,156 +0,0 @@ -var afb = new AFB("api", "HELLO"); -var ws; - -function add_debbug_panel() { - - if (document.getElementById("debug-panel")) - return; - - var itm = document.getElementById("debug-panel-container"); - if (itm) - { - var pnl = - "<div id=\"debug-panel\" class=\"expanded\">\n" + - " <button id=\"debug-panel-collapse\" onclick=\"debug_panel_collapse();\">></button>\n" + - " <button id=\"debug-panel-expand\" onclick=\"debug_panel_expand();\"><</button>\n" + - " <div id=\"debug-panel-content\">\n" + - " <h1>Debug</h1>\n" + - " <h2>Call</h2><div id=\"debug-panel-call\">\n" + - " <ul>\n" + - " <li><strong>api : </strong><span id=\"debug-panel-call-id\"></span></li>\n" + - " <li><strong>verb : </strong><span id=\"debug-panel-call-verb\"></span></li>\n" + - " <li><strong>query : </strong></li>\n" + - " </ul>\n" + - " <pre id=\"debug-panel-call-query\"></pre>\n" + - " </div>\n" + - " <h2>Response</h2><pre id=\"debug-panel-response\"></pre>\n" + - " <h2>Event</h2><pre id=\"debug-panel-event\"></pre>\n" + - " </div>\n" + - "</div>\n"; - itm.insertAdjacentHTML("afterbegin", pnl); - } -} - -function createClass(name,rules) { - var style = document.createElement('style'); - style.type = 'text/css'; - document.getElementsByTagName('head')[0].appendChild(style); - if(!(style.sheet||{}).insertRule) - (style.styleSheet || style.sheet).addRule(name, rules); - else - style.sheet.insertRule(name+"{"+rules+"}",0); -} - -function syntaxHighlight(json) { - if (typeof json != 'string') - json = JSON.stringify(json, undefined, 2); - - json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); - return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { - var cls = 'json-number'; - if (/^"/.test(match)) { - if (/:$/.test(match)) { - cls = 'json-key'; - } else { - cls = 'json-string'; - } - } else if (/true|false/.test(match)) { - cls = 'json-boolean'; - } else if (/null/.test(match)) { - cls = 'json-null'; - } - return '<span class="' + cls + '">' + match + '</span>'; - }); -} - -function set_item_html(id, text) -{ - var itm = document.getElementById(id); - if (itm) itm.innerHTML = text; -} - -function set_item_text(id, text) -{ - var itm = document.getElementById(id); - if (itm) itm.innerText = text; -} - -function debug_panel_collapse() { - var pnl = document.getElementById('debug-panel'); - if (pnl) - { - pnl.classList.remove('expanded'); - pnl.classList.add('collapsed'); - } -} - -function debug_panel_expand() { - var pnl = document.getElementById('debug-panel'); - if (pnl) - { - pnl.classList.remove('collapsed'); - pnl.classList.add('expanded'); - } -} - -function init() { - add_debbug_panel(); - ws = new afb.ws(onopen, onabort); -} - -function onopen() { - //callbinder("ll-auth", "getuser", ""); - ws.onevent("*", gotevent); -} - -function onabort() { -} - -function replyok(obj) { - console.log("replyok:" + JSON.stringify(obj)); - set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4))); -} - -function replyerr(obj) { - console.log("replyerr:" + JSON.stringify(obj)); - set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4))); -} - -function gotevent(obj) { - console.log("gotevent:" + JSON.stringify(obj)); - set_item_html("debug-panel-event", syntaxHighlight(JSON.stringify(obj, null, 4))); -} - -function callbinder(api, verb, query) { - console.log ("subscribe api="+api+" verb="+verb+" query=" +query); - - set_item_text("debug-panel-call-api", api); - set_item_text("debug-panel-call-verb", verb); - set_item_html("debug-panel-call-query", syntaxHighlight(JSON.stringify(query, null, 4))); - - ws.call(api+"/"+verb, query).then(replyok, replyerr); -} - -function subscribe() { - callbinder("nfc", "subscribe", {}); -} - -function unsubscribe() { - callbinder("nfc", "unsubscribe", {}); -} - -function list_devices() { - callbinder("nfc", "list-devices", {}); -} - -function list_devices_capabilities() { - callbinder("nfc", "list-devices-capabilities", {}); -} - -function start_polling() { - callbinder("nfc", "start-polling", {}); -} - -function stop_polling() { - callbinder("nfc", "stop-polling", {}); -} |