retry on remove
[edumed.git] / catalogue / static / catalogue / js / edumed.js
index cc7b9e1..1886b38 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 (!$placeholder.hasClass('multiple')) {
         $placeholder.hide();
       }
-      $added.append('<span class="remove">x</span>');
+      if ($added.is(".add-li")) {
+        $added.wrap("<li/>");
+      }
+      $added.append('<span class="remove">x</span><div class="clr"></div>');
       return $('.remove', $added).click(function(ev) {
-        $added.prev(".placeholder:not(.multiple)").show();
+        _this.retry();
         if (!ismultiple) {
           $($added.data('original')).removeClass('disabled').draggable('enable');
         }
+        if ($added.is(".add-li")) {
+          $added = $added.closest('li');
+        }
+        $added.prev(".placeholder:not(.multiple)").show();
         return $added.remove();
       });
     };
         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) {
           should_be_checked = solution.indexOf(piece_no) >= 0;
         }
         console.log("check " + $("input[type=checkbox]", qpiece).attr("id") + " -> " + should_be_checked);
-        return $("input[type=checkbox]", qpiece).prop('checked', should_be_checked);
+        return $("input[type=checkbox],input[type=radio]", qpiece).prop('checked', should_be_checked);
       });
     };
 
     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');
         });
 
     PrawdaFalsz.prototype.show_solutions = function() {
       var qp, _i, _len, _ref, _results;
-      reset();
+      this.reset();
       _ref = $(".question-piece", this.element);
       _results = [];
       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
         qp = _ref[_i];
-        if ($(qp).data('solution') === 'true') {
+        if ($(qp).data('solution') === true) {
           _results.push($(".true", qp).click());
         } else {
           _results.push($(".false", qp).click());