1 var afb = new AFB("api", "HELLO");
4 function add_debbug_panel() {
6 if (document.getElementById("debug-panel"))
9 var itm = document.getElementById("debug-panel-container");
13 "<div id=\"debug-panel\" class=\"expanded\">\n" +
14 " <button id=\"debug-panel-collapse\" onclick=\"debug_panel_collapse();\">></button>\n" +
15 " <button id=\"debug-panel-expand\" onclick=\"debug_panel_expand();\"><</button>\n" +
16 " <div id=\"debug-panel-content\">\n" +
18 " <h2>Call</h2><div id=\"debug-panel-call\">\n" +
20 " <li><strong>api : </strong><span id=\"debug-panel-call-id\"></span></li>\n" +
21 " <li><strong>verb : </strong><span id=\"debug-panel-call-verb\"></span></li>\n" +
22 " <li><strong>query : </strong></li>\n" +
24 " <pre id=\"debug-panel-call-query\"></pre>\n" +
26 " <h2>Response</h2><pre id=\"debug-panel-response\"></pre>\n" +
27 " <h2>Event</h2><pre id=\"debug-panel-event\"></pre>\n" +
30 itm.insertAdjacentHTML("afterbegin", pnl);
34 function createClass(name,rules) {
35 var style = document.createElement('style');
36 style.type = 'text/css';
37 document.getElementsByTagName('head')[0].appendChild(style);
38 if(!(style.sheet||{}).insertRule)
39 (style.styleSheet || style.sheet).addRule(name, rules);
41 style.sheet.insertRule(name+"{"+rules+"}",0);
44 function syntaxHighlight(json) {
45 if (typeof json != 'string')
46 json = JSON.stringify(json, undefined, 2);
48 json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
49 return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
50 var cls = 'json-number';
51 if (/^"/.test(match)) {
52 if (/:$/.test(match)) {
57 } else if (/true|false/.test(match)) {
59 } else if (/null/.test(match)) {
62 return '<span class="' + cls + '">' + match + '</span>';
66 function set_item_html(id, text)
68 var itm = document.getElementById(id);
69 if (itm) itm.innerHTML = text;
72 function set_item_text(id, text)
74 var itm = document.getElementById(id);
75 if (itm) itm.innerText = text;
78 function debug_panel_collapse() {
79 var pnl = document.getElementById('debug-panel');
82 pnl.classList.remove('expanded');
83 pnl.classList.add('collapsed');
87 function debug_panel_expand() {
88 var pnl = document.getElementById('debug-panel');
91 pnl.classList.remove('collapsed');
92 pnl.classList.add('expanded');
98 ws = new afb.ws(onopen, onabort);
102 //callbinder("ll-auth", "getuser", "");
103 ws.onevent("*", gotevent);
109 function replyok(obj) {
110 console.log("replyok:" + JSON.stringify(obj));
111 set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4)));
114 function replyerr(obj) {
115 console.log("replyerr:" + JSON.stringify(obj));
116 set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4)));
119 function gotevent(obj) {
120 console.log("gotevent:" + JSON.stringify(obj));
121 set_item_html("debug-panel-event", syntaxHighlight(JSON.stringify(obj, null, 4)));
124 function callbinder(api, verb, query) {
125 console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
127 set_item_text("debug-panel-call-api", api);
128 set_item_text("debug-panel-call-verb", verb);
129 set_item_html("debug-panel-call-query", syntaxHighlight(JSON.stringify(query, null, 4)));
131 ws.call(api+"/"+verb, query).then(replyok, replyerr);
135 return document.getElementById(id).value;
138 function readData() {
139 callbinder("persistence", "read", { "key": value("read-key") });
142 function deleteData() {
143 callbinder("persistence", "delete", { "key": value("read-key")});
146 function writeData() {
147 callbinder("persistence", "update", {
148 "key": value("write-key"),
149 "value": value("write-data")
153 function readProfile() {
154 var vin = value("profile-vin")
155 var token = value("get-profile-key")
156 var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token
158 callbinder("persistence", "read", {
168 function deleteProfile() {
169 var vin = value("profile-vin")
170 var token = value("get-profile-key")
171 var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token
173 callbinder("persistence", "delete", {
183 function writeProfile() {
184 var vin = value("profile-vin")
185 var token = value("set-profile-key")
186 var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token
188 callbinder("persistence", "update", {
197 "name": value("set-profile-login"),
198 "first_name": value("set-profile-first-name"),
199 "last_name": value("set-profile-last-name"),
200 "graphPreferredLanguage": value("set-profile-language")