From daacf83adcf2305add277eae0081f59c4c1a7863 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 9 Jan 2013 09:54:37 +0100 Subject: [PATCH] Dragging in excercises --- lib/librarian | 2 +- redakcja/static/edumed/js/edumed.coffee | 50 +++++++++++++++++++++ redakcja/static/edumed/js/edumed.js | 59 ++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 3 deletions(-) diff --git a/lib/librarian b/lib/librarian index e0e76930..79da3449 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit e0e7693096469f5952eef1c5847dabc9cf797f70 +Subproject commit 79da3449684beeb938735346e1d66093f51ba36d diff --git a/redakcja/static/edumed/js/edumed.coffee b/redakcja/static/edumed/js/edumed.coffee index cccc90aa..4bd8bed9 100644 --- a/redakcja/static/edumed/js/edumed.coffee +++ b/redakcja/static/edumed/js/edumed.coffee @@ -190,6 +190,55 @@ class Zastap extends Excercise $(chld).remove() +class Przyporzadkuj extends Excercise + constructor: (element) -> + super element + + if @element.attr('multiple')? + @multiple = true + else + @multiple = false + + $(".question", @element).each (i, question) => + draggable_opts = + revert: 'invalid' + helper: if @multiple then "clone" else null + + $(".draggable", question).draggable(draggable_opts) + .droppable({ + accept: ".draggable" + }) + + $(".predicate .droppable", question).droppable + accept: ".draggable" + drop: (ev, ui) -> + is_multiple = ui.draggable.is(".multiple") + + added = ui.draggable.clone() + + added.attr('style', '') + $(this).append(added) + added.draggable(draggable_opts) + + if not is_multiple + ui.draggable.remove() + + $(".subject", question).droppable + accept: ".draggable" + drop: (ev, ui) -> + is_multiple = ui.draggable.is(".multiple") + + added = ui.draggable.clone() + + added.attr('style', '') + if not is_multiple + $(this).append(added) + added.draggable(draggable_opts) + + ui.draggable.remove() + + + ########## @@ -199,6 +248,7 @@ excercise = (ele) -> uporzadkuj: Uporzadkuj luki: Luki zastap: Zastap + przyporzadkuj: Przyporzadkuj cls = es[$(ele).attr('data-type')] diff --git a/redakcja/static/edumed/js/edumed.js b/redakcja/static/edumed/js/edumed.js index 3e7eadb9..a48e19ac 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, Uporzadkuj, Wybor, Zastap, excercise, + var $, Binding, EduModule, Excercise, Luki, 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; }; @@ -280,13 +280,68 @@ })(Excercise); + Przyporzadkuj = (function(_super) { + + __extends(Przyporzadkuj, _super); + + function Przyporzadkuj(element) { + var _this = this; + Przyporzadkuj.__super__.constructor.call(this, element); + if (this.element.attr('multiple') != null) { + this.multiple = true; + } else { + this.multiple = false; + } + $(".question", this.element).each(function(i, question) { + var draggable_opts; + draggable_opts = { + revert: 'invalid', + helper: _this.multiple ? "clone" : null + }; + $(".draggable", question).draggable(draggable_opts).droppable({ + accept: ".draggable" + }); + $(".predicate .droppable", question).droppable({ + accept: ".draggable", + drop: function(ev, ui) { + var added, is_multiple; + is_multiple = ui.draggable.is(".multiple"); + added = ui.draggable.clone(); + added.attr('style', ''); + $(this).append(added); + added.draggable(draggable_opts); + if (!is_multiple) return ui.draggable.remove(); + } + }); + return $(".subject", question).droppable({ + accept: ".draggable", + drop: function(ev, ui) { + var added, is_multiple; + is_multiple = ui.draggable.is(".multiple"); + added = ui.draggable.clone(); + added.attr('style', ''); + if (!is_multiple) { + $(this).append(added); + added.draggable(draggable_opts); + } + return ui.draggable.remove(); + } + }); + }); + } + + return Przyporzadkuj; + + })(Excercise); + excercise = function(ele) { var cls, es; es = { wybor: Wybor, uporzadkuj: Uporzadkuj, luki: Luki, - zastap: Zastap + zastap: Zastap, + przyporzadkuj: Przyporzadkuj }; cls = es[$(ele).attr('data-type')]; return new cls(ele); -- 2.20.1