!function(){"use strict";function a(a,f){a.state("app",{url:"/addressbooks","abstract":!0,views:{addressbooks:{templateUrl:"UIxContactFoldersView",controller:"AddressBooksController",controllerAs:"app"}},resolve:{stateAddressbooks:b}}).state("app.addressbook",{url:"/:addressbookId",views:{addressbook:{templateUrl:"addressbook",controller:"AddressBookController",controllerAs:"addressbook"}},resolve:{stateAddressbook:c}}).state("app.addressbook.new",{url:"/{contactType:(?:card|list)}/new",views:{card:{templateUrl:"UIxContactEditorTemplate",controller:"CardController",controllerAs:"editor"}},resolve:{stateCard:d}}).state("app.addressbook.card",{url:"/:cardId","abstract":!0,views:{card:{template:""}},resolve:{stateCard:e}}).state("app.addressbook.card.view",{url:"/view",views:{"card@app.addressbook":{templateUrl:"UIxContactViewTemplate",controller:"CardController",controllerAs:"editor"}}}).state("app.addressbook.card.editor",{url:"/edit",views:{"card@app.addressbook":{templateUrl:"UIxContactEditorTemplate",controller:"CardController",controllerAs:"editor"}}}),f.otherwise("/addressbooks/personal")}function b(a){return a.$findAll(window.contactFolders)}function c(a,b,c,d){var e=_.find(d.$findAll(),function(a){return a.id==c.addressbookId});return e?(e.selectedCard=!1,e.$reload(),e):a.reject("Addressbook "+c.addressbookId+" not found")}function d(a,b,c){var d="v"+a.contactType,e=new c({pid:a.addressbookId,c_component:d});return b.selectedCard=!0,e}function e(a,b){return b.selectedCard=a.cardId,b.$getCard(a.cardId)}function f(a,b,c){a.$on("$stateChangeError",function(a,d,e,f,g,h){b.error(h),c.go("app.addressbook",{addressbookId:"personal"})}),a.$on("$routeChangeError",function(a,c,d,e){b.error(a,c,d,e)})}angular.module("SOGo.ContactsUI",["ui.router","angularFileUpload","ck","SOGo.Common","SOGo.PreferencesUI","SOGo.MailerUI"]).config(a).run(f),a.$inject=["$stateProvider","$urlRouterProvider"],b.$inject=["AddressBook"],c.$inject=["$q","$state","$stateParams","AddressBook"],d.$inject=["$stateParams","stateAddressbook","Card"],e.$inject=["$stateParams","stateAddressbook"],f.$inject=["$rootScope","$log","$state"]}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j,k,m,n){function o(a){d.go("app.addressbook.card.view",{addressbookId:n.id,cardId:a.id})}function p(a,b){b.selected=!b.selected,D.mode.multiple+=b.selected?1:-1,a.preventDefault(),a.stopPropagation()}function q(a){function b(a,b,c,d){a.create=function(a){b.hide(),c.go("app.addressbook.new",{addressbookId:d,contactType:a})}}f.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!0,escapeToClose:!0,template:[''," ",' '," "," "+l("Contact")," "," "," "+l("List")," ","
"," ",""].join(""),locals:{addressbookId:D.selectedFolder.id},controller:b}),b.$inject=["scope","$mdDialog","$state","addressbookId"]}function r(a,b){return a&&a.c_component==b&&!a.selected}function s(){_.forEach(D.selectedFolder.$cards,function(a){a.selected=!1}),D.mode.multiple=0}function t(){j.confirm(l("Warning"),l("Are you sure you want to delete the selected contacts?"),{ok:l("Delete")}).then(function(){var a=_.filter(D.selectedFolder.$cards,function(a){return a.selected});D.selectedFolder.$deleteCards(a),delete D.selectedFolder.selectedCard})}function u(){var a=_.filter(D.selectedFolder.$cards,function(a){return a.selected}),b=_.map(a,"id");c.location.href=ApplicationBaseURL+"/"+D.selectedFolder.id+"/export?uid="+b.join("&uid=")}function v(a){var b=_.filter(D.selectedFolder.$cards,function(a){return a.selected});D.selectedFolder.$copyCards(b,a).then(function(){})}function w(){_.forEach(D.selectedFolder.$cards,function(a){a.selected=!0}),D.mode.multiple=D.selectedFolder.$cards.length}function x(a){D.selectedFolder.$filter("",{sort:a})}function y(a){return i.$query.sort==a}function z(){D.mode.search=!1,D.selectedFolder.$filter("")}function A(a,b){g.$findAll().then(function(c){var d=_.filter(c,function(a){return 0===a.id?a:void 0})[0];d.$getMailboxes().then(function(e){d.$newMessage().then(function(d){f.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"../Mail/UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:c,stateMessage:d,stateRecipients:b}})})})})}function B(a,b,c){var d=[{full:c+" <"+b+">"}];D.newMessage(a,d),a.stopPropagation(),a.preventDefault()}function C(a){var c=_.filter(D.selectedFolder.$cards,function(a){return a.selected}),d=[],e=[];_.forEach(c,function(a){"vcard"==a.c_component&&a.c_mail.length?e.push({full:a.c_cn+" <"+a.c_mail+">"}):a.$isList()&&(angular.isDefined(a.refs)&&a.refs.length?_.forEach(a.refs,function(a){a.email.length&&e.push({full:a.c_cn+" <"+a.email+">"})}):d.push(D.selectedFolder.$getCard(a.id).then(function(a){return a.$futureCardData.then(function(a){_.forEach(a.refs,function(a){a.email.length&&e.push({full:a.c_cn+" <"+a.email+">"})})})})))}),b.all(d).then(function(){e.length&&D.newMessage(a,e)})}var D=this;i.selectedFolder=n,D.service=i,D.selectedFolder=n,D.selectCard=o,D.toggleCardSelection=p,D.newComponent=q,D.notSelectedComponent=r,D.unselectCards=s,D.confirmDeleteSelectedCards=t,D.saveSelectedCards=u,D.copySelectedCards=v,D.selectAll=w,D.sort=x,D.sortedBy=y,D.cancelSearch=z,D.newMessage=A,D.newMessageWithSelectedCards=C,D.newMessageWithRecipient=B,D.mode={search:!1,multiple:0}}a.$inject=["$scope","$q","$window","$state","$timeout","$mdDialog","Account","Card","AddressBook","Dialog","sgSettings","stateAddressbooks","stateAddressbook"],angular.module("SOGo.ContactsUI").controller("AddressBookController",a)}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s){function t(b,c){a.params.addressbookId!=c.id&&F.editMode!=c.id?(F.editMode=!1,o.$query.value="",i("xs")&&j("left").close(),a.go("app.addressbook",{addressbookId:c.id})):(b.preventDefault(),b.stopPropagation())}function u(){p.prompt(l("New addressbook"),l("Name of new addressbook")).then(function(a){var b=new o({name:a,isEditable:!0,isRemote:!1,owner:UserLogin});o.$add(b)})}function v(a){a.isRemote||(F.editMode=a.id,F.originalAddressbook=angular.extend({},a.$omit()),m("addressBookName_"+a.id))}function w(a){a.name=F.originalAddressbook.name,F.editMode=!1}function x(a){var b=a.name;b&&b.length>0&&b!=F.originalAddressbook.name&&a.$rename(b).then(function(a){F.editMode=!1},function(a,b){p.alert(l("Warning"),a)})}function y(){F.service.selectedFolder.isSubscription?F.service.selectedFolder.$delete().then(function(){F.service.selectedFolder=null,a.go("app.addressbook",{addressbookId:"personal"})},function(a,b){p.alert(l('An error occured while deleting the addressbook "%{0}".',F.service.selectedFolder.name),l(a.error))}):p.confirm(l("Warning"),l('Are you sure you want to delete the addressbook "%{0}"?',F.service.selectedFolder.name),{ok:l("Delete")}).then(function(){return F.service.selectedFolder.$delete()}).then(function(){return F.service.selectedFolder=null,a.go("app.addressbook",{addressbookId:"personal"}),!0})["catch"](function(a){var b=a.data.message||a.statusText;p.alert(l('An error occured while deleting the addressbook "%{0}".',F.service.selectedFolder.name),b)})}function z(a,b){function c(a,b,c){function d(a){var b=0===a.type.indexOf("text")||/\.(ldif|vcf|vcard)$/.test(a.name);return b||h.show({template:["",' ',' error_outline'," "+l("Select a vCard or LDIF file.")+"","
",""].join(""),position:"top right",hideDelay:3e3}),b}var e=this;e.uploader=new k({url:ApplicationBaseURL+[c.id,"import"].join("/"),autoUpload:!0,queueLimit:1,filters:[{name:d,fn:d}],onSuccessItem:function(a,c,d,e){var f;b.hide(),0===c.imported?f=l("No card was imported."):(f=l("A total of %{0} cards were imported in the addressbook.",c.imported),o.selectedFolder.$reload()),h.show(h.simple().content(f).position("top right").hideDelay(3e3))},onErrorItem:function(a,b,c,d){h.show({template:["",' ',' error_outline'," "+l("An error occured while importing contacts.")+"","
",""].join(""),position:"top right",hideDelay:3e3})}}),e.close=function(){b.hide()}}g.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:"UIxContactsImportDialog",controller:c,controllerAs:"$CardsImportDialogController",locals:{folder:b}}),c.$inject=["scope","$mdDialog","folder"]}function A(){f.location.href=ApplicationBaseURL+"/"+F.service.selectedFolder.id+"/exportFolder"}function B(a){function b(a,b){function c(){a.hide()}this.addressbook=b,this.close=c}g.show({parent:angular.element(document.body),clickOutsideToClose:!0,escapeToClose:!0,templateUrl:a.id+"/links",controller:b,controllerAs:"links",locals:{addressbook:a}}),b.$inject=["$mdDialog","addressbook"]}function C(a){function b(a,b,c){function d(){f.addressbook.$save().then(function(){c.init(f.addressbook.$omit()),b.hide()})}function e(){b.cancel()}var f=this;f.addressbook=new o(c.$omit()),f.saveProperties=d,f.close=e}g.show({templateUrl:a.id+"/properties",controller:b,controllerAs:"properties",clickOutsideToClose:!0,escapeToClose:!0,locals:{srcAddressBook:a}})["catch"](function(){}),b.$inject=["$scope","$mdDialog","srcAddressBook"]}function D(a){a.$acl.$users().then(function(){g.show({templateUrl:a.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:a.$acl.users,User:r,folder:a}})})}function E(a){console.debug("subscribeToFolder "+a.owner+a.name),o.$subscribe(a.owner,a.name).then(function(a){h.show(h.simple().content(l("Successfully subscribed to address book")).position("top right").hideDelay(3e3))})}var F=this;F.activeUser=q.activeUser,F.service=o,F.select=t,F.newAddressbook=u,F.edit=v,F.revertEditing=w,F.save=x,F.confirmDelete=y,F.importCards=z,F.exportCards=A,F.showLinks=B,F.showProperties=C,F.share=D,F.subscribeToFolder=E}a.$inject=["$state","$scope","$rootScope","$stateParams","$timeout","$window","$mdDialog","$mdToast","$mdMedia","$mdSidenav","FileUploader","sgFocus","Card","AddressBook","Dialog","sgSettings","User","stateAddressbooks"],angular.module("SOGo.ContactsUI").controller("AddressBooksController",a)}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j,k){function m(a){return angular.isString(a)?{value:a}:a}function n(){var a=C.card.$addOrgUnit("");h("orgUnit_"+a)}function o(){C.card.birthday=new Date}function p(){C.card.$addScreenName("")}function q(){var a=C.card.$addEmail("");h("email_"+a)}function r(){var a=C.card.$addPhone("");h("phone_"+a)}function s(){var a=C.card.$addUrl("","");h("url_"+a)}function t(){var a=C.card.$addAddress("","","","","","","","");h("address_"+a)}function u(a,b){return e.selectedFolder.$filter(a,{dry:!0,excludeLists:!0},b),e.selectedFolder.$$cards}function v(a){a.$valid&&C.card.$save().then(function(a){var b=_.indexOf(_.map(e.selectedFolder.$cards,"id"),C.card.id);0>b?e.selectedFolder.$reload():e.selectedFolder.$cards[b]=angular.copy(C.card),i.go("app.addressbook.card.view",{cardId:C.card.id})})}function w(){i.go("app.addressbook",{addressbookId:e.selectedFolder.id}).then(function(){C.card=null,delete e.selectedFolder.selectedCard})}function x(){C.card.$reset()}function y(){C.card.$reset(),C.card.isNew?(C.card=null,delete e.selectedFolder.selectedCard,i.go("app.addressbook",{addressbookId:e.selectedFolder.id})):i.go("app.addressbook.card.view",{cardId:C.card.id})}function z(a){g.confirm(l("Warning"),l("Are you sure you want to delete the card of %{0}?",""+a.$fullname()+""),{ok:l("Delete")}).then(function(){a.$delete().then(function(){e.selectedFolder.$cards=_.reject(e.selectedFolder.$cards,function(b){return b.id==a.id}),w()},function(b,c){g.alert(l("Warning"),l('An error occured while deleting the card "%{0}".',a.$fullname()))})})}function A(){c.location.href=ApplicationBaseURL+"/"+C.currentFolder.id+"/export?uid="+C.card.id}function B(a){C.showRawSource||C.rawSource?C.showRawSource=!C.showRawSource:f.$$resource.post(C.currentFolder.id+"/"+C.card.id,"raw").then(function(a){C.rawSource=a,C.showRawSource=!0})}var C=this;C.card=k,C.currentFolder=e.selectedFolder,C.allEmailTypes=f.$EMAIL_TYPES,C.allTelTypes=f.$TEL_TYPES,C.allUrlTypes=f.$URL_TYPES,C.allAddressTypes=f.$ADDRESS_TYPES,C.categories={},C.userFilterResults=[],C.transformCategory=m,C.addOrgUnit=n,C.addBirthday=o,C.addScreenName=p,C.addEmail=q,C.addPhone=r,C.addUrl=s,C.addAddress=t,C.userFilter=u,C.save=v,C.close=w,C.reset=x,C.cancel=y,C.confirmDelete=z,C.exportCard=A,C.toggleRawSource=B,C.showRawSource=!1}a.$inject=["$scope","$timeout","$window","$mdDialog","AddressBook","Card","Dialog","sgFocus","$state","$stateParams","stateCard"],angular.module("SOGo.ContactsUI").controller("CardController",a)}(),function(){"use strict";function a(){return{restrict:"A",scope:{data:"=sgAddress"},controller:["$scope",function(a){a.addressLines=function(a){var b=[],c=[];return a.street&&b.push(a.street),a.street2&&b.push(a.street2),a.locality&&c.push(a.locality),a.region&&c.push(a.region),c.length>0&&b.push(c.join(", ")),a.country&&b.push(a.country),a.postalcode&&b.push(a.postalcode),b.join("
")}}],template:'
'}}angular.module("SOGo.Common").directive("sgAddress",a)}();
//# sourceMappingURL=Contacts.js.map