refactor - only mobile

This commit is contained in:
JDonadio 2017-03-06 12:45:37 -03:00
commit e89847af55
5 changed files with 58 additions and 72 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $timeout, $state, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) { angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $timeout, $state, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
var updateConfig = function() { var updateConfig = function() {
var config = configService.getSync(); var config = configService.getSync();
@ -53,27 +53,22 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
}; };
$scope.usePincodeChange = function() { $scope.usePincodeChange = function() {
// pincodeService.lockChange({
// fromSettings: true,
// locking: $scope.usePincode.enabled
// });
$state.go('tabs.pincode', { $state.go('tabs.pincode', {
fromSettings: true, fromSettings: true,
locking: $scope.usePincode.enabled locking: $scope.usePincode.enabled
}); });
}; };
$rootScope.$on('updatePincodeOption', function(event) { $scope.$on('updatePincodeOption', function(event) {
$timeout(function() { var config = configService.getSync();
var config = configService.getSync(); $scope.usePincode = {
$scope.usePincode = { enabled: config.pincode ? config.pincode.enabled : false
enabled: config.pincode ? config.pincode.enabled : false };
}; $scope.$apply();
$scope.$apply();
});
}); });
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isCordova = platformInfo.isCordova;
updateConfig(); updateConfig();
}); });

View file

@ -1,36 +1,17 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $state, $timeout, $scope, $log, $window, configService) { angular.module('copayApp.controllers').controller('pincodeController', function($state, $stateParams, $timeout, $scope, $log, $window, configService) {
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event) {
$scope.currentPincode = $scope.newPincode = ''; $scope.currentPincode = $scope.newPincode = '';
$scope.fromSettings = data.stateParams.fromSettings == 'true' ? true : false; $scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
$scope.locking = data.stateParams.locking == 'true' ? true : false; $scope.locking = $stateParams.locking == 'true' ? true : false;
console.log('### From Settings:', $scope.fromSettings, 'Locking:', $scope.locking);
}); });
angular.element($window).on('keydown', function(e) {
if (e.which === 8) {
e.preventDefault();
$scope.delete();
}
if (e && e.key.match(/^[0-9]$/))
$scope.add(e.key);
else if (e && e.keyCode == 27)
$scope.close();
else if (e && e.keyCode == 13)
$scope.save();
});
$scope.add = function(value) {
updatePassCode(value);
};
$scope.delete = function() { $scope.delete = function() {
if ($scope.currentPincode.length > 0) { if ($scope.currentPincode.length > 0) {
$scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1); $scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1);
updatePassCode(); $scope.updatePinCode();
} }
}; };
@ -39,12 +20,18 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
else return true; else return true;
}; };
function updatePassCode(value) { $scope.updatePinCode = function(value) {
if (value && $scope.currentPincode.length < 4) if (value && !isComplete()) {
$scope.currentPincode = $scope.currentPincode + value; $scope.currentPincode = $scope.currentPincode + value;
}
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
if (!$scope.locking && isComplete()) {
$timeout(function() {
$scope.save();
});
}
}; };
$scope.save = function() { $scope.save = function() {
@ -52,29 +39,27 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
var config = configService.getSync(); var config = configService.getSync();
var match = config.pincode.value == $scope.currentPincode ? true : false; var match = config.pincode.value == $scope.currentPincode ? true : false;
if (!$scope.fromSettings && match) {
$scope.currentPincode = '';
$scope.close();
return;
}
if (!$scope.locking) { if (!$scope.locking) {
if (!match) return; if (match) {
saveSettings($scope.locking, ''); $scope.fromSettings ? saveSettings($scope.locking, '') : $scope.close();
return;
}
} else {
checkCodes();
} }
checkCodes();
}; };
function checkCodes() { function checkCodes() {
if (!$scope.newPincode) { if (!$scope.newPincode) {
$scope.newPincode = $scope.currentPincode; $scope.newPincode = $scope.currentPincode;
$scope.currentPincode = ''; $scope.currentPincode = '';
$timeout(function() {
$scope.$apply();
});
} else { } else {
if ($scope.newPincode == $scope.currentPincode) if ($scope.newPincode == $scope.currentPincode)
saveSettings($scope.locking, $scope.newPincode); saveSettings($scope.locking, $scope.newPincode);
} }
$timeout(function() {
$scope.$apply();
});
}; };
function saveSettings(enabled, value) { function saveSettings(enabled, value) {
@ -92,7 +77,7 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
}; };
$scope.close = function() { $scope.close = function() {
$rootScope.$emit('updatePincodeOption'); $scope.$emit('updatePincodeOption');
if ($scope.fromSettings) $state.go('tabs.advanced'); if ($scope.fromSettings) $state.go('tabs.advanced');
else $state.go('tabs.home'); else $state.go('tabs.home');
}; };

View file

@ -126,9 +126,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*/ */
.state('pincode', { .state('pincode', {
url: '/pincode/:fromSettings/:locking', url: '/pincode/',
controller: 'pincodeController', controller: 'pincodeController',
templateUrl: 'views/pincode.html' templateUrl: 'views/pincode.html',
}) })
/* /*
@ -457,6 +457,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
'tab-settings@tabs': { 'tab-settings@tabs': {
controller: 'pincodeController', controller: 'pincodeController',
templateUrl: 'views/pincode.html', templateUrl: 'views/pincode.html',
cache: false
} }
} }
}) })
@ -1112,7 +1113,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
}); });
}) })
.run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) { .run(function($rootScope, $state, $location, $log, $timeout, startupService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) {
uxLanguage.init(); uxLanguage.init();
@ -1218,11 +1219,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
historyRoot: true historyRoot: true
}); });
configService.whenAvailable(function(config) { configService.whenAvailable(function(config) {
console.log('### CONFIG', config.pincode); startupService.ready();
if (config.pincode && config.pincode.enabled) { if (platformInfo.isCordova && config.pincode && config.pincode.enabled) {
$state.go('pincode', { $state.transitionTo('pincode').then(function() {
fromSettings: false, // Clear history
locking: false $ionicHistory.clearHistory();
}); });
} else { } else {
$state.transitionTo('tabs.home').then(function() { $state.transitionTo('tabs.home').then(function() {

View file

@ -31,7 +31,7 @@
<div class="item item-divider"></div> <div class="item item-divider"></div>
<ion-toggle ng-model="usePincode.enabled" toggle-class="toggle-balanced" ng-change="usePincodeChange()"> <ion-toggle ng-if="isCordova" ng-model="usePincode.enabled" toggle-class="toggle-balanced" ng-change="usePincodeChange()">
<span class="toggle-label" translate>Use pin to lock/unlock the app</span> <span class="toggle-label" translate>Use pin to lock/unlock the app</span>
</ion-toggle> </ion-toggle>
</div> </div>

View file

@ -1,4 +1,9 @@
<ion-modal-view id="pin-code" ng-controller="pincodeController" hide-tabs> <ion-view id="pin-code" ng-controller="pincodeController" hide-tabs hide-back-button="!fromSettings">
<ion-nav-bar class="bar-royal">
<ion-nav-title>{{'Pin Code' | translate}}</ion-nav-title>
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<div ng-if="fromSettings" ng-click="close()" class="close" translate>Close</div> <div ng-if="fromSettings" ng-click="close()" class="close" translate>Close</div>
<div class="content"> <div class="content">
<div class="block-code"> <div class="block-code">
@ -20,35 +25,35 @@
<div class="block-buttons"> <div class="block-buttons">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('1')">1</button> <button class="button button-light button-stretch" ng-click="updatePinCode('1')">1</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('2')">2</button> <button class="button button-light button-stretch" ng-click="updatePinCode('2')">2</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('3')">3</button> <button class="button button-light button-stretch" ng-click="updatePinCode('3')">3</button>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('4')">4</button> <button class="button button-light button-stretch" ng-click="updatePinCode('4')">4</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('5')">5</button> <button class="button button-light button-stretch" ng-click="updatePinCode('5')">5</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('6')">6</button> <button class="button button-light button-stretch" ng-click="updatePinCode('6')">6</button>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('7')">7</button> <button class="button button-light button-stretch" ng-click="updatePinCode('7')">7</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('8')">8</button> <button class="button button-light button-stretch" ng-click="updatePinCode('8')">8</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('9')">9</button> <button class="button button-light button-stretch" ng-click="updatePinCode('9')">9</button>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@ -56,7 +61,7 @@
<button class="button button-light button-stretch icon ion-checkmark" ng-click="save()" ng-disabled=""></button> <button class="button button-light button-stretch icon ion-checkmark" ng-click="save()" ng-disabled=""></button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch" ng-click="add('0')">0</button> <button class="button button-light button-stretch" ng-click="updatePinCode('0')">0</button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-light button-stretch icon ion-arrow-left-a" ng-click="delete()"></button> <button class="button button-light button-stretch icon ion-arrow-left-a" ng-click="delete()"></button>
@ -64,4 +69,4 @@
</div> </div>
</div> </div>
</div> </div>
</ion-modal-view> </ion-view>