diff --git a/pagure/static/request_ev.js b/pagure/static/request_ev.js index fb42770..852e186 100644 --- a/pagure/static/request_ev.js +++ b/pagure/static/request_ev.js @@ -1,62 +1,88 @@ add_comment = function(data) { console.log('Adding comment ' + data.comment_added); + var field = $('#comments'); + var edit_btn = ' \ + reply '; + var inline = false; if (data.commit_id){ + inline = true; + edit_btn = ''; + } + + var _data = '
\ +
\ + \ + ' + data.comment_user + '\ + \ + \ + seconds ago \ + \ +
\ +
\ +
\ +
\ + \ + \ + ' + data.comment_added + '\ +
\ +
\ +
\ + \ +
\ +
\ +
'; + + if (inline){ // Inline comment console.log('Inline'); - var _data = ' \ - \ - \ -
\ - ' - + data.comment_user + '' + data.comment_date + '
' - + data.comment_added + - '
'; + var _row = ' \ +
' + _data + '
'; var field = $('[data-commit="' + data.commit_id + '"]').parent(); var id = field.children().children().attr('id').split('_')[0]; var row = $('#' + id + '_' + (parseInt(data.line) + 1)).parent().parent(); - row.before(_data); + row.before(_row); } else { // Generic comment console.log('generic'); var field = $('#request_comment'); - var _data = '
\ -
\ - \ - \ - ' + data.comment_user + '\ - - seconds ago \ - ΒΆ \ - \ -
\ -
\ -

' + data.comment_added + '

\ -
\ -
'; - field.html(field.html() + _data); } } update_comment = function(data) { console.log('Updating comment ' + data.comment_id); - var field = $('#comment-' + data.comment_id); - field.find('.edit_date').html( - 'Edited by ' - + data.comment_editor + ' seconds ago'); - var sec = field.parent(); - if (sec.find('.comment_body').length) { - sec.find('.comment_body').html(data.comment_updated); + var field = $('#comment-' + data.comment_id).parent(); + console.log($('#comment-' + data.comment_id)); + console.log(field); + var edited = field.find('.text-muted'); + console.log(edited); + if (edited.length == 0) { + console.log('First edition'); + $(field.find('aside')).before( + 'Edited a just now by ' + + data.comment_editor + ''); } else { - sec.parent().parent().find('.comment_date').html( - 'Edited by ' - + data.comment_editor + ' seconds ago'); - sec.parent().parent().find('.pr_comment').html(data.comment_updated); + console.log('edited before'); + edited.html('Edited a just now by ' + data.comment_editor) } + field.find('.comment_body').html(data.comment_updated); + field.find('.issue_actions').show(); + field.find('.issue_comment').show(); } process_event = function(data, requestid){ diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 60a46e6..4cb35b6 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -627,41 +627,37 @@ } ); - $(".edit_btn").click(function() { - var commentid = $( this ).attr('data-comment'); - var _url = '{{ request.base_url }}' + '/comment/' + commentid + '/edit'; - $.ajax({ - url: _url + '?js=1', - type: 'GET', - dataType: 'html', - success: function(res) { - var el = $('#comment-' + commentid); - var sec = el.parent().children()[1]; - if (!sec) { - sec = el.parent().parent(); - $(sec).next().hide(); - var row = $(sec).parent().parent().append( - "" + res + ""); - } else { + function setup_edit_btns() { + $(".edit_btn").click(function() { + var commentid = $( this ).attr('data-comment'); + var _url = '{{ request.base_url }}' + '/comment/' + commentid + '/edit'; + $.ajax({ + url: _url + '?js=1', + type: 'GET', + dataType: 'html', + success: function(res) { + var el = $('#comment-' + commentid); + console.log(el); + var sec = el.parent().find('.issue_comment'); + console.log(sec); $(sec).hide(); + el.parent().find('.issue_actions').hide(); $(sec).after(res); - } - cancel_edit_btn(); - }, - error: function() { - alert('Could not make edit work'); - } + cancel_edit_btn(); + }, + error: function() { + alert('Could not make edit work'); + } + }); + return false; }); - return false; - }); + }; + setup_edit_btns(); function cancel_edit_btn() { $( ".cancel" ).click( function() { - var item = $(this).closest('tr'); - if (!item.length) { - item = $(this).closest('section'); - } + item = $(this).closest('section'); $(item.parent().children()[1]).show(); item.remove(); return false; @@ -756,35 +752,38 @@ $('#assignee').selectize({ }); function try_async_comment(form, inline) { + $(form).off('submit'); + var _data = $(form).serialize(); + var btn = $(document.activeElement); + if (btn[0].name == 'drop_comment'){ + _data += '&drop_comment=' + btn[0].value; + return true; + } if (!sse) { - $(form).off('submit'); + console.log('no sse, submitting'); form.submit(); return false; } $.post( form.action + "?js=1", $(form).serialize() ) .done(function(data) { if(data == 'ok') { - // We have submitted the comment correctly - $('#update_comment').val(''); - var item = $('#update_comment').closest('tr'); - if (!item.length) { - item = $('#update_comment').closest('section'); - } + $('#comment').val(''); + /* We have submitted the comment correctly */ + var item = $('#comment_block').closest('section'); if (!$(item.parent().children()[1]).is(':visible')){ $(item.parent().children()[1]).show() } item.remove(); } else { // Make the browser submit the form sync - $(form).off('submit'); form.submit(); } }) .fail(function() { // Make the browser submit the form sync - $(form).off('submit'); form.submit(); }) + $(form).on('submit'); return false; }; {% endif %} @@ -815,6 +814,7 @@ source.addEventListener('message', function(e) { console.log(e.data); var data = $.parseJSON(e.data); process_event(data, "{{ request.uid }}"); + setup_edit_btns(); }, false); {% endif %}