!function(){"use strict";function l(t){if("function"!=typeof t.then)if(this.init(t),this.name&&!this.id){var e=l.$$resource.create("createFolder",this.name);this.$unwrap(e),this.acls={objectEditor:1,objectCreator:1,objectEraser:1}}else this.id&&(this.$acl=new l.$$Acl("Contacts/"+this.id));else this.$unwrap(t)}l.$factory=["$q","$timeout","$log","sgSettings","sgAddressBook_PRELOAD","Resource","Card","Acl","Preferences",function(t,e,i,r,s,n,o,a,d){return angular.extend(l,{$q:t,$timeout:e,$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(t){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,t,a){var e={search:n};return n?(angular.isUndefined(o)&&(o=[]),angular.extend(e,t),l.$$resource.fetch(null,"allContactSearch",e).then(function(t){function r(t){return this.id==t.id}var e,i,s;for(e=a?_.filter(t.contacts,function(t){return _.isUndefined(_.find(a,_.bind(r,t)))}):t.contacts,s=o.length-1;0<=s;s--)i=o[s],_.isUndefined(_.find(e,_.bind(r,i)))&&o.splice(s,1);return _.forEach(e,function(t,e){if(_.isUndefined(_.find(o,_.bind(r,t)))){var i=new l.$Card(_.mapKeys(t,function(t,e){return e.toLowerCase()}),n);o.splice(e,0,i)}}),l.$log.debug(o),o})):(o=[],l.$q.when(o))},l.$add=function(e){var t,i,r;t=e.isSubscription?this.$subscriptions:this.$addressbooks,r=(i=_.find(t,function(t){return"personal"==e.id||"personal"!=t.id&&1===t.name.localeCompare(e.name)}))?_.indexOf(_.map(t,"id"),i.id):1,t.splice(r,0,e)},l.$findAll=function(t){var r=this;if(t&&t.length)this.$addressbooks.splice(0,this.$addressbooks.length),this.$subscriptions.splice(0,this.$subscriptions.length),this.$remotes.splice(0,this.$remotes.length),angular.forEach(t,function(t,e){var i=new l(t);i.isRemote?r.$remotes.push(i):i.isSubscription?r.$subscriptions.push(i):r.$addressbooks.push(i)});else if(angular.isArray(t))return l.$$resource.fetch("addressbooksList").then(function(t){return l.$findAll(t.addressbooks)});return _.union(this.$addressbooks,this.$subscriptions,this.$remotes)},l.$subscribe=function(t,e){var i=this;return l.$$resource.userResource(t).fetch(e,"subscribe").then(function(e){var t=new l(e);return _.isUndefined(_.find(i.$subscriptions,function(t){return t.id==e.id}))&&l.$add(t),t})},l.$reloadAll=function(){var r=this;return l.$$resource.fetch("addressbooksList").then(function(t){_.forEach(t.addressbooks,function(e){var t,i;t=e.isRemote?r.$remotes:e.owner!=l.activeUser.login?r.$subscriptions:r.$addressbooks,(i=_.find(t,function(t){return t.id==e.id}))&&i.init(e)})})},l.prototype.init=function(t,e){var i=this;this.$$cards||(this.$$cards=[]),this.idsMap={},this.$cards=[],angular.forEach(t,function(t,e){"headers"!=e&&"cards"!=e&&(i[e]=t)}),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(t){return t?t.id:l.$q.reject()})},l.prototype.getLength=function(){return this.$cards.length},l.prototype.getItemAtIndex=function(t){var e;return!this.$isLoading&&0<=t&&ti.ids.length-1)&&(o.$topIndex=0),angular.forEach(l.$findAll(),function(t,e){t.id==i.id&&angular.extend(o,t)}),o.init(i),o.ids&&(l.$log.debug("unwrapping "+o.ids.length+" cards"),_.reduce(o.ids,function(t,e,i){var r,s={pid:o.id,id:e};return o.idsMap[s.id]=i,(r=new l.$Card(s)).selected=-1e?this[t].splice(e,1):delete this[t]},a.prototype.export=function(){var t,e;return t={uids:[this.id]},e={type:"application/octet-stream",filename:this.$$fullname+".ldif"},a.$$resource.download(this.pid,"export",t,e)},a.prototype.$fullname=function(t){var e,i,r=this.c_cn||"",s=t&&t.html;return 0===r.length&&(i=[],this.c_givenname&&0":"")+this.nickname+(s?"":"")),this.c_sn&&0"),e.join(" ")},a.prototype.$isCard=function(){return"vcard"==this.c_component},a.prototype.$isList=function(t){var e=!t||!t.expandable||t.expandable&&!this.isgroup;return"vlist"==this.c_component&&e},a.prototype.$isGroup=function(t){var e=!t||!t.expandable||t.expandable&&a.$Preferences.defaults.SOGoLDAPGroupExpansionEnabled;return this.isgroup&&e},a.prototype.$addOrg=function(t){return angular.isUndefined(this.orgs)?this.orgs=[t]:t==this.org||_.includes(this.orgs,t)||this.orgs.push(t),this.orgs.length-1},a.prototype.$addEmail=function(t){return angular.isUndefined(this.emails)?this.emails=[{type:t,value:""}]:_.isUndefined(_.find(this.emails,function(t){return""===t.value}))&&this.emails.push({type:t,value:""}),this.emails.length-1},a.prototype.$addScreenName=function(t){this.c_screenname=t},a.prototype.$addPhone=function(t){return angular.isUndefined(this.phones)?this.phones=[{type:t,value:""}]:_.isUndefined(_.find(this.phones,function(t){return""===t.value}))&&this.phones.push({type:t,value:""}),this.phones.length-1},a.prototype.$addUrl=function(t,e){return angular.isUndefined(this.urls)?this.urls=[{type:t,value:e}]:_.isUndefined(_.find(this.urls,function(t){return t.value==e}))&&this.urls.push({type:t,value:e}),this.urls.length-1},a.prototype.$addAddress=function(t,e,i,r,s,n,o,a){return angular.isUndefined(this.addresses)?this.addresses=[{type:t,postoffice:e,street:i,street2:r,locality:s,region:n,country:o,postalcode:a}]:_.find(this.addresses,function(t){return t.street==i&&t.street2==r&&t.locality==s&&t.country==o&&t.postalcode==a})||this.addresses.push({type:t,postoffice:e,street:i,street2:r,locality:s,region:n,country:o,postalcode:a}),this.addresses.length-1},a.prototype.$addMember=function(t){var e,i=new a({email:t,emails:[{value:t}]});if(angular.isUndefined(this.refs))this.refs=[i];else if(0===t.length)this.refs.push(i);else{for(e=0;e"),"["+t+"]"}}(); //# sourceMappingURL=Contacts.services.js.map