2016-09-12 11:57:20 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-11-25 17:15:18 -03:00
|
|
|
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService) {
|
2016-09-21 15:13:22 -03:00
|
|
|
|
|
|
|
|
$scope.fromSendTab = $stateParams.fromSendTab;
|
2016-09-12 11:57:20 -03:00
|
|
|
|
|
|
|
|
$scope.addressbookEntry = {
|
2016-09-21 15:13:22 -03:00
|
|
|
'address': $stateParams.addressbookEntry || '',
|
2016-09-12 11:57:20 -03:00
|
|
|
'name': '',
|
|
|
|
|
'email': ''
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-29 14:37:31 -03:00
|
|
|
$scope.onQrCodeScannedAddressBook = function(data, addressbookForm) {
|
2016-09-12 11:57:20 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
var form = addressbookForm;
|
|
|
|
|
if (data && form) {
|
2017-09-09 19:23:46 -03:00
|
|
|
data = data.replace(/^bitcoin(cash)?:/, '');
|
2016-09-12 11:57:20 -03:00
|
|
|
form.address.$setViewValue(data);
|
|
|
|
|
form.address.$isValid = true;
|
|
|
|
|
form.address.$render();
|
|
|
|
|
}
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.add = function(addressbook) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
addressbookService.add(addressbook, function(err, ab) {
|
|
|
|
|
if (err) {
|
2016-10-26 17:10:21 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
2016-09-12 11:57:20 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2016-09-21 15:13:22 -03:00
|
|
|
if ($scope.fromSendTab) $scope.goHome();
|
2016-09-23 17:10:34 -03:00
|
|
|
else $ionicHistory.goBack();
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-21 15:13:22 -03:00
|
|
|
$scope.goHome = function() {
|
2016-09-23 12:42:33 -03:00
|
|
|
$ionicHistory.removeBackView();
|
2016-09-21 15:13:22 -03:00
|
|
|
$state.go('tabs.home');
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|