add toggle for email notifications

This commit is contained in:
Javier 2016-10-28 10:13:40 -03:00
commit 410d35495b
6 changed files with 100 additions and 49 deletions

View file

@ -1,49 +1,62 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesNotificationsController',
function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) {
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;
var updateConfig = function() {
if ($scope.isIOSApp) {
try {
PushNotification.hasPermission(function(data) {
$scope.PNEnabledByUser = data.isEnabled;
});
} catch (e) {
$log.error(e);
};
}
var config = configService.getSync();
var isCordova = platformInfo.isCordova;
var isIOS = platformInfo.isIOS;
var config = configService.getSync();
$scope.appName = $window.appConfig.nameCase;
$scope.PNEnabledByUser = true;
$scope.isIOSApp = isIOS && isCordova;
if ($scope.isIOSApp) {
try {
PushNotification.hasPermission(function(data) {
$scope.PNEnabledByUser = data.isEnabled;
});
} catch(e) {
$log.error(e);
};
$scope.pushNotifications = {
value: config.pushNotifications.enabled
};
$scope.emailNotifications = {
value: config.emailNotifications ? config.emailNotifications.enabled : false
};
};
$scope.pushNotificationsChange = function() {
if (!$scope.pushNotifications) return;
var opts = {
pushNotifications: {
enabled: $scope.pushNotifications.value
}
$scope.pushNotifications = {
value: config.pushNotifications.enabled
};
};
$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);
});
};
$scope.$on("$ionicView.enter", function(event, data) {
updateConfig();
configService.set(opts, function(err) {
if (opts.pushNotifications.enabled)
profileService.pushNotificationsInit();
else
pushNotificationsService.disableNotifications(profileService.getWallets());
if (err) $log.debug(err);
});
};
$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();
});
});

View file

@ -1,17 +1,11 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService) {
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, profileService, feeService, configService, externalLinkService) {
var updateConfig = function() {
var config = configService.getSync();
var isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP;
$scope.usePushNotifications = isCordova && !isWP;
$scope.appName = $window.appConfig.nameCase;
var config = configService.getSync();
$scope.unitName = config.wallet.settings.unitName;
$scope.currentLanguageName = uxLanguage.getCurrentLanguageName();
$scope.selectedAlternative = {