'wtem': {
'source_filenames': (
'wtem/edumed.js',
+ 'wtem/wtem.js',
),
'output_filename': 'compressed/wtem.js'
},
$(".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
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
});
};
+ 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);
--- /dev/null
+$(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
--- /dev/null
+<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
{% 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
+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))