copay/js/controllers/settings.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-05-13 10:19:37 -07:00
'use strict';
2014-09-03 07:33:45 -07:00
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location, controllerUtils) {
2014-08-04 07:27:46 -07:00
2014-08-11 13:26:48 -07:00
controllerUtils.redirIfLogged();
$scope.title = 'Settings';
$scope.insightHost = config.blockchain.host;
$scope.insightPort = config.blockchain.port;
$scope.insightSecure = config.blockchain.schema === 'https';
$scope.defaultLanguage = config.defaultLanguage || 'en';
$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-06-09 12:58:17 -07:00
2014-06-26 14:47:27 -07:00
2014-08-11 13:26:48 -07:00
$scope.changeInsightSSL = function() {
$scope.insightPort = $scope.insightSecure ? 80 : 443;
};
2014-06-26 14:47:27 -07:00
2014-08-11 13:26:48 -07:00
$scope.save = function() {
var network = config.network;
2014-08-25 14:26:26 -07:00
network.host = $scope.insightHost;
network.port = $scope.insightPort;
network.schema = $scope.insightSecure ? 'https' : 'http';
2014-05-15 11:25:58 -07:00
2014-08-11 13:26:48 -07:00
localStorage.setItem('config', JSON.stringify({
networkName: $scope.networkName,
blockchain: {
host: $scope.insightHost,
port: $scope.insightPort,
schema: $scope.insightSecure ? 'https' : 'http',
},
socket: {
host: $scope.insightHost,
port: $scope.insightPort,
schema: $scope.insightSecure ? 'https' : 'http',
},
network: network,
unitName: $scope.selectedUnit.shortName,
unitToSatoshi: $scope.selectedUnit.value,
2014-08-27 13:15:05 -07:00
unitDecimals: $scope.selectedUnit.decimals,
alternativeName: $scope.selectedAlternative.name,
alternativeIsoCode: $scope.selectedAlternative.isoCode,
version: copay.version,
defaultLanguage: $scope.selectedLanguage.isoCode
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);
};
});