(function(){"use strict";var e=/\bfacebook|\btwitter|\bgoogle/g;u8.Crm.Social=function(){};$.extend(u8.Crm.Social.prototype,{markAsSpam:function(e,a,t){if(!u8.tools.isArray(e)){e=[e]}if(!e.length){if(t){t(this,{cancel:true})}return}var r=this;u8.request("SocialChannel.MarkAsSpam",{uids:e,spam:a},function(a,s){if(!s.error){u8.services.crud.notify("Update",{uids:e,args:{caller:"Social",callerOperation:"markAsSpam",type:"update"}})}if(t){t(r,s)}})},markMessageAsRead:function(e,a,t){if(!u8.tools.isArray(e)){e=[e]}if(!e.length){if(t){t(this,{cancel:true})}return}var r=this;u8.request("SocialChannel.MarkMessageAsRead",{uids:e,read:a},function(a,s){if(!s.error){u8.services.crud.notify("Update",{uids:e,args:{caller:"Social",callerOperation:"markMessageAsRead",type:"update"}})}if(t){t(r,s)}})},sendResponse:function(e,a,t){var r=this;u8.request("SocialChannel.SendResponse",{uid:e,response:a.response},function(a,s){if(s.error){return t&&t(r,s)}u8.services.crud.notify("Create",{uid:e,caller:"Social",callerOperation:"sendResponse",type:"create"});if(t){t(r,{})}})},sendInvitation:function(e,a,t){var r=this;u8.request("SocialChannel.SendInvitation",{uid:e,invitation:a.invitation},function(a,s){if(s.error){return t&&t(r,s)}u8.services.crud.notify("Create",{uid:e,caller:"Social",callerOperation:"sendInvitation",type:"create"});if(t){t(r,{})}})},sendFeedback:function(e,a,t){var r=this;u8.request("SocialChannel.SendFeedback",{uid:e,feedback:a.feedback},function(a,s){if(s.error){return t&&t(r,s)}u8.services.crud.notify("Create",{uid:e,caller:"Social",callerOperation:"sendFeedback",type:"create"});if(t){t(r,{})}})},createInvitation:function(e,a,t){var r=this;u8.request("SocialChannel.CreateInvitation",{uid:e,target:a},function(e,a){if(a.error){return t&&t(r,a)}if(t){t(r,a.response)}})},moveToStage:function(e,a,t){var r=this;u8.request("SocialChannel.MoveToStage",{uid:e,stage:a},function(s,n){if(!n.error){u8.services.crud.notify("Update",{uid:e,caller:"Social",callerOperation:"moveToStage"+a.toPascalCase(),type:"update"})}if(t){t(r,n)}})},assignPerson:function(e,a){var t=[e.personUid];u8.services.crud.update({uid:e.uid,options:{links:t}},a)},getProcesses:function(e){var a=this;if(this._processes){return t()}u8.request("SocialChannel.GetProcesses",{},function(e,r){var s=r.response;a._processes=u8.tools.isArray(s)?s:[];t()});function t(){e(a,{processes:a._processes})}},"RenderHook.isOutbound":function(e){var a=u8.services.typeConverter.toBoolean(e.getValue())?"Outbound":"Inbound";e.imageReplace(a,"s")},"RenderHook.formatRelevanceSentimentReadStatus":function(e){e.imageAdd("CAT_Sentiment_"+e.getValue("Sentiment"),"s");var a=e.getValue("Relevance");if(a==1){e.addClass("u8-messagepriority-high")}else if(a==2){e.addClass("u8-messagepriority-medium")}else if(a==3){e.addClass("u8-messagepriority-low")}else if(a==4){e.addClass("u8-messagepriority-unknown")}else{e.addClass("u8-messagepriority-empty")}if(e.getValue("ReadStatus")==1){e.removeContextClass("u8-message-read");e.addContextClass("u8-message-unread")}else{e.removeContextClass("u8-message-unread");e.addContextClass("u8-message-read")}},"RenderHook.hasPerson":function(e){var a=e.getValue("PeGrp");var t=e.getValue("PeNo");if(a==0&&t==0){return}e.setText("");e.imageAdd("INFOAREA_KP","s")},getUnreadMessageBadgeHtml:function(e,a){if(e<=0){return""}return"<div class='u8-unreadmessagebadge"+(a?"-"+a:"")+"' data-count='"+e+"'>"+e+"</div>"},getSocialNetworkImage:function(a){if(!a){return null}var t="SocialNetwork_";var r=a.match(e);switch(r&&r[0]){case"facebook":return t+"Facebook";case"twitter":return t+"Twitter";case"google":return t+"GooglePlus";default:if(u8.session.images[t+a]){return t+a}return null}}});u8.services.add({name:"social",ctor:u8.Crm.Social,scope:"Session"});u8.services.menus.registerMenuItem("D_SocialInbox_SendInvitation",{needsUpdateOnShow:true,create:function(e,a){var t=a.menuItem;t.visible=false;t.update();u8.services.social.getProcesses(function(e,a){var r=a.processes;var s=t.getParent();var n=s.indexOf(t);r.forEach(function(e){if(e.state!="Active"){return}var a=t.action.clone();a.arguments.push({name:"communityTarget",value:e.target});s.insert(++n,{action:a,label:e.label})});t.remove();s.update()})}})})();