X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=a0bbf8aa47441c97bd003ee799785dad5ed0871b;hb=ecf753a31601e558b681daab0598009fe9eec99a;hp=e790e9e53aa6db54a789294974312b759bbb262e;hpb=cc8499e32a85051b1f8c387d65378f943ee7b00e;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e790e9e..a0bbf8a 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -153,7 +153,13 @@ function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated) { toggleClass("modified", modified); $("#sone .sone." + filterSoneId(soneId) + " .lock").toggleClass("hidden", locked); $("#sone .sone." + filterSoneId(soneId) + " .unlock").toggleClass("hidden", !locked); - $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated); + if (lastUpdated != null) { + $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated); + } else { + getTranslation("View.Sone.Text.UnknownDate", function(unknown) { + $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(unknown); + }); + } $("#sone .sone." + filterSoneId(soneId) + " .profile-link a").text(name); } @@ -485,6 +491,8 @@ function updateReplyLikes(replyId) { /** * Posts a reply and calls the given callback when the request finishes. * + * @param sender + * The ID of the sender * @param postId * The ID of the post the reply refers to * @param text @@ -493,14 +501,14 @@ function updateReplyLikes(replyId) { * The callback function to call when the request finishes (takes 3 * parameters: success, error, replyId) */ -function postReply(postId, text, callbackFunction) { - $.getJSON("createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) { +function postReply(sender, postId, text, callbackFunction) { + $.getJSON("createReply.ajax", { "formPassword" : getFormPassword(), "sender": sender, "post" : postId, "text": text }, function(data, textStatus) { if (data == null) { /* TODO - show error */ return; } if (data.success) { - callbackFunction(true, null, data.reply); + callbackFunction(true, null, data.reply, data.sone); } else { callbackFunction(false, data.error); } @@ -539,21 +547,25 @@ function ajaxifyPost(postElement) { return false; }); $(postElement).find(".create-reply button:submit").click(function() { - inputField = $(this.form).find(":input:enabled").get(0); + sender = $(this.form).find(":input[name=sender]").val(); + inputField = $(this.form).find(":input[name=text]:enabled").get(0); postId = getPostId(this); text = $(inputField).val(); - (function(postId, text, inputField) { - postReply(postId, text, function(success, error, replyId) { + (function(sender, postId, text, inputField) { + postReply(sender, postId, text, function(success, error, replyId, soneId) { if (success) { $(inputField).val(""); - loadNewReply(replyId, getCurrentSoneId(), postId); + loadNewReply(replyId, soneId, postId); markPostAsKnown(getPostElement(inputField)); $("#sone .post#" + postId + " .create-reply").addClass("hidden"); + $("#sone .post#" + postId + " .create-reply .sender").hide(); + $("#sone .post#" + postId + " .create-reply .select-sender").show(); + $("#sone .post#" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId()); } else { alert(error); } }); - })(postId, text, inputField); + })(sender, postId, text, inputField); return false; }); @@ -606,6 +618,15 @@ function ajaxifyPost(postElement) { }); }); + /* process sender selection. */ + $(".select-sender", postElement).css("display", "inline"); + $(".sender", postElement).hide(); + $(".select-sender button", postElement).click(function() { + $(".sender", postElement).show(); + $(".select-sender", postElement).hide(); + return false; + }); + /* mark everything as known on click. */ $(postElement).click(function(event) { if ($(event.target).hasClass("click-to-show")) { @@ -671,9 +692,17 @@ function ajaxifyReply(replyElement) { * jQuery object representing the notification. */ function ajaxifyNotification(notification) { - notification.find("form.dismiss").submit(function() { + notification.find("form").submit(function() { return false; }); + notification.find("input[name=returnPage]").val($.url.attr("relative")); + if (notification.find(".short-text").length > 0) { + notification.find(".short-text").removeClass("hidden"); + notification.find(".text").addClass("hidden"); + } + notification.find("form.mark-as-read button").click(function() { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); + }); notification.find("form.dismiss button").click(function() { $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) { /* dismiss in case of error, too. */ @@ -690,7 +719,7 @@ function getStatus() { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { - updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdated); + updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated); }); /* process notifications. */ $.each(data.notifications, function(index, value) { @@ -915,7 +944,7 @@ function markPostAsKnown(postElements) { postElement = this; if ($(postElement).hasClass("new")) { (function(postElement) { - $.getJSON("markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) { $(postElement).removeClass("new"); $(".click-to-show", postElement).removeClass("new"); }); @@ -930,7 +959,7 @@ function markReplyAsKnown(replyElements) { replyElement = this; if ($(replyElement).hasClass("new")) { (function(replyElement) { - $.getJSON("markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) { $(replyElement).removeClass("new"); }); })(replyElement); @@ -1072,17 +1101,28 @@ $(document).ready(function() { /* this initializes the status update input field. */ getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) { registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false); + $("#sone #update-status .select-sender").css("display", "inline"); + $("#sone #update-status .sender").hide(); + $("#sone #update-status .select-sender button").click(function() { + $("#sone #update-status .sender").show(); + $("#sone #update-status .select-sender").hide(); + return false; + }); $("#sone #update-status").submit(function() { if ($(this).find(":input.default:enabled").length > 0) { return false; } - text = $(this).find(":input:enabled").val(); - $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) { + sender = $(this).find(":input[name=sender]").val(); + text = $(this).find(":input[name=text]:enabled").val(); + $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "sender": sender, "text": text }, function(data, textStatus) { if ((data != null) && data.success) { - loadNewPost(data.postId, getCurrentSoneId()); + loadNewPost(data.postId, data.sone, data.recipient); } }); - $(this).find(":input:enabled").val("").blur(); + $(this).find(":input[name=sender]").val(getCurrentSoneId()); + $(this).find(":input[name=text]:enabled").val("").blur(); + $(this).find(".sender").hide(); + $(this).find(".select-sender").show(); return false; }); });