2016-09-12 11:57:20 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-09-21 15:13:22 -03:00
|
|
|
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, addressbookService, popupService) {
|
|
|
|
|
|
|
|
|
|
$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': ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.onQrCodeScanned = function(data, addressbookForm) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
var form = addressbookForm;
|
|
|
|
|
if (data && form) {
|
|
|
|
|
data = data.replace('bitcoin:', '');
|
|
|
|
|
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) {
|
|
|
|
|
popupService.showAlert(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-21 15:13:22 -03:00
|
|
|
if ($scope.fromSendTab) $scope.goHome();
|
|
|
|
|
else $state.go('tabs.addressbook');
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-21 15:13:22 -03:00
|
|
|
$scope.goHome = function() {
|
|
|
|
|
$ionicHistory.clearHistory();
|
|
|
|
|
$state.go('tabs.home');
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|