#4061 Undo submitting comment via JS if the SSE is down
Merged 6 years ago by pingou. Opened 6 years ago by pingou.

file modified
+5 -57
@@ -917,7 +917,6 @@ 

    console.log('Submitting form:');

    console.log(form);

    set_ui_for_comment(true);

- 

    var _data = $(form).serialize();

    var btn = $(document.activeElement);

    if (btn[0].name == 'drop_comment'){
@@ -925,22 +924,11 @@ 

      set_ui_for_comment(false);

      return true;

    }

- 

-   /* Keep some variable in memory before sending them in case the SSE is down */

-   var _url = form.action;

-   var _update = false;

-   var _comment = $(form).find('#comment').val();

-   var _comment_id = null;

-   if (!_comment && form.update_comment) {

-     _update = true;

-     _comment_id = $(form.edit_comment).val();

-     _comment = $(form).find('#update_comment').val();

+   if (!sse || source.readyState != 1) {

+     $(form).off('submit');

+     form.submit();

+     return false;

    }

-   var _commit_id = null;

-   var _line = null;

-   var _token = "{{ form.csrf_token.current_token }}";

-   var _base_url = _url.split('?')[0];

- 

    var _url = form.action + "?js=1";

    $.post( _url, _data )

      .done(function(data) {
@@ -956,47 +944,7 @@ 

          $('#comments').find('.edit_comment').remove();

          $( ".issue-metadata-form" ).hide();

          $( ".issue-metadata-display" ).show();

-         if (!sse || source.readyState != 1) {

-             console.log('no sse, adding the comment manually');

-             $.ajax({

-               url: "{{ url_for('ui_ns.markdown_preview') }}" ,

-               type: 'POST',

-               data: {

-                 content: _comment,

-                 csrf_token: _token,

-               },

-               dataType: 'html',

-               success: function(res) {

-                 var _comment = emojione.toImage(res);

-                 if (_update) {

-                   var data = {

-                     comment_updated: _comment,

-                     comment_user: "{{ g.fas_user.username }}",

-                     comment_date: Date.now(),

-                     comment_id: _comment_id,

-                     avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

-                   }

-                 } else {

-                   var data = {

-                     comment_added: _comment,

-                     comment_user: "{{ g.fas_user.username }}",

-                     comment_date: Date.now(),

-                     avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

-                   }

-                 }

-                 process_event(

-                     data,

-                     "{{ issue.uid }}",

-                     "{{ g.fas_user.username if g.authenticated or '' }}");

-                 set_ui_for_comment(false);

-                 setup_reply_btns()

-                 return false;

-               }

-             });

-             return false;

-         } else {

-             set_ui_for_comment(false);

-         }

+         set_ui_for_comment(false);

        } else {

          // Make the browser submit the form sync

          $(form).off('submit');

Revert "Show the comment on issues in JS if the SSE isn't responding"

This partially reverts commit e321843
This reverts commit 485acb7.

Fixes https://pagure.io/pagure/issue/3879

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto 4228c30510290da3abff95c53a4312c2970db97c

6 years ago

rebased onto 269ace20897c09f1a67fa2649607f5b90900a094

6 years ago

rebased onto 0f4ecda

6 years ago

Pull-Request has been merged by pingou

6 years ago