Files
web2.0-backend/members/static/js/members_controllers.js
T
2016-08-08 20:47:29 +03:00

69 lines
1.9 KiB
JavaScript

app.controller("getController", function($scope, $http, $window, $location){
$scope.members = [];
$http.get("/members/api/members").then(function(response){
$scope.members = response.data;
});
$scope.delete_member = function(id) {
$http.delete("/members/api/member/" + id).then(
function(response) {
$window.alert("Onnistui! Hyvä Harry!");
$location.path("#/list");
},
function(response) {
$window.alert("Epäonnistui. Yritä uudelleen.");
$location.path("#/list");
}
);
};
})
.directive('ngConfirmClick',
[
function()
{ return {
link: function (scope, element, attr)
{
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.confirmedClick;
element.bind('click',function (event)
{
if ( window.confirm(msg) ) {
scope.$eval(clickAction)
}
});
}
}}]);
app.controller("postController", function($scope, $http) {
$scope.firstName = "";
$scope.lastName = "";
$scope.email = "";
$scope.AYY = "";
$scope.JAS = "";
$scope.POR = "";
$scope.send = function() {
$http.post("/members/api/member/", {"first_name":$scope.firstName, "last_name":$scope.lastName, "email":$scope.email, "AYY":$scope.AYY, "jas":$scope.JAS, "POR":$scope.POR});
}
});
app.controller("editController", function($scope, $http, $route, $routeParams, $window, $location) {
$scope.member = {"id": $routeParams.id};
$http.get("/members/api/member/"+$scope.member.id).then(function(response){
$scope.member = response.data;
});
$scope.send = function() {
$http.put("/members/api/member/"+$scope.member.id, $scope.member).then(function(data){
$window.alert("Jäsentiedot tallennettu");
$location.path("#/list");
});
}
$scope.cancel = function() { //user canceled. return to list
$location.path("#/list");
}
});
app.controller("applController", function($scope, $http){
$http.get("/members/api/requests").then(function(response){
$scope.applications = response.data;
});
});