2012-09-18 19:42:22 +01:00
|
|
|
$(document).ready(function() {
|
2012-10-04 19:40:12 +01:00
|
|
|
var new_comment = $('#open-comment.comment.hidden.new_line_comment');
|
|
|
|
|
|
|
|
$(document).on('click', '.buttons a.edit_comment', function() {
|
2012-10-15 13:30:34 +01:00
|
|
|
$(this).parents('div.activity').hide()
|
|
|
|
.next().show();
|
2012-09-18 19:42:22 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2012-10-04 19:40:12 +01:00
|
|
|
$(document).on('click', '.cancel_edit_comment.button', function() {
|
2012-10-15 13:30:34 +01:00
|
|
|
$(this).parents('#open-comment.comment').hide()
|
|
|
|
.prev().show();
|
2012-09-18 19:42:22 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2012-10-04 19:40:12 +01:00
|
|
|
$(document).on('submit', 'form.edit_comment', function() {
|
2012-09-18 19:42:22 +01:00
|
|
|
var form = $(this);
|
2012-09-24 18:34:14 +01:00
|
|
|
form.parent().find('.flash').remove();
|
2012-09-18 19:42:22 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: form.attr("action"),
|
|
|
|
data: form.serialize(),
|
|
|
|
success: function(data){
|
|
|
|
var cancel_button = form.find('.cancel_edit_comment.button');
|
2012-10-15 13:30:34 +01:00
|
|
|
var id = cancel_button.attr('id').match(/\d+$/)[0];
|
2012-09-18 19:42:22 +01:00
|
|
|
cancel_button.click();
|
2013-03-07 17:38:29 +00:00
|
|
|
$('#comment'+id+', #diff-comment'+id).find('.cm-s-default.md_and_cm').html(data).find('code').each(function (code) { CodeMirrorRun(this); })
|
2012-09-18 19:42:22 +01:00
|
|
|
},
|
|
|
|
error: function(data){
|
2012-09-24 18:34:14 +01:00
|
|
|
form.before(data.responseText);
|
2012-09-18 19:42:22 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2012-10-08 15:42:38 +01:00
|
|
|
$('.new_inline_comment.button').on('click', function() {
|
|
|
|
$(this).parents('tr').prev('tr').find("a[href='"+$(this).attr('href')+"']").click();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2012-10-04 19:40:12 +01:00
|
|
|
$('.add_line-comment').on('click', function() {
|
|
|
|
function ProcessData(data) {
|
2012-10-08 15:42:38 +01:00
|
|
|
if(yield) {
|
|
|
|
var str = "<tr class='inline-comments'><td class='line_numbers' colspan='2'></td>"+"<td>"+data+"</td></tr>";
|
|
|
|
par.after(str);
|
2012-10-19 13:39:11 +01:00
|
|
|
par = par.next();
|
2012-10-08 15:42:38 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
par.find('td:last').append(data);
|
|
|
|
}
|
2012-10-19 13:39:11 +01:00
|
|
|
par.find('#md_tabs.nav.nav-tabs').each(function(i) {
|
|
|
|
$(this).find('a:first').tab('show');
|
|
|
|
$(this).parent().find('#new_line_edit_input').focus();
|
|
|
|
});
|
2012-10-04 19:40:12 +01:00
|
|
|
}
|
|
|
|
var line = $(this);
|
2012-10-08 15:42:38 +01:00
|
|
|
var tmp = line.parents('tr');
|
|
|
|
var yield = false;
|
|
|
|
var par = null;
|
|
|
|
|
|
|
|
if(tmp.hasClass('inline-comments')) {
|
|
|
|
par = tmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
par = tmp.next('tr.inline-comments');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(par.length == 0) {
|
|
|
|
par = tmp;
|
|
|
|
yield = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide visible new comment form
|
|
|
|
$('#open-comment.new_line_comment').parents('.inline-comments').each(function(i) {
|
|
|
|
if($(this).find('.line-comments').length > 0) {
|
2012-10-19 13:39:11 +01:00
|
|
|
$(this).find('#open-comment.new_line_comment').remove();
|
2012-10-08 15:42:38 +01:00
|
|
|
$(this).find('.new_inline_comment.button').show();
|
|
|
|
}
|
|
|
|
else {
|
2012-10-19 13:39:11 +01:00
|
|
|
$(this).remove();
|
2012-10-08 15:42:38 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
par.find('.new_inline_comment.button').hide();
|
|
|
|
|
2012-10-19 13:39:11 +01:00
|
|
|
$.get(line.attr('href'), null, ProcessData);
|
2012-10-04 19:40:12 +01:00
|
|
|
return false;
|
|
|
|
});
|
2012-09-18 19:42:22 +01:00
|
|
|
|
2012-10-04 19:40:12 +01:00
|
|
|
$(document).on('click', '.cancel_inline_comment.button', function() {
|
2012-10-08 15:42:38 +01:00
|
|
|
var tr = $(this).parents('.inline-comments');
|
|
|
|
if(tr.find('.line-comments').length > 0) {
|
2012-10-19 13:39:11 +01:00
|
|
|
tr.find('#open-comment.new_line_comment').remove();
|
2012-10-08 15:42:38 +01:00
|
|
|
tr.find('.new_inline_comment.button').show();
|
|
|
|
}
|
|
|
|
else {
|
2012-10-19 13:39:11 +01:00
|
|
|
tr.remove();
|
2012-10-08 15:42:38 +01:00
|
|
|
}
|
2012-10-04 19:40:12 +01:00
|
|
|
return false;
|
|
|
|
});
|
2012-09-18 19:42:22 +01:00
|
|
|
});
|
2012-10-04 19:40:12 +01:00
|
|
|
|