Refactor RfC creation to prevent users from navigating

This commit is contained in:
Sebastian Serth
2023-08-17 00:25:51 +02:00
parent 08a1eb6201
commit de5bbea4a8
3 changed files with 17 additions and 9 deletions

View File

@ -111,6 +111,8 @@ CodeOceanEditorRequestForComments = {
requestComments: function () {
const cause = $('#requestComments');
this.startSentryTransaction(cause);
$('#question').prop("disabled", true);
$('#closeAskForCommentsButton').addClass('d-none');
var user_id = $('#editor').data('user-id');
var exercise_id = $('#editor').data('exercise-id');
@ -118,6 +120,7 @@ CodeOceanEditorRequestForComments = {
var question = $('#question').val();
var createRequestForComments = function (submission) {
this.showSpinner($('#askForCommentsButton'));
$.ajax({
method: 'POST',
url: Routes.request_for_comments_path(),
@ -129,18 +132,21 @@ CodeOceanEditorRequestForComments = {
question: question
}
}
}).done(function () {
this.hideSpinner();
$.flash.success({text: $('#askForCommentsButton').data('message-success')});
}).done(function() {
// trigger a run
this.runSubmission.call(this, submission);
}.bind(this)).fail(this.ajaxError.bind(this));
$.flash.success({text: $('#askForCommentsButton').data('message-success')});
}.bind(this)).fail(this.ajaxError.bind(this))
.always(function () {
bootstrap.Modal.getInstance($('#comment-modal')).hide();
this.hideSpinner();
$('#question').prop("disabled", false).val('');
$('#closeAskForCommentsButton').removeClass('d-none');
$('#askForCommentsButton').one('click', this.requestComments.bind(this));
}.bind(this));
};
this.createSubmission(cause, null, createRequestForComments.bind(this));
bootstrap.Modal.getInstance($('#comment-modal')).hide();
$('#question').val('');
// we disabled the button to prevent that the user spams RFCs, but decided against this now.
//var button = $('#requestComments');
//button.prop('disabled', true);