-
Notifications
You must be signed in to change notification settings - Fork 10
/
sp-peoplepicker.min.js
1 lines (1 loc) · 9.36 KB
/
sp-peoplepicker.min.js
1
!function(){angular.module("sp-peoplepicker",[]).directive("spPeoplePicker",function(){function t(t,i,r,s){function o(){var e=!0,i=!0;r.hasOwnProperty("minEntries")&&(e=s.$viewValue.length>=parseInt(t.minEntries,10)),r.hasOwnProperty("maxEntries")&&(i=s.$viewValue.length<=parseInt(t.maxEntries,10));var o=e&&i;s.$setValidity("required",o)}peoplePicker=new e.PeoplePicker(t.spContext,$("#spanPeoplePick"),$("#inputPeoplePick"),$("#divPeoplePickSearch"),$("#hdnPeoplePick")),peoplePicker.InstanceName="peoplePicker",peoplePicker.MaxEntriesShown=t.maxEntries,peoplePicker.AllowDuplicates=t.allowDuplicates,peoplePicker.ShowLoginName=t.showLogin,peoplePicker.ShowTitle=t.showTitle,peoplePicker.OnSelectionChanged=function(){var e=JSON.parse($("#hdnPeoplePick").val());s.$setViewValue(e),s.$render(),o()},peoplePicker.PrincipalType=1,peoplePicker.MinimalCharactersBeforeSearching=t.minCharacters,peoplePicker.Initialize(),o()}var i={link:t,restrict:"EA",require:"ngModel",replace:!0,scope:{minEntries:"@",maxEntries:"@",allowDuplicates:"@",showLogin:"=",showTitle:"=",minCharacters:"@",selections:"=",appWebUrl:"="},template:function(){var e='<div class="cam-peoplepicker-input"><div id="divPeoplePick" class="cam-peoplepicker-userlookup ms-fullWidth"><span id="spanPeoplePick"></span><input type="text" id="inputPeoplePick" class="cam-peoplepicker-edit" /></div><div id="divPeoplePickSearch" class="cam-peoplepicker-usersearch ms-emphasisBorder"></div><input type="hidden" name="hdnPeoplePick" id="hdnPeoplePick" /></div>';return e},controller:["$scope",function(e){e.spContext=new SP.ClientContext(e.appWebUrl);var t=new SP.ProxyWebRequestExecutorFactory(e.appWebUrl);e.spContext.set_webRequestExecutorFactory(t)}]};return i});var e;!function(e){var t=function(){function e(e,t,i,r,s){this.SharePointContext=e,this.PeoplePickerControl=t,this.PeoplePickerEdit=i,this.PeoplePickerDisplay=r,this.PeoplePickerData=s,this.InstanceName="",this.MaxEntriesShown=4,this.ShowLoginName=!0,this.ShowTitle=!0,this.MinimalCharactersBeforeSearching=2,this.PrincipalType=1,this.AllowDuplicates=!1,this.Language="en-us",this.OnSelectionChanged=null,this._queryID=1,this._lastQueryID=1,this._ResolvedUsers=[]}return e.prototype.GetPrincipalType=function(){return this.PrincipalType},e.prototype.SetPrincipalType=function(e){this.PrincipalType=e},e.prototype.GetMinimalCharactersBeforeSearching=function(){return this.MinimalCharactersBeforeSearching},e.prototype.SetMinimalCharactersBeforeSearching=function(e){this.MinimalCharactersBeforeSearching=e},e.prototype.HtmlEncode=function(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML},e.prototype.HtmlDecode=function(e){var t=document.createElement("a");return t.innerHTML=e,t.textContent},String.prototype.ReplaceAll=function(e,t,i){var r,s=this+"",o=-1;if("string"==typeof e){if(!i)return this.split(e).join(t);for(r=e.toLowerCase();-1!==(o=s.toLowerCase().indexOf(e,o>=0?o+t.length:0));)s=s.substring(0,o)+t+s.substring(o+e.length)}return s},e.prototype.LoadScript=function(e,t){var i=document.getElementsByTagName("head")[0],r=document.createElement("script");r.src=e;var s=!1;r.onload=r.onreadystatechange=function(){s||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState||(s=!0,t(),r.onload=r.onreadystatechange=null,i.removeChild(r))},i.appendChild(r)},e.prototype.Format=function(e){for(var t=1;t<arguments.length;t++)e=e.ReplaceAll("{"+(t-1)+"}",arguments[t]);return e},e.prototype.HideSelectionBox=function(){this.PeoplePickerDisplay.css("display","none")},e.prototype.ShowSelectionBox=function(){this.PeoplePickerDisplay.css("display","block")},e.prototype.ConstructResolvedUserSpan=function(e,t,i){return resultDisplay="Remove person or group {0}","undefined"!=typeof deleteUser&&(resultDisplay=deleteUser),lookupValue=e?e.replace("\\","\\\\"):i,resultDisplay=this.Format(resultDisplay,t),userDisplaySpanTemplate='<span class="cam-peoplepicker-userSpan"><span class="cam-entity-resolved">{0}</span><a title="{3}" class="cam-peoplepicker-delImage" onclick="{1}.DeleteProcessedUser({2}); return false;" href="#">x</a></span>',this.Format(userDisplaySpanTemplate,t,this.InstanceName,"'"+lookupValue+"'",resultDisplay)},e.prototype.ResolvedUsersToHtml=function(){for(var e="",t=0;t<this._ResolvedUsers.length;t++)e+=this.ConstructResolvedUserSpan(this._ResolvedUsers[t].Login,this._ResolvedUsers[t].Name,this._ResolvedUsers[t].LookupId);return e},e.prototype.ResolvedUser=function(e,t,i){var r=new Object;return r.Login=e,r.Name=t,r.Email=i,r},e.prototype.PushResolvedUser=function(e){if(this.AllowDuplicates)this._ResolvedUsers.push(e);else{for(var t=!1,i=0;i<this._ResolvedUsers.length;i++)this._ResolvedUsers[i].Login==e.Login&&(t=!0);t||this._ResolvedUsers.push(e)}this.PeoplePickerData.val(JSON.stringify(this._ResolvedUsers))},e.prototype.PopResolvedUser=function(){this._ResolvedUsers.pop(),this.PeoplePickerData.val(JSON.stringify(this._ResolvedUsers))},e.prototype.RemoveResolvedUser=function(e){for(var t=[],i=0;i<this._ResolvedUsers.length;i++){var r=this._ResolvedUsers[i].Login?this._ResolvedUsers[i].Login:this._ResolvedUsers[i].LookupId;r!=e&&t.push(this._ResolvedUsers[i])}this._ResolvedUsers=t,this.PeoplePickerData.val(JSON.stringify(this._ResolvedUsers))},e.prototype.RecipientSelected=function(e,t,i){this.HideSelectionBox(),this.PushResolvedUser(this.ResolvedUser(e,t,i)),this.PeoplePickerControl.html(this.ResolvedUsersToHtml()),this.PeoplePickerEdit.val(""),this.PeoplePickerEdit.focus(),this.OnSelectionChanged()},e.prototype.DeleteProcessedUser=function(e){this.RemoveResolvedUser(e),this.PeoplePickerControl.html(this.ResolvedUsersToHtml()),this.PeoplePickerEdit.focus(),this.OnSelectionChanged()},e.prototype.QueryFailure=function(){alert("Error performing user search")},e.prototype.QuerySuccess=function(e,t){var i=this.SharePointContext.parseObjectFromJsonString(t.get_value()),r="",s="<div class='ms-bgHoverable' style='width: 400px; padding: 4px;' onclick='javascript:{0}.RecipientSelected(\"{1}\", \"{2}\", \"{3}\")'>{4}",o="";if(o=this.ShowLoginName&&this.ShowTitle?s+" ({5})<br/>{6}</div>":this.ShowLoginName||this.ShowTitle?s+" ({6})</div>":s+"</div>",i)if(i.length>0){if(e<this._lastQueryID)return;var n=i.length;n>this.MaxEntriesShown&&(n=this.MaxEntriesShown);for(var l=0;n>l;l++){var a=i[l],p=a.Key,c=a.DisplayText,h=a.EntityData.Title,d=a.EntityData.Email,u=d;if(p&&p.indexOf("|")>-1){var P=p.split("|");u=u+" "+P[P.length-1],u=u.trim()}r+=this.Format(o,this.InstanceName,p.replace("\\","\\\\"),this.HtmlEncode(c),d,c,u,h)}var v="";r+="<div class='ms-emphasisBorder' style='width: 400px; padding: 4px; border-left: none; border-bottom: none; border-right: none; cursor: default;'>",1==i.length?(v="Showing {0} result","undefined"!=typeof resultsSingle&&(v=resultsSingle),r+=this.Format(v,i.length)+"</div>"):n!=i.length?(v="Showing {0} of {1} results. <B>Please refine further<B/>","undefined"!=typeof resultsTooMany&&(v=resultsTooMany),r+=this.Format(v,n,i.length)+"</div>"):(v="Showing {0} results","undefined"!=typeof resultsMany&&(v=resultsMany),r+=this.Format(v,i.length)+"</div>"),this.PeoplePickerDisplay.html(r),this.ShowSelectionBox()}else{var f="<div class='ms-emphasisBorder' style='width: 400px; padding: 4px; border-left: none; border-bottom: none; border-right: none; cursor: default;'>No results found</div>";this.PeoplePickerDisplay.html(f),this.ShowSelectionBox()}else this.HideSelectionBox()},e.prototype.Initialize=function(){var e="",t="";$("script").each(function(i,r){r.src.toLowerCase().indexOf("peoplepickercontrol.js")>-1&&(e=r.src,t=e.substring(e.indexOf(".js")+3),e=e.substring(0,e.indexOf(".js")))});var i=e+"_resources."+this.Language.substring(0,2).toLowerCase()+".js";t.length>0&&(i+=t),this.LoadScript(i,function(){}),this.PeoplePickerData.val().length>0&&(this._ResolvedUsers=JSON.parse(this.PeoplePickerData.val()),this.PeoplePickerControl.html(this.ResolvedUsersToHtml()));var r=this;this.PeoplePickerControl.parent().click(function(){r.PeoplePickerEdit.focus()}),this.PeoplePickerEdit.keydown(function(e){var t=e.which;if(8==t){r.HideSelectionBox();var i=r.PeoplePickerEdit.val();if(i.length>0);else if(r._ResolvedUsers.length>0)return r.PopResolvedUser(),r.PeoplePickerControl.html(r.ResolvedUsersToHtml()),r.PeoplePickerEdit.focus(),!1}else if(t>=48&&90>=t||32==t){var s=r.PeoplePickerEdit.val();if(0==e.shiftKey&&t>=65&&90>=t&&(t+=32),s+=String.fromCharCode(t),s.length>0){var o=s;if(r.GetMinimalCharactersBeforeSearching()<1&&r.SetMinimalCharactersBeforeSearching(1),o.length>=r.GetMinimalCharactersBeforeSearching()){resultDisplay="Searching...","undefined"!=typeof resultsSearching&&(resultDisplay=resultsSearching);var n=r.Format("<div class='ms-emphasisBorder' style='width: 400px; padding: 4px; border-left: none; border-bottom: none; border-right: none; cursor: default;'>{0}</div>",resultDisplay);r.PeoplePickerDisplay.html(n),r.ShowSelectionBox();var l=new SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters;l.set_allowMultipleEntities(!1),l.set_maximumEntitySuggestions(2e3),l.set_principalType(r.GetPrincipalType()),l.set_principalSource(15),l.set_queryString(o);var a=SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser(r.SharePointContext,l);r._queryID=r._queryID+1;var p=r._queryID;r._lastQueryID=p,r.SharePointContext.executeQueryAsync(Function.createDelegate(this,function(){r.QuerySuccess(p,a)}),Function.createDelegate(this,function(){r.QueryFailure(p)}))}}}else(9==t||27==t)&&r.HideSelectionBox()})},e}();e.PeoplePicker=t}(e||(e={}))}();