(feat) initial support for contact import in the address book module

This commit is contained in:
Ludovic Marcotte
2015-08-21 20:56:21 -04:00
parent 0a8834193f
commit 85c8aebbd4
4 changed files with 95 additions and 71 deletions

View File

@@ -6,8 +6,8 @@
/**
* @ngInject
*/
AddressBooksController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'User', 'stateAddressbooks'];
function AddressBooksController($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, User, stateAddressbooks) {
AddressBooksController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', '$mdToast', 'FileUploader', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'User', 'stateAddressbooks'];
function AddressBooksController($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, $mdToast, FileUploader, focus, Card, AddressBook, Dialog, Settings, User, stateAddressbooks) {
var vm = this;
vm.activeUser = Settings.activeUser;
@@ -101,8 +101,85 @@
}
}
function importCards() {
function importCards($event, folder) {
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
template: [
'<md-dialog flex="40" flex-sm="100" aria-label="' + l('Import Cards') + '">',
' <md-toolbar class="sg-padded">',
' <div class="md-toolbar-tools">',
' <md-icon class="material-icons sg-icon-toolbar-bg">import_export</md-icon>',
' <div class="md-flex">',
' <div class="sg-md-title">' + l('Import Cards') + '</div>',
' </div>',
' <md-button class="md-icon-button" ng-click="close()">',
' <md-icon aria-label="Close dialog">close</md-icon>',
' </md-button>',
' </div>',
' </md-toolbar>',
' <md-dialog-content>',
' <div layout="column">',
' <div layout="row" layout-align="start center">',
' <span>' + l('Select a vCard or LDIF file.') + '</span>',
' <label class="md-button" for="file-input">',
' <span>' + l('Choose File') + '</span>',
' </label>',
' <input id="file-input" type="file" nv-file-select="nv-file-select" uploader="uploader" ng-show="false"/>',
' </div>',
' <span ng-show="uploader.queue.length == 0">' + l('No file chosen') + '</span>',
' <span ng-show="uploader.queue.length > 0">{{ uploader.queue[0].file.name }}</span>',
' </div>',
' </md-dialog-content>',
' <div class="md-actions">',
' <md-button ng-disabled="uploader.queue.length == 0" ng-click="upload()">' + l('Upload') + '</md-button>',
' </div>',
'</md-dialog>'
].join(''),
controller: CardsImportDialogController,
locals: {
folder: folder
}
});
/**
* @ngInject
*/
CardsImportDialogController.$inject = ['scope', '$mdDialog', 'folder'];
function CardsImportDialogController(scope, $mdDialog, folder) {
scope.uploader = new FileUploader({
url: ApplicationBaseURL + '/' + folder.id + '/import',
onProgressItem: function(item, progress) {
console.debug(item); console.debug(progress);
},
onSuccessItem: function(item, response, status, headers) {
console.debug(item); console.debug('success = ' + JSON.stringify(response, undefined, 2));
$mdDialog.hide();
$mdToast.show(
$mdToast.simple()
.content(l('A total of %{0} cards were imported in the addressbook.', response.imported))
.position('top right')
.hideDelay(3000));
AddressBook.selectedFolder.$reload();
},
onCancelItem: function(item, response, status, headers) {
console.debug(item); console.debug('cancel = ' + JSON.stringify(response, undefined, 2));
},
onErrorItem: function(item, response, status, headers) {
console.debug(item); console.debug('error = ' + JSON.stringify(response, undefined, 2));
}
});
scope.close = function() {
$mdDialog.hide();
};
scope.upload = function() {
scope.uploader.uploadAll();
};
}
}
function exportCards() {