!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",["ngCookies","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,C.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:C.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(C.selectedFolder.$cards,function(a){a.selected=!1}),C.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(C.selectedFolder.$cards,function(a){return a.selected});C.selectedFolder.$deleteCards(a),delete C.selectedFolder.selectedCard})}function u(a){var b=_.filter(C.selectedFolder.$cards,function(a){return a.selected});C.selectedFolder.$copyCards(b,a).then(function(){})}function v(){_.forEach(C.selectedFolder.$cards,function(a){a.selected=!0}),C.mode.multiple=C.selectedFolder.$cards.length}function w(a){C.selectedFolder.$filter("",{sort:a})}function x(a){return i.$query.sort==a}function y(){C.mode.search=!1,C.selectedFolder.$filter("")}function z(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 A(a,b,c){var d=[{full:c+" <"+b+">"}];C.newMessage(a,d),a.stopPropagation(),a.preventDefault()}function B(a){var c=_.filter(C.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(C.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&&C.newMessage(a,e)})}var C=this;i.selectedFolder=n,C.service=i,C.selectedFolder=n,C.selectCard=o,C.toggleCardSelection=p,C.newComponent=q,C.notSelectedComponent=r,C.unselectCards=s,C.confirmDeleteSelectedCards=t,C.copySelectedCards=u,C.selectAll=v,C.sort=w,C.sortedBy=x,C.cancelSearch=y,C.newMessage=z,C.newMessageWithSelectedCards=B,C.newMessageWithRecipient=A,C.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&&E.editMode!=c.id?(E.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||(E.editMode=a.id,E.originalAddressbook=angular.extend({},a.$omit()),m("addressBookName_"+a.id))}function w(a){a.name=E.originalAddressbook.name,E.editMode=!1}function x(a){var b=a.name;b&&b.length>0&&b!=E.originalAddressbook.name&&a.$rename(b).then(function(a){E.editMode=!1},function(a,b){p.alert(l("Warning"),a)})}function y(){E.service.selectedFolder.isSubscription?E.service.selectedFolder.$delete().then(function(){E.service.selectedFolder=null,a.go("app.addressbook",{addressbookId:"personal"})},function(a,b){p.alert(l('An error occured while deleting the addressbook "%{0}".',E.service.selectedFolder.name),l(a.error))}):p.confirm(l("Warning"),l('Are you sure you want to delete the addressbook "%{0}"?',E.service.selectedFolder.name),{ok:l("Delete")}).then(function(){return E.service.selectedFolder.$delete()}).then(function(){return E.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}".',E.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(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 B(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 C(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 D(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 E=this;E.activeUser=q.activeUser,E.service=o,E.select=t,E.newAddressbook=u,E.edit=v,E.revertEditing=w,E.save=x,E.confirmDelete=y,E.importCards=z,E.showLinks=A,E.showProperties=B,E.share=C,E.subscribeToFolder=D}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=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