add switch to enable/disable notifications on global setings

This commit is contained in:
Javier 2015-12-23 14:17:24 -03:00 committed by Gabriel Bazán
commit b3c59e2cb0
4 changed files with 30 additions and 3 deletions

View file

@ -48,6 +48,10 @@
<switch id="spend-unconfirmed" name="spendUnconfirmed" ng-model="spendUnconfirmed" class="green right"></switch>
<div translate>Use Unconfirmed Funds</div>
</li>
<li>
<switch id="enable-notifications" name="notifications" ng-model="notifications" class="green right"></switch>
<div translate>Enable notifications</div>
</li>
</ul>
<h4></h4>
<ul class="no-bullet m0 ">

View file

@ -1197,6 +1197,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateAll();
});
$rootScope.$on('Local/EnableNotifications', function(event, vale) {
//make suscribe/unsuscribe
self.updateAll();
});
$rootScope.$on('Local/FeeLevelUpdated', function(event, level) {
self.setCurrentFeeLevel(level);
});

View file

@ -2,7 +2,7 @@
angular.module('copayApp.controllers').controller('preferencesGlobalController',
function($scope, $rootScope, $log, configService, uxLanguage) {
this.init = function() {
var config = configService.getSync();
this.unitName = config.wallet.settings.unitName;
@ -10,10 +10,11 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
this.selectedAlternative = {
name: config.wallet.settings.alternativeName,
isoCode: config.wallet.settings.alternativeIsoCode
};
};
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
$scope.glideraEnabled = config.glidera.enabled;
$scope.glideraTestnet = config.glidera.testnet;
$scope.notifications = config.notifications ? config.notifications.enabled : true;
};
var unwatchSpendUnconfirmed = $scope.$watch('spendUnconfirmed', function(newVal, oldVal) {
@ -29,6 +30,19 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
});
});
var unwatchNotification = $scope.$watch('notifications', function(newVal, oldVal) {
if (newVal == oldVal) return;
var opts = {
notifications: {
enabled: newVal
}
};
configService.set(opts, function(err) {
$rootScope.$emit('Local/EnableNotifications', opts);
if (err) $log.debug(err);
});
});
var unwatchGlideraEnabled = $scope.$watch('glideraEnabled', function(newVal, oldVal) {
if (newVal == oldVal) return;
var opts = {

View file

@ -41,6 +41,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
rates: {
url: 'https://insight.bitpay.com:443/api/rates',
},
notifications: {
enabled: true
},
};
var configCache = null;
@ -70,7 +74,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
configCache.wallet.settings.unitCode = defaultConfig.wallet.settings.unitCode;
}
if (!configCache.glidera) {
configCache.glidera = defaultConfig.glidera;
configCache.glidera = defaultConfig.glidera;
}
} else {