From 21d213dcff1367c16dc0c3f6585b8e35d7c2f0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Mon, 24 Aug 2015 19:17:43 +0200 Subject: Introduced the Q promises library, created a basic login page to test prolog examples, and started tying the terminal and editor activity to the REST services. --- js/codeq.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 13 deletions(-) (limited to 'js/codeq.js') diff --git a/js/codeq.js b/js/codeq.js index 472cab0..9e33bac 100644 --- a/js/codeq.js +++ b/js/codeq.js @@ -80,6 +80,8 @@ window.phandler = null; // TODO: this is for debug only }; } + codeq.jsonize = jsonize; + codeq.log = {}; (function () { var assembleOutput = function (stuff, e) { @@ -706,7 +708,23 @@ window.phandler = null; // TODO: this is for debug only }; // codeq.system = { - window.start = function () { + /** + * Returns the number of Unicode code points in the given string. + * + * @param s {string} + * @returns {number} + */ + codeq.codePointCount = function (s) { + var n = 0, i, code; + for (i = s.length - 1; i >= 0; i--) { + code = s.charCodeAt(i); + if ((code >= 0xd800) && (code < 0xe000)) i++; + n++; + } + return n; + }; + + $(document).ready(function () { // var s = location.hash; // if (s.length == 0) return; // empty hash // if (s.charAt(0) == '#') s = s.substring(1); @@ -724,17 +742,56 @@ window.phandler = null; // TODO: this is for debug only width: '100%' });*/ - codeq.system.load({ - type: 'text', - url: 'sins.py', - callback: function (data, status, url) { - if (!data) return; - var info = codeq.parseDefinition(data); - window.phandler = codeq.createPrologHandler(info); // TODO: for debug only - // DEBUG: phandler.processServerHints([{id:'x_must_be_female'}]); - // DEBUG: phandler.processServerHints([{id:'popup_unknown', start: 20, end: 26}]); - // DEBUG: phandler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); + var hash = location.hash, + error = false, + params, param, sid, grp, prb, i, key, j; + + if (hash.length < 2) { + error = 'No execution parameters were provided'; + } + else { + location.hash = ''; + if (hash.charAt(0) == '#') hash = hash.substring(1); + params = hash.split('/'); + for (i = params.length - 1; i >= 0; i--) { + param = params[i]; + j = param.indexOf('='); + if (j < 0) continue; + key = param.substring(0, j); + switch (key) { + case 'sid': + sid = param.substring(j+1); + break; + case 'grp': + grp = param.substring(j+1); + break; + case 'prb': + prb = param.substring(j+1); + break; + } } - }); - }; + if (!sid) error = 'No session ID provided'; + else if (!grp) error = 'No problem group provided'; + else if (!prb) error = 'No problem provided'; + } + + if (error) { + alert(error); + } + else { + codeq.sid = sid; + codeq.system.load({ + type: 'text', + url: 'prolog/problems/' + grp + '/' + prb + '/en.py', + callback: function (data, status, url) { + if (!data) return; + var info = codeq.parseDefinition(data); + window.phandler = codeq.createPrologHandler(info, grp, prb); // TODO: for debug only + // DEBUG: phandler.processServerHints([{id:'x_must_be_female'}]); + // DEBUG: phandler.processServerHints([{id:'popup_unknown', start: 20, end: 26}]); + // DEBUG: phandler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); + } + }); + } + }); })(); -- cgit v1.2.1