diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index d3689524..05b2f558 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -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(); }); diff --git a/app/assets/javascripts/editor/participantsupport.js.erb b/app/assets/javascripts/editor/participantsupport.js.erb index a95dbb40..a8fc8437 100644 --- a/app/assets/javascripts/editor/participantsupport.js.erb +++ b/app/assets/javascripts/editor/participantsupport.js.erb @@ -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); diff --git a/app/views/exercises/_request_comment_dialogcontent.html.slim b/app/views/exercises/_request_comment_dialogcontent.html.slim index 62ee2642..62b5dc60 100644 --- a/app/views/exercises/_request_comment_dialogcontent.html.slim +++ b/app/views/exercises/_request_comment_dialogcontent.html.slim @@ -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')