2014-09-19 02:46:52 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-10-25 04:00:27 +02:00
|
|
|
/* JavaScript for SOGo.ContactsUI (mobile) module */
|
2014-08-06 22:11:39 +02:00
|
|
|
|
|
|
|
(function() {
|
2014-09-19 02:46:52 +02:00
|
|
|
'use strict';
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
angular.module('SOGo.Common', []);
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
angular.module('SOGo.ContactsUI', ['ionic', 'SOGo.Common', 'SOGo.UIMobile'])
|
2014-08-06 22:11:39 +02:00
|
|
|
|
|
|
|
.constant('sgSettings', {
|
2014-11-11 17:14:55 +01:00
|
|
|
baseURL: ApplicationBaseURL,
|
|
|
|
activeUser: {
|
|
|
|
login: UserLogin,
|
|
|
|
language: UserLanguage,
|
|
|
|
folderURL: UserFolderURL,
|
|
|
|
isSuperUser: IsSuperUser
|
|
|
|
}
|
2014-08-06 22:11:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
.run(function($ionicPlatform) {
|
2014-09-19 02:46:52 +02:00
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
|
|
|
// for form inputs)
|
|
|
|
if (window.cordova && window.cordova.plugins.Keyboard) {
|
|
|
|
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
|
|
|
|
}
|
|
|
|
if (window.StatusBar) {
|
|
|
|
// org.apache.cordova.statusbar required
|
|
|
|
StatusBar.styleDefault();
|
|
|
|
}
|
|
|
|
});
|
2014-08-06 22:11:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
.config(function($stateProvider, $urlRouterProvider) {
|
2014-09-19 02:46:52 +02:00
|
|
|
$stateProvider
|
|
|
|
.state('app', {
|
|
|
|
url: '/app',
|
|
|
|
abstract: true,
|
|
|
|
templateUrl: 'menu.html',
|
|
|
|
controller: 'AppCtrl'
|
|
|
|
})
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
.state('app.addressbooks', {
|
|
|
|
url: '/addressbooks',
|
|
|
|
views: {
|
|
|
|
menuContent: {
|
|
|
|
templateUrl: 'addressbooks.html',
|
|
|
|
controller: 'AddressBooksCtrl'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
.state('app.addressbook', {
|
|
|
|
url: '/addressbook/:addressbookId',
|
|
|
|
views: {
|
|
|
|
menuContent: {
|
|
|
|
templateUrl: 'addressbook.html',
|
|
|
|
controller: 'AddressBookCtrl',
|
|
|
|
resolve: {
|
2014-11-11 17:14:55 +01:00
|
|
|
stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) {
|
|
|
|
return AddressBook.$find($stateParams.addressbookId);
|
|
|
|
}]
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
.state('app.newCard', {
|
|
|
|
url: '/addressbook/:addressbookId/:contactType/new',
|
|
|
|
views: {
|
|
|
|
menuContent: {
|
|
|
|
templateUrl: 'card.html',
|
|
|
|
controller: 'CardCtrl',
|
|
|
|
resolve: {
|
|
|
|
stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', 'sgCard', function($rootScope, $stateParams, sgAddressBook, Card) {
|
|
|
|
var tag = 'v' + $stateParams.contactType;
|
|
|
|
if (!$rootScope.addressbook) {
|
|
|
|
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
|
|
|
|
}
|
|
|
|
return new Card(
|
|
|
|
{
|
|
|
|
pid: $stateParams.addressbookId,
|
|
|
|
tag: tag,
|
|
|
|
isNew: true
|
2014-09-05 21:12:05 +02:00
|
|
|
}
|
2014-09-19 02:46:52 +02:00
|
|
|
);
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-09-05 21:12:05 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
.state('app.card', {
|
|
|
|
url: '/addressbook/:addressbookId/:cardId',
|
|
|
|
views: {
|
|
|
|
menuContent: {
|
|
|
|
templateUrl: 'card.html',
|
|
|
|
controller: 'CardCtrl',
|
|
|
|
resolve: {
|
2014-09-23 17:52:47 +02:00
|
|
|
stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', function($rootScope, $stateParams, AddressBook) {
|
2014-09-19 02:46:52 +02:00
|
|
|
if (!$rootScope.addressbook) {
|
2014-09-23 17:52:47 +02:00
|
|
|
$rootScope.addressbook = AddressBook.$find($stateParams.addressbookId);
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
return $rootScope.addressbook.$getCard($stateParams.cardId);
|
2014-09-23 17:52:47 +02:00
|
|
|
}]
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/app/addressbooks');
|
2014-08-06 22:11:39 +02:00
|
|
|
})
|
|
|
|
|
2014-11-03 18:19:35 +01:00
|
|
|
// Inspired from http://codepen.io/gastonbesada/pen/eqvJK
|
2014-10-08 19:44:37 +02:00
|
|
|
.directive('ionSearch', function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
replace: true,
|
|
|
|
scope: {
|
2014-11-03 18:19:35 +01:00
|
|
|
getData: '=source',
|
2014-10-08 19:44:37 +02:00
|
|
|
clearData: '&clear',
|
|
|
|
model: '=?',
|
|
|
|
search: '=?filter'
|
|
|
|
},
|
|
|
|
link: function(scope, element, attrs) {
|
|
|
|
attrs.minLength = attrs.minLength || 0;
|
|
|
|
scope.placeholder = attrs.placeholder || '';
|
|
|
|
scope.search = {value: ''};
|
|
|
|
|
|
|
|
if (attrs.class)
|
|
|
|
element.addClass(attrs.class);
|
|
|
|
|
|
|
|
if (attrs.source) {
|
2014-11-03 18:19:35 +01:00
|
|
|
scope.$watch('search.value', function(newValue, oldValue) {
|
2014-10-08 19:44:37 +02:00
|
|
|
if (newValue.length > attrs.minLength) {
|
2014-11-03 18:19:35 +01:00
|
|
|
scope.getData(newValue).then(function(results) {
|
2014-10-08 19:44:37 +02:00
|
|
|
scope.model = results;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
scope.clearSearch = function() {
|
|
|
|
scope.search.value = '';
|
|
|
|
scope.clearData();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
template: '<div class="item-input-wrapper">' +
|
2014-11-03 18:19:35 +01:00
|
|
|
'<i class="icon ion-android-search"></i>' +
|
|
|
|
'<input type="search" placeholder="{{placeholder}}" ng-model="search.value" id="searchInput">' +
|
|
|
|
'<i ng-if="search.value.length > 0" ng-click="clearSearch()" class="icon ion-close"></i>' +
|
|
|
|
'</div>'
|
2014-10-08 19:44:37 +02:00
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
|
|
|
|
$scope.UserLogin = UserLogin;
|
|
|
|
$scope.UserFolderURL = UserFolderURL;
|
|
|
|
$scope.ApplicationBaseURL = ApplicationBaseURL;
|
|
|
|
// $scope.logout = function(url) {
|
|
|
|
// $http.get(url)
|
|
|
|
// .success(function(data, status, headers) {
|
|
|
|
// console.debug(headers);
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
}])
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-11-03 18:19:35 +01:00
|
|
|
.controller('AddressBooksCtrl', ['$scope', '$state', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgUser', function($scope, $state, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, User) {
|
2014-09-19 02:46:52 +02:00
|
|
|
// Initialize with data from template
|
2014-09-23 17:52:47 +02:00
|
|
|
$scope.addressbooks = AddressBook.$findAll(contactFolders);
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.newAddressbook = function() {
|
2014-09-10 22:20:52 +02:00
|
|
|
Dialog.prompt(l('Create addressbook'),
|
|
|
|
l('Name of new addressbook'))
|
2014-09-19 02:46:52 +02:00
|
|
|
.then(function(res) {
|
2014-09-10 22:20:52 +02:00
|
|
|
if (res && res.length > 0) {
|
2014-09-19 02:46:52 +02:00
|
|
|
var addressbook = new AddressBook(
|
|
|
|
{
|
|
|
|
name: res,
|
|
|
|
isEditable: true,
|
|
|
|
isRemote: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
AddressBook.$add(addressbook);
|
2014-09-10 22:20:52 +02:00
|
|
|
}
|
2014-09-19 02:46:52 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.edit = function(addressbook) {
|
2014-09-10 22:20:52 +02:00
|
|
|
$ionicActionSheet.show({
|
2014-09-19 02:46:52 +02:00
|
|
|
buttons: [
|
2014-10-08 19:44:37 +02:00
|
|
|
{ text: l('Rename') },
|
2014-11-03 18:19:35 +01:00
|
|
|
{ text: l('Set Access Rights') }
|
2014-09-19 02:46:52 +02:00
|
|
|
],
|
|
|
|
destructiveText: l('Delete'),
|
|
|
|
cancelText: l('Cancel'),
|
|
|
|
buttonClicked: function(index) {
|
2014-11-03 18:19:35 +01:00
|
|
|
if (index == 0) {
|
|
|
|
// Rename
|
|
|
|
Dialog.prompt(l('Rename addressbook'), addressbook.name)
|
|
|
|
.then(function(name) {
|
|
|
|
if (name && name.length > 0) {
|
|
|
|
addressbook.$rename(name); // TODO check error
|
|
|
|
}
|
|
|
|
});
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
2014-11-03 18:19:35 +01:00
|
|
|
else if (index == 1) {
|
|
|
|
// Set Access Rights
|
2014-10-08 19:44:37 +02:00
|
|
|
$ionicModal.fromTemplateUrl('acl-modal.html', { scope: $scope }).then(function(modal) {
|
|
|
|
var aclUsers = {};
|
|
|
|
|
2014-10-21 20:44:48 +02:00
|
|
|
function refreshUsers(users) {
|
2014-10-08 19:44:37 +02:00
|
|
|
$scope.users = [];
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.search.active = false;
|
|
|
|
angular.forEach(users, function(user) {
|
2014-10-08 19:44:37 +02:00
|
|
|
user.inAclList = true;
|
|
|
|
$scope.users.push(user);
|
|
|
|
aclUsers[user.uid] = user;
|
|
|
|
})
|
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
|
|
|
|
if ($scope.aclEditorModal) {
|
|
|
|
$scope.aclEditorModal.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.title = addressbook.name;
|
|
|
|
$scope.aclEditorModal = modal;
|
|
|
|
$scope.showDelete = false;
|
|
|
|
$scope.search = {active: false};
|
|
|
|
|
|
|
|
// Load ACL users
|
|
|
|
addressbook.$acl.$users().then(function(users) {
|
|
|
|
refreshUsers(users);
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occurs while trying to fetch users from the server.'));
|
|
|
|
});
|
|
|
|
|
2014-10-08 19:44:37 +02:00
|
|
|
$scope.closeModal = function() {
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.aclEditorModal.remove();
|
2014-10-08 19:44:37 +02:00
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.displayIcon = function(user) {
|
|
|
|
if (user.inAclList)
|
|
|
|
return ($scope.userIsSelected(user) ? 'ion-ios7-arrow-down' : 'ion-ios7-arrow-right');
|
|
|
|
else
|
|
|
|
return 'ion-plus';
|
|
|
|
}
|
|
|
|
$scope.toggleUser = function(user) {
|
|
|
|
if (user.inAclList) {
|
|
|
|
if ($scope.userIsSelected(user)) {
|
|
|
|
// Close rights editor
|
|
|
|
delete $scope.selectedUser;
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-11-03 18:19:35 +01:00
|
|
|
// Edit user rights
|
|
|
|
$scope.editUser(user);
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-03 18:19:35 +01:00
|
|
|
else {
|
|
|
|
// Add user
|
|
|
|
$scope.addUser(user);
|
|
|
|
}
|
2014-10-08 19:44:37 +02:00
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.userIsSelected = function(user) {
|
|
|
|
return $scope.selectedUser && $scope.selectedUser.uid == user.uid;
|
|
|
|
};
|
|
|
|
$scope.searchUsers = function(search) {
|
|
|
|
$scope.users = [];
|
|
|
|
$scope.search.active = true;
|
|
|
|
return User.$filter(search).then(function(results) {
|
|
|
|
angular.forEach(results, function(userFound) {
|
|
|
|
userFound.inAclList = (aclUsers[userFound.uid]) ? true : false;
|
|
|
|
$scope.users.push(userFound);
|
|
|
|
})
|
|
|
|
});
|
2014-10-17 17:01:56 +02:00
|
|
|
};
|
2014-10-08 19:44:37 +02:00
|
|
|
$scope.cancelSearch = function() {
|
2014-11-03 18:19:35 +01:00
|
|
|
addressbook.$acl.$users().then(function(users) {
|
2014-10-21 20:44:48 +02:00
|
|
|
refreshUsers(users);
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
2014-10-08 19:44:37 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.toggleDelete = function(boolean) {
|
|
|
|
$scope.showDelete = boolean;
|
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.editUser = function(user) {
|
|
|
|
if ($scope.selectedUser != user) {
|
|
|
|
$scope.selectedUser = user;
|
|
|
|
$scope.selectedUser.$rights();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.confirmChange = function(user) {
|
|
|
|
var confirmation = user.$confirmRights();
|
|
|
|
if (confirmation) {
|
|
|
|
Dialog.confirm(l('Warning'), confirmation).then(function(res) {
|
|
|
|
if (!res)
|
|
|
|
user.$resetRights(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.saveModal = function() {
|
|
|
|
addressbook.$acl.$saveUsersRights().then(function() {
|
|
|
|
$scope.aclEditorModal.remove();
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
|
|
|
});
|
|
|
|
};
|
2014-10-08 19:44:37 +02:00
|
|
|
$scope.removeUser = function(user) {
|
|
|
|
if (user) {
|
2014-11-03 18:19:35 +01:00
|
|
|
addressbook.$acl.$removeUser(user.uid).then(function() {
|
|
|
|
delete aclUsers[user.uid];
|
|
|
|
delete $scope.selectedUser;
|
|
|
|
$scope.users = _.reject($scope.users, function(o) {
|
|
|
|
return o.uid == user.uid;
|
|
|
|
});
|
|
|
|
}, function(data, status) {
|
2014-10-21 20:44:48 +02:00
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
|
|
|
});
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.addUser = function(user) {
|
2014-10-08 20:08:54 +02:00
|
|
|
if (user.uid) {
|
2014-11-03 18:19:35 +01:00
|
|
|
addressbook.$acl.$addUser(user).then(function() {
|
|
|
|
user.inAclList = true;
|
|
|
|
aclUsers[user.uid] = user;
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
|
|
|
});
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
2014-11-03 18:19:35 +01:00
|
|
|
else {
|
2014-10-08 20:08:54 +02:00
|
|
|
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
2014-10-08 19:44:37 +02:00
|
|
|
}
|
|
|
|
};
|
2014-11-03 18:19:35 +01:00
|
|
|
|
2014-10-08 19:44:37 +02:00
|
|
|
// Show modal
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.aclEditorModal.show();
|
2014-10-08 19:44:37 +02:00
|
|
|
});
|
|
|
|
}
|
2014-09-19 02:46:52 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
destructiveButtonClicked: function() {
|
|
|
|
// Delete addressbook
|
|
|
|
addressbook.$delete()
|
|
|
|
.then(function() {
|
|
|
|
addressbook = null;
|
|
|
|
}, function(data) {
|
|
|
|
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
|
|
|
|
addressbook.name),
|
|
|
|
l(data.error));
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// cancel: function() {
|
|
|
|
// },
|
2014-09-10 22:20:52 +02:00
|
|
|
});
|
|
|
|
$ionicListDelegate.closeOptionButtons();
|
2014-09-19 02:46:52 +02:00
|
|
|
};
|
|
|
|
}])
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-10-16 19:27:59 +02:00
|
|
|
.controller('AddressBookCtrl', ['$scope', '$rootScope', '$stateParams', '$state', '$ionicActionSheet', 'sgAddressBook', 'sgCard', 'stateAddressbook', function($scope, $rootScope, $stateParams, $state, $ionicActionSheet, AddressBook, Card, stateAddressbook) {
|
2014-09-19 02:46:52 +02:00
|
|
|
$rootScope.addressbook = stateAddressbook;
|
2014-08-06 22:11:39 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.search = { status: null, filter: null, lastFilter: null };
|
2014-10-16 19:27:59 +02:00
|
|
|
|
|
|
|
$scope.addCard = function() {
|
|
|
|
$ionicActionSheet.show({
|
2014-10-25 04:00:27 +02:00
|
|
|
//titleText: l('Create a new card or a new list'),
|
2014-10-16 19:27:59 +02:00
|
|
|
buttons: [
|
2014-11-03 18:19:35 +01:00
|
|
|
{ text: l('New Card') },
|
|
|
|
{ text: l('New List') }
|
2014-10-16 19:27:59 +02:00
|
|
|
],
|
|
|
|
canceltext: l('Cancel'),
|
|
|
|
buttonClicked: function(index) {
|
2014-11-03 18:19:35 +01:00
|
|
|
if (index == 0) {
|
2014-10-16 19:27:59 +02:00
|
|
|
$state.go('app.newCard', { addressbookId: stateAddressbook.id, contactType: 'card' });
|
|
|
|
}
|
2014-11-03 18:19:35 +01:00
|
|
|
else if (index == 1) {
|
2014-10-16 19:27:59 +02:00
|
|
|
$state.go('app.newCard', { addressbookId: stateAddressbook.id, contactType: 'list' });
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.doSearch = function(keyEvent) {
|
|
|
|
if ($scope.search.lastFilter != $scope.search.filter) {
|
|
|
|
if ($scope.search.filter.length > 2) {
|
|
|
|
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
|
|
|
|
if (data.length == 0)
|
|
|
|
$scope.search.status = 'no-result';
|
|
|
|
else
|
|
|
|
$scope.search.status = '';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if ($scope.search.filter.length == 0) {
|
|
|
|
$scope.searchStatus = '';
|
|
|
|
$rootScope.addressbook = AddressBook.$find($rootScope.addressbook.id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$scope.search.status = 'min-char';
|
|
|
|
$rootScope.addressbook.cards = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.search.lastFilter = $scope.search.filter;
|
|
|
|
};
|
2014-08-06 22:11:39 +02:00
|
|
|
}])
|
|
|
|
|
2014-10-25 04:00:27 +02:00
|
|
|
.controller('CardCtrl', ['$scope', '$rootScope', '$state', '$stateParams', '$ionicModal', '$ionicPopover', 'sgDialog', 'sgAddressBook', 'sgCard', 'stateCard', function($scope, $rootScope, $state, $stateParams, $ionicModal, $ionicPopover, Dialog, AddressBook, Card, stateCard) {
|
2014-09-29 17:06:46 +02:00
|
|
|
$scope.card = stateCard;
|
2014-09-05 21:12:05 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.UserFolderURL = UserFolderURL;
|
|
|
|
$scope.allEmailTypes = Card.$EMAIL_TYPES;
|
|
|
|
$scope.allTelTypes = Card.$TEL_TYPES;
|
|
|
|
$scope.allUrlTypes = Card.$URL_TYPES;
|
|
|
|
$scope.allAddressTypes = Card.$ADDRESS_TYPES;
|
2014-09-05 21:12:05 +02:00
|
|
|
|
2014-11-03 18:19:35 +01:00
|
|
|
$scope.search = {query: ''};
|
2014-10-25 04:00:27 +02:00
|
|
|
$scope.cardsFilter = function(item) {
|
|
|
|
var query, id = false;
|
2014-11-03 18:19:35 +01:00
|
|
|
if (item.tag == 'vcard' && $scope.search.query) {
|
2014-10-25 04:00:27 +02:00
|
|
|
query = $scope.search.query.toLowerCase();
|
|
|
|
if (item.emails && item.emails.length > 0) {
|
|
|
|
// Is one of the email addresses match the query string?
|
|
|
|
if (_.find(item.emails, function(email) {
|
|
|
|
return (email.value.toLowerCase().indexOf(query) >= 0);
|
2014-11-03 18:19:35 +01:00
|
|
|
})) {
|
2014-10-25 04:00:27 +02:00
|
|
|
id = item.id;
|
2014-11-03 18:19:35 +01:00
|
|
|
}
|
2014-10-20 19:52:35 +02:00
|
|
|
}
|
2014-11-03 18:19:35 +01:00
|
|
|
if (!id && item.fn) {
|
2014-10-25 04:00:27 +02:00
|
|
|
// Is the fn attribute matches the query string?
|
2014-11-03 18:19:35 +01:00
|
|
|
if (item.fn.toLowerCase().indexOf(query) >= 0) {
|
2014-10-25 04:00:27 +02:00
|
|
|
id = item.id;
|
2014-11-03 18:19:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-10-25 04:00:27 +02:00
|
|
|
if (id) {
|
|
|
|
// Is the card already part of the members? If so, ignore it.
|
|
|
|
if (_.find($scope.card.refs, function(ref) {
|
|
|
|
return ref.reference == id;
|
2014-11-03 18:19:35 +01:00
|
|
|
})) {
|
2014-10-25 04:00:27 +02:00
|
|
|
id = false;
|
2014-11-03 18:19:35 +01:00
|
|
|
}
|
2014-10-20 19:52:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-25 04:00:27 +02:00
|
|
|
return id;
|
2014-10-20 19:52:35 +02:00
|
|
|
};
|
2014-10-25 04:00:27 +02:00
|
|
|
$scope.resetSearch = function() {
|
2014-10-20 19:52:35 +02:00
|
|
|
$scope.search.query = null;
|
|
|
|
};
|
2014-10-25 04:00:27 +02:00
|
|
|
$scope.addMember = function(member) {
|
|
|
|
var i = $scope.card.$addMember(''),
|
|
|
|
email = member.$preferredEmail($scope.search.query);
|
|
|
|
$scope.card.$updateMember(i, email, member);
|
|
|
|
$scope.popover.hide();
|
2014-10-20 19:52:35 +02:00
|
|
|
};
|
2014-10-25 04:00:27 +02:00
|
|
|
$ionicPopover.fromTemplateUrl('searchFolderContacts.html', {
|
2014-11-03 18:19:35 +01:00
|
|
|
scope: $scope
|
2014-10-25 04:00:27 +02:00
|
|
|
}).then(function(popover) {
|
|
|
|
$scope.popover = popover;
|
|
|
|
});
|
2014-10-16 19:27:59 +02:00
|
|
|
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.edit = function() {
|
|
|
|
// Build modal editor
|
|
|
|
$ionicModal.fromTemplateUrl('cardEditor.html', {
|
|
|
|
scope: $scope,
|
|
|
|
focusFirstInput: false
|
|
|
|
}).then(function(modal) {
|
|
|
|
if ($scope.$cardEditorModal) {
|
|
|
|
// Delete previous modal
|
|
|
|
$scope.$cardEditorModal.remove();
|
|
|
|
}
|
|
|
|
$scope.$cardEditorModal = modal;
|
|
|
|
// Show modal
|
|
|
|
$scope.$cardEditorModal.show();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.cancel = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
if ($scope.card.isNew) {
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.$cardEditorModal.hide().then(function() {
|
2014-11-03 18:19:35 +01:00
|
|
|
// Go back to addressbook
|
|
|
|
$state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
|
|
|
|
});
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-09-29 17:06:46 +02:00
|
|
|
$scope.card.$reset();
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.$cardEditorModal.hide()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.addOrgUnit = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addOrgUnit('');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('orgUnit_' + i);
|
|
|
|
};
|
|
|
|
$scope.addCategory = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addCategory('');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('category_' + i);
|
|
|
|
};
|
|
|
|
$scope.addEmail = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addEmail('');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('email_' + i);
|
|
|
|
};
|
|
|
|
$scope.addPhone = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addPhone('');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('phone_' + i);
|
|
|
|
};
|
|
|
|
$scope.addUrl = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addUrl('', '');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('url_' + i);
|
|
|
|
};
|
|
|
|
$scope.addAddress = function() {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i = $scope.card.$addAddress('', '', '', '', '', '', '', '');
|
2014-09-19 02:46:52 +02:00
|
|
|
focus('address_' + i);
|
|
|
|
};
|
2014-10-16 19:27:59 +02:00
|
|
|
$scope.showPopOver = function(keyEvent) {
|
|
|
|
$scope.popover.show(keyEvent);
|
|
|
|
}
|
2014-09-19 02:46:52 +02:00
|
|
|
$scope.save = function(form) {
|
|
|
|
if (form.$valid) {
|
2014-09-29 17:06:46 +02:00
|
|
|
$scope.card.$save()
|
2014-09-19 02:46:52 +02:00
|
|
|
.then(function(data) {
|
2014-09-29 17:06:46 +02:00
|
|
|
var i;
|
|
|
|
delete $scope.card.isNew;
|
|
|
|
i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $scope.card.id);
|
2014-09-19 02:46:52 +02:00
|
|
|
if (i < 0) {
|
|
|
|
// New card
|
|
|
|
// Reload contacts list and show addressbook in which the card has been created
|
|
|
|
$rootScope.addressbook = AddressBook.$find(data.pid);
|
2014-09-29 17:06:46 +02:00
|
|
|
$state.go('app.addressbook', { addressbookId: data.pid });
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Update contacts list with new version of the Card object
|
2014-09-29 17:06:46 +02:00
|
|
|
$rootScope.addressbook.cards[i] = angular.copy($scope.card);
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
// Close editor
|
|
|
|
$scope.$cardEditorModal.hide();
|
2014-09-05 21:12:05 +02:00
|
|
|
});
|
2014-09-19 02:46:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.confirmDelete = function(card) {
|
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Are you sure you want to delete the card of <b>%{0}</b>?', card.$fullname()))
|
|
|
|
.then(function(res) {
|
|
|
|
if (res) {
|
2014-09-29 18:12:28 +02:00
|
|
|
// User confirmed the deletion
|
2014-09-19 02:46:52 +02:00
|
|
|
card.$delete()
|
|
|
|
.then(function() {
|
2014-09-29 18:12:28 +02:00
|
|
|
// Remove card from list of addressbook
|
2014-09-19 02:46:52 +02:00
|
|
|
$rootScope.addressbook.cards = _.reject($rootScope.addressbook.cards, function(o) {
|
|
|
|
return o.id == card.id;
|
|
|
|
});
|
2014-09-29 18:12:28 +02:00
|
|
|
// Remove card object from scope
|
2014-09-29 17:06:46 +02:00
|
|
|
delete $scope.card;
|
2014-09-19 02:46:52 +02:00
|
|
|
// Delete modal editor
|
|
|
|
$scope.$cardEditorModal.remove();
|
|
|
|
// Go back to addressbook
|
|
|
|
$state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
|
|
|
|
card.$fullname()));
|
2014-09-05 21:12:05 +02:00
|
|
|
});
|
|
|
|
}
|
2014-09-19 02:46:52 +02:00
|
|
|
});
|
|
|
|
};
|
2014-09-05 21:12:05 +02:00
|
|
|
|
2014-09-29 17:06:46 +02:00
|
|
|
if ($scope.card && $scope.card.isNew) {
|
2014-09-19 02:46:52 +02:00
|
|
|
// New contact
|
|
|
|
$scope.edit();
|
|
|
|
}
|
2014-09-05 21:12:05 +02:00
|
|
|
}]);
|
2014-08-06 22:11:39 +02:00
|
|
|
})();
|