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

@ -507,7 +507,7 @@ var CodeOceanEditor = {
new bootstrap.Modal($('#comment-modal')).show();
});
$('#askForCommentsButton').on('click', this.requestComments.bind(this));
$('#askForCommentsButton').one('click', this.requestComments.bind(this));
$('#closeAskForCommentsButton').on('click', function () {
bootstrap.Modal.getInstance($('#comment-modal')).hide();
});

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);

View File

@ -7,5 +7,7 @@ p = ''
/ data-cause='requestComments' is not used here right now, we pass the button #requestComments (not askForCommentsButton) as initiator of the action.
/ But if we use this button, it will work since the correct cause is supplied
.d-grid.gap-2
button#askForCommentsButton.btn.btn-primary(type='button' data-cause='requestComments' data-message-success=t('exercises.editor.request_for_comments_sent')) =t('exercises.implement.comment.request')
button#askForCommentsButton.btn.btn-primary(type='button' data-cause='requestComments' data-message-success=t('exercises.editor.request_for_comments_sent'))
i.fa-solid.fa-circle-notch.fa-spin.d-none
=t('exercises.implement.comment.request')
button#closeAskForCommentsButton.btn.btn-warning(type='button') =t('activerecord.attributes.request_for_comments.close')