/* name: view_Comment purpose: create the ui for the comment */ function view_Comment(oManager) { //properties this.manager = oManager; this.model; this.formatted; //boolean this.expanded; //boolean this.dom_el; this.dom_title; this.dom_replies; this.dom_actions; this.parent; this.dom_parent; //methods this.setId = _view_Comment_setId; this.setModel = _view_Comment_setModel; this.format = _view_Comment_format; this.formatReply= _view_Comment_formatReply; this.formatReport= _view_Comment_formatReport; this.popSubject = _view_Comment_popSubject; this.popBody = _view_Comment_popBody; this.update = _view_Comment_update; this.setParent = _view_Comment_setParent; this.reset = _view_Comment_reset; //this.incrementCount = _view_Comment_incrementCount; this.removeReplies = _view_Comment_removeReplies; //constructor this.init = _view_Comment_init; { this.init(); } } function _view_Comment_setParent(vw) { if (!this.parent) this.parent = vw; } function _view_Comment_update(mdl) { this.setModel(mdl); //if (!this.formatted) { this.format(); //} switch (mdl.state) { case "loading": //switch the icon if (this.dom_icon) this.dom_icon.src = this.manager.icon_loading; break; case "loaded": if (this.dom_icon && this.model.loaded) { this.dom_icon.src = this.manager.icon_expanded; this.popBody(); } if (this.dom_icon && !this.model.loaded) this.dom_icon.src = this.manager.icon_collapsed; //this.popSubject(); break; } } function _view_Comment_init() { this.icon_collapsed = this.manager.icon_collapsed; this.icon_expanded = this.manager.icon_expanded; this.icon_loading = this.manager.icon_loading; } function _view_Comment_setId(id) { this.id = id; } function _view_Comment_setModel(mdl) { this.model = mdl; } function _view_Comment_popSubject() { //the subject contains the subjects text and the number of responses //eg. This is a subject (4) var oModel = this.model; var is_reporter = oModel.author_is_reporter; var title = this.dom_title; if (title && oModel.subject!="" && oModel.subject!="n/a") { //add ellipses to subject if line is truncated... if( (oModel.subject.length>48) && (oModel.subject.lastIndexOf(" ")!=oModel.subject.lastIndexOf(".")-1) ) { oModel.subject = oModel.subject.substr(0,oModel.subject.lastIndexOf(" ")) + "..."; } else { oModel.subject = oModel.subject; } title.innerHTML = (is_reporter)?"StaffStaff: "+oModel.subject:oModel.subject; //if (oModel.reply_count>0) // title.innerHTML += " (" + oModel.reply_count + ") " } } function _view_Comment_popBody() { var oModel = this.model; var body = oModel.body; var p = this.dom_body_text; body = body.replace(/\n/igm, "
"); if (p && p.innerHTML == "" && body != "" && body!="n/a") { p.innerHTML = body; //alert(body); } this.dom_body.style.display = ""; } function _view_Comment_removeReplies() { //this is necessarily to ensure the proper re-ordering of replies //as they're received from the mt var dReplies = this.dom_replies; var len = dReplies.childNodes.length; for (var i=0; i < len; i++) { dReplies.removeChild(dReplies.childNodes[0]); } } function _view_Comment_format(isVisible) { var oModel = this.model; var id = oModel.id; var subject = oModel.subject; var body = oModel.body; var author = oModel.author; var time = oModel.time; var parent_id = oModel.parent_id; var reply_count = oModel.reply_count; var post_path = oModel.post_path; var is_reporter = oModel.author_is_reporter; if (subject=="" && body=="") subject = "[no subject]"; //main li var elLi = document.getElementById("comment-" + id); if (!elLi) { elLi = document.createElement("li"); elLi.setAttribute("id", "comment-" + id); var elHead = document.createElement("a"); elHead.setAttribute("href", "javascript:manager.getData("+id+")"); elHead.className = "head"; elLi.appendChild(elHead); var icon = document.createElement("img"); icon.setAttribute("id", "icon-" + id); icon.setAttribute("border", "0"); icon.src = this.manager.icon_collapsed; elHead.appendChild(icon); var title = document.createElement("span"); title.setAttribute("id", "subject-"+id); elHead.appendChild(title); var counter = document.createElement("span"); counter.setAttribute("id", "counter-"+id); title.appendChild(counter); var info = document.createElement("span"); info.className = "info"; info.appendChild(document.createTextNode(author+ " on " + time)); elHead.appendChild(info); this.dom_title = title; this.dom_icon = icon; this.dom_el = elLi; this.dom_counter = counter; //put this where it belongs if (!this.parent) { if (this.manager.dom_container.childNodes.length==0) this.manager.dom_container.appendChild(elLi); else this.manager.dom_container.insertBefore(elLi, this.manager.dom_container.childNodes[0]); //alert("debugging:top level comment appended"); //SADIE } else { if (this.parent.dom_replies.childNodes.length==0) this.parent.dom_replies.appendChild(elLi); else this.parent.dom_replies.insertBefore(elLi, this.parent.dom_replies.childNodes[0]); //alert("debugging:sub level comment appended"); //SADIE } } var elBody = document.getElementById("body-" + id); if (!elBody) { elBody = document.createElement("div"); elBody.setAttribute("id", "body-" + id); elBody.className = "body"; elBody.style.display = "none"; this.dom_body = elBody; elLi.appendChild(elBody); var p = document.createElement("p"); p.setAttribute("id", "txt-" + id); elBody.appendChild(p); this.dom_body_text = p; var elActions = document.createElement("div"); elActions.className = "actions"; elActions.setAttribute("id", "actions-" + id); elBody.appendChild(elActions); this.dom_actions = elActions; var a = document.createElement("a"); a.className = "reply"; if (this.manager.is_loggedin) { a.appendChild(document.createTextNode("Reply")); a.setAttribute("href", "javascript:manager.reply("+id+")"); } else { a.appendChild(document.createTextNode("Login / Register to Reply")); a.setAttribute("href", "javascript:manager.login("+id+")"); } elActions.appendChild(a); var a = document.createElement("a"); a.appendChild(document.createTextNode("Report this post")); a.setAttribute("href", "javascript:manager.report("+id+")"); elActions.appendChild(a); } var elReplies = document.getElementById("replies-" + id); if (!elReplies) { //alert("debugging:adding new ul"); elReplies = document.createElement("ul"); elReplies.setAttribute("id", "replies-" + id); elReplies.className = "replies"; elBody.appendChild(elReplies); this.dom_replies = elReplies; } if (subject!="" && subject!="n/a") this.popSubject(); this.formatted = true; return elLi; } /* function _view_Comment_updateCount(num) { if (!num) num = 1; //update the reply count display to equal the number of all nested children this.reply_count++; if (this.dom_counter) this.dom_counter.innerHTML = " (" + this.reply_count + ") "; } */ function _view_Comment_formatReply() { var elLi = this.dom_actions; var id = this.model.id; var elPostbox = this.dom_post_box; if (!elPostbox) { elPostbox = document.createElement("div"); elPostbox.className = "postbox"; elPostbox.setAttribute("id", "postbox-" + id); this.dom_post_box = elPostbox; var title = document.createElement("h4"); title.innerHTML = "Reply to this post"; elPostbox.appendChild(title); var txt = document.createElement("textarea"); txt.setAttribute("id", "reply-txt-" + id); txt.className = "postbox"; elPostbox.appendChild(txt); this.dom_post_box_txt = txt; var submit = document.createElement("a"); submit.setAttribute("style", "font-weight:bold;"); submit.setAttribute("type", "submit"); submit.setAttribute("name", "action"); submit.appendChild(document.createTextNode("Post")); submit.setAttribute("href", "javascript:manager.post(" + id + ")"); elPostbox.appendChild(submit); var cancel = document.createElement("a"); cancel.setAttribute("type", "reset"); cancel.setAttribute("value", "Cancel"); cancel.appendChild(document.createTextNode("Cancel")); cancel.setAttribute("href", "javascript:manager.reset(" + id + ")"); elPostbox.appendChild(cancel); elLi.appendChild(elPostbox); } this.reset(); this.dom_current_textcontainer = this.dom_post_box; this.dom_current_textarea = this.dom_post_box_txt; elPostbox.style.display = ""; } function _view_Comment_reset(doClear) { var id = this.model.id; if (this.dom_current_textarea && doClear) { this.dom_current_textarea.value = ""; } if (this.dom_current_textcontainer) { this.dom_current_textcontainer.style.display = 'none'; } } function _view_Comment_formatReport() { var id = this.model.id; var elLi = this.dom_actions; var elPostbox = this.dom_report; if (!elPostbox) { elPostbox = document.createElement("div"); elPostbox.className = "reportbox"; elPostbox.setAttribute("id", "reportbox-" + id); this.dom_report = elPostbox; var title = document.createElement("h4"); title.innerHTML = "Report this post"; elPostbox.appendChild(title); var txt = document.createElement("textarea"); txt.setAttribute("id", "report-txt-" + id); txt.className = "reportbox"; elPostbox.appendChild(txt); this.dom_report_txt = txt; var submit = document.createElement("a"); submit.setAttribute("style", "font-weight:bold;"); submit.setAttribute("type", "submit"); submit.setAttribute("name", "action"); submit.appendChild(document.createTextNode("Send")); submit.setAttribute("href", "javascript:manager.send_report(" + id + ")"); elPostbox.appendChild(submit); var cancel = document.createElement("a"); cancel.setAttribute("type", "reset"); cancel.setAttribute("value", "Cancel"); cancel.appendChild(document.createTextNode("Cancel")); cancel.setAttribute("href", "javascript:manager.reset(" + id + ",'reportbox')"); elPostbox.appendChild(cancel); elLi.appendChild(elPostbox); } this.reset(); this.dom_current_textcontainer = this.dom_report; this.dom_current_textarea = this.dom_report_txt; elPostbox.style.display = ""; }