173 lines
4.6 KiB
JavaScript
173 lines
4.6 KiB
JavaScript
app.controller("getController", function($scope, $http, $window, $location){
|
|
$scope.members = [];
|
|
$http.get("/members/api/members").then(function(response){
|
|
$scope.members = response.data;
|
|
// map trues and falses to more user-friendly format
|
|
_.each($scope.members, function(m){
|
|
m.jas = m.jas ? "Kyllä" : "Ei";
|
|
m.AYY = m.AYY ? "Kyllä" : "Ei";
|
|
});
|
|
});
|
|
$scope.delete_member = function(id) {
|
|
$http.delete("/members/api/member/" + id).then(
|
|
function(response) {
|
|
noty({
|
|
text: "Poistaminen onnistui!",
|
|
layout: "bottomRight",
|
|
type: "success",
|
|
timeout: 10000
|
|
// ,
|
|
// buttons: [
|
|
// {
|
|
// addClass: 'btn btn-primary', text: 'Undo', onClick: function() {
|
|
|
|
// }
|
|
// }
|
|
// ]
|
|
// http://ned.im/noty/#/about
|
|
});
|
|
|
|
$location.path("#/list");
|
|
},
|
|
function(response) {
|
|
noty({
|
|
text: "Epäonnistui. Yritä uudelleen.",
|
|
layout: "bottomRight",
|
|
type: "error",
|
|
timeout: 10000
|
|
});
|
|
$location.path("#/list");
|
|
}
|
|
);
|
|
};
|
|
});
|
|
|
|
app.directive('ngConfirmClick',
|
|
[
|
|
function()
|
|
{ return {
|
|
link: function (scope, element, attr)
|
|
{
|
|
var clickAction = attr.confirmedClick;
|
|
element.bind('click',function (event)
|
|
{
|
|
noty({
|
|
text: 'Haluatko varmasti poistaa?',
|
|
layout: 'bottomRight',
|
|
buttons: [
|
|
{
|
|
addClass: 'btn btn-danger', text: 'Kyllä', onClick: function($noty) {
|
|
// this = button element
|
|
// $noty = $noty element
|
|
$noty.close();
|
|
scope.$eval(clickAction)
|
|
}
|
|
},
|
|
{
|
|
addClass: 'btn btn-primary', text: 'Ei', onClick: function($noty) {
|
|
$noty.close();
|
|
}
|
|
}
|
|
]
|
|
});
|
|
});
|
|
|
|
// 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, $location) {
|
|
$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}).then(function(data){
|
|
noty({
|
|
text: "Jäsenhakemus lähetetty",
|
|
layout: "bottomRight",
|
|
type: "success",
|
|
timeout: 10000
|
|
});
|
|
$location.path("#/list");
|
|
});
|
|
}
|
|
});
|
|
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){
|
|
noty({
|
|
text: "Jäsentiedot tallennettu",
|
|
layout: "bottomRight",
|
|
type: "success",
|
|
timeout: 10000
|
|
});
|
|
$location.path("#/list");
|
|
});
|
|
}
|
|
$scope.cancel = function() { //user canceled. return to list
|
|
$location.path("#/list");
|
|
}
|
|
});
|
|
|
|
app.controller("applController", function($scope, $http, $route, $routeParams, $window, $location){
|
|
$http.get("/members/api/requests").then(function(response){
|
|
$scope.applications = response.data;
|
|
});
|
|
$scope.send_appl = function(id) {
|
|
$http.post("/members/api/request/" + id).then(
|
|
function(response) {
|
|
$window.alert("Onnistui");
|
|
$location.path("#/applications");
|
|
},
|
|
function(response) {
|
|
$window.alert("Epäonnistui");
|
|
$location.path("#/applications");
|
|
}
|
|
);
|
|
};
|
|
$scope.delete_appl = function(id) {
|
|
$http.delete("/members/api/request/" + id).then(
|
|
function(response) {
|
|
$window.alert("Onnistui");
|
|
$location.path("#/applications");
|
|
},
|
|
function(response) {
|
|
$window.alert("Epäonnistui");
|
|
$location.path("#/applications");
|
|
}
|
|
);
|
|
};
|
|
});
|
|
|
|
app.controller("appleditController", function($scope, $http, $route, $routeParams, $window, $location){
|
|
$scope.application = {"id": $routeParams.id};
|
|
$http.get("/members/api/request/"+$scope.application.id).then(function(response){
|
|
$scope.application = response.data;
|
|
});
|
|
|
|
$scope.sendappl = function() {
|
|
$http.put("/members/api/request"+$scope.application.id, $scope.application).then(function(data){
|
|
$window.alert("Jäsentiedot tallennettu");
|
|
$location.path("#/applications");
|
|
});
|
|
}
|
|
$scope.cancelappl = function() { //user canceled. return to applications
|
|
$location.path("#/applications");
|
|
}
|
|
});
|