﻿AppLaunch.View.Activity=function($){var target=$("#activity-list"),_loadPartialActivity=function(url,Source){target.html('<img class="load" src="/Content/images/loader.gif" alt="Loading..." />');var url=url+"&source="+Source;request=$.ajax({url:url,cache:false,success:function(response){target.html(response);AppLaunch.cropimg()}})},_loadMoreActivity=function(){target.on("click","#amore",function(e){var url=$(this).data("ajaxUrl");var source=$(this).data("filterSource");$(this).html('<img class="load" src="/Content/images/loader.gif" alt="Loading..." />');
request=$.ajax({url:url+source,cache:false,success:function(response){$("#amoreContainer").remove();target.append(response);AppLaunch.cropimg()}})})},_showComment=function(){target.on("click","a.reply",function(){var id=$(this).attr("id").replace("reply-target","#divreply");stopajax=1;$(id).slideDown()})},_deleteActivity=function(){target.on("click","a.delete",function(obj){var activityId=$(this).closest("li").attr("id").replace("li","");if(activityId>0)if(Bloc.ObjectModel.Activities.DeleteActivity(CurrentUserID,
Key,activityId).value)$(this).closest("li").slideUp(800)})},_focusComment=function(){target.on("focus","textarea",function(){$(this).parent().find(".button").slideDown();if($(this).nextAll($(".counter")).length==1)$(this).charCount({allowed:300,limit:300,warning:15,counterText:"Characters left: "});if(this.value==this.defaultValue)this.value=""}).blur(function(){if(this.value==this.defaultValue||this.value=="")this.value=this.defaultValue})},_postComment=function(){target.on("click",".reply-button",
function(){var commentId=$(this).closest("li").attr("id").replace("divreply",""),textareaId=$("#li"+commentId+" textarea").attr("id").replace("txtreply",""),appid=$("#appid").val(),reply=$("#txtreply"+textareaId).val();if($.trim("#txtreply"+commentId)!=""){var intreplyid=Bloc.ObjectModel.Activities.PostActivityReply(CurrentUserID,Key,textareaId,reply,appid,SiteID).value;if(intreplyid>0){var div="#divreply"+commentId;var str="";str+='<li id="lireply'+intreplyid+'">';str+='<a href="/profile/profile.rails?uid='+
CurrentUserID+'"><img class="uiProfileTinyImage" gen="1" path="'+profileimage+'" t="_ProfileImage40" w="40" h="40" base="0" alt="'+username+'" /></a>';str+='<div class="feedback-wrap">';str+='<div><a href="/profile/profile.rails?uid='+CurrentUserID+'" ';str+=' class="sex'+sex+'" ';str+=">"+username+"</a> "+reply+"</div>";str+="<small>";str+="just seconds ago ";str+="</small>";str+='<a class="delete">delete</a>';str+="</div>";str+="</li>";$(str).insertBefore(div);$("#txtreply"+textareaId).val("Write your comment here..");
_deleteReply();AppLaunch.cropimg()}}})},_deleteReply=function(){target.on("click","a.delete",function(){var rid=$(this).closest("li").attr("id").replace("lireply","");if(rid>0)Bloc.ObjectModel.Activities.DeleteActivityReply(CurrentUserID,Key,rid,function(res){if(res.value)$("#lireply"+rid).slideUp()})})},_showHiddenReplies=function(){$("#activity-list").on("click",".openreplies",function(){var hiddenactivityid=$(this).attr("data-activityid");$("#hiddenreply"+hiddenactivityid).hide();$(".lireply"+
hiddenactivityid).show()})},_changeSourceDropdown=function(activityFeedUrl){var filter=$("#ChangeActivitySource");filter.change(function(){var url=activityFeedUrl+"&source="+filter.val();target.html('<img class="load" src="/Content/images/loader.gif" alt="Loading..." />');request=jQuery.ajax({url:url,cache:false,success:function(response){target.html(response);AppLaunch.cropimg()}})})},_showEmbed=function(){target.on("click","a.expand",function(e){e.preventDefault();var emb=$(this).closest("li").find("div.embed");
$(this).closest("li").find(".wrap-content, .expand").hide();$(emb).show()})};return{init:function(activityFeedUrl,Source){_deleteActivity();_showHiddenReplies();_showComment();_focusComment();_postComment();_deleteReply();_loadPartialActivity(activityFeedUrl,Source);_loadMoreActivity();_changeSourceDropdown(activityFeedUrl);_showEmbed()}}}(jQuery);

