Allow removing all event handles in JavaScript
This is useful to remove any handlers, e.g., when submitting an exercise. Hopefully, we will see less Javascript errors due to cumbersome behavior with these changes... Also, I am cleaning up unused event handlers. The `showOutput` method doesn't seem to be used, we should observe this in the future. Closes CODEOCEAN-KQ
This commit is contained in:
@ -373,6 +373,15 @@ var CodeOceanEditor = {
|
|||||||
this.initializeRequestForComments()
|
this.initializeRequestForComments()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
teardownEventHandlers: function () {
|
||||||
|
$(document).unbind('click');
|
||||||
|
$(document).unbind('keydown');
|
||||||
|
this.teardownWorkspaceButtons();
|
||||||
|
this.teardownRequestForComments();
|
||||||
|
bootstrap.Modal.getInstance($('#comment-modal'))?.hide();
|
||||||
|
this.teardownFileTreeButtons();
|
||||||
|
},
|
||||||
|
|
||||||
updateEditorModeToFileTypeID: function (editor, fileTypeID) {
|
updateEditorModeToFileTypeID: function (editor, fileTypeID) {
|
||||||
var newMode = 'ace/mode/text'
|
var newMode = 'ace/mode/text'
|
||||||
|
|
||||||
@ -413,7 +422,13 @@ var CodeOceanEditor = {
|
|||||||
$('#destroy-file').on('click', this.confirmDestroy.bind(this));
|
$('#destroy-file').on('click', this.confirmDestroy.bind(this));
|
||||||
$('#destroy-file-collapsed').on('click', this.confirmDestroy.bind(this));
|
$('#destroy-file-collapsed').on('click', this.confirmDestroy.bind(this));
|
||||||
$('#download').on('click', this.downloadCode.bind(this));
|
$('#download').on('click', this.downloadCode.bind(this));
|
||||||
$('#request-for-comments').on('click', this.requestComments.bind(this));
|
},
|
||||||
|
|
||||||
|
teardownFileTreeButtons: function () {
|
||||||
|
$('#create-file').unbind('click');
|
||||||
|
$('#destroy-file').unbind('click');
|
||||||
|
$('#destroy-file-collapsed').unbind('click');
|
||||||
|
$('#download').unbind('click');
|
||||||
},
|
},
|
||||||
|
|
||||||
initializeSideBarCollapse: function () {
|
initializeSideBarCollapse: function () {
|
||||||
@ -446,16 +461,23 @@ var CodeOceanEditor = {
|
|||||||
initializeWorkspaceButtons: function () {
|
initializeWorkspaceButtons: function () {
|
||||||
$('#submit').one('click', this.submitCode.bind(this));
|
$('#submit').one('click', this.submitCode.bind(this));
|
||||||
$('#assess').on('click', this.scoreCode.bind(this));
|
$('#assess').on('click', this.scoreCode.bind(this));
|
||||||
$('#dropdown-render, #render').on('click', this.renderCode.bind(this));
|
$('#render').on('click', this.renderCode.bind(this));
|
||||||
$('#dropdown-run, #run').on('click', this.runCode.bind(this));
|
$('#run').on('click', this.runCode.bind(this));
|
||||||
$('#dropdown-stop, #stop').on('click', this.stopCode.bind(this));
|
$('#stop').on('click', this.stopCode.bind(this));
|
||||||
$('#dropdown-test, #test').on('click', this.testCode.bind(this));
|
$('#test').on('click', this.testCode.bind(this));
|
||||||
$('#save').on('click', this.saveCode.bind(this));
|
|
||||||
$('#start-over').on('click', this.confirmReset.bind(this));
|
$('#start-over').on('click', this.confirmReset.bind(this));
|
||||||
$('#start-over-collapsed').on('click', this.confirmReset.bind(this));
|
|
||||||
$('#start-over-active-file').on('click', this.confirmResetActiveFile.bind(this));
|
$('#start-over-active-file').on('click', this.confirmResetActiveFile.bind(this));
|
||||||
$('#start-over-active-file-collapsed').on('click', this.confirmResetActiveFile.bind(this));
|
},
|
||||||
|
|
||||||
|
teardownWorkspaceButtons: function () {
|
||||||
|
$('#submit').unbind('click');
|
||||||
|
$('#assess').unbind('click');
|
||||||
|
$('#render').unbind('click');
|
||||||
|
$('#run').unbind('click');
|
||||||
|
$('#stop').unbind('click');
|
||||||
|
$('#test').unbind('click');
|
||||||
|
$('#start-over').unbind('click');
|
||||||
|
$('#start-over-active-file').unbind('click');
|
||||||
},
|
},
|
||||||
|
|
||||||
initializeRequestForComments: function () {
|
initializeRequestForComments: function () {
|
||||||
@ -483,6 +505,12 @@ var CodeOceanEditor = {
|
|||||||
}.bind(this), this.REQUEST_FOR_COMMENTS_DELAY);
|
}.bind(this), this.REQUEST_FOR_COMMENTS_DELAY);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
teardownRequestForComments: function () {
|
||||||
|
$('#requestComments').unbind('click');
|
||||||
|
$('#askForCommentsButton').unbind('click');
|
||||||
|
$('#closeAskForCommentsButton').unbind('click');
|
||||||
|
},
|
||||||
|
|
||||||
isActiveFileRenderable: function () {
|
isActiveFileRenderable: function () {
|
||||||
if (this.active_frame.data() === undefined) {
|
if (this.active_frame.data() === undefined) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -202,6 +202,7 @@ CodeOceanEditorSubmissions = {
|
|||||||
|
|
||||||
submitCode: function(event) {
|
submitCode: function(event) {
|
||||||
const button = $(event.target) || $('#submit');
|
const button = $(event.target) || $('#submit');
|
||||||
|
this.teardownEventHandlers();
|
||||||
this.createSubmission(button, null, function (response) {
|
this.createSubmission(button, null, function (response) {
|
||||||
if (response.redirect) {
|
if (response.redirect) {
|
||||||
this.autosaveIfChanged();
|
this.autosaveIfChanged();
|
||||||
@ -211,13 +212,12 @@ CodeOceanEditorSubmissions = {
|
|||||||
Turbolinks.visit(response.redirect);
|
Turbolinks.visit(response.redirect);
|
||||||
} else if (response.status === 'container_depleted') {
|
} else if (response.status === 'container_depleted') {
|
||||||
this.showContainerDepletedMessage();
|
this.showContainerDepletedMessage();
|
||||||
button.one('click', this.submitCode.bind(this));
|
|
||||||
} else if (response.message) {
|
} else if (response.message) {
|
||||||
$.flash.danger({
|
$.flash.danger({
|
||||||
text: response.message
|
text: response.message
|
||||||
});
|
});
|
||||||
button.one('click', this.submitCode.bind(this));
|
|
||||||
}
|
}
|
||||||
|
this.initializeEventHandlers();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user