Wallet/src/js/controllers/onboarding/collectEmail.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-08-25 16:31:47 -03:00
'use strict';
2017-04-27 15:42:23 -03:00
angular.module('copayApp.controllers').controller('collectEmailController', function($scope, $state, $log, $timeout, $http, $httpParamSerializer, profileService, configService, walletService, appConfigService) {
2016-08-29 11:56:31 -03:00
var wallet, walletId;
$scope.data = {};
2017-04-27 15:42:23 -03:00
// Get more info: https://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
var URL = "https://script.google.com/macros/s/AKfycbwQXvUw6-Ix0cRLMi7hBB8dlgNTCTgwfNIQRds6RypPV7dO8evW/exec";
var _post = function(dataSrc) {
return {
method: 'POST',
url: URL,
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data: $httpParamSerializer(dataSrc)
};
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
walletId = data.stateParams.walletId;
wallet = profileService.getWallet(walletId);
$scope.data.accept = true;
});
2017-04-27 15:42:23 -03:00
var collectEmail = function() {
var dataSrc = {
"App": appConfigService.nameCase,
"Email": $scope.data.email,
"Platform": ionic.Platform.platform(),
"DeviceVersion": ionic.Platform.version()
};
$http(_post(dataSrc)).then(function() {
$log.info("SUCCESS: Email collected");
}, function(err) {
$log.error("ERROR: Could not collect email");
});
};
2016-09-09 11:14:04 -03:00
$scope.save = function() {
2016-09-02 11:15:03 -03:00
var opts = {
emailFor: {}
};
opts.emailFor[walletId] = $scope.data.email;
2016-08-25 16:31:47 -03:00
walletService.updateRemotePreferences(wallet, {
email: $scope.data.email,
2016-08-25 16:31:47 -03:00
}, function(err) {
if (err) $log.warn(err);
2016-09-02 11:15:03 -03:00
configService.set(opts, function(err) {
if (err) $log.warn(err);
2017-04-27 15:42:23 -03:00
if ($scope.data.accept) collectEmail();
2016-09-13 23:25:50 -03:00
$scope.goNextView();
2016-09-02 11:15:03 -03:00
});
2016-08-25 16:31:47 -03:00
});
};
2016-09-02 13:00:38 -03:00
2016-09-13 23:25:50 -03:00
$scope.goNextView = function() {
$state.go('onboarding.backupRequest', {
walletId: walletId
});
};
2016-09-09 11:14:04 -03:00
$scope.confirm = function(emailForm) {
if (emailForm.$invalid) return;
$scope.confirmation = true;
};
$scope.cancel = function() {
$scope.confirmation = false;
$timeout(function() {
$scope.$digest();
}, 1);
};
2016-08-25 16:31:47 -03:00
});