wip: showing first couple of questions
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 30 Oct 2013 15:52:44 +0000 (16:52 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 15 Jan 2014 10:18:53 +0000 (11:18 +0100)
edumed/settings.d/50-static.py
wtem/static/wtem/edumed.coffee
wtem/static/wtem/edumed.js
wtem/static/wtem/wtem.js [new file with mode: 0644]
wtem/templates/wtem/exercises/edumed_wybor.html [new file with mode: 0644]
wtem/templates/wtem/main.html
wtem/views.py

index 35aabe2..5b6c079 100644 (file)
@@ -51,6 +51,7 @@ PIPELINE_JS = {
     'wtem': {
         'source_filenames': (
             'wtem/edumed.js',
+            'wtem/wtem.js',
         ),
         'output_filename': 'compressed/wtem.js'
     },
index fb8ea87..baae08e 100644 (file)
@@ -67,6 +67,12 @@ class Exercise extends Binding
     $(".question", @element).each (i, question) =>
       @solve_question question
 
+  get_answers: ->
+    answers = []
+    $('.question', @element).each (i, question) =>
+      answers.push(@get_answer question)
+    return answers
+
   # Parses a list of values, separated by space or comma.
   # The list is read from data attribute of elem using data_key
   # Returns a list with elements
@@ -243,6 +249,13 @@ class Wybor extends Exercise
       console.log("check " + $("input[type=checkbox]", qpiece).attr("id") + " -> " + should_be_checked)
       $("input[type=checkbox],input[type=radio]", qpiece).prop 'checked', should_be_checked
 
+  get_answer: (question) ->
+    answer = []
+    $('.question-piece', question).each (i, qpiece) =>
+      $qpiece = $(qpiece)
+      if $("input[type=checkbox],input[type=radio]", qpiece).is(':checked')
+        answer.push($qpiece.attr('data-name'))
+    return answer
 
 
 class Uporzadkuj extends Exercise
index f828dec..58b5114 100644 (file)
       });
     };
 
+    Exercise.prototype.get_answers = function() {
+      var answers,
+        _this = this;
+      answers = [];
+      $('.question', this.element).each(function(i, question) {
+        return answers.push(_this.get_answer(question));
+      });
+      return answers;
+    };
+
     Exercise.prototype.get_value_list = function(elem, data_key, numbers) {
       var vl;
       vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim);
       });
     };
 
+    Wybor.prototype.get_answer = function(question) {
+      var answer,
+        _this = this;
+      answer = [];
+      $('.question-piece', question).each(function(i, qpiece) {
+        var $qpiece;
+        $qpiece = $(qpiece);
+        if ($("input[type=checkbox],input[type=radio]", qpiece).is(':checked')) {
+          return answer.push($qpiece.attr('data-name'));
+        }
+      });
+      return answer;
+    };
+
     return Wybor;
 
   })(Exercise);
diff --git a/wtem/static/wtem/wtem.js b/wtem/static/wtem/wtem.js
new file mode 100644 (file)
index 0000000..f87ad42
--- /dev/null
@@ -0,0 +1,14 @@
+$(function() {
+
+    $('#submit_answers').click(function() {
+        var to_submit = [];
+        $('.exercise').each(function() {
+            var exercise = $(this).data('exercise');
+            if(exercise.get_answers) {
+                to_submit.push(exercise.get_answers()[0]);
+            }
+        });
+        console.log(JSON.stringify(to_submit));
+    });
+
+});
\ No newline at end of file
diff --git a/wtem/templates/wtem/exercises/edumed_wybor.html b/wtem/templates/wtem/exercises/edumed_wybor.html
new file mode 100644 (file)
index 0000000..511cf7f
--- /dev/null
@@ -0,0 +1,22 @@
+<div class="exercise wybor" data-type="wybor">
+
+    <h3>Zadanie {{no}}</h3>
+
+    <div class="description">
+        <p class="paragraph">
+            {{exercise.description}}
+        </p>
+    </div>
+
+    <div class="question" data-no="1">
+        <ol class="lista num">
+            {% for option in exercise.options %}
+                <li class="question-piece" data-name="{{option.id}}">
+                    <input type="{% if exercise.answer|length == 1 %}radio{% else %}checkbox{% endif %}" name="{% if exercise.answer|length == 1 %}e{{no}}{% else %}q1_{{option.id}}{% endif %}" id="q1_{{option.id}}">
+                    <label for="{% if exercise.answer|length == 1 %}e{{no}}{% else %}q1_{{option.id}}{% endif %}">{{option.text}}</label>
+                </li>
+            {% endfor %}
+        </ol>
+    </div>
+
+</div>
\ No newline at end of file
index bee75ec..ccb6023 100644 (file)
@@ -4,3 +4,19 @@
 {% block extra_script %}
     {% compressed_js 'wtem' %}
 {% endblock %}
+
+
+
+{% block body %}
+
+{% for exercise in exercises %}
+    {% with 'wtem/exercises/'|add:exercise.type|add:'.html' as template_name %}
+    {% include  template_name with exercise=exercise no=forloop.counter %}
+    {% endwith %}
+{% endfor %}
+
+
+<hr/>
+<button style="display: block; margin: auto;" id="submit_answers">Wyślij moje odpowiedzi</button>
+
+{% endblock %}
\ No newline at end of file
index ae1f64b..6578e44 100644 (file)
@@ -1,4 +1,13 @@
+import os
+
 from django.shortcuts import render
+from django.utils import simplejson
+
 
 def main(request):
-    return render(request, 'wtem/main.html')
\ No newline at end of file
+    ## @@ move this out of the view
+    f = file(os.path.dirname(__file__) + '/fixtures/exercises.json')
+    exercises = simplejson.loads(f.read())
+    f.close()
+
+    return render(request, 'wtem/main.html', dict(exercises = exercises))