Refactor message mark/delete listeners
This commit is contained in:
parent
d0cfde2996
commit
179c70f725
1 changed files with 18 additions and 16 deletions
|
@ -1,30 +1,32 @@
|
|||
$(document).ready(function () {
|
||||
$(".inbox-mark-unread").on("ajax:success", function (event, data) {
|
||||
$("#inboxanchor").remove();
|
||||
$(".user-button").before(data.inboxanchor);
|
||||
|
||||
$("#inbox-count").replaceWith(data.inbox_count);
|
||||
|
||||
$(this).parents(".inbox-row").removeClass("inbox-row").addClass("inbox-row-unread");
|
||||
updateHtml(data);
|
||||
updateReadState(this, false);
|
||||
});
|
||||
|
||||
$(".inbox-mark-read").on("ajax:success", function (event, data) {
|
||||
$("#inboxanchor").remove();
|
||||
$(".user-button").before(data.inboxanchor);
|
||||
|
||||
$("#inbox-count").replaceWith(data.inbox_count);
|
||||
|
||||
$(this).parents(".inbox-row-unread").removeClass("inbox-row-unread").addClass("inbox-row");
|
||||
updateHtml(data);
|
||||
updateReadState(this, true);
|
||||
});
|
||||
|
||||
$(".inbox-destroy").on("ajax:success", function (event, data) {
|
||||
updateHtml(data);
|
||||
|
||||
$(this).closest("tr").fadeOut(800, "linear", function () {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
|
||||
function updateHtml(data) {
|
||||
$("#inboxanchor").remove();
|
||||
$(".user-button").before(data.inboxanchor);
|
||||
|
||||
$("#inbox-count").replaceWith(data.inbox_count);
|
||||
}
|
||||
|
||||
$(this).parents(".inbox-row, .inbox-row-unread").fadeOut(800, "linear", function () {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
function updateReadState(target, isRead) {
|
||||
$(target).closest("tr")
|
||||
.toggleClass("inbox-row", isRead)
|
||||
.toggleClass("inbox-row-unread", !isRead);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue