Wallet/src/js/controllers/pincode.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-02-23 16:56:46 -05:00
'use strict';
2017-03-02 11:25:38 -03:00
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $timeout, $scope, $log, $window, configService) {
2017-03-01 17:29:39 -03:00
var config = configService.getSync();
$scope.currentPincode = config.pincode ? config.pincode.value : null;
2017-03-02 11:25:38 -03:00
$scope.pincode = $scope.pc1 = $scope.pc2 = null;
2017-02-23 16:56:46 -05:00
angular.element($window).on('keydown', function(e) {
2017-03-02 11:25:38 -03:00
if (e.which === 8) {
2017-02-23 16:56:46 -05:00
e.preventDefault();
$scope.delete();
}
2017-03-01 17:29:39 -03:00
if (e && e.key.match(/^[0-9]$/))
2017-02-23 16:56:46 -05:00
$scope.add(e.key);
2017-03-01 17:29:39 -03:00
else if (e && e.keyCode == 27)
2017-03-02 11:25:38 -03:00
$scope.cancel();
2017-03-01 17:29:39 -03:00
else if (e && e.keyCode == 13)
$scope.save();
2017-02-23 16:56:46 -05:00
});
$scope.add = function(value) {
2017-03-01 17:29:39 -03:00
updatePassCode(value);
2017-02-23 16:56:46 -05:00
};
$scope.delete = function() {
2017-02-24 14:46:54 -05:00
if ($scope.pincode.length > 0) {
$scope.pincode = $scope.pincode.substring(0, $scope.pincode.length - 1);
2017-02-23 16:56:46 -05:00
updatePassCode();
}
};
function isComplete() {
2017-02-24 14:46:54 -05:00
if ($scope.pincode.length < 4) return false;
2017-02-23 16:56:46 -05:00
else return true;
};
function updatePassCode(value) {
2017-03-01 17:29:39 -03:00
if (value && $scope.pincode.length < 4)
$scope.pincode = $scope.pincode + value;
2017-02-23 16:56:46 -05:00
$timeout(function() {
$scope.$apply();
});
};
2017-02-24 14:46:54 -05:00
2017-03-01 17:29:39 -03:00
$scope.save = function() {
if (!$scope.pc1) {
console.log('No pc 1');
$scope.pc1 = $scope.pincode;
console.log('$scope.pc1', $scope.pc1);
$scope.pincode = '';
$timeout(function() {
$scope.$apply();
});
return;
} else {
$scope.pc2 = $scope.pincode;
console.log('$scope.pc2', $scope.pc2);
}
if ($scope.pc1 == $scope.pc2) {
$scope.close($scope.pc1);
} else {
$scope.enabled ? pincodeService.lockApp() : pincodeService.unlockApp();
}
2017-02-24 14:46:54 -05:00
};
2017-02-28 10:32:10 -03:00
2017-03-01 17:29:39 -03:00
$scope.close = function() {
2017-02-28 10:32:10 -03:00
$scope.pincodeModal.hide();
};
2017-03-02 11:25:38 -03:00
$scope.cancel = function() {
$rootScope.$emit('updatePincodeOption', false);
$scope.close();
};
2017-02-23 16:56:46 -05:00
});