Serializing answers to form field
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 31 Oct 2013 12:51:32 +0000 (13:51 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 15 Jan 2014 10:18:53 +0000 (11:18 +0100)
wtem/static/wtem/wtem.js
wtem/templates/wtem/exercises/edumed_prawdafalsz.html
wtem/templates/wtem/exercises/edumed_przyporzadkuj.html
wtem/templates/wtem/exercises/edumed_uporzadkuj.html
wtem/templates/wtem/exercises/edumed_wybor.html
wtem/templates/wtem/exercises/file_upload.html
wtem/templates/wtem/exercises/open.html
wtem/templates/wtem/main.html

index f7dccdc..209108f 100644 (file)
@@ -1,15 +1,37 @@
 $(function() {
 
+    var to_submit;
+
     $('#submit_answers').click(function(e) {
         e.preventDefault();
-        var to_submit = [];
-        $('.exercise').each(function() {
-            var exercise = $(this).data('exercise');
-            if(exercise.get_answers) {
-                to_submit.push(exercise.get_answers()[0]);
+        to_submit = [];
+
+        $('.exercise-wtem').each(function() {
+            var el = $(this);
+            if(el.hasClass('exercise')) {
+                handlers.edumed(el);
+            } else {
+                var type = el.attr('data-type');
+                if(handlers[type]) {
+                    handlers[type](el);
+                }
             }
         });
         console.log(JSON.stringify(to_submit));
+        $('input[name=wtem_answers]').val(JSON.stringify(to_submit));
     });
 
+    var handlers = {
+        edumed: function(el) {
+            var exercise = el.data('exercise');
+            if(exercise.get_answers) {
+                to_submit.push(exercise.get_answers()[0]);
+            }
+        },
+
+        open: function(el) {
+            to_submit.push(el.find('textarea').val());
+        }
+    }
+
 });
\ No newline at end of file
index a55724a..b5b7c3f 100644 (file)
@@ -1,4 +1,4 @@
-<div class="exercise prawdafalsz" data-type="prawdafalsz">
+<div class="exercise exercise-wtem prawdafalsz" data-type="prawdafalsz">
 
     <h3>Zadanie {{no}}</h3>
 
index c56dec0..b5a1a3d 100644 (file)
@@ -1,4 +1,4 @@
-<div class="exercise przyporzadkuj" data-type="przyporzadkuj">
+<div class="exercise exercise-wtem przyporzadkuj" data-type="przyporzadkuj">
 
     <h3>Zadanie {{no}}</h3>
     
index 1f2068d..082ae49 100644 (file)
@@ -1,4 +1,4 @@
-<div class="exercise uporzadkuj" data-type="uporzadkuj">
+<div class="exercise exercise-wtem uporzadkuj" data-type="uporzadkuj">
 
     <h3>Zadanie {{no}}</h3>
 
index 0fe9600..3fdb80a 100644 (file)
@@ -1,4 +1,4 @@
-<div class="exercise wybor" data-type="wybor">
+<div class="exercise exercise-wtem wybor" data-type="wybor">
 
     <h3>Zadanie {{no}}</h3>
 
index 44b78e6..e4be9a1 100644 (file)
@@ -1,4 +1,4 @@
-<div>
+<div class="exercise-wtem" data-type="file">
 
     <h3>Zadanie {{no}}</h3>
         
index 3e08265..dbb3f53 100644 (file)
@@ -1,4 +1,4 @@
-<div>
+<div class="exercise-wtem" data-type="open">
 
     <h3>Zadanie {{no}}</h3>
         
index e7ce29a..4536cfb 100644 (file)
@@ -19,6 +19,7 @@
 
 
 <hr/>
+<input type="hidden" name="wtem_answers" value=""/>
 <button style="display: block; margin: auto;" id="submit_answers">Wyślij moje odpowiedzi</button>
 
 </form>