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

2 lines
19 KiB
JavaScript

!function(){"use strict";function l(t){var e;"function"!=typeof t.then?(this.init(t),this.name&&!this.id?(e=l.$$resource.create("createFolder",this.name),this.$unwrap(e),this.acls={objectEditor:1,objectCreator:1,objectEraser:1}):this.id&&(this.$acl=new l.$$Acl("Contacts/"+this.id))):this.$unwrap(t)}l.$factory=["$q","$timeout","$log","sgSettings","sgAddressBook_PRELOAD","Resource","Card","Acl","Preferences",function(t,e,i,r,n,s,o,a,d){return angular.extend(l,{$q:t,$timeout:e,$log:i,PRELOAD:n,$$resource:new s(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(s,o,t,a){var e={search:s};return s?(angular.isUndefined(o)&&(o=[]),angular.extend(e,t),l.$$resource.fetch(null,"allContactSearch",e).then(function(t){for(var e,i=function(t){return this.id==t.id},r=a?_.filter(t.contacts,function(t){return _.isUndefined(_.find(a,_.bind(i,t)))}):t.contacts,n=o.length-1;0<=n;n--)e=o[n],_.isUndefined(_.find(r,_.bind(i,e)))&&o.splice(n,1);return _.forEach(r,function(t,e){_.isUndefined(_.find(o,_.bind(i,t)))&&(t=new l.$Card(_.mapKeys(t,function(t,e){return e.toLowerCase()}),s),o.splice(e,0,t))}),l.$log.debug(o),o})):l.$q.when(o=[])},l.$add=function(e){var t=e.isSubscription?this.$subscriptions:this.$addressbooks,i=_.find(t,function(t){return"personal"==e.id||"personal"!=t.id&&1===t.name.localeCompare(e.name)}),i=i?_.indexOf(_.map(t,"id"),i.id):1;t.splice(i,0,e)},l.$findAll=function(t){var i=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){t=new l(t);(t.isRemote?i.$remotes:t.isSubscription?i.$subscriptions:i.$addressbooks).push(t)});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 i=this;return l.$$resource.fetch("addressbooksList").then(function(t){_.forEach(t.addressbooks,function(e){var t=e.isRemote?i.$remotes:e.owner!=l.activeUser.login?i.$subscriptions:i.$addressbooks,t=_.find(t,function(t){return t.id==e.id});t&&t.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,n=t.id,s=this.idsMap[n],o=this.$cards.length,n=!1;if(angular.isUndefined(this.ids)&&t.id)n=!0;else if(angular.isDefined(s)&&s<this.$cards.length&&(t.$loaded!=l.$Card.STATUS.NOT_LOADED&&(n=!0),e=Math.min(s+l.PRELOAD.LOOKAHEAD,o-1),this.$cards[e].$loaded!=l.$Card.STATUS.NOT_LOADED?(r=Math.max(s-l.PRELOAD.LOOKAHEAD,0),this.$cards[r].$loaded!=l.$Card.STATUS.LOADED&&(e=s,s=Math.max(s-l.PRELOAD.SIZE,0))):e=Math.min(s+l.PRELOAD.SIZE,o-1),this.$cards[s].$loaded==l.$Card.STATUS.NOT_LOADED||this.$cards[e].$loaded==l.$Card.STATUS.NOT_LOADED)){for(i=[];s<e&&s<o;s++)this.$cards[s].$loaded!=l.$Card.STATUS.NOT_LOADED?e++:(i.push(this.$cards[s].id),this.$cards[s].$loaded=l.$Card.STATUS.LOADING);l.$log.debug("Loading Ids "+i.join(" ")+" ("+i.length+" cards)"),0<i.length&&(r=l.$$resource.post(this.id,"headers",{ids:i}),this.$unwrapHeaders(r))}return n},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=0;return t=this.$cards?_.filter(this.$cards,function(t){return t.selected}).length:t},l.prototype.$startRefreshTimeout=function(){l.$refreshTimeout&&l.$timeout.cancel(l.$refreshTimeout);var t,e=l.$Preferences.defaults.SOGoRefreshViewCheck;e&&"manually"!=e&&(t=angular.bind(this,l.prototype.$reload),l.$refreshTimeout=l.$timeout(t,1e3*e.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 i(t){return this==t.id}var e,r,n,s,o,a=h.$$cards;for(t.headers&&(s=_.invokeMap(t.headers[0],"toLowerCase"),o=s.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(i,t)))}):t.ids),n=a.length-1;0<=n;n--)r=a[n],_.isUndefined(_.find(e,_.bind(i,r.id)))&&a.splice(n,1);return _.forEach(e,function(t,e){_.isUndefined(_.find(a,_.bind(i,t)))&&(t=new l.$Card({pid:d,id:t},u),a.splice(e,0,t))}),_.forEach(e,function(t,e){a[e].id!=t&&(t=_.findIndex(a,_.bind(i,t)),t=a.splice(t,1),a.splice(e,0,t[0]))}),_.forEach(t.headers,function(t){var e=_.findIndex(a,_.bind(i,t[o]));-1<e&&(t=_.zipObject(s,t),a[e].init(t,u))}),a}):h.$unwrap(t)}))},l.prototype.$rename=function(t){var e=this,i=this.isSubscription?l.$subscriptions:l.$addressbooks,r=_.indexOf(_.map(i,"id"),this.id);return this.$save().then(function(){i.splice(r,1),e.name=t,l.$add(e)})},l.prototype.$delete=function(){var t,e=this,i=l.$q.defer(),r=this.isSubscription?(t=l.$$resource.fetch(this.id,"unsubscribe"),l.$subscriptions):(t=l.$$resource.remove(this.id),l.$addressbooks);return t.then(function(){var t=_.indexOf(_.map(r,"id"),e.id);r.splice(t,1),i.resolve()},i.reject),i.promise},l.prototype.$_deleteCards=function(r){var n=this;_.forEachRight(this.$cards,function(e,t){var i=_.findIndex(r,function(t){return e.id==t});-1<i?(r.splice(i,1),delete n.idsMap[e.id],n.isSelectedCard(e.id)&&delete n.selectedCard,n.$cards.splice(t,1)):n.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){t=_.map(t,"id");return l.$$resource.post(this.id,"copy",{uids:t,folder:e})},l.prototype.$moveCards=function(t,e){var i=this,r=_.map(t,"id");return l.$$resource.post(this.id,"move",{uids:r,folder:e}).then(function(){return i.$_deleteCards(r)})},l.prototype.$save=function(){return l.$$resource.save(this.id,this.$omit()).then(function(t){return t})},l.prototype.exportCards=function(t){var e=null,i={type:"application/octet-stream",filename:this.name+".ldif"};return t&&(t=_.filter(this.$cards,function(t){return t.selected}),e={uids:_.map(t,"id")}),e?l.$$resource.download(this.id,"export",e,i):l.$$resource.open(this.id,"export",e,i)},l.prototype.$unwrap=function(t){var s=this;this.$isLoading=!0,this.$futureAddressBookData=t.then(function(r){var n=_.map(s.$selectedCards(),"id");return l.$timeout(function(){var i;return(!r.ids||s.$topIndex>r.ids.length-1)&&(s.$topIndex=0),angular.forEach(l.$findAll(),function(t,e){t.id==r.id&&angular.extend(s,t)}),s.init(r),s.ids&&(l.$log.debug("unwrapping "+s.ids.length+" cards"),_.reduce(s.ids,function(t,e,i){e={pid:s.id,id:e};return s.idsMap[e.id]=i,(e=new l.$Card(e)).selected=-1<n.indexOf(e.id),t.push(e),t},s.$cards)),r.headers&&(i=_.invokeMap(r.headers[0],"toLowerCase"),r.headers.splice(0,1),s.ids?_.forEach(r.headers,function(t){var e=_.zipObject(i,t),t=s.idsMap[e.id];s.$cards[t].init(e)}):(s.$cards=[],angular.forEach(r.headers,function(t){t=_.zipObject(i,t);angular.extend(t,{pid:s.id}),(t=new l.$Card(t)).selected=-1<n.indexOf(t.id),s.$cards.push(t)}))),s.$acl=new l.$$Acl("Contacts/"+s.id),s.$startRefreshTimeout(),s.$isLoading=!1,l.$log.debug("addressbook "+s.id+" ready"),s})},function(t){s.isError=!0,angular.isObject(t)&&l.$timeout(function(){angular.extend(s,t)})})},l.prototype.$unwrapHeaders=function(t){var r=this,n=l.$q.defer();return this.$futureHeadersData=n.promise,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)})),n.resolve(r.$cards)})},function(){n.reject()}),this.$futureHeadersData},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 d(t,e){"function"!=typeof t.then?(this.init(t,e),this.pid&&!this.id&&(e=d.$$resource.newguid(this.pid),this.$unwrap(e),this.isNew=!0)):this.$unwrap(t)}d.$TEL_TYPES=["work","home","cell","fax","pager"],d.$EMAIL_TYPES=["work","home","pref"],d.$URL_TYPES=["work","home","pref"],d.$ADDRESS_TYPES=["work","home"],d.$factory=["$q","$timeout","sgSettings","sgCard_STATUS","encodeUriFilter","linkyFilter","Resource","Preferences",function(t,e,i,r,n,s,o,a){return angular.extend(d,{STATUS:r,encodeUri:n,linky:s,$$resource:new o(i.activeUser("folderURL")+"Contacts",i.activeUser()),$q:t,$timeout:e,$Preferences:a}),a.defaults.SOGoContactsCategories&&(d.$categories=a.defaults.SOGoContactsCategories),a.defaults.SOGoAlternateAvatar&&(d.$alternateAvatar=a.defaults.SOGoAlternateAvatar),d}];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",d.$factory),d.$find=function(t,e){t=this.$$resource.fetch([t,e].join("/"),"view");return e?new d(t):d.$unwrapCollection(t)},d.filterCategories=function(t){var e=new RegExp(t,"i");return _.map(_.filter(d.$categories,function(t){return-1!=t.search(e)}),function(t){return{value:t}})},d.$unwrapCollection=function(t){var i={};return(i.$futureCardData=t).then(function(t){d.$timeout(function(){angular.forEach(t,function(t,e){i[t.id]=new d(t)})})}),i},d.prototype.init=function(t,e){var i=this;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=d.$Preferences.avatar(this.$$email,40,{no_404:!0})),this.hasphoto&&(this.photoURL=d.$$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 d(t)}),this.birthday&&angular.isString(this.birthday)&&(t=d.$Preferences.$mdDateLocaleProvider,this.birthday=this.birthday.parseDate(t,"%Y-%m-%d"),this.$birthday=t.formatDate(this.birthday)),this.$loaded=angular.isDefined(this.c_name)?d.STATUS.LOADED:d.STATUS.NOT_LOADED,this.empty=" "},d.prototype.$id=function(){return this.$futureCardData.then(function(t){return t.id})},d.prototype.$path=function(){return[this.pid,this.id]},d.prototype.$isLoading=function(){return this.$loaded==d.STATUS.LOADING},d.prototype.$reload=function(){var t;return this.$futureCardData?this:(t=d.$$resource.fetch(this.$path(),"view"),this.$unwrap(t))},d.prototype.$members=function(){var e=this;return this.members?d.$q.when(this.members):this.$isGroup({expandable:!0})?d.$$resource.fetch(this.$path(),"members").then(function(t){return e.members=_.map(t.members,function(t){return new d(t)}),e.members}):d.$q.reject("Card "+this.id+" is not an LDAP group")},d.prototype.$save=function(t){var e,i=this,r="saveAsContact";return"vlist"==this.c_component&&(r="saveAsList",_.forEach(this.refs,function(t){t.reference=t.id})),e=this.$omit(),t&&t.ignoreDuplicate&&angular.extend(e,t),d.$$resource.save([d.encodeUri(this.pid),d.encodeUri(this.id)||"_new_"].join("/"),e,{action:r}).then(function(t){return i.birthday&&(i.$birthday=d.$Preferences.$mdDateLocaleProvider.formatDate(i.birthday)),i.$shadowData=i.$omit(!0),t})},d.prototype.$delete=function(t,e){if(!t)return d.$$resource.remove(this.$path());-1<e&&this[t].length>e?this[t].splice(e,1):delete this[t]},d.prototype.export=function(){var t={uids:[this.id]},e={type:"application/octet-stream",filename:this.$$fullname+".ldif"};return d.$$resource.download(this.pid,"export",t,e)},d.prototype.$fullname=function(t){var e,i=d.linky(this.c_cn)||"",r=t&&t.html;return 0===i.length&&(t=[],this.c_givenname&&0<this.c_givenname.length&&t.push(d.linky(this.c_givenname)),this.nickname&&0<this.nickname.length&&t.push((r?"<em>":"")+d.linky(this.nickname)+(r?"</em>":"")),this.c_sn&&0<this.c_sn.length&&t.push(d.linky(this.c_sn)),0<t.length?i=t.join(" "):this.org&&0<this.org.length?i=d.linky(this.org):this.emails&&0<this.emails.length&&(e=_.find(this.emails,function(t){return""!==t.value}))&&(i=d.linky(e.value))),this.contactinfo&&(i+=" ("+d.linky(this.contactinfo.split("\n").join("; "))+")"),i},d.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(", ")},d.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||_.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]:""},d.prototype.$shortFormat=function(t){var e=[this.$$fullname],t=this.$preferredEmail(t);return t&&t!=this.$$fullname&&e.push(" <"+t+">"),e.join(" ")},d.prototype.$isCard=function(){return"vcard"==this.c_component},d.prototype.$isList=function(t){t=!t||!t.expandable||t.expandable&&!this.isgroup;return"vlist"==this.c_component&&t},d.prototype.$isGroup=function(t){t=!t||!t.expandable||t.expandable&&d.$Preferences.defaults.SOGoLDAPGroupExpansionEnabled;return this.isgroup&&t},d.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},d.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},d.prototype.$addScreenName=function(t){this.c_screenname=t},d.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},d.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},d.prototype.$addAddress=function(t,e,i,r,n,s,o,a){return angular.isUndefined(this.addresses)?this.addresses=[{type:t,postoffice:e,street:i,street2:r,locality:n,region:s,country:o,postalcode:a}]:_.find(this.addresses,function(t){return t.street==i&&t.street2==r&&t.locality==n&&t.country==o&&t.postalcode==a})||this.addresses.push({type:t,postoffice:e,street:i,street2:r,locality:n,region:s,country:o,postalcode:a}),this.addresses.length-1},d.prototype.$addMember=function(t){var e,i=new d({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},d.prototype.$certificate=function(){var e=this;return this.hasCertificate?this.$$certificate?d.$q.when(this.$$certificate):d.$$resource.fetch(this.$path(),"certificate").then(function(t){return e.$$certificate=t}):d.$q.reject()},d.prototype.$removeCertificate=function(){var t=this;return d.$$resource.fetch(this.$path(),"removeCertificate").then(function(){t.hasCertificate=!1})},d.prototype.explode=function(){var e,i=[];return this.emails?1<this.emails.length?(e=this.$omit(),_.forEach(this.emails,function(t){t=new d(angular.extend({},e,{emails:[t]}));i.push(t)}),i):[this]:[]},d.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)},d.prototype.$unwrap=function(t){var e=this;return this.$loaded=d.STATUS.DELAYED_LOADING,d.$timeout(function(){e.$loaded!=d.STATUS.LOADED&&(e.$loaded=d.STATUS.LOADING)},d.STATUS.DELAYED_MS),this.$futureCardData=t.then(function(t){return e.init(t),e.$loaded=d.STATUS.LOADED,e.$shadowData=e.$omit(!0),e}),this.$futureCardData},d.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(d.$Preferences.$mdDateLocaleProvider,"%Y-%m-%d"):r.birthday=""),this.orgs&&(r.orgs=_.map(this.orgs,"value")),this.notes&&(r.notes=_.map(this.notes,"value")),r},d.prototype.toString=function(){var t=this.id+" "+this.$$fullname;return this.$$email&&(t+=" <"+this.$$email+">"),"["+t+"]"}}();
//# sourceMappingURL=Contacts.services.js.map