exercises: retry after move
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 12 Feb 2013 11:59:22 +0000 (12:59 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 12 Feb 2013 11:59:22 +0000 (12:59 +0100)
redakcja/static/edumed/js/edumed.coffee
redakcja/static/edumed/js/edumed.js

index c3d8fa7..7c40bff 100644 (file)
@@ -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
@@ -136,6 +139,7 @@ class Exercise extends Binding
       draggable_opts =
         revert: 'invalid'
         helper: 'clone'
+        start: @retry
 
       $(".draggable", question).draggable(draggable_opts)
       self = this
@@ -188,6 +192,7 @@ class Exercise extends Binding
 class Wybor extends Exercise
   constructor: (element) ->
     super element
+    $(".question-piece input", element).change(@retry);
 
 
   check_question: (question) ->
@@ -234,7 +239,7 @@ class Wybor extends Exercise
 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)
@@ -431,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')
 
index b4912dd..817dd95 100644 (file)
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.4.0
+// Generated by CoffeeScript 1.3.3
 (function() {
   var $, Binding, EduModule, Exercise, Luki, PrawdaFalsz, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, exercise,
     __hasProp = {}.hasOwnProperty,
@@ -44,9 +44,7 @@
         return $(ev.target).hide();
       });
       $(".retry", this.element).click(function(ev) {
-        $(".correct, .incorrect", _this.element).removeClass("correct incorrect");
-        $(ev.target).prev(".check").show();
-        return $(ev.target).hide();
+        return _this.retry();
       });
       $('.solutions', this.element).click(function() {
         _this.show_solutions();
       });
     }
 
+    Exercise.prototype.retry = function() {
+      $(".correct, .incorrect", this.element).removeClass("correct incorrect");
+      $(".check", this.element).show();
+      return $(".retry", this.element).hide();
+    };
+
     Exercise.prototype.reset = function() {
       $(this.element).html($(this.element).data('exercise-html'));
       return exercise(this.element);
       if ($added.is(".add-li")) {
         $added.wrap("<li/>");
       }
-      $added.append('<span class="remove">x</span>');
+      $added.append('<span class="remove">x</span><div class="clr"></div>');
       return $('.remove', $added).click(function(ev) {
         if (!ismultiple) {
           $($added.data('original')).removeClass('disabled').draggable('enable');
         var draggable_opts, self;
         draggable_opts = {
           revert: 'invalid',
-          helper: 'clone'
+          helper: 'clone',
+          start: _this.retry
         };
         $(".draggable", question).draggable(draggable_opts);
         self = _this;
 
     function Wybor(element) {
       Wybor.__super__.constructor.call(this, element);
+      $(".question-piece input", element).change(this.retry);
     }
 
     Wybor.prototype.check_question = function(question) {
     function Uporzadkuj(element) {
       Uporzadkuj.__super__.constructor.call(this, element);
       $('ol, ul', this.element).sortable({
-        items: "> li"
+        items: "> li",
+        start: this.retry
       });
     }
 
         qp = _ref[_i];
         $(".true", qp).click(function(ev) {
           ev.preventDefault();
+          this.retry();
           $(this).closest(".question-piece").data("value", "true");
           return $(this).addClass('chosen').siblings('a').removeClass('chosen');
         });
         $(".false", qp).click(function(ev) {
           ev.preventDefault();
+          this.retry();
           $(this).closest(".question-piece").data("value", "false");
           return $(this).addClass('chosen').siblings('a').removeClass('chosen');
         });