Last active
August 29, 2015 14:10
-
-
Save chrisbodhi/1eba07ef0ac257ccc2eb to your computer and use it in GitHub Desktop.
Angular.js form controller used with the KickoffLabs API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller('FormController', function( $scope, $http, $routeParams ){ | |
'use strict'; | |
var self = this, | |
kickoffId = '99999', // https://app.kickofflabs.com/dashboard/campaigns/36854/api | |
url, | |
config, | |
socialRef, | |
id; | |
// Pulls out the slug used for viral sharing | |
socialRef = $routeParams.socialRef; | |
self.submit = function (isValid, formData) { | |
if (!isValid) return; | |
url = 'https://api.kickofflabs.com/v1/' + kickoffId + '/subscribe'; | |
config = { params: { | |
email: formData.email, | |
social_id: socialRef || null, | |
jsonp: 'JSON_CALLBACK', | |
__url: 'http://CUSTOM-URL.com' // redirect destination after unsubscribing via email link | |
} | |
}; | |
$http.jsonp( url, config ) | |
.success(function(data, status) { | |
console.log( 'bueno' ); | |
console.log( data ); | |
console.log( status ); | |
// for the viral URL | |
self.shareId = data.social_id; | |
}) | |
.error(function(data, status) { | |
console.log( 'no bueno' ); | |
console.log( data ); | |
console.log( status ); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment