209108f0767d8678ea6181ccd7782eff7b68c3c1
[edumed.git] / wtem / static / wtem / wtem.js
1 $(function() {
2
3     var to_submit;
4
5     $('#submit_answers').click(function(e) {
6         e.preventDefault();
7         to_submit = [];
8
9         $('.exercise-wtem').each(function() {
10             var el = $(this);
11             if(el.hasClass('exercise')) {
12                 handlers.edumed(el);
13             } else {
14                 var type = el.attr('data-type');
15                 if(handlers[type]) {
16                     handlers[type](el);
17                 }
18             }
19         });
20         console.log(JSON.stringify(to_submit));
21         $('input[name=wtem_answers]').val(JSON.stringify(to_submit));
22     });
23
24     var handlers = {
25         edumed: function(el) {
26             var exercise = el.data('exercise');
27             if(exercise.get_answers) {
28                 to_submit.push(exercise.get_answers()[0]);
29             }
30         },
31
32         open: function(el) {
33             to_submit.push(el.find('textarea').val());
34         }
35     }
36
37 });