|
|
|
@ -20,9 +20,8 @@ app.controller('TransgressionsController', ['$http', function($http){
|
|
|
|
// Sin Types for Select in HTML
|
|
|
|
// Sin Types for Select in HTML
|
|
|
|
this.SIN_TYPES = [ 'Gluttony', 'Greed', 'Anger', 'Pride', 'Lust', 'Sloth', 'Envy' ];
|
|
|
|
this.SIN_TYPES = [ 'Gluttony', 'Greed', 'Anger', 'Pride', 'Lust', 'Sloth', 'Envy' ];
|
|
|
|
this.newTransgressionSinType = 'Gluttony';
|
|
|
|
this.newTransgressionSinType = 'Gluttony';
|
|
|
|
|
|
|
|
|
|
|
|
//this fetches transgression data and adds it to controller
|
|
|
|
//this fetches transgression data and adds it to controller
|
|
|
|
var getTransgressions = function(){
|
|
|
|
this.getTransgressions = function(){
|
|
|
|
// get transgressions for current User
|
|
|
|
// get transgressions for current User
|
|
|
|
$http.get('/transgressions').success(function(data){
|
|
|
|
$http.get('/transgressions').success(function(data){
|
|
|
|
//just add the transgressions to the controller, data comes back with sinner as well
|
|
|
|
//just add the transgressions to the controller, data comes back with sinner as well
|
|
|
|
@ -30,7 +29,7 @@ app.controller('TransgressionsController', ['$http', function($http){
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//fetch transgression data for current user as TransgressionsController initializes
|
|
|
|
//fetch transgression data for current user as TransgressionsController initializes
|
|
|
|
getTransgressions();
|
|
|
|
this.getTransgressions();
|
|
|
|
|
|
|
|
|
|
|
|
// create a transgression
|
|
|
|
// create a transgression
|
|
|
|
this.createTransgression = function(){
|
|
|
|
this.createTransgression = function(){
|
|
|
|
@ -60,14 +59,19 @@ app.controller('TransgressionsController', ['$http', function($http){
|
|
|
|
controller.current_user_transgressions.pop();
|
|
|
|
controller.current_user_transgressions.pop();
|
|
|
|
controller.current_user_transgressions.push(data.transgression);
|
|
|
|
controller.current_user_transgressions.push(data.transgression);
|
|
|
|
//...and begin refreshing transgression data
|
|
|
|
//...and begin refreshing transgression data
|
|
|
|
getTransgressions();
|
|
|
|
controller.getTransgressions();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.controller('ConfessionsController', ['$http', '$scope', function($http, $scope){
|
|
|
|
|
|
|
|
//get authenticity_token from DOM (rails injects it on load)
|
|
|
|
|
|
|
|
var authenticity_token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
|
|
|
|
|
|
|
|
|
|
// create a confession for a transgression identified by transgression_id
|
|
|
|
// create a confession.!
|
|
|
|
this.createConfession = function(transgression_id){
|
|
|
|
this.createConfession = function(){
|
|
|
|
//AJAX call using parameter that identifies transgression
|
|
|
|
//AJAX call using parameter that identifies transgression
|
|
|
|
$http.post('/transgressions/'+transgression_id+'/confessions', {
|
|
|
|
$http.post('/transgressions/'+$scope.$parent.transgression.id+'/confessions', {
|
|
|
|
//include authenticity_token
|
|
|
|
//include authenticity_token
|
|
|
|
authenticity_token: authenticity_token,
|
|
|
|
authenticity_token: authenticity_token,
|
|
|
|
confession: {
|
|
|
|
confession: {
|
|
|
|
@ -76,7 +80,7 @@ app.controller('TransgressionsController', ['$http', function($http){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).success(function(data){
|
|
|
|
}).success(function(data){
|
|
|
|
//refresh transgression data once POST is complete
|
|
|
|
//refresh transgression data once POST is complete
|
|
|
|
getTransgressions();
|
|
|
|
$scope.$parent.transgressionsCtrl.getTransgressions();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
}]);
|
|
|
|
|