From: Marcin Koziej Date: Mon, 28 Jan 2013 14:26:26 +0000 (+0100) Subject: przyporzadkuj -- minimum answers X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/18039456886ac5b0853076b5f33605f1d6bbe865?ds=inline;hp=ce3d5f6fd76ca2f366088105b6637d68ace76de0 przyporzadkuj -- minimum answers --- 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;