From 3acdb5c1daebfd692344bb93cd8d0594607caa9b Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 11 Jan 2013 12:41:30 +0100 Subject: [PATCH 01/16] Fix wybor --- lib/librarian | 2 +- redakcja/static/edumed/js/edumed.coffee | 10 +++++++--- redakcja/static/edumed/js/edumed.js | 13 +++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/librarian b/lib/librarian index ab001bc3..e569d710 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit ab001bc37c0f8ee0bb92b8762f5151b5b93f6ccc +Subproject commit e569d71063fb6647885ec65abda89d2843be876d diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index adc3ae56..8b02ae96 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -72,10 +72,14 @@ class Wybor extends Excercise check_question: (question) -> all = 0 good = 0 - solution = @get_value_list(question, 'solution', true) + solution = @get_value_list(question, 'solution') $(".question-piece", question).each (i, qpiece) => - piece_no = parseInt $(qpiece).attr 'data-no' - should_be_checked = solution.indexOf(piece_no) >= 0 + piece_no = $(qpiece).attr 'data-no' + piece_name = $(qpiece).attr 'data-name' + if piece_name + should_be_checked = solution.indexOf(piece_name) >= 0 + else + should_be_checked = solution.indexOf(piece_no) >= 0 is_checked = $("input", qpiece).is(":checked") if should_be_checked diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 92ab4c1b..be942174 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -123,11 +123,16 @@ _this = this; all = 0; good = 0; - solution = this.get_value_list(question, 'solution', true); + solution = this.get_value_list(question, 'solution'); $(".question-piece", question).each(function(i, qpiece) { - var is_checked, piece_no, should_be_checked; - piece_no = parseInt($(qpiece).attr('data-no')); - should_be_checked = solution.indexOf(piece_no) >= 0; + var is_checked, piece_name, piece_no, should_be_checked; + piece_no = $(qpiece).attr('data-no'); + piece_name = $(qpiece).attr('data-name'); + if (piece_name) { + should_be_checked = solution.indexOf(piece_name) >= 0; + } else { + should_be_checked = solution.indexOf(piece_no) >= 0; + } is_checked = $("input", qpiece).is(":checked"); if (should_be_checked) all += 1; if (is_checked) { -- 2.20.1 From 9bbe52622c560b271025eef19754c301f6a44c5b Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 14 Jan 2013 14:02:29 +0100 Subject: [PATCH 02/16] Revert "Edit " This reverts commit 45ffc9032091467d8fb3fafa4e0743995114bbb5. --- redakcja/static/xsl/wl2html_client.xsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/redakcja/static/xsl/wl2html_client.xsl b/redakcja/static/xsl/wl2html_client.xsl index 2575b537..8be6e225 100644 --- a/redakcja/static/xsl/wl2html_client.xsl +++ b/redakcja/static/xsl/wl2html_client.xsl @@ -835,13 +835,13 @@ - -

+ + -

+
-- 2.20.1 From 7d9331d0912698ec04e95a8639600306525e00e6 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 14 Jan 2013 16:37:55 +0100 Subject: [PATCH 03/16] 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 From ff191b1dc1ac37864898b775ce973f3900ddda89 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 16 Jan 2013 16:54:28 +0100 Subject: [PATCH 04/16] dragging overhaul --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 41 ++++++- redakcja/static/edumed/js/edumed.coffee | 153 +++++++++++++++--------- redakcja/static/edumed/js/edumed.js | 133 ++++++++++---------- 4 files changed, 204 insertions(+), 125 deletions(-) diff --git a/lib/librarian b/lib/librarian index aeed223c..3a04fe72 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit aeed223c57f453d068216f86941b7de963190536 +Subproject commit 3a04fe720cdaef17c5dfa12c011a540a6f77dfc5 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index 186a6e47..a19bec54 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -473,14 +473,20 @@ em.person { border: 1px solid; } -.przyporzadkuj .lista.predicate { +.excercise .lista.predicate { list-style: none; position: relative; clear: both; padding-left: 0; } -.przyporzadkuj .lista.predicate > li { + +.excercise .subjects { + padding-left: 0; +} + + +.excercise .lista.predicate > li { list-style: none; display: block; float: left; @@ -488,27 +494,50 @@ em.person { margin: 2px; } -.przyporzadkuj.wide .lista.predicate > li { +.excercise.wide .lista.predicate > li { width: 100%; margin: 2px; } -.przyporzadkuj .lista.predicate .droppable { +.excercise .lista.predicate .droppable { min-height: 50px; border: 1px dotted black; } -.przyporzadkuj .draggable { +.excercise .draggable { padding: 3px; border: 1px dotted black; display: inline-block; } -.przyporzadkuj .lista.subjects { +.excercise .draggable.disabled { + background-color: grey; +} + +.excercise .placeholder { + padding: 3px; + border: 1px dotted black; + display: inline-block; + min-width: 200px; + min-height: 1em; +} + + +.excercise .lista.subjects { padding-left: 0px; } + +.draggable .remove { + font-family: sans-serif; + padding: 2px 4px; + background-color: #ee6666; + margin-left: 5px; +} + +/* utils */ + .clr { clear: both; } diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 771e7c72..2c02cd8d 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -64,6 +64,98 @@ class Excercise extends Binding $(".message", @element).text("Wynik: #{score[0]} / #{score[1]}") + draggable_equal: ($draggable1, $draggable2) -> + return false + + draggable_accept: ($draggable, $droppable) -> + dropped = $droppable.closest("ul, ol").find(".draggable") + for d in dropped + if @draggable_equal $draggable, $(d) + return false + return true + + draggable_dropped: ($draggable) -> + $draggable.append('x') + + dragging: (ismultiple, issortable) -> + $(".question", @element).each (i, question) => + draggable_opts = + revert: 'invalid' + helper: 'clone' + + $(".draggable", question).draggable(draggable_opts) + self = this + $(".placeholder", question).droppable + accept: (draggable) -> + $draggable = $(draggable) + if not $draggable.is(".draggable") + return false + return self.draggable_accept $draggable, $(this) + + drop: (ev, ui) -> + added = $(ui.draggable).clone() + $added = added + $added.data("original", ui.draggable) + if not ismultiple + $(ui.draggable).addClass('disabled').draggable('disable') + + $(ev.target).after(added) + if not $(ev.target).hasClass('multiple') + $(ev.target).hide() + $added.append('x') + $('.remove', added).click (ev) => + $added.prev(".placeholder:not(.multiple)").show() + if not ismultiple + $added.data('original').removeClass('disabled').draggable('enable') + $(added).remove() + + + +# $(".droppable", question).each (i, droppable) => +# $droppable = $(droppable) +# $droppable.droppable +# accept: (draggable) => +# return false +# $draggable = $(draggable) +# if not $draggable.is(".draggable") +# console.log('not draggable?') +# return false + +# for added in $droppable.children(".draggable") +# if @draggable_equal($(added), $draggable) +# console.log('already here:' + $draggable.text()) +# return false + +# return @draggable_accept $draggable + +# drop: (ev, ui) => +# added = ui.draggable.clone() +# # added.attr('style', '') +# $(ev.target).append(added) +# added.draggable(draggable_opts) +# @draggable_dropped added + +# if not @multiple +# $(ui.draggable).draggable("disable") + + + # if issortable + # $(".droppable", question).sortable + # items: "> li" + + # receive: (event, ui) => + # console.log("receive " + $(ui.item).text()) + # if not accept(ui.item, event.target) + # console.log("REVERT") + # $(event.target).sortable('cancel') + + # over: (event, ui) => + # if not accept(ui.item, event.target) + # $(event.target).sortable('disable') + # out: (event, ui) => + # $(event.target).sortable('enable') + + class Wybor extends Excercise constructor: (element) -> super element @@ -126,12 +218,14 @@ class Uporzadkuj extends Excercise class Luki extends Excercise constructor: (element) -> super element + @dragging false, false check: -> all = 0 correct = 0 - $(".question-piece", @element).each (i, qpiece) => - if $(qpiece).data('solution') == $(qpiece).val() + $(".placeholder + .question-piece", @element).each (i, qpiece) => + $placeholder = $(qpiece).prev(".placeholder") + if $placeholder.data('solution') == $(qpiece).data('no') @piece_correct qpiece correct += 1 else @@ -220,60 +314,11 @@ class Przyporzadkuj extends Excercise @multiple = @is_multiple() - $(".question", @element).each (i, question) => - draggable_opts = - revert: 'invalid' - if @multiple - helper_opts = { helper: "clone" } - else helper_opts = {} - - $(".draggable", question).draggable($.extend({}, draggable_opts, - helper_opts)) - - $(".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 - - drop: (ev, ui) => - added = ui.draggable.clone() - - added.attr('style', '') - $(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" - drop: (ev, ui) => - # this is to prevent a situation of dragging out and - # dropping back to the same place - if $(ui.draggable).closest(".subject").length > 0 - return - - - added = ui.draggable.clone() + @dragging @multiple, true - added.attr('style', '') - if not @multiple - $(ev.target).append(added) - added.draggable($.extend({}, draggable_opts, helper_opts)) + draggable_equal: (d1, d2) -> + return d1.data("no") == d2.data("no") - ui.draggable.remove() check_question: (question) -> # subjects placed in predicates diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 5709aeb7..622ed0e5 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -106,6 +106,65 @@ return $(".message", this.element).text("Wynik: " + score[0] + " / " + score[1]); }; + Excercise.prototype.draggable_equal = function($draggable1, $draggable2) { + return false; + }; + + Excercise.prototype.draggable_accept = function($draggable, $droppable) { + var d, dropped, _i, _len; + dropped = $droppable.closest("ul, ol").find(".draggable"); + for (_i = 0, _len = dropped.length; _i < _len; _i++) { + d = dropped[_i]; + if (this.draggable_equal($draggable, $(d))) return false; + } + return true; + }; + + Excercise.prototype.draggable_dropped = function($draggable) { + return $draggable.append('x'); + }; + + Excercise.prototype.dragging = function(ismultiple, issortable) { + var _this = this; + return $(".question", this.element).each(function(i, question) { + var draggable_opts, self; + draggable_opts = { + revert: 'invalid', + helper: 'clone' + }; + $(".draggable", question).draggable(draggable_opts); + self = _this; + return $(".placeholder", question).droppable({ + accept: function(draggable) { + var $draggable; + $draggable = $(draggable); + if (!$draggable.is(".draggable")) return false; + return self.draggable_accept($draggable, $(this)); + }, + drop: function(ev, ui) { + var $added, added, + _this = this; + added = $(ui.draggable).clone(); + $added = added; + $added.data("original", ui.draggable); + if (!ismultiple) { + $(ui.draggable).addClass('disabled').draggable('disable'); + } + $(ev.target).after(added); + if (!$(ev.target).hasClass('multiple')) $(ev.target).hide(); + $added.append('x'); + return $('.remove', added).click(function(ev) { + $added.prev(".placeholder:not(.multiple)").show(); + if (!ismultiple) { + $added.data('original').removeClass('disabled').draggable('enable'); + } + return $(added).remove(); + }); + } + }); + }); + }; + return Excercise; })(Binding); @@ -195,6 +254,7 @@ function Luki(element) { Luki.__super__.constructor.call(this, element); + this.dragging(false, false); } Luki.prototype.check = function() { @@ -202,8 +262,10 @@ _this = this; all = 0; correct = 0; - $(".question-piece", this.element).each(function(i, qpiece) { - if ($(qpiece).data('solution') === $(qpiece).val()) { + $(".placeholder + .question-piece", this.element).each(function(i, qpiece) { + var $placeholder; + $placeholder = $(qpiece).prev(".placeholder"); + if ($placeholder.data('solution') === $(qpiece).data('no')) { _this.piece_correct(qpiece); correct += 1; } else { @@ -321,72 +383,15 @@ }; function Przyporzadkuj(element) { - var _this = this; Przyporzadkuj.__super__.constructor.call(this, element); this.multiple = this.is_multiple(); - $(".question", this.element).each(function(i, question) { - var draggable_opts, helper_opts; - draggable_opts = { - revert: 'invalid' - }; - if (_this.multiple) { - helper_opts = { - helper: "clone" - }; - } else { - helper_opts = {}; - } - $(".draggable", question).draggable($.extend({}, draggable_opts, helper_opts)); - $(".predicate .droppable", question).parent().droppable({ - accept: function(draggable) { - var $draggable, $predicate, added, _i, _len, _ref; - $draggable = $(draggable); - 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()) { - console.log('already here:' + $draggable.text()); - return false; - } - } - return true; - }, - drop: function(ev, ui) { - var added; - added = ui.draggable.clone(); - added.attr('style', ''); - $(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) { - var added; - if ($(ui.draggable).closest(".subject").length > 0) return; - added = ui.draggable.clone(); - added.attr('style', ''); - if (!_this.multiple) { - $(ev.target).append(added); - added.draggable($.extend({}, draggable_opts, helper_opts)); - } - return ui.draggable.remove(); - } - }); - }); + this.dragging(this.multiple, true); } + Przyporzadkuj.prototype.draggable_equal = function(d1, d2) { + return d1.data("no") === d2.data("no"); + }; + Przyporzadkuj.prototype.check_question = function(question) { var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2; count = 0; -- 2.20.1 From 6e8379333178e150cb4783e99342e55abc576589 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 18 Jan 2013 13:03:39 +0100 Subject: [PATCH 05/16] zastap excercise --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 22 +++-- redakcja/static/edumed/js/edumed.coffee | 113 ++++++++++-------------- redakcja/static/edumed/js/edumed.js | 61 +++++++------ 4 files changed, 94 insertions(+), 104 deletions(-) diff --git a/lib/librarian b/lib/librarian index 3a04fe72..803cd9d0 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 3a04fe720cdaef17c5dfa12c011a540a6f77dfc5 +Subproject commit 803cd9d0e8aeac8b4bacf197dfae80815367ec36 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index a19bec54..fe6843a0 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -464,14 +464,6 @@ em.person { } -.zastap.question-piece { - padding: 3px; -} - -.question-piece.editing { - margin: 2px; - border: 1px solid; -} .excercise .lista.predicate { list-style: none; @@ -523,6 +515,20 @@ em.person { min-height: 1em; } +.excercise .placeholder.accepting.dragover:hover { + background-color: #ffff99; +} + + +.excercise.zastap .paragraph .placeholder { + display: inline; + min-width: none; + min-height: none; + border: inherit; + padding: inherit; +} + + .excercise .lista.subjects { padding-left: 0px; diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 2c02cd8d..dae80f84 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -43,12 +43,25 @@ class Excercise extends Binding score[1] += s[1] @show_score(score) + # Parses a list of values, separated by space or comma. + # The list is read from data attribute of elem using data_key + # Returns a list with elements + # eg.: things_i_need: "house bike tv playstation" + # yields ["house", "bike", "tv", "playstation"] + # If optional numbers argument is true, returns list of numbers + # instead of strings get_value_list: (elem, data_key, numbers) -> vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim) #.map((x) -> parseInt(x)) if numbers vl = vl.map((x) -> parseInt(x)) return vl + # Parses a list of values, separated by space or comma. + # The list is read from data attribute of elem using data_key + # Returns a 2-element list with mandatory and optional + # items. optional items are marked with a question mark on the end + # eg.: things_i_need: "house bike tv? playstation?" + # yields [[ "house", "bike"], ["tv", "playstation"]] get_value_optional_list: (elem, data_key) -> vals = @get_value_list(elem, data_key) mandat = [] @@ -88,11 +101,23 @@ class Excercise extends Binding $(".placeholder", question).droppable accept: (draggable) -> $draggable = $(draggable) + is_accepted = true + if not $draggable.is(".draggable") - return false - return self.draggable_accept $draggable, $(this) + is_accepted = false + + if is_accepted + is_accepted= self.draggable_accept $draggable, $(this) + + if is_accepted + $(this).addClass 'accepting' + else + $(this).removeClass 'accepting' + return is_accepted drop: (ev, ui) -> + $(ev.target).removeClass 'accepting' + added = $(ui.draggable).clone() $added = added $added.data("original", ui.draggable) @@ -109,51 +134,12 @@ class Excercise extends Binding $added.data('original').removeClass('disabled').draggable('enable') $(added).remove() + over: (ev, ui) -> + $(ev.target).addClass 'dragover' -# $(".droppable", question).each (i, droppable) => -# $droppable = $(droppable) -# $droppable.droppable -# accept: (draggable) => -# return false -# $draggable = $(draggable) -# if not $draggable.is(".draggable") -# console.log('not draggable?') -# return false - -# for added in $droppable.children(".draggable") -# if @draggable_equal($(added), $draggable) -# console.log('already here:' + $draggable.text()) -# return false - -# return @draggable_accept $draggable - -# drop: (ev, ui) => -# added = ui.draggable.clone() -# # added.attr('style', '') -# $(ev.target).append(added) -# added.draggable(draggable_opts) -# @draggable_dropped added - -# if not @multiple -# $(ui.draggable).draggable("disable") - - - # if issortable - # $(".droppable", question).sortable - # items: "> li" - - # receive: (event, ui) => - # console.log("receive " + $(ui.item).text()) - # if not accept(ui.item, event.target) - # console.log("REVERT") - # $(event.target).sortable('cancel') - - # over: (event, ui) => - # if not accept(ui.item, event.target) - # $(event.target).sortable('disable') - # out: (event, ui) => - # $(event.target).sortable('enable') + out: (ev, ui) -> + $(ev.target).removeClass 'dragover' class Wybor extends Excercise @@ -239,34 +225,25 @@ class Zastap extends Excercise constructor: (element) -> super element $(".paragraph", @element).each (i, par) => - @wrap_words $(par), $('') - spans = $("> span", par).attr("contenteditable", "true") - spans.click (ev) => - spans.filter(':not(:empty)').removeClass('editing') - $(ev.target).addClass('editing') - + @wrap_words $(par), $('') + @dragging false, false check: -> all = 0 correct = 0 - $(".question-piece", @element).each (i, qpiece) => - txt = $(qpiece).data('original') - should_be_changed = false - if not txt? - txt = $(qpiece).data('solution') - should_be_changed = true - if not txt? - return - - if should_be_changed - all += 1 - if txt != $(qpiece).text() - @piece_incorrect qpiece - else - if should_be_changed - @piece_correct qpiece - correct += 1 + $(".paragraph", @element).each (i, par) => + $(".placeholder", par).each (j, qpiece) => + should_be_checked = false + $qp = $(qpiece) + $dragged = $qp.next(".draggable") + if $qp.data("solution") + if $dragged and $qp.data("solution") == $dragged.data("no") + @piece_correct $dragged + correct += 1 +# else -- we dont mark enything here, so not to hint user about solution. He sees he hasn't used all the draggables + + all += 1 @show_score [correct, all] diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 622ed0e5..9d22b645 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -136,14 +136,24 @@ self = _this; return $(".placeholder", question).droppable({ accept: function(draggable) { - var $draggable; + var $draggable, is_accepted; $draggable = $(draggable); - if (!$draggable.is(".draggable")) return false; - return self.draggable_accept($draggable, $(this)); + is_accepted = true; + if (!$draggable.is(".draggable")) is_accepted = false; + if (is_accepted) { + is_accepted = self.draggable_accept($draggable, $(this)); + } + if (is_accepted) { + $(this).addClass('accepting'); + } else { + $(this).removeClass('accepting'); + } + return is_accepted; }, drop: function(ev, ui) { var $added, added, _this = this; + $(ev.target).removeClass('accepting'); added = $(ui.draggable).clone(); $added = added; $added.data("original", ui.draggable); @@ -160,6 +170,12 @@ } return $(added).remove(); }); + }, + over: function(ev, ui) { + return $(ev.target).addClass('dragover'); + }, + out: function(ev, ui) { + return $(ev.target).removeClass('dragover'); } }); }); @@ -288,14 +304,9 @@ var _this = this; Zastap.__super__.constructor.call(this, element); $(".paragraph", this.element).each(function(i, par) { - var spans; - _this.wrap_words($(par), $('')); - spans = $("> span", par).attr("contenteditable", "true"); - return spans.click(function(ev) { - spans.filter(':not(:empty)').removeClass('editing'); - return $(ev.target).addClass('editing'); - }); + return _this.wrap_words($(par), $('')); }); + this.dragging(false, false); } Zastap.prototype.check = function() { @@ -303,24 +314,20 @@ _this = this; all = 0; correct = 0; - $(".question-piece", this.element).each(function(i, qpiece) { - var should_be_changed, txt; - txt = $(qpiece).data('original'); - should_be_changed = false; - if (!(txt != null)) { - txt = $(qpiece).data('solution'); - should_be_changed = true; - } - if (!(txt != null)) return; - if (should_be_changed) all += 1; - if (txt !== $(qpiece).text()) { - return _this.piece_incorrect(qpiece); - } else { - if (should_be_changed) { - _this.piece_correct(qpiece); - return correct += 1; + $(".paragraph", this.element).each(function(i, par) { + return $(".placeholder", par).each(function(j, qpiece) { + var $dragged, $qp, should_be_checked; + should_be_checked = false; + $qp = $(qpiece); + $dragged = $qp.next(".draggable"); + if ($qp.data("solution")) { + if ($dragged && $qp.data("solution") === $dragged.data("no")) { + _this.piece_correct($dragged); + correct += 1; + } + return all += 1; } - } + }); }); return this.show_score([correct, all]); }; -- 2.20.1 From 844b960507376aed7fc19b508d08543b494b567d Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 18 Jan 2013 13:43:20 +0100 Subject: [PATCH 06/16] css fix --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librarian b/lib/librarian index 803cd9d0..a17ace82 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 803cd9d0e8aeac8b4bacf197dfae80815367ec36 +Subproject commit a17ace8296df1d91d9f940c80d96a269eba626e5 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index fe6843a0..a65f227e 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -515,7 +515,7 @@ em.person { min-height: 1em; } -.excercise .placeholder.accepting.dragover:hover { +.excercise .placeholder.accepting.dragover { background-color: #ffff99; } -- 2.20.1 From d9bec7e66b9e33e3aca3cca1abd78e9151b5d03a Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 18 Jan 2013 13:49:22 +0100 Subject: [PATCH 07/16] remove dragover on drop, too --- redakcja/static/edumed/js/edumed.coffee | 2 +- redakcja/static/edumed/js/edumed.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index dae80f84..75624ae7 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -116,7 +116,7 @@ class Excercise extends Binding return is_accepted drop: (ev, ui) -> - $(ev.target).removeClass 'accepting' + $(ev.target).removeClass 'accepting dragover' added = $(ui.draggable).clone() $added = added diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 9d22b645..d8f3d946 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -153,7 +153,7 @@ drop: function(ev, ui) { var $added, added, _this = this; - $(ev.target).removeClass('accepting'); + $(ev.target).removeClass('accepting dragover'); added = $(ui.draggable).clone(); $added = added; $added.data("original", ui.draggable); -- 2.20.1 From 88d1651a8ef2ff5e669ab2799fd2d01bbe0f664e Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 23 Jan 2013 15:29:16 +0100 Subject: [PATCH 08/16] reset + solutions --- lib/librarian | 2 +- redakcja/static/edumed/js/edumed.coffee | 130 ++++++++++++--- redakcja/static/edumed/js/edumed.js | 205 +++++++++++++++++++----- 3 files changed, 278 insertions(+), 59 deletions(-) diff --git a/lib/librarian b/lib/librarian index a17ace82..b22e1811 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit a17ace8296df1d91d9f940c80d96a269eba626e5 +Subproject commit b22e1811ddec4e7af6f7e369cf1b868f8cc8140b diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 75624ae7..db198085 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -20,11 +20,19 @@ class EduModule extends Binding class Excercise extends Binding constructor: (element) -> super 'excercise', element + # just save the html to reset the excercise + $(@element).data("excercise-html", $(@element).html()) $(".check", @element).click => @check() $('.solutions', @element).click => @show_solutions() + $('.reset', @element).click => + @reset() + + reset: -> + $(@element).html($(@element).data('excercise-html')) + excercise @element piece_correct: (qpiece) -> $(qpiece).removeClass('incorrect').addClass('correct') @@ -43,6 +51,11 @@ class Excercise extends Binding score[1] += s[1] @show_score(score) + show_solutions: -> + @reset() + $(".question", @element).each (i, question) => + @solve_question question + # Parses a list of values, separated by space or comma. # The list is read from data attribute of elem using data_key # Returns a list with elements @@ -87,8 +100,22 @@ class Excercise extends Binding return false return true - draggable_dropped: ($draggable) -> - $draggable.append('x') + draggable_move: ($draggable, $placeholder, ismultiple) -> + $added = $draggable.clone() + $added.data("original", $draggable.get(0)) + if not ismultiple + $draggable.addClass('disabled').draggable('disable') + + $placeholder.after($added) + if not $placeholder.hasClass('multiple') + $placeholder.hide() + $added.append('x') + $('.remove', $added).click (ev) => + $added.prev(".placeholder:not(.multiple)").show() + if not ismultiple + $($added.data('original')).removeClass('disabled').draggable('enable') + $added.remove() + dragging: (ismultiple, issortable) -> $(".question", @element).each (i, question) => @@ -115,24 +142,25 @@ class Excercise extends Binding $(this).removeClass 'accepting' return is_accepted - drop: (ev, ui) -> + drop: (ev, ui) => $(ev.target).removeClass 'accepting dragover' - added = $(ui.draggable).clone() - $added = added - $added.data("original", ui.draggable) - if not ismultiple - $(ui.draggable).addClass('disabled').draggable('disable') - - $(ev.target).after(added) - if not $(ev.target).hasClass('multiple') - $(ev.target).hide() - $added.append('x') - $('.remove', added).click (ev) => - $added.prev(".placeholder:not(.multiple)").show() - if not ismultiple - $added.data('original').removeClass('disabled').draggable('enable') - $(added).remove() + @draggable_move $(ui.draggable), $(ev.target), ismultiple + + # $added = $(ui.draggable).clone() + # $added.data("original", ui.draggable) + # if not ismultiple + # $(ui.draggable).addClass('disabled').draggable('disable') + + # $(ev.target).after(added) + # if not $(ev.target).hasClass('multiple') + # $(ev.target).hide() + # $added.append('x') + # $('.remove', added).click (ev) => + # $added.prev(".placeholder:not(.multiple)").show() + # if not ismultiple + # $added.data('original').removeClass('disabled').draggable('enable') + # $(added).remove() over: (ev, ui) -> $(ev.target).addClass 'dragover' @@ -142,6 +170,7 @@ class Excercise extends Binding $(ev.target).removeClass 'dragover' + class Wybor extends Excercise constructor: (element) -> super element @@ -174,7 +203,18 @@ class Wybor extends Excercise return [good, all] - show_solutions: -> + solve_question: (question) -> + solution = @get_value_list(question, 'solution') + $(".question-piece", question).each (i, qpiece) => + piece_no = $(qpiece).attr 'data-no' + piece_name = $(qpiece).attr 'data-name' + if piece_name + should_be_checked = solution.indexOf(piece_name) >= 0 + 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 + class Uporzadkuj extends Excercise @@ -191,7 +231,7 @@ class Uporzadkuj extends Excercise all = 0 for pkt in [0...pkts.length] - all +=1 + all += 1 if pkts.eq(pkt).data('pos') == sorted[pkt] correct += 1 @piece_correct pkts.eq(pkt) @@ -199,6 +239,21 @@ class Uporzadkuj extends Excercise @piece_incorrect pkts.eq(pkt) return [correct, all] + solve_question: (question) -> + positions = @get_value_list(question, 'original', true) + sorted = positions.sort() + pkts = $('.question-piece', question) + pkts.sort (a, b) -> + q = $(a).data('pos') + w = $(b).data('pos') + return 1 if q < w + return -1 if q > w + return 0 + + parent = pkts.eq(0).parent() + for p in pkts + parent.prepend(p) + # XXX propozycje="1/0" class Luki extends Excercise @@ -220,6 +275,11 @@ class Luki extends Excercise @show_score [correct, all] + solve_question: (question) -> + $(".placeholder", question).each (i, placeholder) => + $qp = $(".question-piece[data-no=" + $(placeholder).data('solution') + "]", question) + @draggable_move $qp, $(placeholder), false + class Zastap extends Excercise constructor: (element) -> @@ -234,7 +294,6 @@ class Zastap extends Excercise $(".paragraph", @element).each (i, par) => $(".placeholder", par).each (j, qpiece) => - should_be_checked = false $qp = $(qpiece) $dragged = $qp.next(".draggable") if $qp.data("solution") @@ -247,6 +306,15 @@ class Zastap extends Excercise @show_score [correct, all] + show_solutions: -> + @reset() + $(".paragraph", @element).each (i, par) => + $(".placeholder[data-solution]", par).each (j, qpiece) => + $qp = $(qpiece) + $dr = $(".draggable[data-no=" + $qp.data('solution') + "]", @element) + @draggable_move $dr, $qp, false + + wrap_words: (element, wrapper) -> # This function wraps each word of element in wrapper, but does not descend into child-tags of element. # It doesn't wrap things between words (defined by ignore RE below). Warning - ignore must begin with ^ @@ -326,6 +394,17 @@ class Przyporzadkuj extends Excercise else return [count, all] + solve_question: (question) -> + for qp in $(".subject .question-piece", question) + v = @get_value_optional_list qp, 'solution' + mandatory = v[0] + optional = v[1] + for m in mandatory.concat(optional) + $pr = $(".predicate [data-predicate=" + m + "]", question) + $ph = $pr.find ".placeholder" + @draggable_move $(qp), $ph, @multiple + + class PrawdaFalsz extends Excercise constructor: (element) -> @@ -356,6 +435,15 @@ class PrawdaFalsz extends Excercise return [good, all] + show_solutions: -> + reset() + for qp in $(".question-piece", @element) + if $(qp).data('solution') == 'true' + $(".true", qp).click() + else + $(".false", qp).click() + + ########## excercise = (ele) -> diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index d8f3d946..803eb042 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -1,7 +1,8 @@ +// Generated by CoffeeScript 1.4.0 (function() { 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; }; + __hasProp = {}.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; }; $ = jQuery; @@ -44,14 +45,23 @@ function Excercise(element) { var _this = this; Excercise.__super__.constructor.call(this, 'excercise', element); + $(this.element).data("excercise-html", $(this.element).html()); $(".check", this.element).click(function() { return _this.check(); }); $('.solutions', this.element).click(function() { return _this.show_solutions(); }); + $('.reset', this.element).click(function() { + return _this.reset(); + }); } + Excercise.prototype.reset = function() { + $(this.element).html($(this.element).data('excercise-html')); + return excercise(this.element); + }; + Excercise.prototype.piece_correct = function(qpiece) { return $(qpiece).removeClass('incorrect').addClass('correct'); }; @@ -75,6 +85,14 @@ return this.show_score(score); }; + Excercise.prototype.show_solutions = function() { + var _this = this; + this.reset(); + return $(".question", this.element).each(function(i, question) { + return _this.solve_question(question); + }); + }; + Excercise.prototype.get_value_list = function(elem, data_key, numbers) { var vl; vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim); @@ -115,13 +133,33 @@ dropped = $droppable.closest("ul, ol").find(".draggable"); for (_i = 0, _len = dropped.length; _i < _len; _i++) { d = dropped[_i]; - if (this.draggable_equal($draggable, $(d))) return false; + if (this.draggable_equal($draggable, $(d))) { + return false; + } } return true; }; - Excercise.prototype.draggable_dropped = function($draggable) { - return $draggable.append('x'); + Excercise.prototype.draggable_move = function($draggable, $placeholder, ismultiple) { + var $added, + _this = this; + $added = $draggable.clone(); + $added.data("original", $draggable.get(0)); + if (!ismultiple) { + $draggable.addClass('disabled').draggable('disable'); + } + $placeholder.after($added); + if (!$placeholder.hasClass('multiple')) { + $placeholder.hide(); + } + $added.append('x'); + return $('.remove', $added).click(function(ev) { + $added.prev(".placeholder:not(.multiple)").show(); + if (!ismultiple) { + $($added.data('original')).removeClass('disabled').draggable('enable'); + } + return $added.remove(); + }); }; Excercise.prototype.dragging = function(ismultiple, issortable) { @@ -139,7 +177,9 @@ var $draggable, is_accepted; $draggable = $(draggable); is_accepted = true; - if (!$draggable.is(".draggable")) is_accepted = false; + if (!$draggable.is(".draggable")) { + is_accepted = false; + } if (is_accepted) { is_accepted = self.draggable_accept($draggable, $(this)); } @@ -151,25 +191,8 @@ return is_accepted; }, drop: function(ev, ui) { - var $added, added, - _this = this; $(ev.target).removeClass('accepting dragover'); - added = $(ui.draggable).clone(); - $added = added; - $added.data("original", ui.draggable); - if (!ismultiple) { - $(ui.draggable).addClass('disabled').draggable('disable'); - } - $(ev.target).after(added); - if (!$(ev.target).hasClass('multiple')) $(ev.target).hide(); - $added.append('x'); - return $('.remove', added).click(function(ev) { - $added.prev(".placeholder:not(.multiple)").show(); - if (!ismultiple) { - $added.data('original').removeClass('disabled').draggable('enable'); - } - return $(added).remove(); - }); + return _this.draggable_move($(ui.draggable), $(ev.target), ismultiple); }, over: function(ev, ui) { return $(ev.target).addClass('dragover'); @@ -209,7 +232,9 @@ should_be_checked = solution.indexOf(piece_no) >= 0; } is_checked = $("input", qpiece).is(":checked"); - if (should_be_checked) all += 1; + if (should_be_checked) { + all += 1; + } if (is_checked) { if (should_be_checked) { good += 1; @@ -224,7 +249,23 @@ return [good, all]; }; - Wybor.prototype.show_solutions = function() {}; + Wybor.prototype.solve_question = function(question) { + var solution, + _this = this; + solution = this.get_value_list(question, 'solution'); + return $(".question-piece", question).each(function(i, qpiece) { + var piece_name, piece_no, should_be_checked; + piece_no = $(qpiece).attr('data-no'); + piece_name = $(qpiece).attr('data-name'); + if (piece_name) { + should_be_checked = solution.indexOf(piece_name) >= 0; + } else { + 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 Wybor; @@ -242,13 +283,13 @@ } Uporzadkuj.prototype.check_question = function(question) { - var all, correct, pkt, pkts, positions, sorted, _ref; + var all, correct, pkt, pkts, positions, sorted, _i, _ref; positions = this.get_value_list(question, 'original', true); sorted = positions.sort(); pkts = $('.question-piece', question); correct = 0; all = 0; - for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) { + for (pkt = _i = 0, _ref = pkts.length; 0 <= _ref ? _i < _ref : _i > _ref; pkt = 0 <= _ref ? ++_i : --_i) { all += 1; if (pkts.eq(pkt).data('pos') === sorted[pkt]) { correct += 1; @@ -260,6 +301,32 @@ return [correct, all]; }; + Uporzadkuj.prototype.solve_question = function(question) { + var p, parent, pkts, positions, sorted, _i, _len, _results; + positions = this.get_value_list(question, 'original', true); + sorted = positions.sort(); + pkts = $('.question-piece', question); + pkts.sort(function(a, b) { + var q, w; + q = $(a).data('pos'); + w = $(b).data('pos'); + if (q < w) { + return 1; + } + if (q > w) { + return -1; + } + return 0; + }); + parent = pkts.eq(0).parent(); + _results = []; + for (_i = 0, _len = pkts.length; _i < _len; _i++) { + p = pkts[_i]; + _results.push(parent.prepend(p)); + } + return _results; + }; + return Uporzadkuj; })(Excercise); @@ -292,6 +359,15 @@ return this.show_score([correct, all]); }; + Luki.prototype.solve_question = function(question) { + var _this = this; + return $(".placeholder", question).each(function(i, placeholder) { + var $qp; + $qp = $(".question-piece[data-no=" + $(placeholder).data('solution') + "]", question); + return _this.draggable_move($qp, $(placeholder), false); + }); + }; + return Luki; })(Excercise); @@ -316,8 +392,7 @@ correct = 0; $(".paragraph", this.element).each(function(i, par) { return $(".placeholder", par).each(function(j, qpiece) { - var $dragged, $qp, should_be_checked; - should_be_checked = false; + var $dragged, $qp; $qp = $(qpiece); $dragged = $qp.next(".draggable"); if ($qp.data("solution")) { @@ -332,8 +407,21 @@ return this.show_score([correct, all]); }; + Zastap.prototype.show_solutions = function() { + var _this = this; + this.reset(); + return $(".paragraph", this.element).each(function(i, par) { + return $(".placeholder[data-solution]", par).each(function(j, qpiece) { + var $dr, $qp; + $qp = $(qpiece); + $dr = $(".draggable[data-no=" + $qp.data('solution') + "]", _this.element); + return _this.draggable_move($dr, $qp, false); + }); + }); + }; + Zastap.prototype.wrap_words = function(element, wrapper) { - var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results; + var chld, i, ignore, insertWrapped, j, len, space, wordb, _i, _ref, _results; ignore = /^[ \t.,:;()]+/; insertWrapped = function(txt, elem) { var nw; @@ -341,7 +429,7 @@ return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem); }; _results = []; - for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) { + for (j = _i = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; j = _ref <= 0 ? ++_i : --_i) { chld = element.get(0).childNodes[j]; if (chld.nodeType === document.TEXT_NODE) { len = chld.textContent.length; @@ -384,7 +472,9 @@ _ref = $(".question-piece", this.element); for (_i = 0, _len = _ref.length; _i < _len; _i++) { qp = _ref[_i]; - if ($(qp).data('solution').split(/[ ,]+/).length > 1) return true; + if ($(qp).data('solution').split(/[ ,]+/).length > 1) { + return true; + } } return false; }; @@ -400,7 +490,7 @@ }; Przyporzadkuj.prototype.check_question = function(question) { - var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2; + var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len1, _ref, _ref1; count = 0; all = 0; all_multiple = 0; @@ -422,9 +512,9 @@ all += 1; } if (this.multiple) { - _ref2 = $(".subject .question-piece", question); - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - qp = _ref2[_j]; + _ref1 = $(".subject .question-piece", question); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + qp = _ref1[_j]; v = this.get_value_optional_list(qp, 'solution'); mandatory = v[0]; optional = v[1]; @@ -436,6 +526,31 @@ } }; + Przyporzadkuj.prototype.solve_question = function(question) { + var $ph, $pr, m, mandatory, optional, qp, v, _i, _len, _ref, _results; + _ref = $(".subject .question-piece", question); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + qp = _ref[_i]; + v = this.get_value_optional_list(qp, 'solution'); + mandatory = v[0]; + optional = v[1]; + _results.push((function() { + var _j, _len1, _ref1, _results1; + _ref1 = mandatory.concat(optional); + _results1 = []; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + m = _ref1[_j]; + $pr = $(".predicate [data-predicate=" + m + "]", question); + $ph = $pr.find(".placeholder"); + _results1.push(this.draggable_move($(qp), $ph, this.multiple)); + } + return _results1; + }).call(this)); + } + return _results; + }; + return Przyporzadkuj; })(Excercise); @@ -481,6 +596,22 @@ return [good, all]; }; + PrawdaFalsz.prototype.show_solutions = function() { + var qp, _i, _len, _ref, _results; + reset(); + _ref = $(".question-piece", this.element); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + qp = _ref[_i]; + if ($(qp).data('solution') === 'true') { + _results.push($(".true", qp).click()); + } else { + _results.push($(".false", qp).click()); + } + } + return _results; + }; + return PrawdaFalsz; })(Excercise); -- 2.20.1 From 7c7e68c348f0cdcb41aa76685fe2f519b8300eac Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 25 Jan 2013 12:29:56 +0100 Subject: [PATCH 09/16] use attr instead of data --- redakcja/static/edumed/js/edumed.coffee | 2 +- redakcja/static/edumed/js/edumed.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index db198085..0fd39d9a 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -376,7 +376,7 @@ class Przyporzadkuj extends Excercise mandatory = v[0] optional = v[1] all_multiple += mandatory.length + optional.length - pn = pred.data('predicate') + pn = pred.attr('data-predicate') if mandatory.indexOf(pn) >= 0 or optional.indexOf(pn) >= 0 count += 1 @piece_correct qp diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 803eb042..b601128c 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -502,7 +502,7 @@ mandatory = v[0]; optional = v[1]; all_multiple += mandatory.length + optional.length; - pn = pred.data('predicate'); + pn = pred.attr('data-predicate'); if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) { count += 1; this.piece_correct(qp); -- 2.20.1 From ce3d5f6fd76ca2f366088105b6637d68ace76de0 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 25 Jan 2013 12:30:05 +0100 Subject: [PATCH 10/16] wybor styling --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/librarian b/lib/librarian index b22e1811..f03d1fdb 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit b22e1811ddec4e7af6f7e369cf1b868f8cc8140b +Subproject commit f03d1fdbe472dbfb103d00b0e4ee9fa593c7b2c0 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index a65f227e..d944d382 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -542,6 +542,10 @@ em.person { margin-left: 5px; } +.excercise.wybor li[data-name] { + list-style: none; +} + /* utils */ .clr { -- 2.20.1 From 18039456886ac5b0853076b5f33605f1d6bbe865 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 28 Jan 2013 15:26:26 +0100 Subject: [PATCH 11/16] przyporzadkuj -- minimum answers --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 10 ++-- redakcja/static/edumed/js/edumed.coffee | 60 +++++++++++----------- redakcja/static/edumed/js/edumed.js | 66 +++++++++++-------------- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/lib/librarian b/lib/librarian index f03d1fdb..c0761a86 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit f03d1fdbe472dbfb103d00b0e4ee9fa593c7b2c0 +Subproject commit c0761a86fb4687fda8221e56bf911f051fda3499 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index d944d382..d63ce5b4 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -444,12 +444,12 @@ em.person { } .teacher { - display: none; +/* display: none;*/ } -.teacher.show { +/*.teacher.show { display: inherit; -} +}*/ .question-piece.correct { background-color: darkgreen; @@ -535,6 +535,10 @@ em.person { } +.excercise.uporzadkuj li { + cursor: move; +} + .draggable .remove { font-family: sans-serif; padding: 2px 4px; diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 0fd39d9a..e65faaaf 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -10,11 +10,11 @@ class EduModule extends Binding constructor: (element) -> super 'edumodule', element - $("[name=teacher-toggle]").change (ev) => - if $(ev.target).is(":checked") - $(".teacher", @element).addClass "show" - else - $(".teacher", @element).removeClass "show" + # $("[name=teacher-toggle]").change (ev) => + # if $(ev.target).is(":checked") + # $(".teacher", @element).addClass "show" + # else + # $(".teacher", @element).removeClass "show" class Excercise extends Binding @@ -116,7 +116,7 @@ class Excercise extends Binding $($added.data('original')).removeClass('disabled').draggable('enable') $added.remove() - +## XXX co z issortable? dragging: (ismultiple, issortable) -> $(".question", @element).each (i, question) => draggable_opts = @@ -367,41 +367,45 @@ class Przyporzadkuj extends Excercise check_question: (question) -> # subjects placed in predicates + minimum = $(question).data("minimum") count = 0 all = 0 - all_multiple = 0 - for qp in $(".predicate .question-piece", question) - pred = $(qp).closest("[data-predicate]") - v = @get_value_optional_list qp, 'solution' - mandatory = v[0] - optional = v[1] - all_multiple += mandatory.length + optional.length - pn = pred.attr('data-predicate') - if mandatory.indexOf(pn) >= 0 or optional.indexOf(pn) >= 0 - count += 1 - @piece_correct qp - else - @piece_incorrect qp - all += 1 + if not minimum + all = $(".subjects .question-piece", question).length + + for pred in $(".predicate [data-predicate]", question) + pn = $(pred).attr('data-predicate') + if minimum? + all += minimum - if @multiple - for qp in $(".subject .question-piece", question) + for qp in $(".question-piece", pred) v = @get_value_optional_list qp, 'solution' mandatory = v[0] optional = v[1] - all_multiple += mandatory.length + optional.length - return [count, all_multiple] - else - return [count, all] + + if mandatory.indexOf(pn) >= 0 or (minimum and optional.indexOf(pn) >= 0) + count += 1 + @piece_correct qp + else + @piece_incorrect qp + + return [count, all] solve_question: (question) -> + minimum = $(question).data("min") + for qp in $(".subject .question-piece", question) v = @get_value_optional_list qp, 'solution' mandatory = v[0] optional = v[1] - for m in mandatory.concat(optional) + + if minimum + draggables = mandatory.count(optional)[0...minimum] + else + draggables = mandatory + for m in draggables $pr = $(".predicate [data-predicate=" + m + "]", question) - $ph = $pr.find ".placeholder" + $ph = $pr.find ".placeholder:visible" @draggable_move $(qp), $ph, @multiple diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index b601128c..42f0c379 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -23,15 +23,7 @@ __extends(EduModule, _super); function EduModule(element) { - var _this = this; EduModule.__super__.constructor.call(this, 'edumodule', element); - $("[name=teacher-toggle]").change(function(ev) { - if ($(ev.target).is(":checked")) { - return $(".teacher", _this.element).addClass("show"); - } else { - return $(".teacher", _this.element).removeClass("show"); - } - }); } return EduModule; @@ -490,44 +482,40 @@ }; Przyporzadkuj.prototype.check_question = function(question) { - var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len1, _ref, _ref1; + var all, count, mandatory, minimum, optional, pn, pred, qp, v, _i, _j, _len, _len1, _ref, _ref1; + minimum = $(question).data("minimum"); count = 0; all = 0; - all_multiple = 0; - _ref = $(".predicate .question-piece", question); + if (!minimum) { + all = $(".subjects .question-piece", question).length; + } + _ref = $(".predicate [data-predicate]", question); for (_i = 0, _len = _ref.length; _i < _len; _i++) { - qp = _ref[_i]; - pred = $(qp).closest("[data-predicate]"); - v = this.get_value_optional_list(qp, 'solution'); - mandatory = v[0]; - optional = v[1]; - all_multiple += mandatory.length + optional.length; - pn = pred.attr('data-predicate'); - if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) { - count += 1; - this.piece_correct(qp); - } else { - this.piece_incorrect(qp); + pred = _ref[_i]; + pn = $(pred).attr('data-predicate'); + if (minimum != null) { + all += minimum; } - all += 1; - } - if (this.multiple) { - _ref1 = $(".subject .question-piece", question); + _ref1 = $(".question-piece", pred); for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { qp = _ref1[_j]; v = this.get_value_optional_list(qp, 'solution'); mandatory = v[0]; optional = v[1]; - all_multiple += mandatory.length + optional.length; + if (mandatory.indexOf(pn) >= 0 || (minimum && optional.indexOf(pn) >= 0)) { + count += 1; + this.piece_correct(qp); + } else { + this.piece_incorrect(qp); + } } - return [count, all_multiple]; - } else { - return [count, all]; } + return [count, all]; }; Przyporzadkuj.prototype.solve_question = function(question) { - var $ph, $pr, m, mandatory, optional, qp, v, _i, _len, _ref, _results; + var $ph, $pr, draggables, m, mandatory, minimum, optional, qp, v, _i, _len, _ref, _results; + minimum = $(question).data("min"); _ref = $(".subject .question-piece", question); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -535,14 +523,18 @@ v = this.get_value_optional_list(qp, 'solution'); mandatory = v[0]; optional = v[1]; + if (minimum) { + draggables = mandatory.count(optional).slice(0, minimum); + } else { + draggables = mandatory; + } _results.push((function() { - var _j, _len1, _ref1, _results1; - _ref1 = mandatory.concat(optional); + var _j, _len1, _results1; _results1 = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - m = _ref1[_j]; + for (_j = 0, _len1 = draggables.length; _j < _len1; _j++) { + m = draggables[_j]; $pr = $(".predicate [data-predicate=" + m + "]", question); - $ph = $pr.find(".placeholder"); + $ph = $pr.find(".placeholder:visible"); _results1.push(this.draggable_move($(qp), $ph, this.multiple)); } return _results1; -- 2.20.1 From a528895b70b51139a214ace3ef87e585a7496ca5 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 28 Jan 2013 16:04:13 +0100 Subject: [PATCH 12/16] try again button rozw_kom --- lib/librarian | 2 +- redakcja/static/edumed/js/edumed.coffee | 9 ++++++++- redakcja/static/edumed/js/edumed.js | 14 +++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/librarian b/lib/librarian index c0761a86..ae0c7dcc 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit c0761a86fb4687fda8221e56bf911f051fda3499 +Subproject commit ae0c7dcc02fae67423974e65fe8bfdf6e7a7636a diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index e65faaaf..227bce63 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -23,10 +23,17 @@ class Excercise extends Binding # just save the html to reset the excercise $(@element).data("excercise-html", $(@element).html()) - $(".check", @element).click => + $(".check", @element).click (ev) => @check() + $(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() $('.solutions', @element).click => @show_solutions() + $(".comment", @element).show() $('.reset', @element).click => @reset() diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 42f0c379..75ecc9e5 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -38,11 +38,19 @@ var _this = this; Excercise.__super__.constructor.call(this, 'excercise', element); $(this.element).data("excercise-html", $(this.element).html()); - $(".check", this.element).click(function() { - return _this.check(); + $(".check", this.element).click(function(ev) { + _this.check(); + $(ev.target).next(".retry").show(); + 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(); }); $('.solutions', this.element).click(function() { - return _this.show_solutions(); + _this.show_solutions(); + return $(".comment", _this.element).show(); }); $('.reset', this.element).click(function() { return _this.reset(); -- 2.20.1 From 63fa9213819e7006cd1ced0c690dad76f990ec60 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 30 Jan 2013 11:19:25 +0100 Subject: [PATCH 13/16] Epic spelling mistake --- lib/librarian | 2 +- redakcja/static/edumed/css/edumed.css | 28 ++++++------ redakcja/static/edumed/js/edumed.coffee | 30 ++++++------- redakcja/static/edumed/js/edumed.js | 60 ++++++++++++------------- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/lib/librarian b/lib/librarian index ae0c7dcc..cdde48a1 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit ae0c7dcc02fae67423974e65fe8bfdf6e7a7636a +Subproject commit cdde48a1896f8ff4c49221fba175d9b1108b8d21 diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index d63ce5b4..1d2b9ea5 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -439,7 +439,7 @@ em.person { } -.excercise .buttons { +.exercise .buttons { text-align: right; } @@ -465,7 +465,7 @@ em.person { -.excercise .lista.predicate { +.exercise .lista.predicate { list-style: none; position: relative; clear: both; @@ -473,12 +473,12 @@ em.person { } -.excercise .subjects { +.exercise .subjects { padding-left: 0; } -.excercise .lista.predicate > li { +.exercise .lista.predicate > li { list-style: none; display: block; float: left; @@ -486,28 +486,28 @@ em.person { margin: 2px; } -.excercise.wide .lista.predicate > li { +.exercise.wide .lista.predicate > li { width: 100%; margin: 2px; } -.excercise .lista.predicate .droppable { +.exercise .lista.predicate .droppable { min-height: 50px; border: 1px dotted black; } -.excercise .draggable { +.exercise .draggable { padding: 3px; border: 1px dotted black; display: inline-block; } -.excercise .draggable.disabled { +.exercise .draggable.disabled { background-color: grey; } -.excercise .placeholder { +.exercise .placeholder { padding: 3px; border: 1px dotted black; display: inline-block; @@ -515,12 +515,12 @@ em.person { min-height: 1em; } -.excercise .placeholder.accepting.dragover { +.exercise .placeholder.accepting.dragover { background-color: #ffff99; } -.excercise.zastap .paragraph .placeholder { +.exercise.zastap .paragraph .placeholder { display: inline; min-width: none; min-height: none; @@ -530,12 +530,12 @@ em.person { -.excercise .lista.subjects { +.exercise .lista.subjects { padding-left: 0px; } -.excercise.uporzadkuj li { +.exercise.uporzadkuj li { cursor: move; } @@ -546,7 +546,7 @@ em.person { margin-left: 5px; } -.excercise.wybor li[data-name] { +.exercise.wybor li[data-name] { list-style: none; } diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index 227bce63..14c700ce 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -17,11 +17,11 @@ class EduModule extends Binding # $(".teacher", @element).removeClass "show" -class Excercise extends Binding +class Exercise extends Binding constructor: (element) -> - super 'excercise', element - # just save the html to reset the excercise - $(@element).data("excercise-html", $(@element).html()) + super 'exercise', element + # just save the html to reset the exercise + $(@element).data("exercise-html", $(@element).html()) $(".check", @element).click (ev) => @check() @@ -38,8 +38,8 @@ class Excercise extends Binding @reset() reset: -> - $(@element).html($(@element).data('excercise-html')) - excercise @element + $(@element).html($(@element).data('exercise-html')) + exercise @element piece_correct: (qpiece) -> $(qpiece).removeClass('incorrect').addClass('correct') @@ -178,7 +178,7 @@ class Excercise extends Binding -class Wybor extends Excercise +class Wybor extends Exercise constructor: (element) -> super element @@ -224,7 +224,7 @@ class Wybor extends Excercise -class Uporzadkuj extends Excercise +class Uporzadkuj extends Exercise constructor: (element) -> super element $('ol, ul', @element).sortable({ items: "> li" }) @@ -263,7 +263,7 @@ class Uporzadkuj extends Excercise # XXX propozycje="1/0" -class Luki extends Excercise +class Luki extends Exercise constructor: (element) -> super element @dragging false, false @@ -288,7 +288,7 @@ class Luki extends Excercise @draggable_move $qp, $(placeholder), false -class Zastap extends Excercise +class Zastap extends Exercise constructor: (element) -> super element $(".paragraph", @element).each (i, par) => @@ -354,7 +354,7 @@ class Zastap extends Excercise $(chld).remove() -class Przyporzadkuj extends Excercise +class Przyporzadkuj extends Exercise is_multiple: -> for qp in $(".question-piece", @element) if $(qp).data('solution').split(/[ ,]+/).length > 1 @@ -417,7 +417,7 @@ class Przyporzadkuj extends Excercise -class PrawdaFalsz extends Excercise +class PrawdaFalsz extends Exercise constructor: (element) -> super element @@ -457,7 +457,7 @@ class PrawdaFalsz extends Excercise ########## -excercise = (ele) -> +exercise = (ele) -> es = wybor: Wybor uporzadkuj: Uporzadkuj @@ -480,5 +480,5 @@ window.edumed = $(document).ready () -> new EduModule($("#book-text")) - $(".excercise").each (i, el) -> - excercise(this) \ No newline at end of file + $(".exercise").each (i, el) -> + exercise(this) \ No newline at end of file diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 75ecc9e5..cc7b9e12 100644 --- a/redakcja/static/edumed/js/edumed.js +++ b/redakcja/static/edumed/js/edumed.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.4.0 (function() { - var $, Binding, EduModule, Excercise, Luki, PrawdaFalsz, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, excercise, + var $, Binding, EduModule, Exercise, Luki, PrawdaFalsz, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, exercise, __hasProp = {}.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; }; @@ -30,14 +30,14 @@ })(Binding); - Excercise = (function(_super) { + Exercise = (function(_super) { - __extends(Excercise, _super); + __extends(Exercise, _super); - function Excercise(element) { + function Exercise(element) { var _this = this; - Excercise.__super__.constructor.call(this, 'excercise', element); - $(this.element).data("excercise-html", $(this.element).html()); + Exercise.__super__.constructor.call(this, 'exercise', element); + $(this.element).data("exercise-html", $(this.element).html()); $(".check", this.element).click(function(ev) { _this.check(); $(ev.target).next(".retry").show(); @@ -57,20 +57,20 @@ }); } - Excercise.prototype.reset = function() { - $(this.element).html($(this.element).data('excercise-html')); - return excercise(this.element); + Exercise.prototype.reset = function() { + $(this.element).html($(this.element).data('exercise-html')); + return exercise(this.element); }; - Excercise.prototype.piece_correct = function(qpiece) { + Exercise.prototype.piece_correct = function(qpiece) { return $(qpiece).removeClass('incorrect').addClass('correct'); }; - Excercise.prototype.piece_incorrect = function(qpiece) { + Exercise.prototype.piece_incorrect = function(qpiece) { return $(qpiece).removeClass('correct').addClass('incorrect'); }; - Excercise.prototype.check = function() { + Exercise.prototype.check = function() { var score, scores, _this = this; scores = []; @@ -85,7 +85,7 @@ return this.show_score(score); }; - Excercise.prototype.show_solutions = function() { + Exercise.prototype.show_solutions = function() { var _this = this; this.reset(); return $(".question", this.element).each(function(i, question) { @@ -93,7 +93,7 @@ }); }; - Excercise.prototype.get_value_list = function(elem, data_key, numbers) { + Exercise.prototype.get_value_list = function(elem, data_key, numbers) { var vl; vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim); if (numbers) { @@ -104,7 +104,7 @@ return vl; }; - Excercise.prototype.get_value_optional_list = function(elem, data_key) { + Exercise.prototype.get_value_optional_list = function(elem, data_key) { var mandat, opt, v, vals, _i, _len; vals = this.get_value_list(elem, data_key); mandat = []; @@ -120,15 +120,15 @@ return [mandat, opt]; }; - Excercise.prototype.show_score = function(score) { + Exercise.prototype.show_score = function(score) { return $(".message", this.element).text("Wynik: " + score[0] + " / " + score[1]); }; - Excercise.prototype.draggable_equal = function($draggable1, $draggable2) { + Exercise.prototype.draggable_equal = function($draggable1, $draggable2) { return false; }; - Excercise.prototype.draggable_accept = function($draggable, $droppable) { + Exercise.prototype.draggable_accept = function($draggable, $droppable) { var d, dropped, _i, _len; dropped = $droppable.closest("ul, ol").find(".draggable"); for (_i = 0, _len = dropped.length; _i < _len; _i++) { @@ -140,7 +140,7 @@ return true; }; - Excercise.prototype.draggable_move = function($draggable, $placeholder, ismultiple) { + Exercise.prototype.draggable_move = function($draggable, $placeholder, ismultiple) { var $added, _this = this; $added = $draggable.clone(); @@ -162,7 +162,7 @@ }); }; - Excercise.prototype.dragging = function(ismultiple, issortable) { + Exercise.prototype.dragging = function(ismultiple, issortable) { var _this = this; return $(".question", this.element).each(function(i, question) { var draggable_opts, self; @@ -204,7 +204,7 @@ }); }; - return Excercise; + return Exercise; })(Binding); @@ -269,7 +269,7 @@ return Wybor; - })(Excercise); + })(Exercise); Uporzadkuj = (function(_super) { @@ -329,7 +329,7 @@ return Uporzadkuj; - })(Excercise); + })(Exercise); Luki = (function(_super) { @@ -370,7 +370,7 @@ return Luki; - })(Excercise); + })(Exercise); Zastap = (function(_super) { @@ -461,7 +461,7 @@ return Zastap; - })(Excercise); + })(Exercise); Przyporzadkuj = (function(_super) { @@ -553,7 +553,7 @@ return Przyporzadkuj; - })(Excercise); + })(Exercise); PrawdaFalsz = (function(_super) { @@ -614,9 +614,9 @@ return PrawdaFalsz; - })(Excercise); + })(Exercise); - excercise = function(ele) { + exercise = function(ele) { var cls, es; es = { wybor: Wybor, @@ -636,8 +636,8 @@ $(document).ready(function() { new EduModule($("#book-text")); - return $(".excercise").each(function(i, el) { - return excercise(this); + return $(".exercise").each(function(i, el) { + return exercise(this); }); }); -- 2.20.1 From f7b91d0fc5230f026f5e62fcb81122a495bacc2f Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 30 Jan 2013 15:06:37 +0100 Subject: [PATCH 14/16] Table css --- redakcja/static/edumed/css/edumed.css | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/redakcja/static/edumed/css/edumed.css b/redakcja/static/edumed/css/edumed.css index 1d2b9ea5..ccc2a0c8 100644 --- a/redakcja/static/edumed/css/edumed.css +++ b/redakcja/static/edumed/css/edumed.css @@ -464,6 +464,16 @@ em.person { } +table.framed { + border-collapse:collapse; + border: 1px solid black; +} + +table.framed td { + border: 1px solid black; + padding: 5px; +} + .exercise .lista.predicate { list-style: none; -- 2.20.1 From bca6757e1d0a5c2875ef3ee2f99ddc145b38c2a8 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 30 Jan 2013 15:06:50 +0100 Subject: [PATCH 15/16] make master scripts --- .../management/commands/make_master.py | 130 ++++++++++++++++++ apps/catalogue/management/prompt.py | 41 ++++++ 2 files changed, 171 insertions(+) create mode 100644 apps/catalogue/management/commands/make_master.py create mode 100644 apps/catalogue/management/prompt.py diff --git a/apps/catalogue/management/commands/make_master.py b/apps/catalogue/management/commands/make_master.py new file mode 100644 index 00000000..220c66cc --- /dev/null +++ b/apps/catalogue/management/commands/make_master.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- + +from django.core.management.base import BaseCommand +from django.core.management.color import color_style +from catalogue.management.prompt import confirm +from catalogue.models import Book +from optparse import make_option +from datetime import date +import re +from slughifi import slughifi + + +dc_fixed = { + 'description': u'Publikacja zrealizowana w ramach projektu Cyfrowa Przyszłość (http://edukacjamedialna.edu.pl).', + 'rights': u'Creative Commons Uznanie autorstwa - Na tych samych warunkach 3.0', + 'rights_license': u'http://creativecommons.org/licenses/by-sa/3.0/', + } + + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('-s', '--slug', dest='slug', help="Slug for master module"), + make_option('-F', '--file', dest='slugs_file', help="file with child module slugs per line"), + make_option('-t', '--title', dest='title', default='', help="title of master module"), + make_option('-l', '--level', dest='audience', default='', help='Audience level'), + ) + help = 'Create a master module skeleton' + + def looks_like_syntetic(self, slug): + if re.match(r"^(gim|lic) \d[.]? ", slug): + return True + return False + + def gen_xml(self, options, syntetic_modules=[], course_modules=[], project_modules=[]): + holder = {} + holder['xml'] = u"" + + def p(t): + holder['xml'] += u"%s\n" % t + + def dc(k, v): + p(u'%s' % (k, v, k)) + + def t(tag, ct): + p(u'<%s>%s' % (tag, ct, tag)) + + def slug_url(slug): + return u"http://edukacjamedialna/%s/" % slug + + p("") + p(u'') + p(u'') + + dc(u'title', options['title']) + for slug in syntetic_modules: + dc(u'relation.hasChild.syntetic', slug_url(slug)) + for slug in course_modules: + dc(u'relation.hasChild.course', slug_url(slug)) + for slug in project_modules: + dc(u'relation.hasChild.project', slug_url(slug)) + dc(u'publisher', u'Fundacja Nowoczesna Polska') + # dc(u'subject.competence', meta.get(u'Wybrana kompetencja z Katalogu', u'')) + # dc(u'subject.curriculum', meta.get(u'Odniesienie do podstawy programowej', u'')) + ## for keyword in meta.get(u'Słowa kluczowe', u'').split(u','): + ## keyword = keyword.strip() + ## dc(u'subject', keyword) + dc(u'description', dc_fixed['description']) + dc(u'identifier.url', u'http://edukacjamedialna.edu.pl/%s' % options['slug']) + dc(u'rights', dc_fixed['rights']) + dc(u'rights.license', dc_fixed['rights_license']) + dc(u'format', u'syntetic, course, project') + dc(u'type', u'text') + dc(u'date', date.strftime(date.today(), "%Y-%m-%d")) + dc(u'audience', options['audience']) + dc(u'language', u'pol') + p(u'') + p(u'') + + return holder['xml'] + + def handle(self, *args, **options): + slug = options['slug'] + if not slug: + slug = slughifi(options['title']) + existing = Book.objects.filter(slug=slug) + + master = None + if existing: + overwrite = confirm("%s exists. Overwrite?" % slug, True) + if not overwrite: + return + master = existing[0] + else: + master = Book() + master.slug = slug + master.title = options['title'] + master.save() + + if len(master) == 0: + master.add(slug, options['title']) + + syntetic_modules = [] + course_modules = [] + if 'slugs_file' in options: + f = open(options['slugs_file'], 'r') + try: + titles = [l.strip() for l in f.readlines()] + + for t in titles: + if not t: continue + try: + b = Book.objects.get(title=t) + except Book.DoesNotExist: + print "Book for title %s does not exist" % t + continue + if self.looks_like_syntetic(t): + syntetic_modules.append(b.slug) + else: + course_modules.append(b.slug) + except Exception, e: + print "Error getting slug list (file %s): %s" % (options['slugs_file'], e) + + print "syntetic: %s" % syntetic_modules + print "course: %s" % course_modules + + xml = self.gen_xml(options, syntetic_modules, course_modules) + + print xml + + # master.save() diff --git a/apps/catalogue/management/prompt.py b/apps/catalogue/management/prompt.py new file mode 100644 index 00000000..8fcb9805 --- /dev/null +++ b/apps/catalogue/management/prompt.py @@ -0,0 +1,41 @@ +# http://code.activestate.com/recipes/541096-prompt-the-user-for-confirmation/ + +def confirm(prompt=None, resp=False): + """prompts for yes or no response from the user. Returns True for yes and + False for no. + + 'resp' should be set to the default value assumed by the caller when + user simply types ENTER. + + >>> confirm(prompt='Create Directory?', resp=True) + Create Directory? [y]|n: + True + >>> confirm(prompt='Create Directory?', resp=False) + Create Directory? [n]|y: + False + >>> confirm(prompt='Create Directory?', resp=False) + Create Directory? [n]|y: y + True + + """ + + if prompt is None: + prompt = 'Confirm' + + if resp: + prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n') + else: + prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y') + + while True: + ans = raw_input(prompt) + if not ans: + return resp + if ans not in ['y', 'Y', 'n', 'N']: + print 'please enter y or n.' + continue + if ans == 'y' or ans == 'Y': + return True + if ans == 'n' or ans == 'N': + return False + -- 2.20.1 From 64b40d8e431d74335d88551554cce94d1d2e07e6 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 30 Jan 2013 15:35:08 +0100 Subject: [PATCH 16/16] master xml making script --- .../management/commands/make_master.py | 34 ++++++++++++------- scripts/fix_something.py | 28 ++++++++++++--- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/apps/catalogue/management/commands/make_master.py b/apps/catalogue/management/commands/make_master.py index 220c66cc..5d907b90 100644 --- a/apps/catalogue/management/commands/make_master.py +++ b/apps/catalogue/management/commands/make_master.py @@ -26,12 +26,12 @@ class Command(BaseCommand): ) help = 'Create a master module skeleton' - def looks_like_syntetic(self, slug): - if re.match(r"^(gim|lic) \d[.]? ", slug): + def looks_like_synthetic(self, title): + if re.match(r"^(gim|lic)_\d[.]? ", title): return True return False - def gen_xml(self, options, syntetic_modules=[], course_modules=[], project_modules=[]): + def gen_xml(self, options, synthetic_modules=[], course_modules=[], project_modules=[]): holder = {} holder['xml'] = u"" @@ -52,8 +52,8 @@ class Command(BaseCommand): p(u'') dc(u'title', options['title']) - for slug in syntetic_modules: - dc(u'relation.hasChild.syntetic', slug_url(slug)) + for slug in synthetic_modules: + dc(u'relation.hasChild.synthetic', slug_url(slug)) for slug in course_modules: dc(u'relation.hasChild.course', slug_url(slug)) for slug in project_modules: @@ -68,17 +68,24 @@ class Command(BaseCommand): dc(u'identifier.url', u'http://edukacjamedialna.edu.pl/%s' % options['slug']) dc(u'rights', dc_fixed['rights']) dc(u'rights.license', dc_fixed['rights_license']) - dc(u'format', u'syntetic, course, project') + dc(u'format', u'synthetic, course, project') dc(u'type', u'text') dc(u'date', date.strftime(date.today(), "%Y-%m-%d")) dc(u'audience', options['audience']) dc(u'language', u'pol') p(u'') p(u'') + p(u'') return holder['xml'] def handle(self, *args, **options): + commit_args = { + "author_name": 'Platforma', + "description": 'Automatycznie zaimportowane z EtherPad', + "publishable": False, + } + slug = options['slug'] if not slug: slug = slughifi(options['title']) @@ -99,7 +106,7 @@ class Command(BaseCommand): if len(master) == 0: master.add(slug, options['title']) - syntetic_modules = [] + synthetic_modules = [] course_modules = [] if 'slugs_file' in options: f = open(options['slugs_file'], 'r') @@ -113,18 +120,19 @@ class Command(BaseCommand): except Book.DoesNotExist: print "Book for title %s does not exist" % t continue - if self.looks_like_syntetic(t): - syntetic_modules.append(b.slug) + if self.looks_like_synthetic(t): + synthetic_modules.append(b.slug) else: course_modules.append(b.slug) except Exception, e: print "Error getting slug list (file %s): %s" % (options['slugs_file'], e) - print "syntetic: %s" % syntetic_modules + print "synthetic: %s" % synthetic_modules print "course: %s" % course_modules - xml = self.gen_xml(options, syntetic_modules, course_modules) - + xml = self.gen_xml(options, synthetic_modules, course_modules) + c = master[0] print xml + if confirm("Commit?", True): + c.commit(xml, **commit_args) - # master.save() diff --git a/scripts/fix_something.py b/scripts/fix_something.py index 2d73ba16..c9f9a681 100755 --- a/scripts/fix_something.py +++ b/scripts/fix_something.py @@ -10,6 +10,7 @@ sys.path.append('./lib') from django.core.management import setup_environ from redakcja import settings +from lxml import etree setup_environ(settings) @@ -21,9 +22,6 @@ fixed = {} tag_with_name = r"<([^>]+)name=\"([^>]+)>" def fix(book, author, dry_run=True): - if len(book) == 0: - print "%s ==> does not contain chunks" % book.slug - return fc = book[0] txt = fc.materialize() @@ -38,6 +36,25 @@ def fix(book, author, dry_run=True): else: print "%s ==> i would change this" % book.slug +def fix_empty_opis(book, author, dry_run=True): + fc = book[0] + txt = fc.materialize() + try: + t = etree.fromstring(txt) + empty_opis = t.xpath('//opis[not(node())]') + empty_cwiczenie = t.xpath('//cwiczenie[not(node())]') + + if empty_opis: + print "%s: opis/ x %d" % (book.slug, len(empty_opis)) + + if empty_cwiczenie: + print "%s: cwiczenie/ x %d" % (book.slug, len(empty_cwiczenie)) + + except: + print "%s didn't parse" % b.slug + return + + import sys import getopt @@ -50,7 +67,10 @@ me = User.objects.get(username='marcinkoziej') if dry_run: print "This is a dry run, to really fix something, run with --seriously" for b in Book.objects.all(): - fix(b, me, dry_run) + if len(b) == 0: + print "%s ==> does not contain chunks" % b.slug + continue + fix_empty_opis(b, me, dry_run) -- 2.20.1