X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=8be028279d2b549a4a15e9eef9c57cd3d88b1f2d;hb=ecf753a31601e558b681daab0598009fe9eec99a;hp=3b61e29b561deb87cb2608fbb5f717db7501ef67;hpb=45abd9c2c690c31e2c251072f9e7633f02977e22;p=Sone.git
diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js
index 3b61e29..a0bbf8a 100644
--- a/src/main/resources/static/javascript/sone.js
+++ b/src/main/resources/static/javascript/sone.js
@@ -47,6 +47,7 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op
textarea.show();
}
$(inputField.get(0).form).submit(function() {
+ inputField.attr("disabled", "disabled");
if (!optional && (textarea.val() == "")) {
return false;
}
@@ -63,12 +64,14 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op
* @param element
* The element to add a âcommentâ link to
*/
-function addCommentLink(postId, element) {
- if ($(element).find(".show-reply-form").length > 0) {
+function addCommentLink(postId, element, insertAfterThisElement) {
+ if (($(element).find(".show-reply-form").length > 0) || (getPostElement(element).find(".create-reply").length == 0)) {
return;
}
commentElement = (function(postId) {
+ separator = $(" · ").addClass("separator");
var commentElement = $("
Comment
").addClass("show-reply-form").click(function() {
+ markPostAsKnown(getPostElement(this));
replyElement = $("#sone .post#" + postId + " .create-reply");
replyElement.removeClass("hidden");
replyElement.removeClass("light");
@@ -85,9 +88,8 @@ function addCommentLink(postId, element) {
});
return commentElement;
})(postId);
- $(element).find(".status-line .time").each(function() {
- $(this).after(commentElement.clone(true));
- });
+ $(insertAfterThisElement).after(commentElement.clone(true));
+ $(insertAfterThisElement).after(separator);
}
var translations = {};
@@ -106,7 +108,7 @@ function getTranslation(key, callback) {
callback(translations[key]);
return;
}
- $.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) {
+ $.getJSON("getTranslation.ajax", {"key": key}, function(data, textStatus) {
if ((data != null) && data.success) {
translations[key] = data.value;
callback(data.value);
@@ -151,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);
}
@@ -202,7 +210,7 @@ function enhanceDeleteButton(button, text, deleteCallback) {
*/
function enhanceDeletePostButton(button, postId, text) {
enhanceDeleteButton(button, text, function() {
- $.getJSON("ajax/deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if (data == null) {
return;
}
@@ -233,7 +241,7 @@ function enhanceDeletePostButton(button, postId, text) {
*/
function enhanceDeleteReplyButton(button, replyId, text) {
enhanceDeleteButton(button, text, function() {
- $.getJSON("ajax/deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
+ $.getJSON("deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
if (data == null) {
return;
}
@@ -257,7 +265,7 @@ function getFormPassword() {
}
function getSoneElement(element) {
- return $(element).parents(".sone");
+ return $(element).closest(".sone");
}
/**
@@ -302,6 +310,17 @@ function getPostTime(element) {
return getPostElement(element).find(".post-time").text();
}
+/**
+ * Returns the author of the post the given element belongs to.
+ *
+ * @param element
+ * The element whose post to get the author for
+ * @returns The ID of the authoring Sone
+ */
+function getPostAuthor(element) {
+ return getPostElement(element).find(".post-author").text();
+}
+
function getReplyElement(element) {
return $(element).closest(".reply");
}
@@ -314,8 +333,19 @@ function getReplyTime(element) {
return getReplyElement(element).find(".reply-time").text();
}
+/**
+ * Returns the author of the reply the given element belongs to.
+ *
+ * @param element
+ * The element whose reply to get the author for
+ * @returns The ID of the authoring Sone
+ */
+function getReplyAuthor(element) {
+ return getReplyElement(element).find(".reply-author").text();
+}
+
function likePost(postId) {
- $.getJSON("ajax/like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
@@ -328,7 +358,7 @@ function likePost(postId) {
}
function unlikePost(postId) {
- $.getJSON("ajax/unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
@@ -341,7 +371,7 @@ function unlikePost(postId) {
}
function updatePostLikes(postId) {
- $.getJSON("ajax/getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
+ $.getJSON("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
if ((data != null) && data.success) {
$("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0)
$("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
@@ -353,7 +383,7 @@ function updatePostLikes(postId) {
}
function likeReply(replyId) {
- $.getJSON("ajax/like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
@@ -366,7 +396,7 @@ function likeReply(replyId) {
}
function unlikeReply(replyId) {
- $.getJSON("ajax/unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
@@ -378,8 +408,76 @@ function unlikeReply(replyId) {
});
}
+/**
+ * Trusts the Sone with the given ID.
+ *
+ * @param soneId
+ * The ID of the Sone to trust
+ */
+function trustSone(soneId) {
+ $.getJSON("trustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
+ if ((data != null) && data.success) {
+ updateTrustControls(soneId, data.trustValue);
+ }
+ });
+}
+
+/**
+ * Distrusts the Sone with the given ID, i.e. assigns a negative trust value.
+ *
+ * @param soneId
+ * The ID of the Sone to distrust
+ */
+function distrustSone(soneId) {
+ $.getJSON("distrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
+ if ((data != null) && data.success) {
+ updateTrustControls(soneId, data.trustValue);
+ }
+ });
+}
+
+/**
+ * Untrusts the Sone with the given ID, i.e. removes any trust assignment.
+ *
+ * @param soneId
+ * The ID of the Sone to untrust
+ */
+function untrustSone(soneId) {
+ $.getJSON("untrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
+ if ((data != null) && data.success) {
+ updateTrustControls(soneId, data.trustValue);
+ }
+ });
+}
+
+/**
+ * Updates the trust controls for all posts and replies of the given Sone,
+ * according to the given trust value.
+ *
+ * @param soneId
+ * The ID of the Sone to update all trust controls for
+ * @param trustValue
+ * The trust value for the Sone
+ */
+function updateTrustControls(soneId, trustValue) {
+ $("#sone .post").each(function() {
+ if (getPostAuthor(this) == soneId) {
+ getPostElement(this).find(".post-trust").toggleClass("hidden", trustValue != null);
+ getPostElement(this).find(".post-distrust").toggleClass("hidden", trustValue != null);
+ getPostElement(this).find(".post-untrust").toggleClass("hidden", trustValue == null);
+ }
+ });
+ $("#sone .reply").each(function() {
+ if (getReplyAuthor(this) == soneId) {
+ getReplyElement(this).find(".reply-trust").toggleClass("hidden", trustValue != null);
+ getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null);
+ getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null);
+ }
+ });
+}
+
function updateReplyLikes(replyId) {
- $.getJSON("ajax/getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
+ $.getJSON("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
if ((data != null) && data.success) {
$("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0)
$("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
@@ -393,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
@@ -401,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("ajax/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);
}
@@ -427,7 +527,7 @@ function postReply(postId, text, callbackFunction) {
* replyDisplayTime, text, html)
*/
function getReply(replyId, callbackFunction) {
- $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
+ $.getJSON("getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
if ((data != null) && data.success) {
callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html);
}
@@ -447,20 +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();
- $(inputField).val("");
- postReply(postId, text, function(success, error, replyId) {
- if (success) {
- loadNewReply(replyId);
- markPostAsKnown(postElement);
- markReplyAsKnown($(postElement).find(".reply"));
- $("#sone .post#" + postId + " .create-reply").addClass("hidden");
- } else {
- alert(error);
- }
- });
+ (function(sender, postId, text, inputField) {
+ postReply(sender, postId, text, function(success, error, replyId, soneId) {
+ if (success) {
+ $(inputField).val("");
+ 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);
+ }
+ });
+ })(sender, postId, text, inputField);
return false;
});
@@ -475,12 +580,31 @@ function ajaxifyPost(postElement) {
/* convert all âlikeâ buttons to javascript functions. */
$(postElement).find(".like-post").submit(function() {
likePost(getPostId(this));
+ markPostAsKnown(getPostElement(this));
return false;
});
$(postElement).find(".unlike-post").submit(function() {
unlikePost(getPostId(this));
+ markPostAsKnown(getPostElement(this));
+ return false;
+ });
+
+ /* convert trust control buttons to javascript functions. */
+ $(postElement).find(".post-trust").submit(function() {
+ trustSone(getPostAuthor(this));
+ return false;
+ });
+ $(postElement).find(".post-distrust").submit(function() {
+ distrustSone(getPostAuthor(this));
return false;
});
+ $(postElement).find(".post-untrust").submit(function() {
+ untrustSone(getPostAuthor(this));
+ return false;
+ });
+
+ /* add âcommentâ link. */
+ addCommentLink(getPostId(postElement), postElement, $(postElement).find(".post-status-line .time"));
/* process all replies. */
$(postElement).find(".reply").each(function() {
@@ -491,12 +615,25 @@ function ajaxifyPost(postElement) {
getTranslation("WebInterface.DefaultText.Reply", function(text) {
$(postElement).find("input.reply-input").each(function() {
registerInputTextareaSwap(this, text, "text", false, false);
- addCommentLink(getPostId(postElement), postElement);
});
});
- /* add âcommentâ link. */
- addCommentLink(getPostId(postElement), 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")) {
+ return false;
+ }
+ markPostAsKnown(this);
+ });
/* hide reply input field. */
$(postElement).find(".create-reply").addClass("hidden");
@@ -511,10 +648,12 @@ function ajaxifyPost(postElement) {
function ajaxifyReply(replyElement) {
$(replyElement).find(".like-reply").submit(function() {
likeReply(getReplyId(this));
+ markPostAsKnown(getPostElement(this));
return false;
});
$(replyElement).find(".unlike-reply").submit(function() {
unlikeReply(getReplyId(this));
+ markPostAsKnown(getPostElement(this));
return false;
});
(function(replyElement) {
@@ -524,7 +663,26 @@ function ajaxifyReply(replyElement) {
});
});
})(replyElement);
- addCommentLink(getPostId(replyElement), replyElement);
+ addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time"));
+
+ /* convert trust control buttons to javascript functions. */
+ $(replyElement).find(".reply-trust").submit(function() {
+ trustSone(getReplyAuthor(this));
+ return false;
+ });
+ $(replyElement).find(".reply-distrust").submit(function() {
+ distrustSone(getReplyAuthor(this));
+ return false;
+ });
+ $(replyElement).find(".reply-untrust").submit(function() {
+ untrustSone(getReplyAuthor(this));
+ return false;
+ });
+
+ /* mark post and all replies as known on click. */
+ $(replyElement).click(function() {
+ markPostAsKnown(getPostElement(this));
+ });
}
/**
@@ -534,11 +692,19 @@ 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("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
+ $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
/* dismiss in case of error, too. */
notification.slideUp();
}, function(xmlHttpRequest, textStatus, error) {
@@ -549,11 +715,11 @@ function ajaxifyNotification(notification) {
}
function getStatus() {
- $.getJSON("ajax/getStatus.ajax", {}, function(data, textStatus) {
+ $.getJSON("getStatus.ajax", {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) {
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) {
@@ -565,17 +731,18 @@ function getStatus() {
$("#sone #notification-area").append(notification);
notification.slideDown();
}
+ setActivity();
});
$.each(data.removedNotifications, function(index, value) {
$("#sone #notification-area .notification#" + value.id).slideUp();
});
/* process new posts. */
$.each(data.newPosts, function(index, value) {
- loadNewPost(value);
+ loadNewPost(value.id, value.sone, value.recipient, value.time);
});
/* process new replies. */
$.each(data.newReplies, function(index, value) {
- loadNewReply(value);
+ loadNewReply(value.id, value.sone, value.post, value.postSone);
});
/* do it again in 5 seconds. */
setTimeout(getStatus, 5000);
@@ -589,16 +756,131 @@ function getStatus() {
})
}
-var loadedPosts = {};
-var loadedReplies = {};
+/**
+ * Returns the ID of the currently logged in Sone.
+ *
+ * @return The ID of the current Sone, or an empty string if no Sone is logged
+ * in
+ */
+function getCurrentSoneId() {
+ return $("#currentSoneId").text();
+}
+
+/**
+ * Returns the content of the page-id attribute.
+ *
+ * @returns The page ID
+ */
+function getPageId() {
+ return $("#sone .page-id").text();
+}
+
+/**
+ * Returns whether the current page is the index page.
+ *
+ * @returns {Boolean} true
if the current page is the index page,
+ * false
otherwise
+ */
+function isIndexPage() {
+ return getPageId() == "index";
+}
+
+/**
+ * Returns whether the current page is a âview Soneâ page.
+ *
+ * @returns {Boolean} true
if the current page is a âview Soneâ
+ * page, false
otherwise
+ */
+function isViewSonePage() {
+ return getPageId() == "view-sone";
+}
+
+/**
+ * Returns the ID of the currently shown Sone. This will only return a sensible
+ * value if isViewSonePage() returns true
.
+ *
+ * @returns The ID of the currently shown Sone
+ */
+function getShownSoneId() {
+ return $("#sone .sone-id").text();
+}
+
+/**
+ * Returns whether the current page is a âview postâ page.
+ *
+ * @returns {Boolean} true
if the current page is a âview postâ
+ * page, false
otherwise
+ */
+function isViewPostPage() {
+ return getPageId() == "view-post";
+}
+
+/**
+ * Returns the ID of the currently shown post. This will only return a sensible
+ * value if isViewPostPage() returns true
.
+ *
+ * @returns The ID of the currently shown post
+ */
+function getShownPostId() {
+ return $("#sone .post-id").text();
+}
+
+/**
+ * Returns whether the current page is the âknown Sonesâ page.
+ *
+ * @returns {Boolean} true
if the current page is the âknown
+ * Sonesâ page, false
otherwise
+ */
+function isKnownSonesPage() {
+ return getPageId() == "known-sones";
+}
+
+/**
+ * Returns whether a post with the given ID exists on the current page.
+ *
+ * @param postId
+ * The post ID to check for
+ * @returns {Boolean} true
if a post with the given ID already
+ * exists on the page, false
otherwise
+ */
+function hasPost(postId) {
+ return $(".post#" + postId).length > 0;
+}
+
+/**
+ * Returns whether a reply with the given ID exists on the current page.
+ *
+ * @param replyId
+ * The reply ID to check for
+ * @returns {Boolean} true
if a reply with the given ID already
+ * exists on the page, false
otherwise
+ */
+function hasReply(replyId) {
+ return $("#sone .reply#" + replyId).length > 0;
+}
-function loadNewPost(postId) {
- if (postId in loadedPosts) {
+function loadNewPost(postId, soneId, recipientId, time) {
+ if (hasPost(postId)) {
+ return;
+ }
+ if (!isIndexPage()) {
+ if (!isViewPostPage() || (getShownPostId() != postId)) {
+ if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId))) {
+ return;
+ }
+ }
+ }
+ if (getPostTime($("#sone .post").last()) > time) {
return;
}
- loadedPosts[postId] = true;
- $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) {
+ $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
+ if (hasPost(data.post.id)) {
+ return;
+ }
+ if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
+ return;
+ }
var firstOlderPost = null;
$("#sone .post").each(function() {
if (getPostTime(this) < data.post.time) {
@@ -609,23 +891,27 @@ function loadNewPost(postId) {
newPost = $(data.post.html).addClass("hidden");
if (firstOlderPost != null) {
newPost.insertBefore(firstOlderPost);
- } else {
- $("#sone #posts").append(newPost);
}
ajaxifyPost(newPost);
newPost.slideDown();
+ setActivity();
}
});
}
-function loadNewReply(replyId) {
- if (replyId in loadedReplies) {
+function loadNewReply(replyId, soneId, postId, postSoneId) {
+ if (hasReply(replyId)) {
return;
}
- loadedReplies[replyId] = true;
- $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) {
+ if (!hasPost(postId)) {
+ return;
+ }
+ $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
+ if (hasReply(data.reply.id)) {
+ return;
+ }
$("#sone .post#" + data.reply.postId).each(function() {
var firstNewerReply = null;
$(this).find(".replies .reply").each(function() {
@@ -646,6 +932,8 @@ function loadNewReply(replyId) {
}
ajaxifyReply(newReply);
newReply.slideDown();
+ setActivity();
+ return false;
});
}
});
@@ -655,9 +943,12 @@ function markPostAsKnown(postElements) {
$(postElements).each(function() {
postElement = this;
if ($(postElement).hasClass("new")) {
- $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
- $(postElement).removeClass("new");
- });
+ (function(postElement) {
+ $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) {
+ $(postElement).removeClass("new");
+ $(".click-to-show", postElement).removeClass("new");
+ });
+ })(postElement);
}
});
markReplyAsKnown($(postElements).find(".reply"));
@@ -667,13 +958,31 @@ function markReplyAsKnown(replyElements) {
$(replyElements).each(function() {
replyElement = this;
if ($(replyElement).hasClass("new")) {
- $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
- $(replyElement).removeClass("new");
- });
+ (function(replyElement) {
+ $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) {
+ $(replyElement).removeClass("new");
+ });
+ })(replyElement);
}
});
}
+function resetActivity() {
+ title = document.title;
+ if (title.indexOf('(') == 0) {
+ document.title = title.substr(title.indexOf(' ') + 1);
+ }
+}
+
+function setActivity() {
+ if (!focus) {
+ title = document.title;
+ if (title.indexOf('(') != 0) {
+ document.title = "(!) " + title;
+ }
+ }
+}
+
/**
* Creates a new notification.
*
@@ -696,20 +1005,136 @@ function createNotification(id, text, dismissable) {
return notification;
}
+/**
+ * Shows the details of the notification with the given ID.
+ *
+ * @param notificationId
+ * The ID of the notification
+ */
+function showNotificationDetails(notificationId) {
+ $("#sone .notification#" + notificationId + " .text").show();
+ $("#sone .notification#" + notificationId + " .short-text").hide();
+}
+
+/**
+ * Deletes the field with the given ID from the profile.
+ *
+ * @param fieldId
+ * The ID of the field to delete
+ */
+function deleteProfileField(fieldId) {
+ $.getJSON("deleteProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId}, function(data, textStatus) {
+ if (data && data.success) {
+ $("#sone .profile-field#" + data.field.id).slideUp();
+ }
+ });
+}
+
+/**
+ * Renames a profile field.
+ *
+ * @param fieldId
+ * The ID of the field to rename
+ * @param newName
+ * The new name of the field
+ * @param successFunction
+ * Called when the renaming was successful
+ */
+function editProfileField(fieldId, newName, successFunction) {
+ $.getJSON("editProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "name": newName}, function(data, textStatus) {
+ if (data && data.success) {
+ successFunction();
+ }
+ });
+}
+
+/**
+ * Moves the profile field with the given ID one slot in the given direction.
+ *
+ * @param fieldId
+ * The ID of the field to move
+ * @param direction
+ * The direction to move in (âupâ or âdownâ)
+ * @param successFunction
+ * Function to call on success
+ */
+function moveProfileField(fieldId, direction, successFunction) {
+ $.getJSON("moveProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "direction": direction}, function(data, textStatus) {
+ if (data && data.success) {
+ successFunction();
+ }
+ });
+}
+
+/**
+ * Moves the profile field with the given ID up one slot.
+ *
+ * @param fieldId
+ * The ID of the field to move
+ * @param successFunction
+ * Function to call on success
+ */
+function moveProfileFieldUp(fieldId, successFunction) {
+ moveProfileField(fieldId, "up", successFunction);
+}
+
+/**
+ * Moves the profile field with the given ID down one slot.
+ *
+ * @param fieldId
+ * The ID of the field to move
+ * @param successFunction
+ * Function to call on success
+ */
+function moveProfileFieldDown(fieldId, successFunction) {
+ moveProfileField(fieldId, "down", successFunction);
+}
+
//
// EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE
//
+var focus = true;
+
$(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;
+ }
+ 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, data.sone, data.recipient);
+ }
+ });
+ $(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;
+ });
+ });
+
+ /* ajaxify input field on âview Soneâ page. */
+ getTranslation("WebInterface.DefaultText.Message", function(defaultText) {
+ registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false);
+ $("#sone #post-message").submit(function() {
text = $(this).find(":input:enabled").val();
- $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
+ $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "text": text }, function(data, textStatus) {
if ((data != null) && data.success) {
- loadNewPost(data.postId);
+ loadNewPost(data.postId, getCurrentSoneId());
}
});
$(this).find(":input:enabled").val("").blur();
@@ -730,30 +1155,32 @@ $(document).ready(function() {
});
/* hides all replies but the latest two. */
- getTranslation("WebInterface.ClickToShow.Replies", function(text) {
- $("#sone .post .replies").each(function() {
- allReplies = $(this).find(".reply");
- if (allReplies.length > 2) {
- newHidden = false;
- for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
- $(allReplies[replyIndex]).addClass("hidden");
- newHidden |= $(allReplies[replyIndex]).hasClass("new");
- }
- clickToShowElement = $("").addClass("click-to-show");
- if (newHidden) {
- clickToShowElement.addClass("new");
+ if (!isViewPostPage()) {
+ getTranslation("WebInterface.ClickToShow.Replies", function(text) {
+ $("#sone .post .replies").each(function() {
+ allReplies = $(this).find(".reply");
+ if (allReplies.length > 2) {
+ newHidden = false;
+ for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
+ $(allReplies[replyIndex]).addClass("hidden");
+ newHidden |= $(allReplies[replyIndex]).hasClass("new");
+ }
+ clickToShowElement = $("").addClass("click-to-show");
+ if (newHidden) {
+ clickToShowElement.addClass("new");
+ }
+ (function(clickToShowElement, allReplies, text) {
+ clickToShowElement.text(text);
+ clickToShowElement.click(function() {
+ allReplies.removeClass("hidden");
+ clickToShowElement.addClass("hidden");
+ });
+ })(clickToShowElement, allReplies, text);
+ $(allReplies[0]).before(clickToShowElement);
}
- (function(clickToShowElement, allReplies, text) {
- clickToShowElement.text(text);
- clickToShowElement.click(function() {
- allReplies.removeClass("hidden");
- clickToShowElement.addClass("hidden");
- });
- })(clickToShowElement, allReplies, text);
- $(allReplies[0]).before(clickToShowElement);
- }
+ });
});
- });
+ }
/*
* convert all âfollowâ, âunfollowâ, âlockâ, and âunlockâ links to something
@@ -761,7 +1188,7 @@ $(document).ready(function() {
*/
$("#sone .follow").submit(function() {
var followElement = this;
- $.getJSON("ajax/followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+ $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
$(followElement).addClass("hidden");
$(followElement).parent().find(".unfollow").removeClass("hidden");
});
@@ -769,7 +1196,7 @@ $(document).ready(function() {
});
$("#sone .unfollow").submit(function() {
var unfollowElement = this;
- $.getJSON("ajax/unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+ $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
$(unfollowElement).addClass("hidden");
$(unfollowElement).parent().find(".follow").removeClass("hidden");
});
@@ -777,7 +1204,7 @@ $(document).ready(function() {
});
$("#sone .lock").submit(function() {
var lockElement = this;
- $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+ $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
$(lockElement).addClass("hidden");
$(lockElement).parent().find(".unlock").removeClass("hidden");
});
@@ -785,7 +1212,7 @@ $(document).ready(function() {
});
$("#sone .unlock").submit(function() {
var unlockElement = this;
- $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+ $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
$(unlockElement).addClass("hidden");
$(unlockElement).parent().find(".lock").removeClass("hidden");
});
@@ -799,4 +1226,13 @@ $(document).ready(function() {
/* activate status polling. */
setTimeout(getStatus, 5000);
+
+ /* reset activity counter when the page has focus. */
+ $(window).focus(function() {
+ focus = true;
+ resetActivity();
+ }).blur(function() {
+ focus = false;
+ })
+
});