!function(){"use strict";function a(a,h){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},onEnter:f,onExit:g}).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"}}}),h.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,c){var d;return(d=_.find(c.$cards,function(a){return a.id==b.cardId}))?d.$reload():void a.go("app.addressbook")}function f(a,b){b.selectedCard=a.cardId}function g(a){delete c.selectedCard}function h(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",["ngCookies","ui.router","angularFileUpload","ck","SOGo.Common","SOGo.PreferencesUI","SOGo.MailerUI"]).config(a).run(h),a.$inject=["$stateProvider","$urlRouterProvider"],b.$inject=["AddressBook"],c.$inject=["$q","$state","$stateParams","AddressBook"],d.$inject=["$stateParams","stateAddressbook","Card"],e.$inject=["$state","$stateParams","stateAddressbook"],f.$inject=["$stateParams","stateAddressbook"],g.$inject=["stateAddressbook"],h.$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",{cardId:a.id})}function p(a,b){b.selected=!b.selected,B.mode.multiple+=b.selected?1:-1,a.preventDefault(),a.stopPropagation()}function q(a){d.go("app.addressbook.new",{contactType:a})}function r(){_.forEach(B.selectedFolder.$cards,function(a){a.selected=!1}),B.mode.multiple=0}function s(){j.confirm(l("Warning"),l("Are you sure you want to delete the selected contacts?"),{ok:l("Delete")}).then(function(){var a=_.filter(B.selectedFolder.$cards,function(a){return a.selected});B.selectedFolder.$deleteCards(a),delete B.selectedFolder.selectedCard})}function t(a){var b=_.filter(B.selectedFolder.$cards,function(a){return a.selected});B.selectedFolder.$copyCards(b,a).then(function(){})}function u(){_.forEach(B.selectedFolder.$cards,function(a){a.selected=!0}),B.mode.multiple=B.selectedFolder.$cards.length}function v(a){B.selectedFolder.$filter("",{sort:a})}function w(a){return i.$query.sort==a}function x(){B.mode.search=!1,B.selectedFolder.$filter("")}function y(a,b){g.$findAll().then(function(c){var d=_.find(c,function(a){return 0===a.id?a:void 0});d.$getMailboxes().then(function(c){d.$newMessage().then(function(c){angular.extend(c.editable,{to:b}),f.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"../Mail/UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccount:d,stateMessage:c}})})})})}function z(a,b,c){var d=[c+" <"+b+">"];B.newMessage(a,d),a.stopPropagation(),a.preventDefault()}function A(a){var c=_.filter(B.selectedFolder.$cards,function(a){return a.selected}),d=[],e=[];_.forEach(c,function(a){a.$isList({expandable:!0})?angular.isDefined(a.refs)&&a.refs.length?_.forEach(a.refs,function(a){a.email.length&&e.push(a.$shortFormat())}):d.push(a.$reload().then(function(a){_.forEach(a.refs,function(a){a.email.length&&e.push(a.$shortFormat())})})):a.c_mail.length&&e.push(a.$shortFormat())}),b.all(d).then(function(){e=_.uniq(e),e.length&&B.newMessage(a,e)})}var B=this;i.selectedFolder=n,B.service=i,B.selectedFolder=n,B.selectCard=o,B.toggleCardSelection=p,B.newComponent=q,B.unselectCards=r,B.confirmDeleteSelectedCards=s,B.copySelectedCards=t,B.selectAll=u,B.sort=v,B.sortedBy=w,B.cancelSearch=x,B.newMessage=y,B.newMessageWithSelectedCards=A,B.newMessageWithRecipient=z,B.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,t){function u(b,c){a.params.addressbookId!=c.id&&F.editMode!=c.id?(F.editMode=!1,p.$query.value="",i(m["gt-md"])||j("left").close(),a.go("app.addressbook",{addressbookId:c.id})):(b.preventDefault(),b.stopPropagation())}function v(){q.prompt(l("New addressbook"),l("Name of new addressbook")).then(function(a){var b=new p({name:a,isEditable:!0,isRemote:!1,owner:UserLogin});p.$add(b)})}function w(a){a.isRemote||(F.editMode=a.id,F.originalAddressbook=angular.extend({},a.$omit()),n("addressBookName_"+a.id))}function x(a){a.name=F.originalAddressbook.name,F.editMode=!1}function y(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){q.alert(l("Warning"),a)})}function z(){F.service.selectedFolder.isSubscription?F.service.selectedFolder.$delete().then(function(){F.service.selectedFolder=null,a.go("app.addressbook",{addressbookId:"personal"})},function(a,b){q.alert(l('An error occured while deleting the addressbook "%{0}".',F.service.selectedFolder.name),l(a.error))}):q.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;q.alert(l('An error occured while deleting the addressbook "%{0}".',F.service.selectedFolder.name),b)})}function A(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),p.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 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 p(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:s,folder:a}})})}function E(a){console.debug("subscribeToFolder "+a.owner+a.name),p.$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=r.activeUser,F.service=p,F.select=u,F.newAddressbook=v,F.edit=w,F.revertEditing=x,F.save=y,F.confirmDelete=z,F.importCards=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","sgConstant","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=B.card.$addOrgUnit("");h("orgUnit_"+a)}function o(){B.card.birthday=new Date}function p(){B.card.$addScreenName("")}function q(){var a=B.card.$addEmail("");h("email_"+a)}function r(){var a=B.card.$addPhone("");h("phone_"+a)}function s(){var a=B.card.$addUrl("","");h("url_"+a)}function t(){var a=B.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&&B.card.$save().then(function(a){var b=_.indexOf(_.map(e.selectedFolder.$cards,"id"),B.card.id);0>b?e.selectedFolder.$reload():e.selectedFolder.$cards[b]=angular.copy(B.card),i.go("app.addressbook.card.view",{cardId:B.card.id})})}function w(){i.go("app.addressbook",{addressbookId:e.selectedFolder.id}).then(function(){B.card=null,delete e.selectedFolder.selectedCard})}function x(){B.card.$reset()}function y(){B.card.$reset(),B.card.isNew?(B.card=null,delete e.selectedFolder.selectedCard,i.go("app.addressbook",{addressbookId:e.selectedFolder.id})):i.go("app.addressbook.card.view",{cardId:B.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(a){B.showRawSource||B.rawSource?B.showRawSource=!B.showRawSource:f.$$resource.post(B.currentFolder.id+"/"+B.card.id,"raw").then(function(a){B.rawSource=a,B.showRawSource=!0})}var B=this;B.card=k,B.currentFolder=e.selectedFolder,B.allEmailTypes=f.$EMAIL_TYPES,B.allTelTypes=f.$TEL_TYPES,B.allUrlTypes=f.$URL_TYPES,B.allAddressTypes=f.$ADDRESS_TYPES,B.categories={},B.userFilterResults=[],B.transformCategory=m,B.addOrgUnit=n,B.addBirthday=o,B.addScreenName=p,B.addEmail=q,B.addPhone=r,B.addUrl=s,B.addAddress=t,B.userFilter=u,B.save=v,B.close=w,B.reset=x,B.cancel=y,B.confirmDelete=z,B.toggleRawSource=A,B.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