(()=>{function l(e){var t;"function"!=typeof e.then?(this.init(e),this.name&&!this.id?(t=l.$$resource.create("createFolder",this.name),this.$unwrap(t),this.acls={objectEditor:1,objectCreator:1,objectEraser:1}):this.id&&(this.$acl=new l.$$Acl("Contacts/"+this.id))):this.$unwrap(e)}l.$factory=["$q","$timeout","$log","sgSettings","sgAddressBook_PRELOAD","Resource","Card","Acl","Preferences",function(e,t,i,r,s,n,o,a,d){return angular.extend(l,{$q:e,$timeout:t,$log:i,PRELOAD:s,$$resource:new n(r.activeUser("folderURL")+"Contacts",r.activeUser()),$Card:o,$$Acl:a,$Preferences:d,$query:{value:"",sort:"c_cn",asc:1},activeUser:r.activeUser(),$addressbooks:[],$subscriptions:[],$remotes:[],selectedFolder:null,$refreshTimeout:null}),d.settings.Contact.SortingState&&(l.$query.sort=d.settings.Contact.SortingState[0],l.$query.asc=parseInt(d.settings.Contact.SortingState[1])),l}];try{angular.module("SOGo.ContactsUI")}catch(e){angular.module("SOGo.ContactsUI",["SOGo.Common","SOGo.PreferencesUI"])}angular.module("SOGo.ContactsUI").constant("sgAddressBook_PRELOAD",{LOOKAHEAD:50,SIZE:100}).factory("AddressBook",l.$factory),l.$filterAll=function(n,o,e,a){var t={search:n};return n?(angular.isUndefined(o)&&(o=[]),angular.extend(t,e),l.$$resource.fetch(null,"allContactSearch",t).then(function(e){for(var t,i=function(e){return void 0===this.sourceID||void 0===e.sourceid?this.id==e.id:this.id==e.id&&this.sourceID==e.sourceid},r=a?_.filter(e.contacts,function(e){return _.isUndefined(_.find(a,_.bind(i,e)))}):e.contacts,s=o.length-1;0<=s;s--)t=o[s],_.isUndefined(_.find(r,_.bind(i,t)))&&o.splice(s,1);return _.forEach(r,function(e,t){_.isUndefined(_.find(o,_.bind(i,e)))&&(e=new l.$Card(_.mapKeys(e,function(e,t){return t.toLowerCase()}),n),o.splice(t,0,e))}),o})):(o=[],l.$q.when(o))},l.$add=function(t){var e=t.isSubscription?this.$subscriptions:this.$addressbooks,i=_.find(e,function(e){return"personal"==t.id||"personal"!=e.id&&1===e.name.localeCompare(t.name)}),i=i?_.indexOf(_.map(e,"id"),i.id):1;e.splice(i,0,t)},l.$findAll=function(e){var i=this;if(e&&e.length)this.$addressbooks.splice(0,this.$addressbooks.length),this.$subscriptions.splice(0,this.$subscriptions.length),this.$remotes.splice(0,this.$remotes.length),angular.forEach(e,function(e,t){e=new l(e);(e.isRemote?i.$remotes:e.isSubscription?i.$subscriptions:i.$addressbooks).push(e)});else if(angular.isArray(e))return l.$$resource.fetch("addressbooksList").then(function(e){return l.$findAll(e.addressbooks)});return _.union(this.$addressbooks,this.$subscriptions,this.$remotes)},l.$subscribe=function(e,t){var i=this;return l.$$resource.userResource(e).fetch(t,"subscribe").then(function(t){var e=new l(t);return _.isUndefined(_.find(i.$subscriptions,function(e){return e.id==t.id}))&&l.$add(e),e})},l.$reloadAll=function(){var i=this;return l.$$resource.fetch("addressbooksList").then(function(e){_.forEach(e.addressbooks,function(t){var e=t.isRemote?i.$remotes:t.owner!=l.activeUser.login?i.$subscriptions:i.$addressbooks,e=_.find(e,function(e){return e.id==t.id});e&&e.init(t)})})},l.prototype.init=function(e,t){var i=this;this.$$cards||(this.$$cards=[]),this.idsMap={},this.$cards=[],angular.forEach(e,function(e,t){"headers"!=t&&"cards"!=t&&(i[t]=e)}),this.isOwned=l.activeUser.isSuperUser||this.owner==l.activeUser.login,this.isSubscription=!this.isRemote&&this.owner!=l.activeUser.login},l.prototype.$id=function(){return this.id?l.$q.when(this.id):this.$futureAddressBookData.then(function(e){return e?e.id:l.$q.reject()})},l.prototype.getLength=function(){return this.$cards.length},l.prototype.getItemAtIndex=function(e){var t;return!this.$isLoading&&0<=e&&er.ids.length-1)&&(n.$topIndex=0),angular.forEach(l.$findAll(),function(e,t){e.id==r.id&&angular.extend(n,e)}),n.init(r),n.ids&&(l.$log.debug("unwrapping "+n.ids.length+" cards"),_.reduce(n.ids,function(e,t,i){t={pid:n.id,id:t};return n.idsMap[t.id]=i,(i=new l.$Card(t)).selected=-1{function a(e,t){"function"!=typeof e.then?(this.init(e,t),this.pid&&!this.id&&(t=a.$$resource.newguid(this.pid),this.$unwrap(t),this.isNew=!0)):this.$unwrap(e)}a.$TEL_TYPES=["work","home","cell","fax","pager"],a.$EMAIL_TYPES=["work","home","pref"],a.$URL_TYPES=["work","home","pref"],a.$ADDRESS_TYPES=["work","home"],a.$factory=["$q","$timeout","sgSettings","sgCard_STATUS","encodeUriFilter","Resource","Preferences",function(e,t,i,r,s,n,o){return angular.extend(a,{STATUS:r,encodeUri:s,$$resource:new n(i.activeUser("folderURL")+"Contacts",i.activeUser()),$q:e,$timeout:t,$Preferences:o}),o.defaults.SOGoContactsCategories&&(a.$categories=o.defaults.SOGoContactsCategories),o.defaults.SOGoAlternateAvatar&&(a.$alternateAvatar=o.defaults.SOGoAlternateAvatar),a}];try{angular.module("SOGo.ContactsUI")}catch(e){angular.module("SOGo.ContactsUI",["SOGo.Common","SOGo.PreferencesUI"])}angular.module("SOGo.ContactsUI").constant("sgCard_STATUS",{NOT_LOADED:0,DELAYED_LOADING:1,LOADING:2,LOADED:3,DELAYED_MS:300}).factory("Card",a.$factory),a.$find=function(e,t){e=this.$$resource.fetch([e,t].join("/"),"view");return t?new a(e):a.$unwrapCollection(e)},a.filterCategories=function(e){var t=new RegExp(e,"i");return _.map(_.filter(a.$categories,function(e){return-1!=e.search(t)}),function(e){return{value:e}})},a.$unwrapCollection=function(e){var i={};return(i.$futureCardData=e).then(function(e){a.$timeout(function(){angular.forEach(e,function(e,t){i[e.id]=new a(e)})})}),i},a.prototype.init=function(e,t){var i=this;angular.isUndefined(this.refs)&&(this.refs=[]),angular.isUndefined(this.categories)&&(this.categories=[]),this.c_screenname=null,angular.extend(this,e),this.pid||(this.pid=this.container),this.$$fullname||(this.$$fullname=this.$fullname()),this.$$email||(this.$$email=this.$preferredEmail(t)),this.$$image||(this.$$image=this.image),this.$$image||(this.$$image=a.$Preferences.avatar(this.$$email,40,{no_404:!0})),this.hasphoto&&(this.photoURL=a.$$resource.path(this.pid,this.id,"photo")),this.isgroup&&(this.c_component="vlist"),this.$avatarIcon=this.$isList()?"group":"person",e.orgs&&e.orgs.length&&(this.orgs=_.map(e.orgs,function(e){return{value:e}})),e.notes&&e.notes.length?this.notes=_.map(e.notes,function(e){return{value:e}}):this.notes&&this.notes.length||(this.notes=[{value:""}]),angular.forEach(["addresses","phones","urls"],function(e){angular.forEach(i[e],function(e){e.type&&(e.type=e.type.toLowerCase())})}),angular.forEach(this.refs,function(e,t){e.email&&(e.emails=[{value:e.email}]),e.id=e.reference,i.refs[t]=new a(e)}),this.birthday&&angular.isString(this.birthday)&&(t=a.$Preferences.$mdDateLocaleProvider,this.birthday=this.birthday.parseDate(t,"%Y-%m-%d"),this.$birthday=t.formatDate(this.birthday)),this.$loaded=angular.isDefined(this.c_name)?a.STATUS.LOADED:a.STATUS.NOT_LOADED,this.empty=" "},a.prototype.$id=function(){return this.$futureCardData.then(function(e){return e.id})},a.prototype.$path=function(){return[this.pid,this.id]},a.prototype.$isLoading=function(){return this.$loaded==a.STATUS.LOADING},a.prototype.$reload=function(){var e;return this.$futureCardData?this:(e=a.$$resource.fetch(this.$path(),"view"),this.$unwrap(e))},a.prototype.$members=function(){var t=this;return this.members?a.$q.when(this.members):this.$isGroup({expandable:!0})?a.$$resource.fetch(this.$path(),"members").then(function(e){return t.members=_.map(e.members,function(e){return new a(e)}),t.members}):a.$q.reject("Card "+this.id+" is not an LDAP group")},a.prototype.$save=function(e){var t,i=this,r="saveAsContact";return"vlist"==this.c_component&&(r="saveAsList",_.forEach(this.refs,function(e){e.reference=e.id})),t=this.$omit(),e&&e.ignoreDuplicate&&angular.extend(t,e),a.$$resource.save([a.encodeUri(this.pid),a.encodeUri(this.id)||"_new_"].join("/"),t,{action:r}).then(function(e){return i.birthday&&(i.$birthday=a.$Preferences.$mdDateLocaleProvider.formatDate(i.birthday)),i.$shadowData=i.$omit(!0),e})},a.prototype.$delete=function(e,t){if(!e)return a.$$resource.remove(this.$path());-1t?this[e].splice(t,1):delete this[e]},a.prototype.export=function(){var e={uids:[this.id]},t={type:"application/octet-stream",filename:this.$$fullname+".ldif"};return a.$$resource.download(this.pid,"export",e,t)},a.prototype.$fullname=function(t){function e(e){return t&&t.html&&e&&0":"")+e(this.nickname)+(s?"":"")),this.c_sn&&0"),t.join(" ")},a.prototype.$isCard=function(){return"vcard"==this.c_component},a.prototype.$isList=function(e){e=!e||!e.expandable||e.expandable&&!this.isgroup;return"vlist"==this.c_component&&e},a.prototype.$isGroup=function(e){e=!e||!e.expandable||e.expandable&&a.$Preferences.defaults.SOGoLDAPGroupExpansionEnabled;return this.isgroup&&e},a.prototype.$addOrg=function(e){return angular.isUndefined(this.orgs)?this.orgs=[e]:e==this.org||_.includes(this.orgs,e)||this.orgs.push(e),this.orgs.length-1},a.prototype.$addEmail=function(e){return angular.isUndefined(this.emails)?this.emails=[{type:e,value:""}]:_.isUndefined(_.find(this.emails,function(e){return""===e.value}))&&this.emails.push({type:e,value:""}),this.emails.length-1},a.prototype.$addScreenName=function(e){this.c_screenname=e},a.prototype.$addPhone=function(e){return angular.isUndefined(this.phones)?this.phones=[{type:e,value:""}]:_.isUndefined(_.find(this.phones,function(e){return""===e.value}))&&this.phones.push({type:e,value:""}),this.phones.length-1},a.prototype.$addUrl=function(e,t){return angular.isUndefined(this.urls)?this.urls=[{type:e,value:t}]:_.isUndefined(_.find(this.urls,function(e){return e.value==t}))&&this.urls.push({type:e,value:t}),this.urls.length-1},a.prototype.$addAddress=function(e,t,i,r,s,n,o,a){return angular.isUndefined(this.addresses)?this.addresses=[{type:e,postoffice:t,street:i,street2:r,locality:s,region:n,country:o,postalcode:a}]:_.find(this.addresses,function(e){return e.street==i&&e.street2==r&&e.locality==s&&e.country==o&&e.postalcode==a})||this.addresses.push({type:e,postoffice:t,street:i,street2:r,locality:s,region:n,country:o,postalcode:a}),this.addresses.length-1},a.prototype.$addMember=function(e){var t,i=new a({email:e,emails:[{value:e}]});if(angular.isUndefined(this.refs))this.refs=[i];else if(0===e.length)this.refs.push(i);else{for(t=0;t"),"["+e+"]"}})(); //# sourceMappingURL=Contacts.services.js.map