Changeset - 054c6d98454b
[Not reviewed]
default
0 1 0
Mads Kiilerich - 10 years ago 2016-01-20 01:47:11
madski@unity3d.com
comments: reload after some kinds of general comments - the ones that change the whole page state
1 file changed with 19 insertions and 15 deletions:
0 comments (0 inline, 0 general)
kallithea/public/js/base.js
Show inline comments
 
@@ -622,8 +622,12 @@ function move_comments($anchorcomments) 
 
        var line_no = $anchorcomment.data('line_no');
 
        if ($comment_div[0]) {
 
            $comment_div.append($anchorcomment.children());
 
            if (f_path && line_no) {
 
            _comment_div_append_add($comment_div, f_path, line_no);
 
        } else {
 
                _comment_div_append_form($comment_div, f_path, line_no);
 
            }
 
        } else {
 
           $anchorcomment.before("Comment to {0} line {1} which is outside the diff context:".format(f_path || '?', line_no || '?'));
 
        }
 
    });
 
@@ -653,36 +657,31 @@ function _get_add_comment_div(target_id)
 
    return $comments_box;
 
}
 

	
 
// set $comment_div state - showing or not showing form and Add button
 
function comment_div_state($comment_div, f_path, line_no, show_form) {
 
// Set $comment_div state - showing or not showing form and Add button.
 
// An Add button is shown on non-empty forms when no form is shown.
 
// The form is controlled by show_form - if undefined, form is only shown for general comments.
 
function comment_div_state($comment_div, f_path, line_no, show_form_opt) {
 
    var show_form = show_form_opt !== undefined ? show_form_opt : !f_path && !line_no;
 
    var $forms = $comment_div.children('.comment-inline-form');
 
    var $buttonrow = $comment_div.children('.add-button-row');
 
    var $comments = $comment_div.children('.comment');
 
    $forms.remove();
 
    $buttonrow.remove();
 
    if (show_form) {
 
        if (!$forms.length) {
 
            _comment_div_append_form($comment_div, f_path, line_no);
 
        }
 
    } else {
 
        $forms.remove();
 
    }
 
    $buttonrow.remove();
 
    if ($comments.length && !show_form) {
 
    } else if ($comments.length) {
 
        _comment_div_append_add($comment_div, f_path, line_no);
 
    }
 
}
 

	
 
// append an Add button to $comment_div and hook it up to show form
 
function _comment_div_append_add($comment_div, f_path, line_no) {
 
    if (f_path && line_no) {
 
        var addlabel = TRANSLATION_MAP['Add Another Comment'];
 
        var $add = $('<div class="add-button-row"><span class="btn btn-mini add-button">{0}</span></div>'.format(addlabel));
 
        $comment_div.append($add);
 
        $add.children('.add-button').click(function(e) {
 
            comment_div_state($comment_div, f_path, line_no, true);
 
        });
 
    } else {
 
        comment_div_state($comment_div, f_path, line_no, true);
 
    }
 
}
 

	
 
// append a comment form to $comment_div
 
@@ -718,15 +717,20 @@ function _comment_div_append_form($comme
 
        };
 
        var success = function(json_data) {
 
            $comment_div.append(json_data['rendered_text']);
 
            comment_div_state($comment_div, f_path, line_no);
 
            linkInlineComments($('.firstlink'), $('.comment:first-child'));
 
            if ((review_status || pr_close) && !f_path && !line_no) {
 
                // Page changed a lot - reload it after closing the submitted form
 
            comment_div_state($comment_div, f_path, line_no, false);
 
            linkInlineComments($('.firstlink'), $('.comment:first-child'));
 
                location.reload(true);
 
            }
 
        };
 
        ajaxPOST(AJAX_COMMENT_URL, postData, success);
 
    });
 

	
 
    // create event for hide button
 
    $form.find('.hide-inline-form').click(function(e) {
 
        comment_div_state($comment_div, f_path, line_no, false);
 
        comment_div_state($comment_div, f_path, line_no);
 
    });
 

	
 
    setTimeout(function() {
0 comments (0 inline, 0 general)