From 985a407d3afd4dae71a362116a2d8bd91fe6babd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 31 Oct 2013 13:51:32 +0100 Subject: [PATCH] Serializing answers to form field --- wtem/static/wtem/wtem.js | 32 ++++++++++++++++--- .../wtem/exercises/edumed_prawdafalsz.html | 2 +- .../wtem/exercises/edumed_przyporzadkuj.html | 2 +- .../wtem/exercises/edumed_uporzadkuj.html | 2 +- .../wtem/exercises/edumed_wybor.html | 2 +- .../templates/wtem/exercises/file_upload.html | 2 +- wtem/templates/wtem/exercises/open.html | 2 +- wtem/templates/wtem/main.html | 1 + 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/wtem/static/wtem/wtem.js b/wtem/static/wtem/wtem.js index f7dccdc..209108f 100644 --- a/wtem/static/wtem/wtem.js +++ b/wtem/static/wtem/wtem.js @@ -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 diff --git a/wtem/templates/wtem/exercises/edumed_prawdafalsz.html b/wtem/templates/wtem/exercises/edumed_prawdafalsz.html index a55724a..b5b7c3f 100644 --- a/wtem/templates/wtem/exercises/edumed_prawdafalsz.html +++ b/wtem/templates/wtem/exercises/edumed_prawdafalsz.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/exercises/edumed_przyporzadkuj.html b/wtem/templates/wtem/exercises/edumed_przyporzadkuj.html index c56dec0..b5a1a3d 100644 --- a/wtem/templates/wtem/exercises/edumed_przyporzadkuj.html +++ b/wtem/templates/wtem/exercises/edumed_przyporzadkuj.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/exercises/edumed_uporzadkuj.html b/wtem/templates/wtem/exercises/edumed_uporzadkuj.html index 1f2068d..082ae49 100644 --- a/wtem/templates/wtem/exercises/edumed_uporzadkuj.html +++ b/wtem/templates/wtem/exercises/edumed_uporzadkuj.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/exercises/edumed_wybor.html b/wtem/templates/wtem/exercises/edumed_wybor.html index 0fe9600..3fdb80a 100644 --- a/wtem/templates/wtem/exercises/edumed_wybor.html +++ b/wtem/templates/wtem/exercises/edumed_wybor.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/exercises/file_upload.html b/wtem/templates/wtem/exercises/file_upload.html index 44b78e6..e4be9a1 100644 --- a/wtem/templates/wtem/exercises/file_upload.html +++ b/wtem/templates/wtem/exercises/file_upload.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/exercises/open.html b/wtem/templates/wtem/exercises/open.html index 3e08265..dbb3f53 100644 --- a/wtem/templates/wtem/exercises/open.html +++ b/wtem/templates/wtem/exercises/open.html @@ -1,4 +1,4 @@ -
+

Zadanie {{no}}

diff --git a/wtem/templates/wtem/main.html b/wtem/templates/wtem/main.html index e7ce29a..4536cfb 100644 --- a/wtem/templates/wtem/main.html +++ b/wtem/templates/wtem/main.html @@ -19,6 +19,7 @@
+ -- 2.20.1