Skip to content

Commit

Permalink
Add import menu item to all addressBooks
Browse files Browse the repository at this point in the history
Relates to owncloud#654
  • Loading branch information
Daniel Gröger committed Nov 10, 2021
1 parent aa573b2 commit e72e8ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
12 changes: 10 additions & 2 deletions js/components/addressBook/addressBook_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('contactsApp')
.controller('addressbookCtrl', function($scope, AddressBookService) {
.controller('addressbookCtrl', function($scope, $document, AddressBookService) {
var ctrl = this;

ctrl.t = {
Expand All @@ -12,7 +12,8 @@ angular.module('contactsApp')
shareInputPlaceHolder: t('contacts', 'Share with users or groups'),
delete: t('contacts', 'Delete'),
more: t('contacts', 'More'),
canEdit: t('contacts', 'can edit')
canEdit: t('contacts', 'can edit'),
import: t('contacts', 'Import')
};

ctrl.showUrl = false;
Expand Down Expand Up @@ -152,6 +153,13 @@ angular.module('contactsApp')
});
};

ctrl.triggerImport = function() {
var element = $document.find('#contact-import-' + $scope.index);
if (element) {
element.click();
}
};

ctrl.download = function() {
window.open(ctrl.addressBook.url + '?export');
};
Expand Down
21 changes: 20 additions & 1 deletion js/components/addressBook/addressBook_directive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
angular.module('contactsApp')
.directive('addressbook', function() {
.directive('addressbook', function(ContactService) {
return {
link: function(scope, element, ctrl) {
var input = element.find('input');
input.bind('change', function() {
angular.forEach(input.get(0).files, function(file) {
var reader = new FileReader();

reader.addEventListener('load', function () {
scope.$apply(function () {
ContactService.import.call(ContactService, reader.result, file.type, ctrl.addressBook);
});
}, false);

if (file) {
reader.readAsText(file);
}
});
input.get(0).value = '';
});
},
restrict: 'A', // has to be an attribute to work with core css
scope: {
index: '@'
Expand Down
8 changes: 8 additions & 0 deletions templates/addressBook.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
</button>
</li>

<li>
<button ng-click="ctrl.triggerImport()">
<span class="icon-upload svg"></span>
<span>{{ctrl.t.import}}</span>
</button>
<input type="file" id="contact-import-{{index}}" class="hidden-visually" multiple/>
</li>

<li>
<button ng-click="ctrl.deleteAddressBook()">
<span class="icon-delete svg"></span>
Expand Down

0 comments on commit e72e8ae

Please sign in to comment.