From 6e8379333178e150cb4783e99342e55abc576589 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 18 Jan 2013 13:03:39 +0100 Subject: [PATCH] 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