Skip to content

Instantly share code, notes, and snippets.

@mickelsonm
Created October 22, 2014 15:03
Show Gist options
  • Save mickelsonm/03269a475540be778f36 to your computer and use it in GitHub Desktop.
Save mickelsonm/03269a475540be778f36 to your computer and use it in GitHub Desktop.
tmp
/**
* Contact controller definition
*/
define(['./module'], function (module) {
'use strict';
module.controller('ContactController', ['$scope', 'GeographyService', 'FormService', function(scope, GeographyService, FormService){
GeographyService.GetCountryStates(function(countries, err){
if(err){
console.log(err);
return;
}
scope.countries = countries;
});
scope.formData = {};
scope.message = "";
var formSettings = {
method: 'POST',
path: '/contact'
};
scope.processForm = function(){
FormService.ProcessForm(formSettings, scope.formData, function(results, err){
if(err){
console.log(err);
scope.message = err.message;
return;
}
console.log(results);
});
}
}]);
});
}]).factory('FormService', ['$http', 'AppConfig', function($http, AppConfig){
return {
ProcessForm: function(settings, data, callback){
$http({
method: settings.method,
url: AppConfig.APIURL + settings.path + '?key=' + AppConfig.APIKEY,
data: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
}
}).success(function(results, status, headers, config){
callback(results, null);
}).error(function(results, status, headers, config){
callback(null, results);
});
}
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment