X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d3700e6201b4b78a70bbb2941572edc985b63c2c..3ea2c30c58bb23247296fc212fcf7426668248a6:/app/assets/javascripts/messages.js?ds=inline diff --git a/app/assets/javascripts/messages.js b/app/assets/javascripts/messages.js index 0cae79a58..cc86da05e 100644 --- a/app/assets/javascripts/messages.js +++ b/app/assets/javascripts/messages.js @@ -1,30 +1,36 @@ $(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); + updateHtml(data); + updateReadState(this, true); + }); - $("#inbox-count").replaceWith(data.inbox_count); + $(".inbox-destroy").on("ajax:success", function (event, data) { + updateHtml(data); - $(this).parents(".inbox-row-unread").removeClass("inbox-row-unread").addClass("inbox-row"); + $(this).closest("tr").fadeOut(800, "linear", function () { + $(this).remove(); + }); }); - $(".inbox-destroy").on("ajax:success", function (event, data) { + 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(); - }); - }); + $("#outbox-count").replaceWith(data.outbox_count); + $("#muted-count").replaceWith(data.muted_count); + } + + function updateReadState(target, isRead) { + $(target).closest("tr") + .toggleClass("inbox-row", isRead) + .toggleClass("inbox-row-unread", !isRead) + .find(".inbox-mark-unread").prop("hidden", !isRead).end() + .find(".inbox-mark-read").prop("hidden", isRead); + } });