]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6182 @4:00 question drag and drop
authorsoufiane <soufiane@cubedesigners.com>
Mon, 11 Sep 2023 16:08:34 +0000 (18:08 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 11 Sep 2023 16:08:34 +0000 (18:08 +0200)
js/quiz.draganddrop.js
js/quiz.js
js/quiz.screens.js
views/screens/question_draganddrop.blade.php

index 387ecc169934f7cd1614c46a6adcbc785c6000e0..3630101813c07beb0827c0049bfa41aa893f08fd 100644 (file)
@@ -25,6 +25,11 @@ QuizDragAndDrop.prototype = {
         this.offsetLeftItemDragged = 0
         this.offsetRightItemDragged = 0
 
+        this.createDraggable()
+    },
+
+    createDraggable: function() {
+        const $this = this
         Draggable.create(this.item, {
             type: "x,y",
             edgeResistance: 0.2,
@@ -83,23 +88,26 @@ QuizDragAndDrop.prototype = {
                             target.addClass("isValidated")
                         },
                         onComplete: function () {
-                            let html = target.html()
-                            $(zone).find(".slot:not(.active)").eq(0).addClass("active").html(html)
+                            let html = target.html(),
+                                id = "answer-"+target.data("id")
+
+                            $(zone).find(".slot:not(.active)").eq(0).addClass("active").html(html).attr('data-order',target.data("id"))
+                            $this.saveAnswer(zone,id)
                             target.remove()
                         }
                     })
-                    .to(".list .overlay", {
-                        y: -heightTarget,
-                        opacity: 0,
-                        onStart: function () {
-                            $(".list-item.isValidated").next().addClass("isNext")
-                        }
-                    }, "<")
-                    .to(".list .overlay", {
-                        y: 0,
-                        opacity: 1,
-                        duration: 0
-                    }, "+=1")
+                        .to(".list .overlay", {
+                            y: -heightTarget,
+                            opacity: 0,
+                            onStart: function () {
+                                $(".list-item.isValidated").next().addClass("isNext")
+                            }
+                        }, "<")
+                        .to(".list .overlay", {
+                            y: 0,
+                            opacity: 1,
+                            duration: 0
+                        }, "+=1")
                 }
 
             },
@@ -123,7 +131,6 @@ QuizDragAndDrop.prototype = {
                 })
             }
         });
-
     },
 
     rotateItem: function($this, direction) {
@@ -175,7 +182,29 @@ QuizDragAndDrop.prototype = {
         return {"x" : x, "y" : y, "w" : w, "h": h, "el": el}
     },
 
+    reset: function() {
+        //this.activeScreen.find("input").prop("checked", false)
+    },
+
+    retreiveAnswer: function () {
+        let question = this.quiz.quiz.question.current(),
+            answers = question.answers
+
+        const $this = this
+
+        this.list.empty()
+        for(let k in answers) {
+            let content = answers[k].answer
+            $this.list.append("<li class='list-item'>"+content+"</li>")
+        }
+        this.item = this.activeScreen.find(".list-item")
+        this.createDraggable()
+    },
 
+    saveAnswer: function(zone,id) {
+        $(zone).find("input[id="+id+"]").prop("checked", true)
+        this.retreiveAnswer()
+    }
 }
 
 export default QuizDragAndDrop;
index 8d8e52c63ee2478a4f498afbc0e7446d1c63df35..ceadc3ec19a0c82bce97291934a415d17cc01e0d 100644 (file)
@@ -12,6 +12,7 @@ import QuizUtils from './quiz.utils';
 import QuizScreens from './quiz.screens';
 import QuizProgressbar from "./quiz.progressbar";
 import QuizL10n from "./quiz.l10n";
+import QuizDraganddrop from "./quiz.draganddrop";
 
 window.cubeSCORM = new CubeSCORM();
 window.$ = window.jQuery = $;
@@ -43,6 +44,7 @@ Quiz.prototype = {
         this.screens = new QuizScreens(this);
         this.progressbar = new QuizProgressbar(this);
         this.l10n = new QuizL10n(this);
+        this.draganddrop = new QuizDraganddrop(this);
 
         console.log(this.data);
         // ICI tout commence vraiment
index 58a5bd51d4b9c0285a1d060a750999fda5bc6482..848be3683632ed79dec81839b24d786c9cd07335 100644 (file)
@@ -194,7 +194,6 @@ QuizScreens.prototype = {
         this.getCurrentForm().find("input").prop("checked", false)
     },
 
-
     getActiveScreen() {
         return this.activeScreen;
     },
index 10d9bc1243fcdd291045b9a7186e63920849b50e..58e27ea360b3aade9ccbb08f33e393728ddab594 100644 (file)
@@ -9,6 +9,8 @@
             <form>
                 @foreach($question['answers'] as $key => $answer)
                     <div class="slot">
+                        <input type="checkbox"
+                               id="answer-{{$key}}" class="none" value="{{$key}}">
                     </div>
                 @endforeach
             </form>
@@ -22,7 +24,7 @@
         </div>
         <ul class="list">
             @foreach($question['answers'] as $key => $answer)
-                <li class="list-item {{ $key === 0 ? 'current' : '' }}">
+                <li class="list-item {{ $key === 0 ? 'current' : '' }}" data-id="{{$key}}">
                     {{$answer['answer']}}
                 </li>
             @endforeach