(function(){"use strict";angular.module("SOGo.ContactsUI",["ngSanitize","ui.router","angularFileUpload","ck","SOGo.Common","SOGo.PreferencesUI","SOGo.MailerUI"]).config(configure).run(runBlock);configure.$inject=["$stateProvider","$urlRouterProvider"];function configure($stateProvider,$urlRouterProvider){$stateProvider.state("app",{url:"/addressbooks","abstract":true,views:{addressbooks:{templateUrl:"UIxContactFoldersView",controller:"AddressBooksController",controllerAs:"app"}},resolve:{stateAddressbooks:stateAddressbooks}}).state("app.addressbook",{url:"/:addressbookId",views:{addressbook:{templateUrl:"addressbook",controller:"AddressBookController",controllerAs:"addressbook"}},resolve:{stateAddressbook:stateAddressbook}}).state("app.addressbook.new",{url:"/{contactType:(?:card|list)}/new",views:{card:{templateUrl:"UIxContactEditorTemplate",controller:"CardController",controllerAs:"editor"}},resolve:{stateCard:stateNewCard}}).state("app.addressbook.card",{url:"/:cardId","abstract":true,views:{card:{template:""}},resolve:{stateCard:stateCard}}).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"}}});$urlRouterProvider.otherwise("/addressbooks/personal")}stateAddressbooks.$inject=["AddressBook"];function stateAddressbooks(AddressBook){return AddressBook.$findAll(window.contactFolders)}stateAddressbook.$inject=["$stateParams","stateAddressbooks","AddressBook"];function stateAddressbook($stateParams,stateAddressbooks,AddressBook){var addressbook=_.find(stateAddressbooks,function(addressbook){return addressbook.id==$stateParams.addressbookId});addressbook.$reload();return addressbook}stateNewCard.$inject=["$stateParams","stateAddressbook","Card"];function stateNewCard($stateParams,stateAddressbook,Card){var tag="v"+$stateParams.contactType,card=new Card({pid:$stateParams.addressbookId,c_component:tag});stateAddressbook.selectedCard=true;return card}stateCard.$inject=["$stateParams","stateAddressbook"];function stateCard($stateParams,stateAddressbook){stateAddressbook.selectedCard=$stateParams.cardId;return stateAddressbook.$getCard($stateParams.cardId)}runBlock.$inject=["$rootScope","$log","$state"];function runBlock($rootScope,$log,$state){$rootScope.$on("$stateChangeError",function(event,toState,toParams,fromState,fromParams,error){$log.error(error);$state.go("app")});$rootScope.$on("$routeChangeError",function(event,current,previous,rejection){$log.error(event,current,previous,rejection)})}})();(function(){"use strict";AddressBookController.$inject=["$scope","$q","$state","$timeout","$mdDialog","Account","Card","AddressBook","Dialog","sgSettings","stateAddressbooks","stateAddressbook"];function AddressBookController($scope,$q,$state,$timeout,$mdDialog,Account,Card,AddressBook,Dialog,Settings,stateAddressbooks,stateAddressbook){var vm=this;AddressBook.selectedFolder=stateAddressbook;vm.service=AddressBook;vm.selectedFolder=stateAddressbook;vm.selectCard=selectCard;vm.toggleCardSelection=toggleCardSelection;vm.newComponent=newComponent;vm.notSelectedComponent=notSelectedComponent;vm.unselectCards=unselectCards;vm.confirmDeleteSelectedCards=confirmDeleteSelectedCards;vm.saveSelectedCards=saveSelectedCards;vm.copySelectedCards=copySelectedCards;vm.selectAll=selectAll;vm.sort=sort;vm.sortedBy=sortedBy;vm.cancelSearch=cancelSearch;vm.newMessage=newMessage;vm.newMessageWithSelectedCards=newMessageWithSelectedCards;vm.newMessageWithRecipient=newMessageWithRecipient;vm.mode={search:false};function selectCard(card){$state.go("app.addressbook.card.view",{addressbookId:stateAddressbook.id,cardId:card.id})}function toggleCardSelection($event,card){card.selected=!card.selected;$event.preventDefault();$event.stopPropagation()}function newComponent(ev){$mdDialog.show({parent:angular.element(document.body),targetEvent:ev,clickOutsideToClose:true,escapeToClose:true,template:[''," ",' '," "," "+l("Contact")," "," "," "+l("List")," ","
"," ",""].join(""),locals:{addressbookId:vm.selectedFolder.id},controller:ComponentDialogController});ComponentDialogController.$inject=["scope","$mdDialog","$state","addressbookId"];function ComponentDialogController(scope,$mdDialog,$state,addressbookId){scope.create=function(type){$mdDialog.hide();$state.go("app.addressbook.new",{addressbookId:addressbookId,contactType:type})}}}function notSelectedComponent(currentCard,type){return currentCard&¤tCard.c_component==type&&!currentCard.selected}function unselectCards(){_.each(vm.selectedFolder.cards,function(card){card.selected=false})}function confirmDeleteSelectedCards(){Dialog.confirm(l("Warning"),l("Are you sure you want to delete the selected contacts?")).then(function(){var selectedCards=_.filter(vm.selectedFolder.cards,function(card){return card.selected});vm.selectedFolder.$deleteCards(selectedCards);delete vm.selectedFolder.selectedCard},function(data,status){})}function saveSelectedCards(){var selectedCards=_.filter(vm.selectedFolder.cards,function(card){return card.selected});var selectedUIDs=_.pluck(selectedCards,"id");window.location.href=ApplicationBaseURL+"/"+vm.selectedFolder.id+"/export?uid="+selectedUIDs.join("&uid=")}function copySelectedCards(folder){var selectedCards=_.filter(vm.selectedFolder.cards,function(card){return card.selected});vm.selectedFolder.$copyCards(selectedCards,folder).then(function(){},function(error){Dialog.alert(l("Error"),error)})}function selectAll(){_.each(vm.selectedFolder.cards,function(card){card.selected=true})}function sort(field){vm.selectedFolder.$filter("",{sort:field})}function sortedBy(field){return AddressBook.$query.sort==field}function cancelSearch(){vm.mode.search=false;vm.selectedFolder.$filter("")}function newMessage($event,recipients){Account.$findAll().then(function(accounts){var account=_.filter(accounts,function(o){if(o.id===0)return o})[0];account.$getMailboxes().then(function(mailboxes){account.$newMessage().then(function(message){$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:false,escapeToClose:false,templateUrl:"../Mail/UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:accounts,stateMessage:message,stateRecipients:recipients}})})})})}function newMessageWithRecipient($event,recipient,fn){var recipients=[{full:fn+" <"+recipient+">"}];vm.newMessage($event,recipients);$event.stopPropagation();$event.preventDefault()}function newMessageWithSelectedCards($event){var selectedCards=_.filter(vm.selectedFolder.cards,function(card){return card.selected});var promises=[],recipients=[];_.each(selectedCards,function(card){if(card.c_component=="vcard"&&card.c_mail.length){recipients.push({full:card.c_cn+" <"+card.c_mail+">"})}else if(card.c_component=="vlist"){if(angular.isDefined(card.refs)&&card.refs.length){_.each(card.refs,function(ref){if(ref.email.length)recipients.push({full:ref.c_cn+" <"+ref.email+">"})})}else{promises.push(vm.selectedFolder.$getCard(card.id).then(function(card){return card.$futureCardData.then(function(data){_.each(data.refs,function(ref){if(ref.email.length)recipients.push({full:ref.c_cn+" <"+ref.email+">"})})})}))}}});$q.all(promises).then(function(){if(recipients.length)vm.newMessage($event,recipients)})}}angular.module("SOGo.ContactsUI").controller("AddressBookController",AddressBookController)})();(function(){"use strict";AddressBooksController.$inject=["$state","$scope","$rootScope","$stateParams","$timeout","$mdDialog","$mdToast","$mdMedia","$mdSidenav","FileUploader","sgFocus","Card","AddressBook","Dialog","sgSettings","User","stateAddressbooks"];function AddressBooksController($state,$scope,$rootScope,$stateParams,$timeout,$mdDialog,$mdToast,$mdMedia,$mdSidenav,FileUploader,focus,Card,AddressBook,Dialog,Settings,User,stateAddressbooks){var vm=this;vm.activeUser=Settings.activeUser;vm.service=AddressBook;vm.select=select;vm.newAddressbook=newAddressbook;vm.edit=edit;vm.revertEditing=revertEditing;vm.save=save;vm.confirmDelete=confirmDelete;vm.importCards=importCards;vm.exportCards=exportCards;vm.showLinks=showLinks;vm.showProperties=showProperties;vm.share=share;vm.subscribeToFolder=subscribeToFolder;function select($event,folder){if($state.params.addressbookId!=folder.id&&vm.editMode!=folder.id){vm.editMode=false;AddressBook.$query.value="";if($mdMedia("sm"))$mdSidenav("left").close();$state.go("app.addressbook",{addressbookId:folder.id})}else{$event.preventDefault();$event.stopPropagation()}}function newAddressbook(){Dialog.prompt(l("New addressbook"),l("Name of new addressbook")).then(function(name){var addressbook=new AddressBook({name:name,isEditable:true,isRemote:false,owner:UserLogin});AddressBook.$add(addressbook)})}function edit(folder){if(!folder.isRemote){vm.editMode=folder.id;vm.originalAddressbook=angular.extend({},folder.$omit());focus("addressBookName_"+folder.id)}}function revertEditing(folder){folder.name=vm.originalAddressbook.name;vm.editMode=false}function save(folder){var name=folder.name;if(name&&name.length>0&&name!=vm.originalAddressbook.name){folder.$rename(name).then(function(data){vm.editMode=false},function(data,status){Dialog.alert(l("Warning"),data)})}}function confirmDelete(){if(vm.service.selectedFolder.isSubscription){vm.service.selectedFolder.$delete().then(function(){vm.service.selectedFolder=null;$state.go("app.addressbook",{addressbookId:"personal"})},function(data,status){Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',vm.service.selectedFolder.name),l(data.error))})}else{Dialog.confirm(l("Warning"),l("Are you sure you want to delete the addressbook %{0}?",vm.service.selectedFolder.name)).then(function(){return vm.service.selectedFolder.$delete()}).then(function(){vm.service.selectedFolder=null;return true}).catch(function(data,status){Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',vm.service.selectedFolder.name),l(data.error))})}}function importCards($event,folder){$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:true,escapeToClose:true,templateUrl:"UIxContactsImportDialog",controller:CardsImportDialogController,controllerAs:"$CardsImportDialogController",locals:{folder:folder}});CardsImportDialogController.$inject=["scope","$mdDialog","folder"];function CardsImportDialogController(scope,$mdDialog,folder){var vm=this;vm.uploader=new FileUploader({url:ApplicationBaseURL+[folder.id,"import"].join("/"),autoUpload:true,queueLimit:1,filters:[{name:filterByExtension,fn:filterByExtension}],onSuccessItem:function(item,response,status,headers){var msg;$mdDialog.hide();if(response.imported===0)msg=l("No card was imported.");else{msg=l("A total of %{0} cards were imported in the addressbook.",response.imported);AddressBook.selectedFolder.$reload()}$mdToast.show($mdToast.simple().content(msg).position("top right").hideDelay(3e3))},onErrorItem:function(item,response,status,headers){$mdToast.show({template:["",' error_outline'," "+l("An error occured while importing contacts.")+"",""].join(""),position:"top right",hideDelay:3e3})}});vm.close=function(){$mdDialog.hide()};function filterByExtension(item){var isTextFile=item.type.indexOf("text")===0||/\.(ldif|vcf|vcard)$/.test(item.name);if(!isTextFile)$mdToast.show({template:["",' error_outline'," "+l("Select a vCard or LDIF file.")+"",""].join(""),position:"top right",hideDelay:3e3});return isTextFile}}}function exportCards(){window.location.href=ApplicationBaseURL+"/"+vm.service.selectedFolder.id+"/exportFolder"}function showLinks(addressbook){$mdDialog.show({parent:angular.element(document.body),clickOutsideToClose:true,escapeToClose:true,templateUrl:addressbook.id+"/links",controller:LinksDialogController,controllerAs:"links",locals:{addressbook:addressbook}});LinksDialogController.$inject=["$mdDialog","addressbook"];function LinksDialogController($mdDialog,addressbook){var vm=this;this.addressbook=addressbook;this.close=close;function close(){$mdDialog.hide()}}}function showProperties(addressbook){$mdDialog.show({templateUrl:addressbook.id+"/properties",controller:PropertiesDialogController,controllerAs:"properties",clickOutsideToClose:true,escapeToClose:true,locals:{srcAddressBook:addressbook}}).catch(function(){});PropertiesDialogController.$inject=["$scope","$mdDialog","srcAddressBook"];function PropertiesDialogController($scope,$mdDialog,srcAddressBook){var vm=this;vm.addressbook=new AddressBook(srcAddressBook.$omit());vm.saveProperties=saveProperties;vm.close=close;function saveProperties(){vm.addressbook.$save().then(function(){srcAddressBook.init(vm.addressbook.$omit());$mdDialog.hide()},function(){})}function close(){$mdDialog.cancel()}}}function share(addressbook){addressbook.$acl.$users().then(function(){$mdDialog.show({templateUrl:addressbook.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:true,escapeToClose:true,locals:{usersWithACL:addressbook.$acl.users,User:User,folder:addressbook}})})}function subscribeToFolder(addressbookData){console.debug("subscribeToFolder "+addressbookData.owner+addressbookData.name);AddressBook.$subscribe(addressbookData.owner,addressbookData.name).catch(function(data){Dialog.alert(l("Warning"),l("An error occured please try again."))})}}angular.module("SOGo.ContactsUI").controller("AddressBooksController",AddressBooksController)})();(function(){"use strict";CardController.$inject=["$scope","$timeout","$mdDialog","AddressBook","Card","Dialog","sgFocus","$state","$stateParams","stateCard"];function CardController($scope,$timeout,$mdDialog,AddressBook,Card,Dialog,focus,$state,$stateParams,stateCard){var vm=this;vm.card=stateCard;vm.currentFolder=AddressBook.selectedFolder;vm.allEmailTypes=Card.$EMAIL_TYPES;vm.allTelTypes=Card.$TEL_TYPES;vm.allUrlTypes=Card.$URL_TYPES;vm.allAddressTypes=Card.$ADDRESS_TYPES;vm.categories={};vm.userFilterResults=[];vm.addOrgUnit=addOrgUnit;vm.addBirthday=addBirthday;vm.addScreenName=addScreenName;vm.addEmail=addEmail;vm.addPhone=addPhone;vm.addUrl=addUrl;vm.addAddress=addAddress;vm.addMember=addMember;vm.userFilter=userFilter;vm.save=save;vm.close=close;vm.reset=reset;vm.cancel=cancel;vm.confirmDelete=confirmDelete;vm.exportCard=exportCard;vm.toggleRawSource=toggleRawSource;vm.showRawSource=false;function addOrgUnit(){var i=vm.card.$addOrgUnit("");focus("orgUnit_"+i)}function addBirthday(){vm.card.birthday=new Date}function addScreenName(){vm.card.$addScreenName("")}function addEmail(){var i=vm.card.$addEmail("");focus("email_"+i)}function addPhone(){var i=vm.card.$addPhone("");focus("phone_"+i)}function addUrl(){var i=vm.card.$addUrl("","");focus("url_"+i)}function addAddress(){var i=vm.card.$addAddress("","","","","","","","");focus("address_"+i)}function addMember(){var i=vm.card.$addMember("");focus("ref_"+i)}function userFilter($query,excludedCards){AddressBook.selectedFolder.$filter($query,{dry:true,excludeLists:true},excludedCards);return AddressBook.selectedFolder.$cards}function save(form){if(form.$valid){vm.card.$save().then(function(data){var i=_.indexOf(_.pluck(AddressBook.selectedFolder.cards,"id"),vm.card.id);if(i<0){AddressBook.selectedFolder.$reload()}else{AddressBook.selectedFolder.cards[i]=angular.copy(vm.card)}$state.go("app.addressbook.card.view",{cardId:vm.card.id})}).catch(function(err){console.log(err)})}}function close(){$state.go("app.addressbook",{addressbookId:AddressBook.selectedFolder.id}).then(function(){vm.card=null;delete AddressBook.selectedFolder.selectedCard})}function reset(){vm.card.$reset()}function cancel(){vm.card.$reset();if(vm.card.isNew){vm.card=null;delete AddressBook.selectedFolder.selectedCard;$state.go("app.addressbook",{addressbookId:AddressBook.selectedFolder.id})}else{$state.go("app.addressbook.card.view",{cardId:vm.card.id})}}function confirmDelete(card){Dialog.confirm(l("Warning"),l("Are you sure you want to delete the card of %{0}?",card.$fullname()),{ok:l("Yes"),cancel:l("No")}).then(function(){card.$delete().then(function(){AddressBook.selectedFolder.cards=_.reject(AddressBook.selectedFolder.cards,function(o){return o.id==card.id});close()},function(data,status){Dialog.alert(l("Warning"),l('An error occured while deleting the card "%{0}".',card.$fullname()))})})}function exportCard(){window.location.href=ApplicationBaseURL+"/"+vm.currentFolder.id+"/export?uid="+vm.card.id}function toggleRawSource($event){if(!vm.showRawSource&&!vm.rawSource){Card.$$resource.post(vm.currentFolder.id+"/"+vm.card.id,"raw").then(function(data){vm.rawSource=data;vm.showRawSource=true})}else{vm.showRawSource=!vm.showRawSource}}}angular.module("SOGo.ContactsUI").controller("CardController",CardController)})();(function(){"use strict";function sgAddress(){return{restrict:"A",scope:{data:"=sgAddress"},controller:["$scope",function($scope){$scope.addressLines=function(data){var lines=[],locality_region=[];if(data.street)lines.push(data.street);if(data.street2)lines.push(data.street2);if(data.locality)locality_region.push(data.locality);if(data.region)locality_region.push(data.region);if(locality_region.length>0)lines.push(locality_region.join(", "));if(data.country)lines.push(data.country);if(data.postalcode)lines.push(data.postalcode);return lines.join("
")}}],template:'
'}}angular.module("SOGo.Common").directive("sgAddress",sgAddress)})();
//# sourceMappingURL=Contacts.js.map