X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/22f04fb4b3e8521af673554c2f51b7ec47940019..fb8befbb76d37a32317ef82324cecc5dd5208c08:/redakcja/static/edumed/js/edumed.coffee diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index afe75d0c..fb8ea872 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -25,18 +25,21 @@ class Exercise extends Binding $(".check", @element).click (ev) => @check() - $(ev.target).next(".retry").show() - $(ev.target).hide() + $(".retry", @element).show() + $(".check", @element).hide() $(".retry", @element).click (ev) => - $(".correct, .incorrect", @element).removeClass("correct incorrect") - $(ev.target).prev(".check").show() - $(ev.target).hide() + @retry() $('.solutions', @element).click => @show_solutions() $(".comment", @element).show() $('.reset', @element).click => @reset() + retry: -> + $(".correct, .incorrect", @element).removeClass("correct incorrect") + $(".check", @element).show() + $(".retry", @element).hide() + reset: -> $(@element).html($(@element).data('exercise-html')) exercise @element @@ -52,10 +55,11 @@ class Exercise extends Binding $(".question", @element).each (i, question) => scores.push(@check_question question) - score = [0, 0] + score = [0, 0, 0] $.each scores, (i, s) -> score[0] += s[0] score[1] += s[1] + score[2] += s[2] @show_score(score) show_solutions: -> @@ -94,7 +98,12 @@ class Exercise extends Binding return [mandat, opt] show_score: (score) -> - $(".message", @element).text("Wynik: #{score[0]} / #{score[1]}") + $msg = $(".message", @element) + $msg.text("Wynik: #{score[0]} / #{score[2]}") + if score[0] >= score[2] and score[1] == 0 + $msg.addClass("maxscore") + else + $msg.removeClass("maxscore") draggable_equal: ($draggable1, $draggable2) -> @@ -119,8 +128,9 @@ class Exercise extends Binding if $added.is(".add-li") $added.wrap("
") - $added.append('x') + $added.append('x') $('.remove', $added).click (ev) => + @retry() if not ismultiple $($added.data('original')).removeClass('disabled').draggable('enable') @@ -136,6 +146,7 @@ class Exercise extends Binding draggable_opts = revert: 'invalid' helper: 'clone' + start: @retry $(".draggable", question).draggable(draggable_opts) self = this @@ -188,11 +199,13 @@ class Exercise extends Binding class Wybor extends Exercise constructor: (element) -> super element + $(".question-piece input", element).change(@retry); check_question: (question) -> all = 0 good = 0 + bad = 0 solution = @get_value_list(question, 'solution') $(".question-piece", question).each (i, qpiece) => piece_no = $(qpiece).attr 'data-no' @@ -211,11 +224,12 @@ class Wybor extends Exercise good += 1 @piece_correct qpiece else + bad += 1 @piece_incorrect qpiece else $(qpiece).removeClass("correct,incorrect") - return [good, all] + return [good, bad, all] solve_question: (question) -> solution = @get_value_list(question, 'solution') @@ -227,14 +241,14 @@ class Wybor extends Exercise else should_be_checked = solution.indexOf(piece_no) >= 0 console.log("check " + $("input[type=checkbox]", qpiece).attr("id") + " -> " + should_be_checked) - $("input[type=checkbox]", qpiece).prop 'checked', should_be_checked + $("input[type=checkbox],input[type=radio]", qpiece).prop 'checked', should_be_checked class Uporzadkuj extends Exercise constructor: (element) -> super element - $('ol, ul', @element).sortable({ items: "> li" }) + $('ol, ul', @element).sortable({ items: "> li", start: @retry }) check_question: (question) -> positions = @get_value_list(question, 'original', true) @@ -242,6 +256,7 @@ class Uporzadkuj extends Exercise pkts = $('.question-piece', question) correct = 0 + bad = 0 all = 0 for pkt in [0...pkts.length] @@ -250,8 +265,9 @@ class Uporzadkuj extends Exercise correct += 1 @piece_correct pkts.eq(pkt) else + bad += 1 @piece_incorrect pkts.eq(pkt) - return [correct, all] + return [correct, bad, all] solve_question: (question) -> positions = @get_value_list(question, 'original', true) @@ -276,18 +292,19 @@ class Luki extends Exercise @dragging false, false check: -> - all = 0 + all = $(".placeholder", @element).length correct = 0 + bad = 0 $(".placeholder + .question-piece", @element).each (i, qpiece) => $placeholder = $(qpiece).prev(".placeholder") if $placeholder.data('solution') == $(qpiece).data('no') @piece_correct qpiece correct += 1 else + bad += 1 @piece_incorrect qpiece - all += 1 - @show_score [correct, all] + @show_score [correct, bad, all] solve_question: (question) -> $(".placeholder", question).each (i, placeholder) => @@ -305,6 +322,7 @@ class Zastap extends Exercise check: -> all = 0 correct = 0 + bad = 0 $(".paragraph", @element).each (i, par) => $(".placeholder", par).each (j, qpiece) => @@ -318,7 +336,7 @@ class Zastap extends Exercise all += 1 - @show_score [correct, all] + @show_score [correct, bad, all] show_solutions: -> @reset() @@ -364,7 +382,7 @@ class Zastap extends Exercise class Przyporzadkuj extends Exercise is_multiple: -> for qp in $(".question-piece", @element) - if $(qp).data('solution').split(/[ ,]+/).length > 1 + if $(qp).attr('data-solution').split(/[ ,]+/).length > 1 return true return false @@ -383,14 +401,19 @@ class Przyporzadkuj extends Exercise # subjects placed in predicates minimum = $(question).data("minimum") count = 0 + bad_count = 0 all = 0 if not minimum - all = $(".subjects .question-piece", question).length + self = this + $(".subject .question-piece", question).each (i, el) -> + v = self.get_value_optional_list el, 'solution' + mandatory = v[0] + all += mandatory.length for pred in $(".predicate [data-predicate]", question) pn = $(pred).attr('data-predicate') - if minimum? - all += minimum + #if minimum? + # all += minimum for qp in $(".question-piece", pred) v = @get_value_optional_list qp, 'solution' @@ -401,9 +424,10 @@ class Przyporzadkuj extends Exercise count += 1 @piece_correct qp else + bad_count += 1 @piece_incorrect qp - return [count, all] + return [count, bad_count, all] solve_question: (question) -> minimum = $(question).data("min") @@ -420,7 +444,7 @@ class Przyporzadkuj extends Exercise for m in draggables $pr = $(".predicate [data-predicate=" + m + "]", question) $ph = $pr.find ".placeholder:visible" - @draggable_move $(qp), $ph, @multiple + @draggable_move $(qp), $ph.eq(0), @multiple @@ -429,34 +453,38 @@ class PrawdaFalsz extends Exercise super element for qp in $(".question-piece", @element) - $(".true", qp).click (ev) -> + $(".true", qp).click (ev) => ev.preventDefault() - $(this).closest(".question-piece").data("value", "true") - $(this).addClass('chosen').siblings('a').removeClass('chosen') - $(".false", qp).click (ev) -> + @retry() + $(ev.target).closest(".question-piece").data("value", "true") + $(ev.target).addClass('chosen').siblings('a').removeClass('chosen') + $(".false", qp).click (ev) => ev.preventDefault() - $(this).closest(".question-piece").data("value", "false") - $(this).addClass('chosen').siblings('a').removeClass('chosen') + @retry() + $(ev.target).closest(".question-piece").data("value", "false") + $(ev.target).addClass('chosen').siblings('a').removeClass('chosen') check_question: -> all = 0 good = 0 + bad = 0 for qp in $(".question-piece", @element) if $(qp).data("solution").toString() == $(qp).data("value") good += 1 @piece_correct qp else + bad += 1 @piece_incorrect qp all += 1 - return [good, all] + return [good, bad, all] show_solutions: -> @reset() for qp in $(".question-piece", @element) - if $(qp).data('solution') == 'true' + if $(qp).data('solution') == true $(".true", qp).click() else $(".false", qp).click()