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 () {
|
$(document).ready(function () {
|
||||||
$(".inbox-mark-unread").on("ajax:success", function (event, data) {
|
$(".inbox-mark-unread").on("ajax:success", function (event, data) {
|
||||||
$("#inboxanchor").remove();
|
updateHtml(data);
|
||||||
$(".user-button").before(data.inboxanchor);
|
updateReadState(this, false);
|
||||||
|
|
||||||
$("#inbox-count").replaceWith(data.inbox_count);
|
|
||||||
|
|
||||||
$(this).parents(".inbox-row").removeClass("inbox-row").addClass("inbox-row-unread");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".inbox-mark-read").on("ajax:success", function (event, data) {
|
$(".inbox-mark-read").on("ajax:success", function (event, data) {
|
||||||
$("#inboxanchor").remove();
|
updateHtml(data);
|
||||||
$(".user-button").before(data.inboxanchor);
|
updateReadState(this, true);
|
||||||
|
|
||||||
$("#inbox-count").replaceWith(data.inbox_count);
|
|
||||||
|
|
||||||
$(this).parents(".inbox-row-unread").removeClass("inbox-row-unread").addClass("inbox-row");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".inbox-destroy").on("ajax:success", function (event, data) {
|
$(".inbox-destroy").on("ajax:success", function (event, data) {
|
||||||
|
updateHtml(data);
|
||||||
|
|
||||||
|
$(this).closest("tr").fadeOut(800, "linear", function () {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateHtml(data) {
|
||||||
$("#inboxanchor").remove();
|
$("#inboxanchor").remove();
|
||||||
$(".user-button").before(data.inboxanchor);
|
$(".user-button").before(data.inboxanchor);
|
||||||
|
|
||||||
$("#inbox-count").replaceWith(data.inbox_count);
|
$("#inbox-count").replaceWith(data.inbox_count);
|
||||||
|
}
|
||||||
|
|
||||||
$(this).parents(".inbox-row, .inbox-row-unread").fadeOut(800, "linear", function () {
|
function updateReadState(target, isRead) {
|
||||||
$(this).remove();
|
$(target).closest("tr")
|
||||||
});
|
.toggleClass("inbox-row", isRead)
|
||||||
});
|
.toggleClass("inbox-row-unread", !isRead);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue