Wallet/src/js/controllers/onboarding/notifications.js
Gustavo Maximiliano Cortez 4e8bd0634c
New push notifications
2017-03-09 12:22:06 -03:00

53 lines
1.4 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('notificationsController', function($scope, $state, $timeout, $stateParams, $ionicConfig, profileService, configService, $interval, pushNotificationsService) {
$scope.$on("$ionicView.enter", function() {
$ionicConfig.views.swipeBackEnabled(false);
});
$scope.$on("$ionicView.beforeLeave", function() {
$ionicConfig.views.swipeBackEnabled(true);
});
$scope.walletId = $stateParams.walletId;
$scope.allowNotif = function() {
$scope.notificationDialogOpen = true;
$timeout(function() {
pushNotificationsService.init();
});
$scope.notificationPromise = $interval(function() {
PushNotification.hasPermission(function(data) {
if (data.isEnabled) {
$interval.cancel($scope.notificationPromise);
$state.go('onboarding.backupRequest', {
walletId: $scope.walletId
});
}
});
}, 100);
}
$scope.continue = function() {
$interval.cancel($scope.notificationPromise);
$state.go('onboarding.backupRequest', {
walletId: $scope.walletId
});
}
$scope.disableNotif = function() {
var opts = {
pushNotifications: {
enabled: false
}
};
configService.set(opts, function(err) {
if (err) $log.warn(err);
$state.go('onboarding.backupRequest', {
walletId: $scope.walletId
});
});
};
});