Wallet/src/js/controllers/preferencesNotifications.js

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-09-28 10:50:33 -03:00
'use strict';
2016-10-28 10:13:40 -03:00
angular.module('copayApp.controllers').controller('preferencesNotificationsController', function($scope, $log, $window, configService, platformInfo, pushNotificationsService, profileService, emailService) {
var updateConfig = function() {
$scope.appName = $window.appConfig.nameCase;
$scope.PNEnabledByUser = true;
$scope.usePushNotifications = platformInfo.isCordova && !platformInfo.isWP;
$scope.isIOSApp = platformInfo.isIOS && platformInfo.isCordova;
2016-09-28 10:50:33 -03:00
2016-10-28 10:13:40 -03:00
if ($scope.isIOSApp) {
try {
PushNotification.hasPermission(function(data) {
$scope.PNEnabledByUser = data.isEnabled;
});
} catch (e) {
$log.error(e);
2016-09-28 10:50:33 -03:00
};
2016-10-28 10:13:40 -03:00
}
var config = configService.getSync();
$scope.pushNotifications = {
value: config.pushNotifications.enabled
2016-09-28 10:50:33 -03:00
};
2016-10-28 10:13:40 -03:00
$scope.emailNotifications = {
value: config.emailNotifications ? config.emailNotifications.enabled : false
2016-09-28 10:50:33 -03:00
};
2016-10-28 10:13:40 -03:00
};
2016-09-28 10:50:33 -03:00
2016-10-28 10:13:40 -03:00
$scope.pushNotificationsChange = function() {
if (!$scope.pushNotifications) return;
var opts = {
pushNotifications: {
enabled: $scope.pushNotifications.value
}
};
configService.set(opts, function(err) {
if (opts.pushNotifications.enabled)
profileService.pushNotificationsInit();
else
pushNotificationsService.disableNotifications(profileService.getWallets());
if (err) $log.debug(err);
2016-09-28 10:50:33 -03:00
});
2016-10-28 10:13:40 -03:00
};
$scope.emailNotificationsChange = function() {
var opts = {
emailNotifications: {
enabled: $scope.emailNotifications.value
}
};
emailService.enableEmailNotifications($scope.emailNotifications.value);
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.$on("$ionicView.enter", function(event, data) {
updateConfig();
2016-09-28 10:50:33 -03:00
});
2016-10-28 10:13:40 -03:00
});