Merge pull request #4958 from JDonadio/feat/email-toggle-02
New email notifications settings
This commit is contained in:
commit
ac3885a716
9 changed files with 166 additions and 125 deletions
|
|
@ -1,32 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesEmailController', function($scope, $ionicHistory, $stateParams, gettextCatalog, profileService, walletService, configService) {
|
||||
|
||||
$scope.wallet = profileService.getWallet($stateParams.walletId);
|
||||
var walletId = $scope.wallet.credentials.walletId;
|
||||
|
||||
var config = configService.getSync();
|
||||
config.emailFor = config.emailFor || {};
|
||||
$scope.emailForExist = config.emailFor && config.emailFor[walletId];
|
||||
$scope.email = {
|
||||
value: config.emailFor && config.emailFor[walletId]
|
||||
};
|
||||
|
||||
|
||||
$scope.save = function(val) {
|
||||
var opts = {
|
||||
emailFor: {}
|
||||
};
|
||||
opts.emailFor[walletId] = val;
|
||||
|
||||
walletService.updateRemotePreferences($scope.wallet, {
|
||||
email: val,
|
||||
}, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
$ionicHistory.goBack();
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
@ -1,49 +1,97 @@
|
|||
'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, $timeout, $window, lodash, configService, platformInfo, pushNotificationsService, profileService, emailService) {
|
||||
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() {
|
||||
|
||||
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.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.latestEmail = {
|
||||
value: getLatestEmailConfig()
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
updateConfig();
|
||||
$scope.newEmail = lodash.clone($scope.latestEmail);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -276,7 +276,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
templateUrl: 'views/confirm.html'
|
||||
}
|
||||
},
|
||||
params: { paypro: null }
|
||||
params: {
|
||||
paypro: null
|
||||
}
|
||||
})
|
||||
.state('tabs.send.addressbook', {
|
||||
url: '/addressbook/add/:fromSendTab/:addressbookEntry',
|
||||
|
|
@ -465,15 +467,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.preferences.preferencesEmail', {
|
||||
url: '/preferencesEmail',
|
||||
views: {
|
||||
'tab-settings@tabs': {
|
||||
controller: 'preferencesEmailController',
|
||||
templateUrl: 'views/preferencesEmail.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.preferences.backupWarning', {
|
||||
url: '/backupWarning/:from',
|
||||
views: {
|
||||
|
|
@ -892,7 +885,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
templateUrl: 'views/confirm.html'
|
||||
}
|
||||
},
|
||||
params: { paypro: null }
|
||||
params: {
|
||||
paypro: null
|
||||
}
|
||||
})
|
||||
.state('tabs.bitpayCard.preferences', {
|
||||
url: '/preferences',
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
windows: {},
|
||||
}
|
||||
},
|
||||
|
||||
emailNotifications: {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
var configCache = null;
|
||||
|
|
|
|||
40
src/js/services/emailService.js
Normal file
40
src/js/services/emailService.js
Normal file
|
|
@ -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;
|
||||
});
|
||||
|
|
@ -29,14 +29,6 @@
|
|||
</span>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</a>
|
||||
<a class="item has-setting-value item-icon-right" ui-sref="tabs.preferences.preferencesEmail">
|
||||
<span class="setting-title" translate>Email Notifications</span>
|
||||
<span class="setting-value">
|
||||
<span ng-if="!wallet.email" translate>Disabled</span>
|
||||
<span ng-if="wallet.email">{{wallet.email}}</span>
|
||||
</span>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</a>
|
||||
<div class="item item-divider" translate>
|
||||
Security
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
<ion-view class="settings">
|
||||
<ion-nav-bar class="bar-royal">
|
||||
<ion-nav-title>
|
||||
{{'Email Notifications'|translate}}
|
||||
</ion-nav-title>
|
||||
<ion-nav-back-button>
|
||||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
<ion-content>
|
||||
<div class="settings-explanation">
|
||||
<div class="settings-description" translate>
|
||||
You'll receive email notifications about payments sent and received from {{wallet.name}}.
|
||||
</div>
|
||||
<a href ng-if="emailForExist" class="settings-description-disabled" ng-click="save(null)" translate>Remove email notifications</a>
|
||||
</div>
|
||||
<form name="emailForm" ng-submit="save(email.value)" 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="email.value" required></input>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit"
|
||||
class="button button-standard button-primary"
|
||||
ng-disabled="emailForm.$invalid" translate>
|
||||
Save
|
||||
</button>
|
||||
</form>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
|
|
@ -7,20 +7,44 @@
|
|||
|
||||
<ion-content>
|
||||
<div class="list">
|
||||
<div ng-show="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()">
|
||||
<div ng-if="PNEnabledByUser">
|
||||
<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>
|
||||
</ion-toggle>
|
||||
</div>
|
||||
|
||||
<div ng-show="!PNEnabledByUser && isIOSApp">
|
||||
<div class="item item-divider" translate>Notifications</div>
|
||||
<div ng-if="!PNEnabledByUser && isIOSApp">
|
||||
<div class="padding text-light" translate>
|
||||
Push notifications for {{appName}} are currently disabled. Enable them in the Settings app.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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 your wallets.
|
||||
</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>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
<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">
|
||||
<img src="img/icon-notifications.svg" class="bg"/>
|
||||
</i>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue