From 7d9331d0912698ec04e95a8639600306525e00e6 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 14 Jan 2013 16:37:55 +0100 Subject: [PATCH] prawda/falsz questions --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 22 ++++++-- redakcja/static/edumed/js/edumed.coffee | 34 ++++++++++++- redakcja/static/edumed/js/edumed.js | 67 ++++++++++++++++++++++--- 4 files changed, 113 insertions(+), 12 deletions(-) diff --git a/lib/librarian b/lib/librarian index e569d710..aeed223c 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit e569d71063fb6647885ec65abda89d2843be876d +Subproject commit aeed223c57f453d068216f86941b7de963190536 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index f1de5918..186a6e47 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -12,7 +12,7 @@ a { #book-text { margin: 3em; - max-width: 500px; + max-width: 640px; } /* ================================== */ @@ -459,6 +459,10 @@ em.person { background-color: orange; } +.buttons .chosen { + background-color: lightblue; +} + .zastap.question-piece { padding: 3px; @@ -473,13 +477,20 @@ em.person { list-style: none; position: relative; clear: both; + padding-left: 0; } .przyporzadkuj .lista.predicate > li { list-style: none; display: block; float: left; - width: 250px; + width: 208px; + margin: 2px; +} + +.przyporzadkuj.wide .lista.predicate > li { + width: 100%; + margin: 2px; } .przyporzadkuj .lista.predicate .droppable { @@ -494,6 +505,11 @@ em.person { display: inline-block; } +.przyporzadkuj .lista.subjects { + padding-left: 0px; +} + .clr { clear: both; -} \ No newline at end of file +} + diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 8b02ae96..771e7c72 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -230,15 +230,17 @@ class Przyporzadkuj extends Excercise $(".draggable", question).draggable($.extend({}, draggable_opts, helper_opts)) - $(".predicate .droppable", question).droppable + $(".predicate .droppable", question).parent().droppable accept: (draggable) -> $draggable = $(draggable) if not $draggable.is(".draggable") + console.log('not draggable?') return false $predicate = $(this) for added in $predicate.find("li") if $(added).text() == $draggable.text() + console.log('already here:' + $draggable.text()) return false return true @@ -246,12 +248,14 @@ class Przyporzadkuj extends Excercise added = ui.draggable.clone() added.attr('style', '') - $(ev.target).append(added) + $(ev.target).find(".droppable").append(added) added.draggable(draggable_opts) if not @multiple or ui.draggable.closest(".predicate").length > 0 ui.draggable.remove() + $(".predicate .droppable", question).sortable + items: "> li" $(".subject", question).droppable accept: ".draggable" @@ -301,9 +305,34 @@ class Przyporzadkuj extends Excercise return [count, all] +class PrawdaFalsz extends Excercise + constructor: (element) -> + super element + for qp in $(".question-piece", @element) + $(".true", qp).click (ev) -> + ev.preventDefault() + $(this).closest(".question-piece").data("value", "true") + $(this).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') + check_question: -> + all = 0 + good = 0 + for qp in $(".question-piece", @element) + if $(qp).data("solution").toString() == $(qp).data("value") + good += 1 + @piece_correct qp + else + @piece_incorrect qp + + all += 1 + + return [good, all] ########## @@ -314,6 +343,7 @@ excercise = (ele) -> luki: Luki zastap: Zastap przyporzadkuj: Przyporzadkuj + prawdafalsz: PrawdaFalsz cls = es[$(ele).attr('data-type')] diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index be942174..5709aeb7 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -1,5 +1,5 @@ (function() { - var $, Binding, EduModule, Excercise, Luki, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, excercise, + var $, Binding, EduModule, Excercise, Luki, PrawdaFalsz, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, excercise, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; @@ -337,16 +337,22 @@ helper_opts = {}; } $(".draggable", question).draggable($.extend({}, draggable_opts, helper_opts)); - $(".predicate .droppable", question).droppable({ + $(".predicate .droppable", question).parent().droppable({ accept: function(draggable) { var $draggable, $predicate, added, _i, _len, _ref; $draggable = $(draggable); - if (!$draggable.is(".draggable")) return false; + if (!$draggable.is(".draggable")) { + console.log('not draggable?'); + return false; + } $predicate = $(this); _ref = $predicate.find("li"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { added = _ref[_i]; - if ($(added).text() === $draggable.text()) return false; + if ($(added).text() === $draggable.text()) { + console.log('already here:' + $draggable.text()); + return false; + } } return true; }, @@ -354,13 +360,16 @@ var added; added = ui.draggable.clone(); added.attr('style', ''); - $(ev.target).append(added); + $(ev.target).find(".droppable").append(added); added.draggable(draggable_opts); if (!_this.multiple || ui.draggable.closest(".predicate").length > 0) { return ui.draggable.remove(); } } }); + $(".predicate .droppable", question).sortable({ + items: "> li" + }); return $(".subject", question).droppable({ accept: ".draggable", drop: function(ev, ui) { @@ -419,6 +428,51 @@ })(Excercise); + PrawdaFalsz = (function(_super) { + + __extends(PrawdaFalsz, _super); + + function PrawdaFalsz(element) { + var qp, _i, _len, _ref; + PrawdaFalsz.__super__.constructor.call(this, element); + _ref = $(".question-piece", this.element); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + qp = _ref[_i]; + $(".true", qp).click(function(ev) { + ev.preventDefault(); + $(this).closest(".question-piece").data("value", "true"); + return $(this).addClass('chosen').siblings('a').removeClass('chosen'); + }); + $(".false", qp).click(function(ev) { + ev.preventDefault(); + $(this).closest(".question-piece").data("value", "false"); + return $(this).addClass('chosen').siblings('a').removeClass('chosen'); + }); + } + } + + PrawdaFalsz.prototype.check_question = function() { + var all, good, qp, _i, _len, _ref; + all = 0; + good = 0; + _ref = $(".question-piece", this.element); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + qp = _ref[_i]; + if ($(qp).data("solution").toString() === $(qp).data("value")) { + good += 1; + this.piece_correct(qp); + } else { + this.piece_incorrect(qp); + } + all += 1; + } + return [good, all]; + }; + + return PrawdaFalsz; + + })(Excercise); + excercise = function(ele) { var cls, es; es = { @@ -426,7 +480,8 @@ uporzadkuj: Uporzadkuj, luki: Luki, zastap: Zastap, - przyporzadkuj: Przyporzadkuj + przyporzadkuj: Przyporzadkuj, + prawdafalsz: PrawdaFalsz }; cls = es[$(ele).attr('data-type')]; return new cls(ele); -- 2.20.1