copay/js/controllers/settings.js

87 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-05-13 10:19:37 -07:00
'use strict';
2014-12-05 08:24:46 -08:00
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, notification, configService) {
2014-08-11 13:26:48 -07:00
$scope.title = 'Settings';
$scope.insightLivenet = config.network.livenet.url;
$scope.insightTestnet = config.network.testnet.url;
2014-10-30 07:08:34 -07:00
$scope.defaultLogLevel = config.logLevel || 'log';
var logLevels = copay.logger.getLevels();
2014-10-30 07:08:34 -07:00
$scope.availableLogLevels = [];
2014-10-30 07:08:34 -07:00
for (var key in logLevels) {
$scope.availableLogLevels.push({
'name': key
});
2014-10-30 07:08:34 -07:00
}
2014-10-30 12:20:25 -07:00
$scope.availableStorages = [{
2014-12-05 10:21:35 -08:00
name: 'In the cloud (Insight server)',
2014-10-30 07:08:34 -07:00
pluginName: 'EncryptedInsightStorage',
}, {
2014-12-06 14:56:51 -08:00
name: 'On this device (localstorage)',
2014-10-30 07:08:34 -07:00
pluginName: 'EncryptedLocalStorage',
},
// {
// name: 'GoogleDrive',
// pluginName: 'GoogleDrive',
// }
2014-10-30 12:20:25 -07:00
];
2014-10-30 07:08:34 -07:00
_.each($scope.availableStorages, function(v) {
2014-10-30 12:20:25 -07:00
if (config.plugins[v.pluginName])
$scope.selectedStorage = v;
});
2014-10-30 07:08:34 -07:00
for (var ii in $scope.availableLogLevels) {
if ($scope.defaultLogLevel === $scope.availableLogLevels[ii].name) {
2014-10-30 07:08:34 -07:00
$scope.selectedLogLevel = $scope.availableLogLevels[ii];
break;
}
}
2014-08-11 13:26:48 -07:00
$scope.save = function() {
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
2014-09-03 09:11:32 -07:00
var insightSettings = {
livenet: {
url: $scope.insightLivenet,
2014-10-30 18:59:47 -07:00
transports: ['polling'],
},
testnet: {
url: $scope.insightTestnet,
2014-10-30 18:59:47 -07:00
transports: ['polling'],
},
2014-09-03 09:11:32 -07:00
}
2014-10-30 12:20:25 -07:00
var plugins = {};
plugins[$scope.selectedStorage.pluginName] = true;
2014-12-02 05:40:24 -08:00
2014-12-05 08:24:46 -08:00
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");
2014-12-05 08:24:46 -08:00
$location.path('/');
});
2014-08-11 13:26:48 -07:00
};
2014-11-12 16:31:07 -08:00
$scope.reset = function() {
2014-12-05 08:24:46 -08:00
configService.reset(function() {
notification.success('Settings reseted',"Settings were reseted");
2014-12-05 08:24:46 -08:00
$location.path('/');
2014-12-01 22:55:29 -08:00
});
2014-11-12 16:31:07 -08:00
};
2014-08-11 13:26:48 -07:00
});