Skip to content

Commit

Permalink
Exercise: Allow reset answers in annotation - refs BT#18831
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 22, 2021
1 parent b7fcd77 commit 992eddb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
23 changes: 15 additions & 8 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -1703,14 +1703,6 @@ class="window window_left_question window{$questionId}_question">
<div class="col-sm-8 col-md-9">
<div id="annotation-canvas-'.$questionId.'" class="annotation-canvas center-block">
</div>
<script>
AnnotationQuestion({
questionId: '.$questionId.',
exerciseId: '.$exe_id.',
relPath: \''.$relPath.'\',
courseId: '.$course_id.',
});
</script>
</div>
<div class="col-sm-4 col-md-3">
<div class="well well-sm" id="annotation-toolbar-'.$questionId.'">
Expand All @@ -1731,11 +1723,26 @@ class="window window_left_question window{$questionId}_question">
<span class="fa fa-font fa-fw" aria-hidden="true"></span>
</label>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default btn-small"
title="'.get_lang('ClearAnswers').'"
id="btn-reset-'.$questionId.'">
<span class="fa fa-times-rectangle fa-fw" aria-hidden="true"></span>
</button>
</div>
</div>
<ul class="list-unstyled"></ul>
</div>
</div>
</div>
<script>
AnnotationQuestion({
questionId: '.$questionId.',
exerciseId: '.$exe_id.',
relPath: \''.$relPath.'\',
courseId: '.$course_id.',
});
</script>
</div>
';
}
Expand Down
30 changes: 28 additions & 2 deletions main/inc/lib/javascript/annotation/js/annotation.js
Expand Up @@ -157,6 +157,7 @@
this.models = [];
this.length = 0;
this.addEvent = null;
this.resetEvent = null;
};
ElementsCollection.prototype.add = function (pathModel) {
pathModel.id = ++this.length;
Expand All @@ -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;
Expand All @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 992eddb

Please sign in to comment.