﻿fb.message = function () { this.data = { messages: [] }; this.messageCount = function () { return this.data.messages.length }; this.loadMessages = function (b, a) { var c = this; $.ajax({ type: "GET", url: b.loadObj.getHandlerUri, dataType: "json", error: function (a, c) { b.msgContainer.html("<p>An error occured: " + c + "</p>") }, success: function (b) { c.data = { messages: [] }; if (b.messages != void 0 && !fb.util.isObjEmpty(b)) c.data = b; typeof a == "function" && a() } }) }; this.findMessage = function (b, a) { var c; if (typeof b != "undefined") for (var d = 0; d < b.length; d++) { if (c != void 0) break; if (b[d].messageId == a) { c = b[d]; break } b[d].messages != void 0 && b[d].messages.length > 0 && (c = this.findMessage(b[d].messages, a)) } return c }; this.addChildMessage = function (b) { if (typeof b != "undefined") { var a = this.findMessage(this.data.messages, b.fk_parentId); typeof a != "undefined" && a.messages.splice(0, 0, b) } }; this.addParentMessage = function (b) { this.data.messages.splice(0, 0, b) }; this.first = function () { return this.data.messages.length > 0 ? this.data.messages[0] : null }; this.last = function () { return this.data.messages.length > 0 ? this.data.messages[data.messages.length - 1] : null }; this.renderMessages = function (b) { this.messageCount() > 0 && (b.msgContainer.empty(), this.doRenderMessages(this.data.messages, 0, this, b)) }; this.doRenderMessages = function (b, a, c, d) { $.each(b, function (b, e) { var l = $("<div>").css({ "margin-left": a + "px", "margin-bottom": "1.25em", overflow: "hidden" }), i = $("<div>").css({ "float": "left" }), g = $("<a>").attr({ href: root() + e.senderProfileUrl, title: "Visit member's profile." }), h = $("<img>").attr({ src: fb.util.root() + e.senderprofileimageurl }).addClass("tinythumb"); e.isSenderActive === "True" ? l.append(i.append(g.append(h))) : l.append(i.append(h)); i = $("<div>").css({ "margin-left": "50px", position: "relative" }); g = $("<div>"); i.append(g); if (e.isSenderActive === "True") { var j; e.isSenderPremium === "True" && (j = $("<div>").css({ "float": "left" }).attr({ title: "Premium Member" }).append($("<img>").attr({ src: fb.util.root() + "images/icons/premium.gif" }).addClass("img16x16"))); h = $("<div>").css({ "float": "left", "margin-right": "10px" }).addClass("b inset msg-author").append($("<a>" + e.senderFullname + "</a>").attr({ href: root() + e.senderProfileUrl, title: "Visit member's profile." })); typeof j != "undefined" ? g.append(j).append(h).append($("<br>")) : g.append(h).append($("<br>")) } else h = $("<span>" + e.senderFullname + "</span>").attr({ title: "This member is no longer active." }).addClass("b inset inactive"), h.append($("<span>(inactive)</span>").addClass("sidenote n").css({ "margin-left": "5px" })), g.append(h); j = $("<p>" + e.dateAdded + "</p>").addClass("commentDetail"); g = $("<p>" + HtmlDecode(e.message) + "</p>").addClass("commentText"); i.append(g).append(j); if (fb.util.loggedInUser.userId != 0 && fb.util.loggedInUser.userId != e.senderUserId && e.isSenderActive == "True") { var f = e.messageId; j = $("<div></div>").attr("id", "divReplyForm" + f).append($("<p></p>").addClass("sidenote").append($("<span>Reply</span>").attr("id", "divReply" + f).addClass("replyButton replyIcon").click(function () { var a = $("#div" + f), b = $("#txt" + f), e = $("#" + this.id); $(a).css("display") == "block" || $(a).css("display") == "" ? $(a).hide(50, function () { $(e).text("Reply"); $(b).val("") }) : $(a).show(50, function () { $(e).text("Cancel"); $(b).focus() }) }))).append($("<div></div").attr("id", "div" + f).css("display", "none").addClass("replyForm").append($("<div></div>").append($("<textarea></textarea>").attr({ id: "txt" + f, rows: "7", cols: "70" }).addClass("replyTextArea"))).append($("<div></div>").css("padding-top", "5px").append($("<input type='button' />").attr("value", "Post Reply").addClass("fbButton").click(function () { c.saveReply(f, "#txt" + f, "#divReplyForm" + f, d) })))); i.append(j) } l.append(i); d.msgContainer.append(l); e.messages != void 0 && e.messages.length > 0 && c.doRenderMessages(e.messages, a + 50, c, d) }) }; this.loadingMessage = function () { return '<p class="commentReplyLoading"><img src="' + fb.util.root() + 'images/indicator.gif" class="img16x16" />Posting reply&#0133;</p>' }; this.saveReply = function (b, a, c, d) { a = $.trim($(a).val()); if (a.length < 1) alert("Please provide some text with your reply."); else { b = { message: a, parentId: b }; $.extend(b, d.replyObj.miscReplyPostData); $(c).html(this.loadingMessage()); var k = this; $.ajax({ type: "POST", url: d.replyObj.replyHandlerUri, data: b, success: function (a) { if (a != void 0 && !fb.util.isObjEmpty(a)) if (typeof a.resource != "undefined" && a.resource === 0) { if (typeof d.replyObj.onNoResource != "undefined") d.replyObj.onNoResource() } else k.addChildMessage(a); else alert("An error occured during your request. Please try again."); k.renderMessages(d) }, error: function (a) { a.status == 401 && fb.util.sendToLogin(window.location.pathname) }, dataType: "json" }) } }; this.saveNewMessage = function (b) { var a = b.newMessageObj, c = $.trim(a.message.val()); if (c.length < 1) alert("Please provide some text with your message."); else { a.saveButton.attr("disabled", "disabled"); "privacyDropDown" in a && a.privacyDropDown.attr("disabled", "disabled"); a.feedbackMsg.html('<img src="' + fb.util.root() + 'images/indicator.gif" class="img16x16" />Posting Message&#0133;'); var d = { message: c }; $.extend(d, a.miscNewMessagePostData); "privacyDropDown" in a && (d["private"] = a.privacyDropDown.find("option").filter(":selected").val()); var k = function () { a.saveButton.removeAttr("disabled"); "privacyDropDown" in a && a.privacyDropDown.removeAttr("disabled") }, e = this; $.ajax({ type: "POST", url: a.newMessageHandlerUri, dataType: "json", data: d, success: function (c) { if (c != void 0 && !fb.util.isObjEmpty(c)) { if ("private" in d && d["private"] == "true") a.feedbackMsg.html("Your private message has been sent."), setTimeout(function () { a.feedbackMsg.empty() }, 5E3); else if (a.feedbackMsg.html(""), typeof c.resource != "undefined" && c.resource === 0) { if (typeof a.onNoResource != "undefined") a.onNoResource() } else e.addParentMessage(c), e.renderMessages(b); a.message.val("") } else a.feedbackMsg.html("An error occurred during your post. Please try again."); k() }, error: function (b, c) { b.status == 401 ? fb.util.sendToLogin(window.location.pathname) : (a.feedbackMsg.text("An error occured: " + c), k()) } }) } } };
