copay/js/controllers/settings.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-05-13 10:19:37 -07:00
'use strict';
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location, controllerUtils, notification) {
2014-05-13 10:19:37 -07:00
2014-08-04 07:27:46 -07:00
2014-08-11 13:26:48 -07:00
controllerUtils.redirIfLogged();
2014-08-11 13:26:48 -07:00
$scope.title = 'Settings';
$scope.defaultLanguage = config.defaultLanguage || 'en';
$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-10-30 07:08:34 -07:00
name: 'Insight',
pluginName: 'EncryptedInsightStorage',
}, {
name: 'Localstorage',
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;
});
$scope.availableLanguages = [{
name: 'English',
isoCode: 'en',
}, {
name: 'Spanish',
isoCode: 'es',
}];
for (var ii in $scope.availableLanguages) {
if ($scope.defaultLanguage === $scope.availableLanguages[ii].isoCode) {
$scope.selectedLanguage = $scope.availableLanguages[ii];
break;
}
}
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;
copay.logger.setLevel($scope.selectedLogLevel.name);
2014-10-30 07:08:34 -07:00
2014-08-11 13:26:48 -07:00
localStorage.setItem('config', JSON.stringify({
network: insightSettings,
2014-09-08 16:26:58 -07:00
version: copay.version,
2014-10-30 12:20:25 -07:00
defaultLanguage: $scope.selectedLanguage.isoCode,
plugins: plugins,
logLevel: $scope.selectedLogLevel.name,
2014-11-10 17:58:46 -08:00
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
url: insightSettings.livenet.url + '/api/email'
}),
2014-08-11 13:26:48 -07:00
}));
2014-08-11 13:26:48 -07:00
// Go home reloading the application
var hashIndex = window.location.href.indexOf('#!/');
window.location = window.location.href.substr(0, hashIndex);
};
});