From ca3aa94da7798bba4fed6ae467d8fa94324a832e Mon Sep 17 00:00:00 2001 From: Robert Zorko Date: Wed, 16 Dec 2015 14:05:18 +0100 Subject: moved loading of problem data into the 'enter' of the python, robot and prolog states --- js/codeq/python.js | 60 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'js/codeq/python.js') diff --git a/js/codeq/python.js b/js/codeq/python.js index 4033a63..472d700 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -86,19 +86,58 @@ along with this program. If not, see . */ } }; var pythonHandler; //created when we enter the python state and destroyed once we leave it + + var enterFun = function(problemDef, commonDef, currentSolution){ + $('#navigation-problem_list').css('display', ''); + var navigationPhython = $("#navigation-python"); + navigationPhython.addClass("active"); + navigationPhython.css('display', ''); + + jqScreen.css('display', '');//we have to show the screen now so the code editor shows its initial values correctly + pythonHandler = createPythonHandler(problemDef, commonDef, currentSolution); + subScreens = codeq.makeStateMachine(substates); + subScreens.transition(jqDescription.data(stateNameTag)); + + jqInfoButtons.on(transitionEventName, function (event) { + subScreens.transition('info'); // set focus on the hints quadrant + event.stopPropagation(); // don't allow the event to go on and trigger further transition + }); + jqBtnRun.on(transitionEventName, function (event) { + subScreens.transition('console'); // set focus on the hints quadrant + event.stopPropagation(); // don't allow the event to go on and trigger further transition + }); + + jqAllQuadrants.on(transitionEventName, function () { + subScreens.transition($(this).data(stateNameTag)); + }); + }; + codeq.globalStateMachine.register('python', { - 'enter': function (problemDef, commonDef, currentSolution) { - $('#navigation-problem_list').css('display', ''); - $("#navigation-python").addClass("active"); - $('#navigation-python').css('display', ''); + 'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {// + + codeq.loadProblemData(ref,data).then(function(problem){ + //codeq.log.debug("then:"+JSON.stringify(problem)); + enterFun(problem.generalProblemData,data.commonDef,problem.solution); + }) + .fail(function (reason) { + codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); + alert('Failed to obtain the problem definition: ' + reason); + + history.back();//TODO test + }) + .done(); + + + /*$('#navigation-problem_list').css('display', ''); + var navigationPhython = $("#navigation-python"); + navigationPhython.addClass("active"); + navigationPhython.css('display', ''); jqScreen.css('display', '');//we have to show the screen now so the code editor shows its initial values correctly pythonHandler = createPythonHandler(problemDef, commonDef, currentSolution); subScreens = codeq.makeStateMachine(substates); subScreens.transition(jqDescription.data(stateNameTag)); -/* Q.delay(100).then(function(){ - jqAllQuadrants.addClass('transition');//for smooth animations - need to be delayed, because otherwise we get some weird "animations" while the page is loading - }).done();*/ + jqInfoButtons.on(transitionEventName, function (event) { subScreens.transition('info'); // set focus on the hints quadrant event.stopPropagation(); // don't allow the event to go on and trigger further transition @@ -110,7 +149,7 @@ along with this program. If not, see . */ jqAllQuadrants.on(transitionEventName, function () { subScreens.transition($(this).data(stateNameTag)); - }); + });*/ }, 'exit': function () { jqAllButtons.off(); // unregister all event handlers @@ -124,8 +163,9 @@ along with this program. If not, see . */ jqScreen.addClass('block1'); $('#navigation-problem_list').css('display', 'none'); - $("#navigation-python").removeClass("active"); - $('#navigation-python').css('display', 'none'); + var navigationPhython = $("#navigation-python"); + navigationPhython.removeClass("active"); + navigationPhython.css('display', 'none'); } }); -- cgit v1.2.1