update option if enabled/disabled

This commit is contained in:
JDonadio 2017-03-02 11:25:38 -03:00
commit 34413278ec
3 changed files with 23 additions and 21 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $timeout, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
var updateConfig = function() {
var config = configService.getSync();
@ -53,22 +53,21 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
};
$scope.usePincodeChange = function() {
var opts = {};
opts.enabled = $scope.usePincode.enabled;
opts.from = 'settings';
pincodeService.lockChange(opts, function(err) {
if (err) {
$log.warn(err);
// ToDo show error?
$scope.usePincode.enabled = false;
$scope.$apply();
return;
}
pincodeService.lockChange({
enabled: $scope.usePincode.enabled,
from: 'settings'
});
};
$rootScope.$on('updatePincodeOption', function(event) {
console.log('ON');
var config = configService.getSync();
$scope.usePincode = {
enabled: config.pincode ? config.pincode.enabled : false
};
$scope.$apply();
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
updateConfig();
});

View file

@ -1,14 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('pincodeController', function($timeout, $scope, $log, $window, configService) {
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $timeout, $scope, $log, $window, configService) {
var config = configService.getSync();
$scope.currentPincode = config.pincode ? config.pincode.value : null;
$scope.pincode = $scope.pc1 = $scope.pc2 = '';
console.log('#######', $scope.from, $scope.enabled);
$scope.pincode = $scope.pc1 = $scope.pc2 = null;
angular.element($window).on('keydown', function(e) {
if (e.which === 8) { // you can add others here inside brackets.
if (e.which === 8) {
e.preventDefault();
$scope.delete();
}
@ -16,7 +14,7 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
if (e && e.key.match(/^[0-9]$/))
$scope.add(e.key);
else if (e && e.keyCode == 27)
$scope.close(false);
$scope.cancel();
else if (e && e.keyCode == 13)
$scope.save();
});
@ -70,4 +68,9 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
$scope.close = function() {
$scope.pincodeModal.hide();
};
$scope.cancel = function() {
$rootScope.$emit('updatePincodeOption', false);
$scope.close();
};
});

View file

@ -17,7 +17,7 @@ angular.module('copayApp.services').factory('pincodeService', function($log, $ro
});
};
root.lockChange = function(opts, cb) {
root.lockChange = function(opts) {
if (opts.enabled) console.log('Locking app from service');
else console.log('Unlocking app from service');
openPincodeModal(opts);