Collect email with google sheets

This commit is contained in:
Gustavo Maximiliano Cortez 2017-04-27 15:42:23 -03:00
parent 893fda112f
commit ffb19e00b9
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
1 changed files with 30 additions and 1 deletions

View File

@ -1,9 +1,22 @@
'use strict';
angular.module('copayApp.controllers').controller('collectEmailController', function($scope, $state, $timeout, profileService, configService, walletService) {
angular.module('copayApp.controllers').controller('collectEmailController', function($scope, $state, $log, $timeout, $http, $httpParamSerializer, profileService, configService, walletService, appConfigService) {
var wallet, walletId;
$scope.data = {};
// 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;
@ -11,6 +24,21 @@ angular.module('copayApp.controllers').controller('collectEmailController', func
$scope.data.accept = true;
});
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");
});
};
$scope.save = function() {
var opts = {
emailFor: {}
@ -22,6 +50,7 @@ angular.module('copayApp.controllers').controller('collectEmailController', func
if (err) $log.warn(err);
configService.set(opts, function(err) {
if (err) $log.warn(err);
if ($scope.data.accept) collectEmail();
$scope.goNextView();
});
});