Move comment posting into its own function

This commit is contained in:
2017-09-22 19:12:13 +02:00
parent 58b8cea757
commit 7d740c74e3
2 changed files with 33 additions and 27 deletions

View File

@@ -303,3 +303,33 @@ function save_comment(is_new_comment, $commentContainer)
return promise;
}
/* Used when clicking the .comment-action-submit button or by a shortcut */
function post_comment($submit_button){
save_comment(true)
.progress(function() {
$submit_button
.addClass('submitting')
.html('<i class="pi-spin spin"></i> Posting...');
})
.fail(function(xhr){
if (typeof xhr === 'string') {
show_comment_button_error(xhr);
} else {
// If it's not a string, we assume it's a jQuery XHR object.
if (console) console.log('Error saving comment:', xhr.responseText);
show_comment_button_error("Houston! Try again?");
}
toastr.error(xhr.responseText, 'Error saving comment');
})
.done(function(comment_node_id) {
$submit_button
.removeClass('submitting')
.html('Post Comment');
$('#comment_field').val('');
$('body').trigger('pillar:comment-posted', [comment_node_id]);
toastr.success('Comment posted!');
});
}