diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 33062428a..b3e4fb152 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -94,7 +94,6 @@ - @@ -441,6 +440,40 @@ + + + diff --git a/UI/WebServerResources/js/Contacts/AddressBooksController.js b/UI/WebServerResources/js/Contacts/AddressBooksController.js index 54df1434c..d70ca3983 100644 --- a/UI/WebServerResources/js/Contacts/AddressBooksController.js +++ b/UI/WebServerResources/js/Contacts/AddressBooksController.js @@ -116,38 +116,9 @@ 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(''), + templateUrl: 'UIxContactsImportDialog', controller: CardsImportDialogController, + controllerAs: '$CardsImportDialogController', locals: { folder: folder } @@ -158,36 +129,67 @@ */ CardsImportDialogController.$inject = ['scope', '$mdDialog', 'folder']; function CardsImportDialogController(scope, $mdDialog, folder) { + var vm = this; - scope.uploader = new FileUploader({ - url: ApplicationBaseURL + '/' + folder.id + '/import', - onProgressItem: function(item, progress) { - console.debug(item); console.debug(progress); - }, + 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) { - console.debug(item); console.debug('success = ' + JSON.stringify(response, undefined, 2)); + 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(l('A total of %{0} cards were imported in the addressbook.', response.imported)) + .content(msg) .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)); + $mdToast.show({ + template: [ + '', + ' error_outline', + ' ' + l('An error occured while importing contacts.') + '', + '' + ].join(''), + position: 'top right', + hideDelay: 3000 + }); } }); - scope.close = function() { + vm.close = function() { $mdDialog.hide(); }; - scope.upload = function() { - scope.uploader.uploadAll(); - }; + + 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: 3000 + }); + + return isTextFile; + } } } diff --git a/UI/WebServerResources/scss/components/toast/toast.scss b/UI/WebServerResources/scss/components/toast/toast.scss index 48c4ab4ca..ee7218357 100644 --- a/UI/WebServerResources/scss/components/toast/toast.scss +++ b/UI/WebServerResources/scss/components/toast/toast.scss @@ -1 +1,7 @@ -@import 'extends'; \ No newline at end of file +@import 'extends'; + +md-toast { + > md-icon { + margin-right: 12px; + } +} \ No newline at end of file