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

2 lines
17 KiB
JavaScript
Raw Normal View History

2017-12-16 07:28:47 +01:00
!function(){"use strict";function t(e){if("function"!=typeof e.then)if(this.init(e),this.name&&!this.id){var i=t.$$resource.create("createFolder",this.name);this.$unwrap(i),this.acls={objectEditor:1,objectCreator:1,objectEraser:1}}else this.id&&(this.$acl=new t.$$Acl("Contacts/"+this.id));else this.$unwrap(e)}t.$factory=["$q","$timeout","$log","sgSettings","sgAddressBook_PRELOAD","Resource","Card","Acl","Preferences",function(e,i,r,s,n,a,o,d,u){return angular.extend(t,{$q:e,$timeout:i,$log:r,PRELOAD:n,$$resource:new a(s.activeUser("folderURL")+"Contacts",s.activeUser()),$Card:o,$$Acl:d,$Preferences:u,$query:{value:"",sort:"c_cn",asc:1},activeUser:s.activeUser(),selectedFolder:null,$refreshTimeout:null}),u.settings.Contact.SortingState&&(t.$query.sort=u.settings.Contact.SortingState[0],t.$query.asc=parseInt(u.settings.Contact.SortingState[1])),t}];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",t.$factory),t.$filterAll=function(e,i,r){var s={search:e};return e?(angular.isUndefined(t.$cards)&&(t.$cards=[]),angular.extend(s,i),t.$$resource.fetch(null,"allContactSearch",s).then(function(i){var s,n,a,o=function(t){return this.id==t.id};for(s=r?_.filter(i.contacts,function(t){return _.isUndefined(_.find(r,_.bind(o,t)))}):i.contacts,a=t.$cards.length-1;a>=0;a--)n=t.$cards[a],_.isUndefined(_.find(s,_.bind(o,n)))&&t.$cards.splice(a,1);return _.forEach(s,function(i,r){if(_.isUndefined(_.find(t.$cards,_.bind(o,i)))){var s=new t.$Card(_.mapKeys(i,function(t,e){return e.toLowerCase()}),e);t.$cards.splice(r,0,s)}}),t.$log.debug(t.$cards),t.$cards})):(t.$cards=[],t.$q.when(t.$cards))},t.$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)},t.$findAll=function(e){var i=this;return e&&(this.$addressbooks=[],this.$subscriptions=[],this.$remotes=[],angular.forEach(e,function(e,r){var s=new t(e);s.isRemote?i.$remotes.push(s):s.isSubscription?i.$subscriptions.push(s):i.$addressbooks.push(s)})),_.union(this.$addressbooks,this.$subscriptions,this.$remotes)},t.$subscribe=function(e,i){var r=this;return t.$$resource.userResource(e).fetch(i,"subscribe").then(function(e){var i=new t(e);return _.isUndefined(_.find(r.$subscriptions,function(t){return t.id==e.id}))&&t.$add(i),i})},t.$reloadAll=function(){var e=this;return t.$$resource.fetch("addressbooksList").then(function(i){_.forEach(i.addressbooks,function(i){var r,s;r=i.isRemote?e.$remotes:i.owner!=t.activeUser.login?e.$subscriptions:e.$addressbooks,(s=_.find(r,function(t){return t.id==i.id}))&&s.init(i)})})},t.prototype.init=function(e,i){var r=this;this.$$cards||(this.$$cards=[]),this.idsMap={},this.$cards=[],angular.forEach(e,function(t,e){"headers"!=e&&"cards"!=e&&(r[e]=t)}),this.isOwned=t.activeUser.isSuperUser||this.owner==t.activeUser.login,this.isSubscription=!this.isRemote&&this.owner!=t.activeUser.login},t.prototype.$id=function(){return this.id?t.$q.when(this.id):this.$futureAddressBookData.then(function(t){return t.id})},t.prototype.getLength=function(){return this.$cards.length},t.prototype.getItemAtIndex=function(t){var e;return!this.$isLoading&&t>=0&&t<this.$cards.length&&(e=this.$cards[t],this.$lastVisibleIndex=Math.max(0,t-3),this.$loadCard(e))?e:null},t.prototype.$loadCard=function(e){var i,r,s,n,a=e.id,o=this.idsMap[a],d=this.$cards.length,u=!1;if(angular.isUndefined(this.ids)&&e.id)u=!0;else if(angular.isDefined(o)&&o<this.$cards.length&&(e.$loaded!=t.$Card.STATUS.NOT_LOADED&&(u=!0),i=Math.min(o+t.PRELOAD.LOOKAHEAD,d-1),this.$cards[i].$loaded!=t.$Card.STATUS.NOT_LOADED?(r=Math.max(o-t.PRELOAD.LOOKAHEAD,0),this.$cards[r].$loaded!=t.$Card.STATUS.LOADED&&(i=o,o=Math.max(o-t.PRELOAD.SIZE,0))):i=Math.min(o+t.PRELOAD.SIZE,d-1),this.$cards[o].$loaded==t.$Card.STATUS.NOT_LOADED||this.$cards[i].$loaded==t.$Card.STATUS.NOT_
//# sourceMappingURL=Contacts.services.js.map