Allow for only one item in a bucket in questions of type "przyporzadkuj"
[edumed.git] / wtem / static / wtem / edumed.coffee
index fb8ea87..ae7aea9 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
@@ -284,6 +297,12 @@ class Uporzadkuj extends Exercise
     for p in pkts
       parent.prepend(p)
 
+  get_answer: (question) ->
+    answer = []
+    $(".question-piece", @element).each (i, qpiece) =>
+      answer.push($(qpiece).attr('data-pos'))
+    return answer
+
 
 # XXX propozycje="1/0"
 class Luki extends Exercise
@@ -396,6 +415,9 @@ class Przyporzadkuj extends Exercise
   draggable_equal: (d1, d2) ->
     return d1.data("no") == d2.data("no")
 
+  draggable_accept: ($draggable, $droppable) ->
+    dropped = $droppable.closest("ul, ol").find(".draggable")
+    return (super $draggable, $droppable) && dropped.length == 0
 
   check_question: (question) ->
     # subjects placed in predicates
@@ -446,6 +468,15 @@ class Przyporzadkuj extends Exercise
         $ph = $pr.find ".placeholder:visible"
         @draggable_move $(qp), $ph.eq(0), @multiple
 
+  get_answer: (question) ->
+    answer = {}
+    $(".predicate [data-predicate]", question).each (i, subjects) =>
+      predicate = $(subjects).attr('data-predicate')
+      answer[predicate] = []
+      $('.question-piece', subjects).each (i, qpiece) =>
+        $qpiece = $(qpiece)
+        answer[predicate].push($qpiece.attr('data-id'))
+    return answer
 
 
 class PrawdaFalsz extends Exercise
@@ -489,6 +520,11 @@ class PrawdaFalsz extends Exercise
       else
         $(".false", qp).click()
 
+  get_answer: (question) ->
+    answer = []
+    $(".question-piece", @element).each (i, qpiece) =>
+      answer.push($(qpiece).data('value') || '-')
+    return answer
 
 ##########