crowdxblock.js 5.29 KB
Newer Older
1 2 3

//my coding attemps start here i guess
    /*this.url = this.el.data('url');
4 5
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/
6
    /*function capture_problem(event_type, data, element) {
7 8 9 10
var answers, response,
_this = this;
answers = data[0];
response = data[1];*/ //use this snippet for actual code? maybe?
Sola committed
11

12 13 14
function CrowdXBlock(runtime, element){
    var WrongAnswer = [];
    var HintUsed = [];
15 16
    $("#answer").hide();
    $(".problem").hide();
17
    $("#feedback").hide();
18 19 20 21 22 23

    function seehint(result){//use html to show these results somewhere i guess
        $('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
    }

    function getfeedback(result){
24 25
        $("#answer").show();
        $(".problem").show();
Sola committed
26 27 28
        $("#feedback").show();
        $.each(result, function(index, value) {
        console.log("the type of value is" + ' '+ typeof(value));
29
        if($("#submit"+value).length == 0){
Sola committed
30 31 32 33 34 35 36 37
        console.log("#submit"+value);
        $('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
        console.log('hintsarea made for ' + value);
        $('#submit'+value).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + value + "\"> The following hints exist: </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
        }
        $('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
        console.log("the value is " + value);
        });
38
};
39

40
    $(document).on('click', '.hintbutton', function(){ //upvote
Sola committed
41 42 43 44
        console.log("the first id" + this.id);
        id = this.id;
        console.log($(this).attr('id'));
        $.ajax({
45 46
            type: "POST",
            url: runtime.handlerUrl(element, 'rate_hint'),
47
            data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id'), "value": $(this).attr('data-value')}),
48 49
            success: finish
        });})
50
    $(document).on('click', '.submitbutton', function(){ //upvote
Sola committed
51 52
        console.log("submitbutton hit");
        id = this.id;
53
        value = $('#'+id).attr('data-value');
Sola committed
54 55
        console.log("this id " + $(this).attr('id'));
        $('#submit' + value).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");})
56 57 58
    $(document).on('click', '#submit', function(){
        console.log("the other id thing" + this.id);
        console.log("thisthing" + $(".math").attr('id'));
Sola committed
59
        $.ajax({
60 61
            type: "POST",
            url: runtime.handlerUrl(element, 'give_hint'),
62
            data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
63
            success: finish
Sola committed
64
        });
Sola committed
65
        $("#answer").val('');})
66 67

    $('#caus', element).click(function(eventObject) {
Sola committed
68 69
        console.debug("ca working this is edited");
        $.ajax({
70 71 72 73
            type: "POST",
            url: runtime.handlerUrl(element, 'clear_states'),
            data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
            success: clearstates
Sola committed
74
        });
Sola committed
75 76
        $("#studentsubmit").val('');
        $("#answer").val('');})
77
    function finish(){
Sola committed
78 79
        $('.Thankyou', element).text("Thankyou for your help!");
        $('.correct', element).hide();
80
        $( ".hintansarea" ).empty();
81
    }
82
    function clearstates(){
Sola committed
83 84
        $('.Thankyou', element).text();
        $('.correct', element).hide();
85
        $( ".hintansarea" ).empty();
86 87 88
        $("#answer").hide();
        $(".problem").hide();
    }
89

90
    function checkreply(result){
91 92

if(result.correct == 1){
93
        console.debug("yay");
Sola committed
94 95
        $('.correct', element).show();
        $('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
96 97
        $.ajax({
            type: "POST",
98
            url: runtime.handlerUrl(element, 'get_feedback'),
99
            data: JSON.stringify({"hello": "world"}),
100 101 102
            success: getfeedback
        });
        }else{
Sola committed
103 104
        console.debug("nay");
        seehint(result)
105 106
        }
    }
107
    $('#studentanswer', element).click(function(eventObject) { //for test //when answer is incorrect /*response.search(/class="correct/) === -1*/
Sola committed
108
        console.debug($('#studentsubmit').val()); //currently data is passed to python and then returned whether it is correct or not
109 110
        $.ajax({ //that probably will be changed once i use response.search or something?
            type: "POST", //if/when that is changed, remove checkreply and uncomment the else statement below
111
            url: runtime.handlerUrl(element, 'get_hint'),
112 113
            data: JSON.stringify({"submittedanswer": $('#studentsubmit').val()}), //return student's incorrect answer here
            success: checkreply
114
        });
Sola committed
115
        $("#studentsubmit").val('');
116
     /* } else { //answer is correct
117 118 119 120 121 122 123 124
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};*/
125 126
    }
)}