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
$($added.data('original')).removeClass('disabled').draggable('enable')
$added.remove()
-
+## XXX co z issortable?
dragging: (ismultiple, issortable) ->
$(".question", @element).each (i, question) =>
draggable_opts =
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
__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;
};
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++) {
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;