wrapper.html 4.12 KB
Newer Older
1
2
3
4
5
6
7
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
    <script src="/static/lib/jquery/jquery-3.2.1.min.js"></script>
    <script src="/static/lib/fioipem/jschannel-190528.js"></script>
8
    <script src="/static/lib/fioipem/task-xd-pr-190528.js"></script>
9
10
11
12
13
    <script src="/static/lib/medal/medal-0.0.2.js"></script>
  </head>
  <body style="margin:0px; padding:0px; overflow: hidden;">
    <script>

14
15
16
17
18
$("body").prepend('<iframe src="' + location.search.substr(1) + '?channelId=task" id="ifr" style="border: 0px; width:100vw; height:100vh;margin:0px; padding:0px; "></iframe>');


var options = {
  minScore:0,
19
  maxScore:100,
20
21
22
  noScore:0,
  randomSeed:0,
  readOnly:false,
23
  options:{difficulty:"easy", log:1},
24
25
26
27
28
29
30
31
}

var myLoadViews = {
  editor: true,
  forum: true,
  hints: true,
  submission: true,
  task: true,
32
  grader: true,
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  metadata: true,
}

var myViews = {
  task: true,
}

function ec(name) {
  return function(e){
    console.log(name + " error:");
    console.log(e);
  }
}

function noop(){}

function getTaskProxyCallback(task) {
  function reloadAnswerCallback() {
51
    task.gradeAnswer("", {}, noop, ec("task.gradeAnswer"));
52
53
54
55
56
57
58
59
60
  }

  function reloadStateCallback() {
    function load_task_callback(data) {
      if ("text" in data) {
        task.reloadAnswer(data["text"], reloadAnswerCallback, ec("task.reloadAnswer"));
      } else {
        task.reloadAnswer('', reloadAnswerCallback, ec("task.reloadAnswer"));
      }
61
    }
62
63
64
65
    function load_task_error() {
      task.reloadAnswer('', reloadAnswerCallback, ec("task.reloadAnswer"));
      alert("Laden fehlgeschlagen");
    }
66

67
    window.load_task_object(load_task_callback, load_task_error);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  }

  function showViewsCallback(){
    task.reloadState('', reloadStateCallback, ec("task.reloadState"));
  }

  function loadCallback(){
    task.showViews(myViews, showViewsCallback, ec("task.showViews"));
  }

  function getViewsCallback(views){
    task.load(myLoadViews, loadCallback, ec("task.load"))
  }

82
83
  var previous_answer = "";

84
  function getAnswerCallback(answer) {
85
86
87
88
89
    // If the answer did not change since last save, there is nothing to do
    if (answer == previous_answer) {
      return;
    }

90
91
92
    console.log("In task.gradeAnswer callback:");
    console.log(answer);

93
94
95
    function gradeAnswerCallback(score, message, scoreToken){
      function save_task_callback() {
        console.log("OK transmission");
96
97
98

        // Now we know that the answer has been saved
        previous_answer = answer;
99
      };
100
101
102
103
      function save_task_error() {
        console.log("ERROR transmission");
        alert("Speichern fehlgeschlagen");
      };
104

105
      window.save_task_object({"text": answer}, score, save_task_callback, save_task_error);
106
107
    }

108
109
110
111
112
113
114
115
116
117
118
119
120
    task.gradeAnswer(answer, {}, gradeAnswerCallback, ec("task.gradeAnswer"));
  }

  var platform = {
    getTaskParams: function(key, def, cb, ecb) {
      if (!key && !def) {
        cb(options);
      }
      else {
        cb();
      }
    },
    validate: function(mode, cb, ecb) {
121
122
123
124
125
126
127
      if (mode == 'done') {
        task.getAnswer(getAnswerCallback, ec("task.getAnswer"));
        if (cb) {cb();}
      }
      else if (mode == 'next' || mode == 'nextImmediate') {
        window.parent.redirectOverview();
      }
128
129
130
131
      if (mode == 'log') {
        task.getAnswer(getAnswerCallback, ec("task.getAnswer"));
        if (cb) {cb();}
      }
132
133
134
135
      else {
        console.error("Unknown mode: '" + mode + "'");
        if (ecb) {ecb();}
      }
136
    },
137
    showViews: function(views, cb, ecb) {
138
139
      cb(options);
    },
140
    openUrl: function(textId, cb, ecb) {
141
142
      cb();
    },
143
    askHint: function(ht, cb, ecb) {
144
145
146
147
148
      cb();
    },
    updateDisplay: function(opt, cb, ecb) {
      cb();
    },
149
    initWithTask: function(t, cb, ecb) {
150
151
152
153
154
155
156
      cb(options);
    },
  };

  TaskProxyManager.setPlatform(task, platform);

  task.getViews(getViewsCallback, ec("task.getViews"));
157
158
159
160

  setInterval(function(){
    task.getAnswer(getAnswerCallback, ec("task.getAnswer"));
  }, 10000);
161
162
163
164
165
166
167
}

function main() {
  TaskProxyManager.getTaskProxy("ifr", getTaskProxyCallback, false, ec("task.getTaskProxy"));
}

setTimeout(main, 1);
168
169
170
171

    </script>
  </body>
</html>