Skip to content
Snippets Groups Projects
Commit bb37d16d authored by Antonin's avatar Antonin
Browse files

Sugar for comment sending.

    - Do not send if comment empty
    - Disable submit button while submit is in progress
parent 22253b4e
No related branches found
No related tags found
No related merge requests found
......@@ -49,40 +49,45 @@ $(document).ready(function () {
form.submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize(),
dataType: 'json',
success: function(data)
{
$('#comment').val('');
if (data.result) {
$('#comments_list')
.replaceWith(data.comments);
var lastComment = $('#comments_list')
.find('div.comment')
.last();
lastComment.effect('highlight', {color: 'green'}, 401);
$('html, body').animate({
scrollTop: lastComment.offset().top
}, 750);
} else {
var newMessage = $('#genericErrorTemplate').clone();
newMessage
.find('.contents')
.text(data.message.message);
var commentsAlert = $('#comments_alerts');
commentsAlert
.empty()
.append(newMessage);
$('html, body').animate({
scrollTop: commentsAlert.offset().top
}, 750);
if ($('#comment').val()) {
$('#add_comment').attr("disabled", "disabled");
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize(),
dataType: 'json',
success: function(data)
{
$('#comment').val('');
if (data.result) {
$('#comments_list')
.replaceWith(data.comments);
var lastComment = $('#comments_list')
.find('div.comment')
.last();
lastComment.effect('highlight', {color: 'green'}, 401);
$('html, body').animate({
scrollTop: lastComment.offset().top
}, 750);
} else {
var newMessage = $('#genericErrorTemplate').clone();
newMessage
.find('.contents')
.text(data.message.message);
var commentsAlert = $('#comments_alerts');
commentsAlert
.empty()
.append(newMessage);
$('html, body').animate({
scrollTop: commentsAlert.offset().top
}, 750);
}
},
complete: function() {
$('#add_comment').removeAttr("disabled");
}
}
});
});
}
return false;
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment