fixed task comments

This commit is contained in:
zmagod 2016-09-27 09:18:46 +02:00
parent 02bfa1949e
commit 980ff63104
2 changed files with 9 additions and 81 deletions

View file

@ -656,85 +656,6 @@ function bindFullZoomAjaxTabs() {
});
}
// Initialize comment form.
function initCommentForm($el) {
var $form = $el.find("ul form");
$(".help-block", $form).addClass("hide");
$form.on("ajax:send", function (data) {
$("#comment_message", $form).attr("readonly", true);
})
.on("ajax:success", function (e, data) {
if (data.html) {
var list = $form.parents("ul");
// Remove potential "no comments" element
list.parent().find(".content-comments")
.find("li.no-comments").remove();
list.parent().find(".content-comments")
.prepend("<li class='comment'>" + data.html + "</li>")
.scrollTop(0);
list.parents("ul").find("> li.comment:gt(8)").remove();
$("#comment_message", $form).val("");
$(".form-group", $form)
.removeClass("has-error");
$(".help-block", $form)
.html("")
.addClass("hide");
scrollCommentOptions(
list.parent().find(".content-comments .dropdown-comment"),
false
);
}
})
.on("ajax:error", function (ev, xhr) {
if (xhr.status === 400) {
var messageError = xhr.responseJSON.errors.message;
if (messageError) {
$(".form-group", $form)
.addClass("has-error");
$(".help-block", $form)
.html(messageError[0])
.removeClass("hide");
}
}
})
.on("ajax:complete", function () {
$("#comment_message", $form)
.attr("readonly", false)
.focus();
});
}
// Initialize show more comments link.
function initCommentsLink($el) {
$el.find(".btn-more-comments")
.on("ajax:success", function (e, data) {
if (data.html) {
var list = $(this).parents("ul");
var moreBtn = list.find(".btn-more-comments");
var listItem = moreBtn.parents('li');
$(data.html).insertBefore(listItem);
if (data.results_number < data.per_page) {
moreBtn.remove();
} else {
moreBtn.attr("href", data.more_url);
}
// Reposition dropdown comment options
scrollCommentOptions(
listItem.closest(".content-comments").find(".dropdown-comment"),
false
);
}
});
}
// Initialize reloading manage user modal content after posting new
// user.
function initAddUserForm() {
@ -838,14 +759,20 @@ function bindFullZoomAjaxTabs() {
} else if (targetContents === "users") {
initUsersEditLink(parentNode);
} else if (targetContents === "comments") {
initCommentForm(parentNode);
initCommentsLink(parentNode);
CommentsHelper.form(parentNode);
CommentsHelper.moreComments(parentNode);
}
$this.parents("ul").parent().find(".active").removeClass("active");
$this.parents("li").addClass("active");
target.addClass("active");
$this.parents(".module-large").addClass("expanded");
// Call scrollBotton after the comments are displayed
// so that the scrollHight can be calculated
if ( targetContents === 'comments' ) {
CommentsHelper.scrollBottom(parentNode);
}
})
.on("ajax:error", function (e, xhr, status, error) {
// TODO

View file

@ -80,5 +80,6 @@
<%= javascript_include_tag("jsnetworkx") %>
<%= javascript_include_tag("eventPause-min") %>
<%= javascript_include_tag("comments_helper") %>
<%= javascript_include_tag("projects/canvas") %>
<%= javascript_include_tag("experiments/dropdown_actions") %>