copay/js/controllers/settings.js

87 lines
2.3 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, notification, configService) {
$scope.title = 'Settings';
$scope.insightLivenet = config.network.livenet.url;
$scope.insightTestnet = config.network.testnet.url;
$scope.defaultLogLevel = config.logLevel || 'log';
var logLevels = copay.logger.getLevels();
$scope.availableLogLevels = [];
for (var key in logLevels) {
$scope.availableLogLevels.push({
'name': key
});
}
$scope.availableStorages = [{
name: 'In the cloud (Insight server)',
pluginName: 'EncryptedInsightStorage',
}, {
name: 'On this device (localstorage)',
pluginName: 'EncryptedLocalStorage',
},
// {
// name: 'GoogleDrive',
// pluginName: 'GoogleDrive',
// }
];
_.each($scope.availableStorages, function(v) {
if (config.plugins[v.pluginName])
$scope.selectedStorage = v;
});
for (var ii in $scope.availableLogLevels) {
if ($scope.defaultLogLevel === $scope.availableLogLevels[ii].name) {
$scope.selectedLogLevel = $scope.availableLogLevels[ii];
break;
}
}
$scope.save = function() {
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
var insightSettings = {
livenet: {
url: $scope.insightLivenet,
transports: ['polling'],
},
testnet: {
url: $scope.insightTestnet,
transports: ['polling'],
},
}
var plugins = {};
plugins[$scope.selectedStorage.pluginName] = true;
configService.set({
network: insightSettings,
plugins: plugins,
logLevel: $scope.selectedLogLevel.name,
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
url: insightSettings.livenet.url + '/api/email'
}),
rates: _.extend(config.rates, {
url: insightSettings.livenet.url + '/api/rates'
}),
},
function() {
notification.success('Settings saved',"Settings were saved");
$location.path('/');
});
};
$scope.reset = function() {
configService.reset(function() {
notification.success('Settings reseted',"Settings were reseted");
$location.path('/');
});
};
});