design-protein-2d.js 3.19 KB
Newer Older
jmclaus committed
1 2 3
(function () {
    var timeout = 1000;

4
    waitForProtex();
5

6 7 8 9
    function waitForProtex() {
        if (typeof(protex) !== "undefined" && protex) {
            protex.onInjectionDone("protex");
        }
jmclaus committed
10 11 12
        /*if (typeof(protex) !== "undefined") {
            //initializeProtex();    
        }*/
13 14 15 16 17
        else {
            setTimeout(function() { waitForProtex(); }, timeout);
        }
    }
    
jmclaus committed
18 19 20 21 22 23 24
    //NOTE:
    // Protex uses three global functions:
    // protexSetTargetShape (exported from GWT)
    // exported protexCheckAnswer (exported from GWT)
    // It calls protexIsReady with a deferred command when it has finished 
    // initialization and has drawn itself
    
25 26 27 28 29 30 31 32 33
    function updateProtexField() {
            var problem = $('#protex_container').parents('.problem');
            var input_field = problem.find('input[type=hidden]');
            var protex_answer = protexCheckAnswer();
            var value = {protex_answer: protex_answer};
            //console.log(JSON.stringify(value));
            input_field.val(JSON.stringify(value));
        }
        
jmclaus committed
34 35 36 37 38 39 40
    protexIsReady = function() {
        //Load target shape
        var target_shape = $('#target_shape').val();
        protexSetTargetShape(target_shape);
            
        //Get answer from protex and store it into the hidden input field
        //when Check button is clicked
41 42 43 44
        var fold_button = $("#fold-button");
        fold_button.on('click', function(){
            var problem = $('#protex_container').parents('.problem');
            var input_field = problem.find('input[type=hidden]');
jmclaus committed
45 46
            var protex_answer = protexCheckAnswer();
            var value = {protex_answer: protex_answer};
47
            //console.log(JSON.stringify(value));
jmclaus committed
48
            input_field.val(JSON.stringify(value));
49 50
        });
        updateProtexField();              
jmclaus committed
51
    };
52

jmclaus committed
53 54
    
    /*function initializeProtex() {
55 56 57 58 59 60 61 62
        //Check to see if the two exported GWT functions protexSetTargetShape 
        // and protexCheckAnswer have been appended to global scope -- this 
        //happens at the end of onModuleLoad() in GWT
        if (typeof(protexSetTargetShape) === "function" &&
            typeof(protexCheckAnswer) === "function") {
            
            //Load target shape
            var target_shape = $('#target_shape').val();
jmclaus committed
63
            //protexSetTargetShape(target_shape);
64 65 66 67
            
            //Get answer from protex and store it into the hidden input field
            //when Check button is clicked
            var problem = $('#protex_container').parents('.problem');
68
            var check_button = problem.find('input.check');
69
        	var input_field = problem.find('input[type=hidden]');
70
            check_button.on('click', function() {
71 72 73
                var protex_answer = protexCheckAnswer();
                var value = {protex_answer: protex_answer};
                input_field.val(JSON.stringify(value));
74
            });
jmclaus committed
75 76 77 78 79
            
            //TO DO: Fix this, it works but is utterly ugly and unreliable
            setTimeout(function() {
              protexSetTargetShape(target_shape);}, 2000);

80 81 82
        }
        else {
            setTimeout(function() {initializeProtex(); }, timeout);
jmclaus committed
83
        }
jmclaus committed
84
    }*/
jmclaus committed
85
}).call(this);