From 992eddb87cd0f86ced6c720718683052fbd2f91f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 22 Oct 2021 02:37:25 -0500 Subject: [PATCH] Exercise: Allow reset answers in annotation - refs BT#18831 --- main/inc/lib/exercise.lib.php | 23 +++++++++----- .../javascript/annotation/js/annotation.js | 30 +++++++++++++++++-- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 732bf2ce23..41c564656c 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1703,14 +1703,6 @@ HOTSPOT;
-
@@ -1731,11 +1723,26 @@ HOTSPOT;
+
+ +
+ '; } diff --git a/main/inc/lib/javascript/annotation/js/annotation.js b/main/inc/lib/javascript/annotation/js/annotation.js index 67ecf852cc..fda5f39fa2 100644 --- a/main/inc/lib/javascript/annotation/js/annotation.js +++ b/main/inc/lib/javascript/annotation/js/annotation.js @@ -157,6 +157,7 @@ this.models = []; this.length = 0; this.addEvent = null; + this.resetEvent = null; }; ElementsCollection.prototype.add = function (pathModel) { pathModel.id = ++this.length; @@ -170,9 +171,19 @@ ElementsCollection.prototype.get = function (index) { return this.models[index]; }; + ElementsCollection.prototype.reset = function () { + if (this.resetEvent) { + this.resetEvent(); + } + + this.models = []; + } ElementsCollection.prototype.onAdd = function (callback) { this.addEvent = callback; }; + ElementsCollection.prototype.onReset = function (callback) { + this.resetEvent = callback; + } var AnnotationCanvasView = function (elementsCollection, image, questionId) { var self = this; @@ -199,13 +210,22 @@ this.elementsCollection.onAdd(function (pathModel) { self.renderElement(pathModel); }); + this.elementsCollection.onReset(function () { + $(self.el.parentNode).children('input').remove(); + + self.$el.children('text, path').remove(); + + $('#annotation-toolbar-' + self.questionId + ' ul').empty(); + }) this.$rdbOptions = null; + this.$btnReset = null; }; AnnotationCanvasView.prototype.render = function () { - this.setEvents(); - this.$rdbOptions = $('[name="' + this.questionId + '-options"]'); + this.$btnReset = $('#btn-reset-' + this.questionId); + + this.setEvents(); return this; }; @@ -264,6 +284,12 @@ elementModel = null; isMoving = false; }); + + this.$btnReset.on('click', function (e) { + e.preventDefault(); + + self.elementsCollection.reset(); + }); }; AnnotationCanvasView.prototype.renderElement = function (elementModel) { var elementView = null,