diff --git a/UI/Contacts/UIxContactFolderActions.m b/UI/Contacts/UIxContactFolderActions.m index e45b8d27d..017bd0049 100644 --- a/UI/Contacts/UIxContactFolderActions.m +++ b/UI/Contacts/UIxContactFolderActions.m @@ -112,15 +112,11 @@ request = [context request]; rc = [NSMutableDictionary dictionary]; - data = [request formValueForKey: @"contactsFile"]; - if ([data respondsToSelector: @selector(isEqualToString:)]) - fileContent = (NSString *) data; - else - { - fileContent = [[NSString alloc] initWithData: (NSData *) data - encoding: NSUTF8StringEncoding]; - [fileContent autorelease]; - } + data = [[[[[request httpRequest] body] parts] lastObject] body]; + + fileContent = [[NSString alloc] initWithData: (NSData *) data + encoding: NSUTF8StringEncoding]; + [fileContent autorelease]; if (fileContent && [fileContent length]) { @@ -132,12 +128,10 @@ imported = 0; } - [rc setObject: [NSNumber numberWithInt: imported] - forKey: @"imported"]; + [rc setObject: [NSNumber numberWithInt: imported] forKey: @"imported"]; response = [self responseWithStatus: 200]; - [response setHeader: @"text/html" - forKey: @"content-type"]; + [response setHeader: @"text/html" forKey: @"content-type"]; [(WOResponse*)response appendContentString: [rc jsonRepresentation]]; return response; diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 06e10b4a0..246b10c84 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -9,64 +9,11 @@ className="UIxPageFrame" title="title" const:userDefaultsKeys="SOGoContactsCategories" - const:jsFiles="Common.js, Preferences.services.js, Contacts.js, Contacts.services.js"> + const:jsFiles="Common.js, Preferences.services.js, Contacts.js, Contacts.services.js, vendor/angular-file-upload.min.js"> - - @@ -125,6 +72,12 @@ + + + + + + diff --git a/UI/WebServerResources/js/Contacts/AddressBooksController.js b/UI/WebServerResources/js/Contacts/AddressBooksController.js index 3a4c6d1dd..30a1667fe 100644 --- a/UI/WebServerResources/js/Contacts/AddressBooksController.js +++ b/UI/WebServerResources/js/Contacts/AddressBooksController.js @@ -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: [ + '', + ' ', + ' ', + ' import_export', + ' ', + ' ' + l('Import Cards') + '', + ' ', + ' ', + ' close', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ' + l('Select a vCard or LDIF file.') + '', + ' ', + ' ' + l('Choose File') + '', + ' ', + ' ', + ' ', + ' ' + l('No file chosen') + '', + ' {{ uploader.queue[0].file.name }}', + ' ', + ' ', + ' ', + ' ' + l('Upload') + '', + ' ', + '' + ].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() { diff --git a/UI/WebServerResources/js/Contacts/Contacts.app.js b/UI/WebServerResources/js/Contacts/Contacts.app.js index ac25c4f98..16205a872 100644 --- a/UI/WebServerResources/js/Contacts/Contacts.app.js +++ b/UI/WebServerResources/js/Contacts/Contacts.app.js @@ -4,7 +4,7 @@ (function() { 'use strict'; - angular.module('SOGo.ContactsUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.PreferencesUI']) + angular.module('SOGo.ContactsUI', ['ngSanitize', 'ui.router', 'angularFileUpload', 'SOGo.Common', 'SOGo.PreferencesUI']) .config(configure) .run(runBlock);