textarea.show();
}
$(inputField.get(0).form).submit(function() {
+ inputField.attr("disabled", "disabled");
if (!optional && (textarea.val() == "")) {
return false;
}
* The element to add a “comment” link to
*/
function addCommentLink(postId, element, insertAfterThisElement) {
- if ($(element).find(".show-reply-form").length > 0) {
+ if (($(element).find(".show-reply-form").length > 0) || (getPostElement(element).find(".create-reply").length == 0)) {
return;
}
commentElement = (function(postId) {
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);
}
$("#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) && (trustValue < 0));
+ 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) && (trustValue < 0));
+ getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null);
getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null);
}
});
postReply(postId, text, function(success, error, replyId) {
if (success) {
$(inputField).val("");
- loadNewReply(replyId);
+ loadNewReply(replyId, getCurrentSoneId(), postId);
markPostAsKnown(getPostElement(inputField));
$("#sone .post#" + postId + " .create-reply").addClass("hidden");
} else {
});
/* mark everything as known on click. */
- $(postElement).click(function() {
+ $(postElement).click(function(event) {
+ if ($(event.target).hasClass("click-to-show")) {
+ return false;
+ }
markPostAsKnown(this);
});
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) {
});
/* 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);
}
/**
+ * 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
return $("#sone .reply#" + replyId).length > 0;
}
-function loadNewPost(postId) {
+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;
+ }
$.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
if (hasPost(data.post.id)) {
newPost = $(data.post.html).addClass("hidden");
if (firstOlderPost != null) {
newPost.insertBefore(firstOlderPost);
- } else {
- $("#sone #posts").append(newPost);
}
ajaxifyPost(newPost);
newPost.slideDown();
});
}
-function loadNewReply(replyId) {
+function loadNewReply(replyId, soneId, postId, postSoneId) {
if (hasReply(replyId)) {
return;
}
+ if (!hasPost(postId)) {
+ return;
+ }
$.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
(function(postElement) {
$.getJSON("markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
$(postElement).removeClass("new");
+ $(".click-to-show", postElement).removeClass("new");
});
})(postElement);
}
$("#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
//
text = $(this).find(":input:enabled").val();
$.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
if ((data != null) && data.success) {
- loadNewPost(data.postId);
+ loadNewPost(data.postId, getCurrentSoneId());
}
});
$(this).find(":input:enabled").val("").blur();
text = $(this).find(":input:enabled").val();
$.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();