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

4
    waitForProtex();
5

6
    function waitForProtex() {
7 8
        if (typeof(protex) !== 'undefined' && protex) {
            protex.onInjectionDone('protex');
9
        }
10 11
        /* if (typeof(protex) !== "undefined") {
            //initializeProtex();
jmclaus committed
12
        }*/
13 14 15 16
        else {
            setTimeout(function() { waitForProtex(); }, timeout);
        }
    }
17 18

    // NOTE:
jmclaus committed
19 20 21
    // Protex uses three global functions:
    // protexSetTargetShape (exported from GWT)
    // exported protexCheckAnswer (exported from GWT)
22
    // It calls protexIsReady with a deferred command when it has finished
jmclaus committed
23
    // initialization and has drawn itself
24

25
    function updateProtexField() {
26 27 28 29 30 31 32 33
        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
    protexIsReady = function() {
35
        // Load target shape
jmclaus committed
36 37
        var target_shape = $('#target_shape').val();
        protexSetTargetShape(target_shape);
38 39 40 41 42

        // Get answer from protex and store it into the hidden input field
        // when Check button is clicked
        var fold_button = $('#fold-button');
        fold_button.on('click', function() {
43 44
            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

53 54 55 56

    /* function initializeProtex() {
        //Check to see if the two exported GWT functions protexSetTargetShape
        // and protexCheckAnswer have been appended to global scope -- this
57 58 59
        //happens at the end of onModuleLoad() in GWT
        if (typeof(protexSetTargetShape) === "function" &&
            typeof(protexCheckAnswer) === "function") {
60

61 62
            //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
            });
75

jmclaus committed
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);