jmaki.namespace("jmaki.widgets.moa.homesitebloggerwidget");jmaki.widgets.moa.homesitebloggerwidget.Widget=function(wargs){try{var _widget=this;var uuid="#"+wargs.uuid;var publish="/moa/homesitebloggerwidget";var subscribe=["/moa/homesitebloggerwidget"];var tasks=["/loadBlogs"];if(wargs.publish){publish=wargs.publish;}if(wargs.subscribe){if(typeof wargs.subscribe=="string"){subscribe=[];subscribe.push(wargs.subscribe);}else{subscribe=wargs.subscribe;}}var initSubscribe=function(){_widget.subs=[];for(var task=0;task<tasks.length;task++){doSubscribe(subscribe+tasks[task],_widget.loadBlogs);}};var doSubscribe=function(topic,handler){var i=jmaki.subscribe(topic,handler);_widget.subs.push(i);};var init=function(){initSubscribe();};this.postLoad=function(){init();};var weblogId;var blogType;var pageNo=0;var totalBlogEntries=0;this.loadBlogs=function(e,c){if(e.entryId&&e.entryId!="-1"){showBlogDetails(e.entryId);}else{if(e.entryId&&e.entryId=="-1"){pageNo=0;$(uuid).html("");listBlogEntries();}else{listBlogEntries();}}};var listBlogEntries=function(){load();};var load=function(){try{blogger.listHomeSiteBlogs(pageNo,renderPanel);}catch(e){}};var getAnchorEle=function(){return $("<a></a>").clone();};var renderPanel=function(homeBlogDTO){totalBlogEntries=homeBlogDTO.totalRecords;blogEntriesList=homeBlogDTO.blogEntriesList;if(blogEntriesList!=null){if(blogEntriesList.length>0){var titleDiv=getDivEle();titleDiv.attr("class","blog_header");var titleImageDiv=getDivEle();titleImageDiv.attr("class","blog_ico");titleDiv.append(titleImageDiv);var imgMedia=getImageEle();titleImageDiv.append(imgMedia);imgMedia.attr("src","imagesMOAHome/ico-weblog-big.png");var headerSpan=getSpanEle();headerSpan.attr("class","ClsBodyText_weblog_header");headerSpan.append("Blog");titleDiv.append(headerSpan);var bodySpan=getSpanEle();bodySpan.attr("class","ClsBodyText");bodySpan.text("");var helpDiv=getDivEle();helpDiv.attr("class","blog_help_text");helpDiv.append(bodySpan);titleDiv.append(helpDiv);var baseDiv=getDivEle();baseDiv.attr("class","blog_container");baseDiv.attr("id","baseDiv");baseDiv.append(titleDiv);for(var i=0;i<blogEntriesList.length;i++){var styleClass="blog_topic_row";if(i%2==0){styleClass="blog_topic_row_alternate";}baseDiv.append(getEntryHolderRow(blogEntriesList[i].entryId,blogEntriesList[i].imageUrl,blogEntriesList[i].title,blogEntriesList[i].createdBy,blogEntriesList[i].pubtime,blogEntriesList[i].commentCount,stripText(blogEntriesList[i].text),styleClass));}baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());var pagingDiv=getDivEle();pagingDiv.attr("class","pagination_text");baseDiv.append(pagingDiv);if(pageNo>0){var prevAnchor=getAnchorEle();prevAnchor.attr("style","cursor: pointer;");prevAnchor.click(function(){nextLink(-1);});prevAnchor.append("&lt;&lt;&nbsp;&nbsp;Previous ");prevAnchor.attr("class","cursor:pointer");pagingDiv.append(prevAnchor);}var temp=totalBlogEntries/5;temp=parseInt(temp);var tempPageNo=0;if(totalBlogEntries%5==0){tempPageNo=pageNo+1;}else{tempPageNo=pageNo;}if(pageNo>0&&tempPageNo<temp){pagingDiv.append("&nbsp;&nbsp;|&nbsp;&nbsp;");}if(tempPageNo<temp){var nextAnchor=getAnchorEle();nextAnchor.attr("style","cursor: pointer;");nextAnchor.click(function(){nextLink(1);});nextAnchor.append("Next&nbsp;&nbsp;&gt;&gt;");nextAnchor.attr("class","cursor:pointer");pagingDiv.append(nextAnchor);}$(uuid).append(baseDiv);}}jmaki.publish("/moahome/moaHomeloginwidget/load",{});};var resolveNext=function(blogEntriesList){totalBlogEntries=blogEntriesList.length;};var nextLink=function(nav){$(uuid).html("");if(nav>0){pageNo=pageNo+1;}else{pageNo=pageNo-1;}load();};var getEntryHolderRow=function(entryId,imageUrl,titleVal,createdBy,pubtime,commentCount,textVal,styleClass){var blogDiv=getDivEle();blogDiv.attr("class",styleClass);var imageDiv=getDivEle();imageDiv.attr("class","blog_profile_img");var profileImg=getImageEle();if(imageUrl==null||imageUrl==""){profileImg.attr("src","images/default-artist-img.jpg");}else{profileImg.attr("src",imageUrl);}profileImg.attr("class","profile_img");imageDiv.append(profileImg);blogDiv.append(imageDiv);var blogTitleDiv=getDivEle();blogTitleDiv.attr("class","blog_topic_header border_bottom");var blogTitleSpan=getSpanEle();blogTitleSpan.attr("class","ClsBodyTextContentHeader");var titleAnchor=getAnchorEle();titleAnchor.attr("style","cursor: pointer;");titleAnchor.attr("id",entryId);titleAnchor.click(function(){showBlogDetails($(this).attr("id"));});titleAnchor.append(titleVal);blogTitleSpan.append(titleAnchor);blogTitleDiv.append(blogTitleSpan);blogTitleDiv.append(getPaddingDiv5px());blogDiv.append(blogTitleDiv);blogDiv.append(getPaddingDiv5px());var writtenByDiv=getDivEle();writtenByDiv.attr("class","written_by_text");var writtenBySpan=getSpanEle();writtenBySpan.attr("class","ClsBodyTextGrey");writtenBySpan.append(createdBy+" on ");writtenBySpan.append(pubtime);writtenByDiv.append(writtenBySpan);blogDiv.append(writtenByDiv);var blogTextDiv=getDivEle();blogTextDiv.attr("class","topic_desc border_bottom");var blogTextSpan=getSpanEle();blogTextSpan.attr("class","ClsBodyText");blogTextSpan.append(textVal);blogTextDiv.append(blogTextSpan);blogDiv.append(blogTextDiv);blogDiv.append(getPaddingDiv());var commentsContDiv=getDivEle();commentsContDiv.attr("class","comments_container");var commentsImgDiv=getDivEle();commentsImgDiv.attr("class","comments_ico");var commentImg=getImageEle();commentImg.attr("src","imagesMOAHome/ico-comments.png");commentsImgDiv.append(commentImg);commentsContDiv.append(commentsImgDiv);var commentsTextDiv=getDivEle();commentsTextDiv.attr("class","comments_text");var commentsAnchor=getAnchorEle();commentsAnchor.attr("style","cursor: pointer;");if(commentCount==0){commentsAnchor.append("Leave a Comment");}else{commentsAnchor.append("Comments("+commentCount+")");}commentsAnchor.click(function(){showBlogDetails(entryId);});commentsTextDiv.append(commentsAnchor);commentsContDiv.append(commentsTextDiv);blogDiv.append(commentsContDiv);var clearDiv=getDivEle();clearDiv.attr("class","clear");blogDiv.append(clearDiv);blogDiv.append(getPaddingDiv());return blogDiv;};var showBlogDetails=function(entryId){$(uuid).html("");try{blogger.getBlogDetails(entryId,renderBlogDetails);}catch(e){}};renderBlogDetails=function(blogEntryDTO){if(blogEntryDTO!=null){var baseDiv=getDivEle();baseDiv.attr("class","blog_container");baseDiv.attr("id","baseDiv");var titleDiv=getDivEle();titleDiv.attr("class","blog_header");var titleImageDiv=getDivEle();titleImageDiv.attr("class","blog_ico");titleDiv.append(titleImageDiv);var imgMedia=getImageEle();titleImageDiv.append(imgMedia);imgMedia.attr("src","imagesMOAHome/ico-weblog-big.png");var headerSpan=getSpanEle();headerSpan.attr("class","ClsBodyText_weblog_header");headerSpan.append("Weblog");titleDiv.append(headerSpan);baseDiv.append(titleDiv);var bodySpan=getSpanEle();bodySpan.attr("class","ClsBodyText");bodySpan.text("Want to maintain your 'Artistic Dairy' - Blog it here...");var helpDiv=getDivEle();helpDiv.attr("class","blog_help_text");helpDiv.append(bodySpan);baseDiv.append(helpDiv);var blogDiv=getDivEle();blogDiv.attr("class","blog_topic_row_alternate");var imageDiv=getDivEle();imageDiv.attr("class","blog_profile_img");var profileImg=getImageEle();if(blogEntryDTO.imageUrl==null||blogEntryDTO.imageUrl==""){profileImg.attr("src","images/default-artist-img.jpg");}else{profileImg.attr("src",blogEntryDTO.imageUrl);}profileImg.attr("class","profile_img");imageDiv.append(profileImg);blogDiv.append(imageDiv);var blogTitleDiv=getDivEle();blogTitleDiv.attr("class","blog_topic_header border_bottom");var blogTitleSpan=getSpanEle();blogTitleSpan.attr("class","ClsBodyTextContentHeader");blogTitleSpan.append(blogEntryDTO.title);blogTitleDiv.append(blogTitleSpan);blogTitleDiv.append(getPaddingDiv());blogDiv.append(blogTitleDiv);blogDiv.append(getPaddingDiv());var writtenByDiv=getDivEle();writtenByDiv.attr("class","written_by_text");var writtenBySpan=getSpanEle();writtenBySpan.attr("class","ClsBodyTextGrey");writtenBySpan.append(blogEntryDTO.createdBy+" on ");writtenBySpan.append(blogEntryDTO.pubtime);writtenByDiv.append(writtenBySpan);blogDiv.append(writtenByDiv);var blogTextDiv=getDivEle();blogTextDiv.attr("class","topic_desc border_bottom");var blogTextSpan=getSpanEle();blogTextSpan.attr("class","ClsBodyText");blogTextSpan.append(blogEntryDTO.text);blogTextDiv.append(blogTextSpan);blogDiv.append(blogTextDiv);blogDiv.append(getPaddingDiv());var commentsContDiv=getDivEle();commentsContDiv.attr("class","comments_container");var commentsImgDiv=getDivEle();commentsImgDiv.attr("class","comments_ico");var commentImg=getImageEle();commentImg.attr("src","imagesMOAHome/ico-comments.png");commentsImgDiv.append(commentImg);commentsContDiv.append(commentsImgDiv);blogDiv.append(getPaddingDiv());baseDiv.append(blogDiv);var respContDiv=getDivEle();respContDiv.attr("class","response_text_container");var respImgDiv=getDivEle();respImgDiv.attr("class","response_text_ico");var respCommentImg=getImageEle();respCommentImg.attr("src","imagesMOAHome/ico-comments.png");respImgDiv.append(respCommentImg);respContDiv.append(respImgDiv);var respTextDiv=getDivEle();respTextDiv.attr("class","response_text");var respTextSpan=getSpanEle();respTextSpan.attr("class","ClsBodyTextBoldGrey");if(blogEntryDTO.commentCount==0){var replyAnchor=getAnchorEle();replyAnchor.attr("style","cursor: pointer;");replyAnchor.append("Leave a Comment");replyAnchor.click(function(){if(!isLoggedIn()){activatehomeloginpopupwidget("user","Login Details");}else{respTextDiv.append(getCommentContainer(blogEntryDTO.entryId,-1,blogEntryDTO.createdBy,"false"));}});respTextSpan.append(replyAnchor);}else{respTextSpan.append(blogEntryDTO.commentCount+" Responses to "+blogEntryDTO.title);}respTextDiv.append(respTextSpan);respContDiv.append(respTextDiv);baseDiv.append(respContDiv);var blogCommentsList=blogEntryDTO.blogCommentDTO;if(blogEntryDTO.blogCommentDTO!=null){for(var i=blogCommentsList.length-1;i>=0;i--){var styleClass="comment_row";if(i%2==0){styleClass="comment_row_alternate";}var commentDiv=getDivEle();commentDiv.attr("class",styleClass);var commentByDiv=getDivEle();commentByDiv.attr("class","commentby_text border_bottom");var bySpan=getSpanEle();bySpan.attr("class","ClsBodyTextItalics");bySpan.append("By ");var commentBySpan=getSpanEle();commentBySpan.attr("class","ClsBodyTextBoldItalic");commentBySpan.append(blogCommentsList[i].createdBy);commentByDiv.append(bySpan);commentByDiv.append(commentBySpan);commentDiv.append(commentByDiv);var commentDateDiv=getDivEle();commentDateDiv.attr("class","written_by_text");var commentDateSpan=getSpanEle();commentDateSpan.attr("class","ClsBodyTextGrey");commentDateSpan.append(blogCommentsList[i].posttime);commentDateDiv.append(commentDateSpan);commentDiv.append(commentDateDiv);var commentTextDiv=getDivEle();commentTextDiv.attr("class","topic_desc border_bottom");var commentTextSpan=getSpanEle();commentTextSpan.attr("class","ClsBodyText");commentTextSpan.append(blogCommentsList[i].content);commentTextDiv.append(commentTextSpan);commentDiv.append(commentTextDiv);commentDiv.append(getPaddingDiv());var replyContDiv=getDivEle();replyContDiv.attr("class","reply_comment_container");var replyTexContDiv=getDivEle();replyTexContDiv.attr("class","reply_text_container");var replyTexDiv=getDivEle();replyTexDiv.attr("class","reply_text");var replyAnchor=getAnchorEle();replyAnchor.attr("style","cursor: pointer;");replyAnchor.append("Reply");var cmntId=blogCommentsList[i].commentId;var repTouser=blogCommentsList[i].replyToUserDetail;replyAnchor.click(function(){if(!isLoggedIn()){activatehomeloginpopupwidget("user","Login Details");}else{$(this).closest("div.reply_text").hide();$(this).closest("div.reply_text_container").append(getCommentContainer(blogEntryDTO.entryId,cmntId,repTouser,"true"));}});replyTexDiv.append(replyAnchor);replyTexContDiv.append(replyTexDiv);replyTexContDiv.append(getClearDiv());replyTexContDiv.append(getPaddingDiv());replyContDiv.append(replyTexContDiv);commentDiv.append(replyContDiv);baseDiv.append(commentDiv);}}var pagingTexDiv=getDivEle();pagingTexDiv.attr("class","pagination_text");var pagingAnchor=getAnchorEle();pagingAnchor.attr("style","cursor: pointer;");pagingAnchor.append("See all Weblogs");pagingAnchor.click(function(){$(uuid).html("");load();});pagingTexDiv.append(pagingAnchor);baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());baseDiv.append(pagingTexDiv);baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());baseDiv.append(getPaddingDiv());$(uuid).append(baseDiv);}jmaki.publish("/moahome/moaHomeloginwidget/load",{});};var getCommentContainer=function(entryId,commentId,replyToUser,isReplyToComment){var cont=createCommentContainer(replyToUser);var addButton=getAddButton();addButton.click(function(){if(!isLoggedIn()){activatehomeloginpopupwidget("user","Login Details");}else{var textContent=$("#commentTextArea").val();$(uuid).html("");blogger.saveComment(entryId,commentId,textContent,isReplyToComment,renderBlogDetails);}});cont.append(addButton);cont.append("&nbsp;");var cancelButton=getCancelButton();cancelButton.click(function(){$(this).closest("div.reply_text_container").find("div.reply_text").show();$(this).closest("div.comment_container").remove();});cont.append(cancelButton);cont.append(getPaddingDiv());cont.append(getPaddingDiv());return cont;};var createCommentContainer=function(replyToUser){return $("<div class='comment_container'><div class='commentby_text'><span class='ClsBodyTextItalics'>Reply to</span>&nbsp;<span class='ClsBodyTextBoldItalic'>"+replyToUser+"</div><div class='general_padding_10px'></div><div class='comment'><textarea tabindex='4' rows='12' name='commentTextArea' id='commentTextArea'></textarea></div><div class='general_padding_10px'></div>&nbsp;&nbsp;").clone();};var stripText=function(textVal){if(textVal.length>350){return(textVal.substring(0,350)+getBoldEle().text("...").html());}return textVal;};var getAddButton=function(){return $("<input class='ClsButton' type='button' value='Add Comment'/>").clone();};var getCancelButton=function(){return $("<input class='ClsButton' type='button' value='Cancel'/>").clone();};var getClearDiv=function(){return $("<div class='clear'></div>").clone();};var getPaddingDiv=function(){return $("<div class='general_padding_10px'></div>").clone();};var getPaddingDiv5px=function(){return $("<div class='general_padding_5px'></div>").clone();};var getImageEle=function(){return $("<img></img>").clone();};var setDefaults=function(){$(".blog_comment_entry_container").remove();};var getDivEle=function(){return $("<div></div>").clone();};var getSpanEle=function(){return $("<span></span>").clone();};var getHeader4Ele=function(){return $("<h4></h4>").clone();};var getHeader6Ele=function(){return $("<h6></h6>").clone();};var getHeader5Ele=function(){return $("<h5></h5>").clone();};var getParagraphsEle=function(){return $("<p></p>").clone();};var getBoldEle=function(){return $("<b></b>").clone();};var getTextAreaEntryEle=function(){return $("<textarea></textarea>").clone();};var getTableEle=function(){return $("<table border='0' cellpadding='0' cellspacing='0'></table>").clone();};var getTheadEle=function(){return $("<thead></thead>").clone();};var getTbodyEle=function(){return $("<tbody></tbody>").clone();};var getTrEle=function(){return $("<tr></tr>").clone();};var getThEle=function(){return $("<th></th>").clone();};var getTdEle=function(){return $("<td></td>").clone();};}catch(error){}};
