From 652164680ac0d1b4ace0ae9ec55f69b28740d11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Thu, 24 Sep 2015 10:19:52 +0200 Subject: Reimplemented language selection with simple links. Removed unused startup.js, moved the boot sequence to core.js. --- js/codeq/core.js | 8 +++++ js/codeq/language.js | 34 ++++++++---------- js/codeq/startup.js | 100 --------------------------------------------------- 3 files changed, 22 insertions(+), 120 deletions(-) delete mode 100644 js/codeq/startup.js (limited to 'js/codeq') diff --git a/js/codeq/core.js b/js/codeq/core.js index 564aec3..61ef607 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -264,4 +264,12 @@ }; } }; + + // ================================================================================ + // The boot sequence + // ================================================================================ + + $(document).ready(function () { + codeq.globalStateMachine.transition('login'); + }); })(); diff --git a/js/codeq/language.js b/js/codeq/language.js index d4b6ee4..be2a319 100644 --- a/js/codeq/language.js +++ b/js/codeq/language.js @@ -3,34 +3,28 @@ */ (function(){ + var jqScreen = $('#screen_language'), + jqProlog = $('#choose-prolog'), + jqPython = $('#choose-python'), + chooseProlog = function () {codeq.globalStateMachine.transition('problem', 'prolog');}, + choosePython = function () {codeq.globalStateMachine.transition('problem', 'python');}; + codeq.globalStateMachine.register('language',{ 'enter': function(){ - $('#submit_language').on('click',function(){ - codeq.globalStateMachine.transition('problem',$('#language').val()); - //var lan = $('#language').val(); - //codeq.activateState('problem',{'lan':lan}); - }); - $('#navigation-login').css('display', ''); - /*$('#navigation-login').on('click', function(){ - codeq.globalStateMachine.transition('login'); - //codeq.activateState('login'); - });*/ - $("#navigation-language").addClass("active"); - $('#navigation-language').css('display', ''); + $("#navigation-language").addClass("active").css('display', ''); - $("#screen_language").css('display', ''); + jqScreen.css('display', ''); + jqProlog.on('click', chooseProlog); + jqPython.on('click', choosePython); }, 'exit' : function(){ - $("#submit_language").off(); - $("#screen_language").css('display', 'none'); + jqProlog.off(); + jqPython.off(); + jqScreen.css('display', 'none'); $('#navigation-login').css('display', 'none'); - //$('#navigation-login').off(); - $('#navigation-language').css('display', 'none'); - $("#navigation-language").removeClass("active"); - - $('#language').val("prolog");//reset to the default value + $('#navigation-language').css('display', 'none').removeClass("active"); } }); })(); \ No newline at end of file diff --git a/js/codeq/startup.js b/js/codeq/startup.js deleted file mode 100644 index ccef9f9..0000000 --- a/js/codeq/startup.js +++ /dev/null @@ -1,100 +0,0 @@ -$(document).ready(function () { - /*codeq.comms.connect().then(function () { - return codeq.comms.send({'action': 'list_problems'}); - }).then( - function success(data) { - var i, groups, group, problems, problem, first_group, - jqGroup = $('#problem_group'), - jqProblems = $('#problems'), - html = [], - mapping = {}, - onGroupChange = function () { - var problems = mapping[jqGroup.val()], - html = [], - i, p; - if (problems) { - for (i = 0; i < problems.length; i++) { - p = problems[i]; - html.push('\n') - } - } - jqProblems.html(html.join('')); - }; - - if (data && (data.code === 0)) { - $('#disabled').css('display', 'none'); - groups = data.problems; - for (i = 0; i < groups.length; i++) { - group = groups[i]; - var identifier = group.identifier.language + '/' + group.identifier.group; - var name = group.name.language + ': ' + group.name.group; - html.push('\n'); - mapping[identifier] = group.problems; - } - jqGroup.html(html.join('')); - first_group = html[1]; - html = null; - - jqGroup.on('click', onGroupChange); - jqGroup.val(first_group); - onGroupChange(); - - $("#submit").on('click', function () { - var identifier = $('#problem_group').val().split('/'), - problem = $('#problems').val(); - if (identifier.length < 2) alert('Choose a problem group'); - else if (!problem) alert('Choose a problem'); - else { - $('#disabled').css('display', ''); - codeq.comms.login($('#username').val(), $('#password').val()) - .then(function (data) { - $('#disabled').css('display', 'none'); - if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message); - }) - .then(function () { - return codeq.comms.getProblem(identifier[0], identifier[1], problem); - }) - .then(function (data) { - if (data.code !== 0) throw new Error('Failed to obtain problem data, code: ' + data.code + ', message: ' + data.message); - $('#disabled').css('display', 'none'); - switch (identifier[0]) { - case 'prolog': - // TODO: assignment to window for debug only - $('#screen_login').css('display', 'none'); - $('#screen_prolog').css('display', ''); - window.phandler = codeq.createPrologHandler(data.data); - break; - case 'python': - // TODO: assignment to window for debug only - $('#screen_login').css('display', 'none'); - $('#screen_prolog').css('display', ''); - window.phandler = codeq.createPythonHandler(data.data); - break; - default: - alert('Unknown language: ' + identifier[0]); - break; - } - }) - .fail(function (reason) { - $('#disabled').css('display', 'none'); - codeq.log.error('Login request failed: ' + reason, reason); - alert('Login request failed: ' + reason); - }) - .done(); - } - }); - } - else { - $('#disabled').css('cursor', ''); - alert('Obtaining list of problems failed: code=' + data.code + ', reason=' + data.message); - } - }, - - function failure(reason) { - $('#disabled').css('cursor', ''); - alert('Request to obtain list of problems failed: ' + reason); - } - ).done();*/ - - codeq.globalStateMachine.transition('login'); -}); \ No newline at end of file -- cgit v1.2.1