X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/63fa9213819e7006cd1ced0c690dad76f990ec60..3ca26d2173a3c1e0d03508f0de049ab6928fe2dd:/redakcja/static/edumed/js/edumed.coffee?ds=sidebyside diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 14c700ce..7c40bff3 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -28,15 +28,18 @@ class Exercise extends Binding $(ev.target).next(".retry").show() $(ev.target).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 @@ -116,19 +119,27 @@ class Exercise extends Binding $placeholder.after($added) if not $placeholder.hasClass('multiple') $placeholder.hide() - $added.append('x') + if $added.is(".add-li") + $added.wrap("
") + + $added.append('x') $('.remove', $added).click (ev) => - $added.prev(".placeholder:not(.multiple)").show() if not ismultiple $($added.data('original')).removeClass('disabled').draggable('enable') + + if $added.is(".add-li") + $added = $added.closest('li') + $added.prev(".placeholder:not(.multiple)").show() $added.remove() + ## XXX co z issortable? dragging: (ismultiple, issortable) -> $(".question", @element).each (i, question) => draggable_opts = revert: 'invalid' helper: 'clone' + start: @retry $(".draggable", question).draggable(draggable_opts) self = this @@ -181,6 +192,7 @@ class Exercise extends Binding class Wybor extends Exercise constructor: (element) -> super element + $(".question-piece input", element).change(@retry); check_question: (question) -> @@ -220,14 +232,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) @@ -424,10 +436,12 @@ class PrawdaFalsz extends Exercise for qp in $(".question-piece", @element) $(".true", qp).click (ev) -> ev.preventDefault() + @retry() $(this).closest(".question-piece").data("value", "true") $(this).addClass('chosen').siblings('a').removeClass('chosen') $(".false", qp).click (ev) -> ev.preventDefault() + @retry() $(this).closest(".question-piece").data("value", "false") $(this).addClass('chosen').siblings('a').removeClass('chosen') @@ -447,9 +461,9 @@ class PrawdaFalsz extends Exercise return [good, all] show_solutions: -> - reset() + @reset() for qp in $(".question-piece", @element) - if $(qp).data('solution') == 'true' + if $(qp).data('solution') == true $(".true", qp).click() else $(".false", qp).click() @@ -481,4 +495,4 @@ $(document).ready () -> new EduModule($("#book-text")) $(".exercise").each (i, el) -> - exercise(this) \ No newline at end of file + exercise(this)