sogo/UI/WebServerResources/js/Contacts.services.js
2020-06-24 01:34:15 -04:00

2 lines
19 KiB
JavaScript

!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&&t<this.$cards.length&&(e=this.$cards[t],this.$lastVisibleIndex=Math.max(0,t-3),this.$loadCard(e))?e:null},l.prototype.$loadCard=function(t){var e,i,r,s,n=t.id,o=this.idsMap[n],a=this.$cards.length,d=!1;if(angular.isUndefined(this.ids)&&t.id)d=!0;else if(angular.isDefined(o)&&o<this.$cards.length&&(t.$loaded!=l.$Card.STATUS.NOT_LOADED&&(d=!0),e=Math.min(o+l.PRELOAD.LOOKAHEAD,a-1),this.$cards[e].$loaded!=l.$Card.STATUS.NOT_LOADED?(i=Math.max(o-l.PRELOAD.LOOKAHEAD,0),this.$cards[i].$loaded!=l.$Card.STATUS.LOADED&&(e=o,o=Math.max(o-l.PRELOAD.SIZE,0))):e=Math.min(o+l.PRELOAD.SIZE,a-1),this.$cards[o].$loaded==l.$Card.STATUS.NOT_LOADED||this.$cards[e].$loaded==l.$Card.STATUS.NOT_LOADED)){for(r=[];o<e&&o<a;o++)this.$cards[o].$loaded!=l.$Card.STATUS.NOT_LOADED?e++:(r.push(this.$cards[o].id),this.$cards[o].$loaded=l.$Card.STATUS.LOADING);l.$log.debug("Loading Ids "+r.join(" ")+" ("+r.length+" cards)"),0<r.length&&(s=l.$$resource.post(this.id,"headers",{ids:r}),this.$unwrapHeaders(s))}return d},l.prototype.hasSelectedCard=function(){return angular.isDefined(this.selectedCard)},l.prototype.isSelectedCard=function(t){return this.hasSelectedCard()&&this.selectedCard==t},l.prototype.$selectedCard=function(){var e=this;return _.find(this.$cards,function(t){return t.id==e.selectedCard})},l.prototype.$selectedCardIndex=function(){return _.indexOf(_.map(this.$cards,"id"),this.selectedCard)},l.prototype.$selectedCards=function(){return _.filter(this.$cards,function(t){return t.selected})},l.prototype.$selectedCount=function(){var t;return t=0,this.$cards&&(t=_.filter(this.$cards,function(t){return t.selected}).length),t},l.prototype.$startRefreshTimeout=function(){l.$refreshTimeout&&l.$timeout.cancel(l.$refreshTimeout);var t=l.$Preferences.defaults.SOGoRefreshViewCheck;if(t&&"manually"!=t){var e=angular.bind(this,l.prototype.$reload);l.$refreshTimeout=l.$timeout(e,1e3*t.timeInterval())}},l.prototype.$reload=function(){return this.$startRefreshTimeout(),this.$filter()},l.prototype.$filter=function(u,t,c){var e,h=this,i=t&&t.dry;return i?e={value:"",sort:"c_cn",asc:1}:(this.$isLoading=!0,e=l.$query,this.isRemote||(e.partial=1)),t&&(angular.extend(e,t),i&&!u)?(h.$$cards=[],l.$q.when(h.$$cards)):(angular.isDefined(u)&&(e.value=u),h.$id().then(function(d){var t=l.$$resource.post(d,"view",e);return i?t.then(function(t){function s(t){return this==t.id}var e,i,r,n,o,a=h.$$cards;for(t.headers&&(n=_.invokeMap(t.headers[0],"toLowerCase"),o=n.indexOf("id"),t.headers.splice(0,1),e=_.map(t.headers,function(t){return t[o]})),t.ids&&(e=c?_.filter(t.ids,function(t){return _.isUndefined(_.find(c,_.bind(s,t)))}):t.ids),r=a.length-1;0<=r;r--)i=a[r],_.isUndefined(_.find(e,_.bind(s,i.id)))&&a.splice(r,1);return _.forEach(e,function(t,e){if(_.isUndefined(_.find(a,_.bind(s,t)))){var i=new l.$Card({pid:d,id:t},u);a.splice(e,0,i)}}),_.forEach(e,function(t,e){var i,r;a[e].id!=t&&(i=_.findIndex(a,_.bind(s,t)),r=a.splice(i,1),a.splice(e,0,r[0]))}),_.forEach(t.headers,function(t){var e,i=_.findIndex(a,_.bind(s,t[o]));-1<i&&(e=_.zipObject(n,t),a[i].init(e,u))}),a}):h.$unwrap(t)}))},l.prototype.$rename=function(t){var e,i,r=this;return i=this.isSubscription?l.$subscriptions:l.$addressbooks,e=_.indexOf(_.map(i,"id"),this.id),this.$save().then(function(){i.splice(e,1),r.name=t,l.$add(r)})},l.prototype.$delete=function(){var e,t,i=this,r=l.$q.defer();return e=this.isSubscription?(t=l.$$resource.fetch(this.id,"unsubscribe"),l.$subscriptions):(t=l.$$resource.remove(this.id),l.$addressbooks),t.then(function(){var t=_.indexOf(_.map(e,"id"),i.id);e.splice(t,1),r.resolve()},r.reject),r.promise},l.prototype.$_deleteCards=function(r){var s=this;_.forEachRight(this.$cards,function(e,t){var i=_.findIndex(r,function(t){return e.id==t});-1<i?(r.splice(i,1),delete s.idsMap[e.id],s.isSelectedCard(e.id)&&delete s.selectedCard,s.$cards.splice(t,1)):s.idsMap[e.id]-=r.length})},l.prototype.$deleteCards=function(t){var e=this,i=_.map(t,"id");return l.$$resource.post(this.id,"batchDelete",{uids:i}).then(function(){e.$_deleteCards(i)})},l.prototype.$copyCards=function(t,e){var i=_.map(t,"id");return l.$$resource.post(this.id,"copy",{uids:i,folder:e})},l.prototype.$moveCards=function(t,e){var i,r=this;return i=_.map(t,"id"),l.$$resource.post(this.id,"move",{uids:i,folder:e}).then(function(){return r.$_deleteCards(i)})},l.prototype.$save=function(){return l.$$resource.save(this.id,this.$omit()).then(function(t){return t})},l.prototype.exportCards=function(t){var e,i,r=null;return e={type:"application/octet-stream",filename:this.name+".ldif"},t&&(i=_.filter(this.$cards,function(t){return t.selected}),r={uids:_.map(i,"id")}),r?l.$$resource.download(this.id,"export",r,e):l.$$resource.open(this.id,"export",r,e)},l.prototype.$unwrap=function(t){var o=this;this.$isLoading=!0,this.$futureAddressBookData=t.then(function(i){var n=_.map(o.$selectedCards(),"id");return l.$timeout(function(){var r;return(!i.ids||o.$topIndex>i.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=-1<n.indexOf(r.id),t.push(r),t},o.$cards)),i.headers&&(r=_.invokeMap(i.headers[0],"toLowerCase"),i.headers.splice(0,1),o.ids?_.forEach(i.headers,function(t){var e=_.zipObject(r,t),i=o.idsMap[e.id];o.$cards[i].init(e)}):(o.$cards=[],angular.forEach(i.headers,function(t){var e,i=_.zipObject(r,t);angular.extend(i,{pid:o.id}),(e=new l.$Card(i)).selected=-1<n.indexOf(e.id),o.$cards.push(e)}))),o.$acl=new l.$$Acl("Contacts/"+o.id),o.$startRefreshTimeout(),o.$isLoading=!1,l.$log.debug("addressbook "+o.id+" ready"),o})},function(t){o.isError=!0,angular.isObject(t)&&l.$timeout(function(){angular.extend(o,t)})})},l.prototype.$unwrapHeaders=function(t){var r=this;t.then(function(t){l.$timeout(function(){var e,i;0<t.length&&(e=_.invokeMap(t[0],"toLowerCase"),t.splice(0,1),_.forEach(t,function(t){t=_.zipObject(e,t),i=r.idsMap[t.id],angular.isDefined(i)&&r.$cards[i].init(t)}))})})},l.prototype.$omit=function(){var i={};return angular.forEach(this,function(t,e){"constructor"!=e&&"acls"!=e&&"ids"!=e&&"idsMap"!=e&&"urls"!=e&&"$"!=e[0]&&(i[e]=t)}),i}}(),function(){"use strict";function a(t,e){if("function"!=typeof t.then){if(this.init(t,e),this.pid&&!this.id){var i=a.$$resource.newguid(this.pid);this.$unwrap(i),this.isNew=!0}}else this.$unwrap(t)}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(t,e,i,r,s,n,o){return angular.extend(a,{STATUS:r,encodeUri:s,$$resource:new n(i.activeUser("folderURL")+"Contacts",i.activeUser()),$q:t,$timeout:e,$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(t){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(t,e){var i=this.$$resource.fetch([t,e].join("/"),"view");return e?new a(i):a.$unwrapCollection(i)},a.filterCategories=function(t){var e=new RegExp(t,"i");return _.map(_.filter(a.$categories,function(t){return-1!=t.search(e)}),function(t){return{value:t}})},a.$unwrapCollection=function(t){var i={};return(i.$futureCardData=t).then(function(t){a.$timeout(function(){angular.forEach(t,function(t,e){i[t.id]=new a(t)})})}),i},a.prototype.init=function(t,e){var i=this;if(angular.isUndefined(this.refs)&&(this.refs=[]),angular.isUndefined(this.categories)&&(this.categories=[]),this.c_screenname=null,angular.extend(this,t),this.pid||(this.pid=this.container),this.$$fullname||(this.$$fullname=this.$fullname()),this.$$email||(this.$$email=this.$preferredEmail(e)),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",t.orgs&&t.orgs.length&&(this.orgs=_.map(t.orgs,function(t){return{value:t}})),t.notes&&t.notes.length?this.notes=_.map(t.notes,function(t){return{value:t}}):this.notes&&this.notes.length||(this.notes=[{value:""}]),angular.forEach(["addresses","phones","urls"],function(t){angular.forEach(i[t],function(t){t.type&&(t.type=t.type.toLowerCase())})}),angular.forEach(this.refs,function(t,e){t.email&&(t.emails=[{value:t.email}]),t.id=t.reference,i.refs[e]=new a(t)}),this.birthday&&angular.isString(this.birthday)){var r=a.$Preferences.$mdDateLocaleProvider;this.birthday=this.birthday.parseDate(r,"%Y-%m-%d"),this.$birthday=r.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(t){return t.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 t;return this.$futureCardData?this:(t=a.$$resource.fetch(this.$path(),"view"),this.$unwrap(t))},a.prototype.$members=function(){var e=this;return this.members?a.$q.when(this.members):this.$isGroup({expandable:!0})?a.$$resource.fetch(this.$path(),"members").then(function(t){return e.members=_.map(t.members,function(t){return new a(t)}),e.members}):a.$q.reject("Card "+this.id+" is not an LDAP group")},a.prototype.$save=function(){var e=this,t="saveAsContact";return"vlist"==this.c_component&&(t="saveAsList",_.forEach(this.refs,function(t){t.reference=t.id})),a.$$resource.save([a.encodeUri(this.pid),a.encodeUri(this.id)||"_new_"].join("/"),this.$omit(),{action:t}).then(function(t){return e.birthday&&(e.$birthday=a.$Preferences.$mdDateLocaleProvider.formatDate(e.birthday)),e.$shadowData=e.$omit(!0),t})},a.prototype.$delete=function(t,e){if(!t)return a.$$resource.remove(this.$path());-1<e&&this[t].length>e?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.c_givenname.length&&i.push(this.c_givenname),this.nickname&&0<this.nickname.length&&i.push((s?"<em>":"")+this.nickname+(s?"</em>":"")),this.c_sn&&0<this.c_sn.length&&i.push(this.c_sn),0<i.length?r=i.join(" "):this.org&&0<this.org.length?r=this.org:this.emails&&0<this.emails.length&&(e=_.find(this.emails,function(t){return""!==t.value}))&&(r=e.value)),this.contactinfo&&(r+=" ("+this.contactinfo.split("\n").join("; ")+")"),r},a.prototype.$description=function(){var t=[];return this.title&&t.push(this.title),this.role&&t.push(this.role),this.org&&t.push(this.org),this.orgs&&(t=_.concat(t,_.map(this.orgs,"value"))),this.description&&t.push(this.description),t.join(", ")},a.prototype.$preferredEmail=function(t){var e,i;return t&&(i=new RegExp(t,"i"),e=_.find(this.emails,function(t){return i.test(t.value)})),e=e?e.value:(e=_.find(this.emails,function(t){return"pref"==t.type}))?e.value:this.emails&&this.emails.length?this.emails[0].value:this.c_mail&&this.c_mail.length?this.c_mail[0]:""},a.prototype.$shortFormat=function(t){var e=[this.$$fullname],i=this.$preferredEmail(t);return i&&i!=this.$$fullname&&e.push(" <"+i+">"),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<this.refs.length&&this.refs[e].email!=t;e++);e==this.refs.length&&this.refs.push(i)}return this.refs.length-1},a.prototype.$certificate=function(){var e=this;return this.hasCertificate?this.$$certificate?a.$q.when(this.$$certificate):a.$$resource.fetch(this.$path(),"certificate").then(function(t){return e.$$certificate=t}):a.$q.reject()},a.prototype.$removeCertificate=function(){var t=this;return a.$$resource.fetch(this.$path(),"removeCertificate").then(function(){t.hasCertificate=!1})},a.prototype.explode=function(){var i,r=[];return this.emails?1<this.emails.length?(i=this.$omit(),_.forEach(this.emails,function(t){var e=new a(angular.extend({},i,{emails:[t]}));r.push(e)}),r):[this]:[]},a.prototype.$reset=function(){var i=this;angular.forEach(this,function(t,e){"constructor"!=e&&"$"!=e[0]&&delete i[e]}),this.init(this.$shadowData),this.$shadowData=this.$omit(!0)},a.prototype.$unwrap=function(t){var e=this;return this.$loaded=a.STATUS.DELAYED_LOADING,a.$timeout(function(){e.$loaded!=a.STATUS.LOADED&&(e.$loaded=a.STATUS.LOADING)},a.STATUS.DELAYED_MS),this.$futureCardData=t.then(function(t){return e.init(t),e.$loaded=a.STATUS.LOADED,e.$shadowData=e.$omit(!0),e}),this.$futureCardData},a.prototype.$omit=function(i){var r={};return angular.forEach(this,function(t,e){"refs"==e?r.refs=_.map(t,function(t){return t.$omit(i)}):"constructor"!=e&&"$"!=e[0]&&(r[e]=i?angular.copy(t):t)}),i||(r.birthday?r.birthday=r.birthday.format(a.$Preferences.$mdDateLocaleProvider,"%Y-%m-%d"):r.birthday=""),this.orgs&&(r.orgs=_.map(this.orgs,"value")),this.notes&&(r.notes=_.map(this.notes,"value")),r},a.prototype.toString=function(){var t=this.id+" "+this.$$fullname;return this.$$email&&(t+=" <"+this.$$email+">"),"["+t+"]"}}();
//# sourceMappingURL=Contacts.services.js.map