sogo/UI/WebServerResources/js/Contacts.services.js

2 lines
19 KiB
JavaScript
Raw Normal View History

2019-11-22 07:17:37 +01:00
!function(){"use strict";function l(e){if("function"!=typeof e.then)if(this.init(e),this.name&&!this.id){var t=l.$$resource.create("createFolder",this.name);this.$unwrap(t),this.acls={objectEditor:1,objectCreator:1,objectEraser:1}}else this.id&&(this.$acl=new l.$$Acl("Contacts/"+this.id));else 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,e,o){var t={search:n};return n?(angular.isUndefined(l.$cards)&&(l.$cards=[]),angular.extend(t,e),l.$$resource.fetch(null,"allContactSearch",t).then(function(e){function r(e){return this.id==e.id}var t,i,s;for(t=o?_.filter(e.contacts,function(e){return _.isUndefined(_.find(o,_.bind(r,e)))}):e.contacts,s=l.$cards.length-1;0<=s;s--)i=l.$cards[s],_.isUndefined(_.find(t,_.bind(r,i)))&&l.$cards.splice(s,1);return _.forEach(t,function(e,t){if(_.isUndefined(_.find(l.$cards,_.bind(r,e)))){var i=new l.$Card(_.mapKeys(e,function(e,t){return t.toLowerCase()}),n);l.$cards.splice(t,0,i)}}),l.$log.debug(l.$cards),l.$cards})):(l.$cards=[],l.$q.when(l.$cards))},l.$add=function(t){var e,i,r;e=t.isSubscription?this.$subscriptions:this.$addressbooks,r=(i=_.find(e,function(e){return"personal"==t.id||"personal"!=e.id&&1===e.name.localeCompare(t.name)}))?_.indexOf(_.map(e,"id"),i.id):1,e.splice(r,0,t)},l.$findAll=function(e){var r=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){var i=new l(e);i.isRemote?r.$remotes.push(i):i.isSubscription?r.$subscriptions.push(i):r.$addressbooks.push(i)});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 r=this;return l.$$resource.fetch("addressbooksList").then(function(e){_.forEach(e.addressbooks,function(t){var e,i;e=t.isRemote?r.$remotes:t.owner!=l.activeUser.login?r.$subscriptions:r.$addressbooks,(i=_.find(e,function(e){return e.id==t.id}))&&i.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&&e<this.$cards.length&&(t=this.$cards[e],this.$lastVisibleIndex=Math.max(0,e-3),this.$loadCard(t))?t:null},l.prototype.$loadCard=function(e){var t,i,r,s,n=e.id,o=this.idsMap[n],a=this.$cards.length,d=!1;if(angular.isUndefined(this.ids)&&e.id)d=!0;else if(angular.isDefined(o)&&o<this.$cards.length&&(e.$loaded!=l.$Card.STATUS.NOT_LOADED&&(d=!0),t=Math.min(o+l.PRELOAD.LOOKAHEAD,a-1),this.$
//# sourceMappingURL=Contacts.services.js.map