mirror of https://github.com/BTCPrivate/copay.git
move to notification settings
This commit is contained in:
parent
6ce01155d4
commit
2dace50816
|
@ -1,49 +1,97 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesNotificationsController',
|
angular.module('copayApp.controllers').controller('preferencesNotificationsController', function($scope, $log, $timeout, $window, lodash, configService, platformInfo, pushNotificationsService, profileService, emailService) {
|
||||||
function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) {
|
var updateConfig = function() {
|
||||||
|
var config = configService.getSync();
|
||||||
|
$scope.appName = $window.appConfig.nameCase;
|
||||||
|
$scope.PNEnabledByUser = true;
|
||||||
|
$scope.usePushNotifications = platformInfo.isCordova && !platformInfo.isWP;
|
||||||
|
$scope.isIOSApp = platformInfo.isIOS && platformInfo.isCordova;
|
||||||
|
|
||||||
var updateConfig = function() {
|
$scope.pushNotifications = {
|
||||||
|
value: config.pushNotifications.enabled
|
||||||
var config = configService.getSync();
|
|
||||||
var isCordova = platformInfo.isCordova;
|
|
||||||
var isIOS = platformInfo.isIOS;
|
|
||||||
|
|
||||||
$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.pushNotificationsChange = function() {
|
$scope.latestEmail = {
|
||||||
if (!$scope.pushNotifications) return;
|
value: getLatestEmailConfig()
|
||||||
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) {
|
$scope.newEmail = lodash.clone($scope.latestEmail);
|
||||||
updateConfig();
|
var isEmailEnabled = config.emailNotifications ? config.emailNotifications.enabled : false;
|
||||||
|
|
||||||
|
$scope.emailNotifications = {
|
||||||
|
value: isEmailEnabled && $scope.newEmail.value ? true : false
|
||||||
|
};
|
||||||
|
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$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.emailNotificationsChange = function() {
|
||||||
|
var opts = {
|
||||||
|
emailNotifications: {
|
||||||
|
enabled: $scope.emailNotifications.value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.latestEmail = {
|
||||||
|
value: getLatestEmailConfig()
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.newEmail = lodash.clone($scope.latestEmail);
|
||||||
|
|
||||||
|
if (!$scope.emailNotifications.value) {
|
||||||
|
emailService.enableEmailNotifications({
|
||||||
|
enabled: $scope.emailNotifications.value,
|
||||||
|
email: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.save = function() {
|
||||||
|
emailService.enableEmailNotifications({
|
||||||
|
enabled: $scope.emailNotifications.value,
|
||||||
|
email: $scope.newEmail.value
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.latestEmail = {
|
||||||
|
value: $scope.newEmail.value
|
||||||
|
};
|
||||||
|
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function getLatestEmailConfig() {
|
||||||
|
var config = configService.getSync();
|
||||||
|
return config.emailFor ? lodash.values(config.emailFor)[0] : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.$on("$ionicView.enter", function(event, data) {
|
||||||
|
updateConfig();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -85,6 +85,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
windows: {},
|
windows: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emailNotifications: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var configCache = null;
|
var configCache = null;
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').factory('emailService', function($log, configService, profileService, lodash, walletService) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.enableEmailNotifications = function(opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
|
var wallets = profileService.getWallets();
|
||||||
|
var keys = lodash.map(wallets, function(w) {
|
||||||
|
return w.credentials.walletId;
|
||||||
|
});
|
||||||
|
|
||||||
|
lodash.each(wallets, function(w) {
|
||||||
|
walletService.updateRemotePreferences(w, {
|
||||||
|
email: opts.enabled ? opts.email : null
|
||||||
|
}, function(err) {
|
||||||
|
if (err) $log.warn(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var config = configService.getSync();
|
||||||
|
if (!config.emailFor)
|
||||||
|
config.emailFor = {};
|
||||||
|
|
||||||
|
lodash.each(keys, function(k) {
|
||||||
|
config.emailFor[k] = opts.email;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!opts.enabled) return;
|
||||||
|
|
||||||
|
configService.set({
|
||||||
|
emailFor: config.emailFor
|
||||||
|
}, function(err) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
|
@ -7,15 +7,40 @@
|
||||||
|
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div ng-show="PNEnabledByUser">
|
<div ng-if="PNEnabledByUser">
|
||||||
<div class="item item-divider" translate>Notifications</div>
|
<div class="item item-divider" translate>Notifications</div>
|
||||||
|
|
||||||
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()">
|
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()" ng-if="usePushNotifications">
|
||||||
<span class="toggle-label" translate>Enable push notifications</span>
|
<span class="toggle-label" translate>Enable push notifications</span>
|
||||||
</ion-toggle>
|
</ion-toggle>
|
||||||
|
|
||||||
|
<ion-toggle ng-model="emailNotifications.value" toggle-class="toggle-balanced" ng-change="emailNotificationsChange()">
|
||||||
|
<span class="toggle-label" translate>Enable email notifications</span>
|
||||||
|
</ion-toggle>
|
||||||
|
|
||||||
|
<div ng-if="emailNotifications.value">
|
||||||
|
<div class="settings-explanation">
|
||||||
|
<div class="settings-description" translate>
|
||||||
|
You'll receive email notifications about payments sent and received from {{wallet.name}}.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form name="emailForm" ng-submit="save()" novalidate>
|
||||||
|
<div class="list settings-input-group">
|
||||||
|
<label class="item item-input item-stacked-label">
|
||||||
|
<span class="input-label" translate>Email Address</span>
|
||||||
|
<input type="email" id="email" name="email" ng-model="newEmail.value" required></input>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit"
|
||||||
|
class="button button-standard button-primary"
|
||||||
|
ng-disabled="emailForm.$invalid || (newEmail.value == latestEmail.value)" translate>Save
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="!PNEnabledByUser && isIOSApp">
|
<div ng-if="!PNEnabledByUser && isIOSApp">
|
||||||
<div class="item item-divider" translate>Notifications</div>
|
<div class="item item-divider" translate>Notifications</div>
|
||||||
<div class="padding text-light" translate>
|
<div class="padding text-light" translate>
|
||||||
Push notifications for {{appName}} are currently disabled. Enable them in the Settings app.
|
Push notifications for {{appName}} are currently disabled. Enable them in the Settings app.
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
<div class="item item-divider" translate>Preferences</div>
|
<div class="item item-divider" translate>Preferences</div>
|
||||||
|
|
||||||
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications" ng-show="usePushNotifications">
|
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications">
|
||||||
<i class="icon big-icon-svg">
|
<i class="icon big-icon-svg">
|
||||||
<img src="img/icon-notifications.svg" class="bg"/>
|
<img src="img/icon-notifications.svg" class="bg"/>
|
||||||
</i>
|
</i>
|
||||||
|
|
Loading…
Reference in New Issue