restructured controllers and did little sanitization to notifications
This commit is contained in:
@@ -1,40 +1,36 @@
|
||||
app.controller("getController", function($scope, $http, $window, $location){
|
||||
$scope.members = [];
|
||||
$scope.getFunction = function() {
|
||||
$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.getFunction();
|
||||
$scope.delete_member = function(id) {
|
||||
$http.delete("/members/api/member/" + id).then(
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Poistaminen onnistui!",
|
||||
layout: "bottomRight",
|
||||
type: "success",
|
||||
timeout: 10000
|
||||
});
|
||||
$scope.getFunction();
|
||||
},
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Epäonnistui. Yritä uudelleen.",
|
||||
layout: "bottomRight",
|
||||
type: "error",
|
||||
timeout: 10000
|
||||
});
|
||||
$scope.getFunction();
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
// helpers
|
||||
|
||||
function notyfication(type,timeout){
|
||||
return function(msg){
|
||||
noty({
|
||||
'text': msg,
|
||||
'layout': "bottomRight",
|
||||
'type': type,
|
||||
'timeout': timeout
|
||||
});
|
||||
};
|
||||
}
|
||||
var notyError = notyfication('error',4000);
|
||||
var notySuccess = notyfication('success',4000);
|
||||
|
||||
function editor(returnpath){
|
||||
return 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){
|
||||
notySuccess("Jäsentiedot tallennettu");
|
||||
$location.path(returnpath);
|
||||
});
|
||||
}
|
||||
$scope.cancel = function() { //user canceled. return to list
|
||||
$location.path(returnpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
app.directive('ngConfirmClick',
|
||||
[
|
||||
function()
|
||||
@@ -67,6 +63,35 @@ function()
|
||||
}
|
||||
}}]);
|
||||
|
||||
// controllers
|
||||
|
||||
app.controller("getController", function($scope, $http, $window, $location){
|
||||
$scope.members = [];
|
||||
$scope.getFunction = function() {
|
||||
$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.getFunction();
|
||||
$scope.delete_member = function(id) {
|
||||
$http.delete("/members/api/member/" + id).then(
|
||||
function(response) {
|
||||
notySuccess("Poistaminen onnistui")
|
||||
$scope.getFunction();
|
||||
},
|
||||
function(response) {
|
||||
notyError("Epäonnistui. Yritä uudelleen.");
|
||||
$scope.getFunction();
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
app.controller("postController", function($scope, $http, $location) {
|
||||
$scope.firstName = "";
|
||||
$scope.lastName = "";
|
||||
@@ -76,40 +101,11 @@ app.controller("postController", function($scope, $http, $location) {
|
||||
$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
|
||||
});
|
||||
notySuccess("Jäsen lisätty!");
|
||||
$location.path("/list");
|
||||
});
|
||||
}
|
||||
});
|
||||
function editor(returnpath){
|
||||
return 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(returnpath);
|
||||
});
|
||||
}
|
||||
$scope.cancel = function() { //user canceled. return to list
|
||||
$location.path(returnpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
app.controller("editController",editor("/list"));
|
||||
|
||||
app.controller("applController", function($scope, $http, $route, $routeParams, $window, $location){
|
||||
$scope.applGetFunction = function() {
|
||||
@@ -121,21 +117,11 @@ app.controller("applController", function($scope, $http, $route, $routeParams, $
|
||||
$scope.send_appl = function(id) {
|
||||
$http.post("/members/api/request/" + id).then(
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Onnistui",
|
||||
layout: "bottomRight",
|
||||
type: "success",
|
||||
timeout: 10000
|
||||
});
|
||||
notySuccess("Hakemus hyväksytty");
|
||||
$scope.applGetFunction();
|
||||
},
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Epäonnistui",
|
||||
layout: "bottomRight",
|
||||
type: "success",
|
||||
timeout: 10000
|
||||
});
|
||||
notyError("Hakemuksen hyväksyminen epäonnistui");
|
||||
$scope.applGetFunction();
|
||||
}
|
||||
);
|
||||
@@ -143,25 +129,16 @@ app.controller("applController", function($scope, $http, $route, $routeParams, $
|
||||
$scope.delete_appl = function(id) {
|
||||
$http.delete("/members/api/request/" + id).then(
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Onnistui",
|
||||
layout: "bottomRight",
|
||||
type: "success",
|
||||
timeout: 10000
|
||||
});
|
||||
$scope.applGetFunction();
|
||||
notySuccess("Hakemus hylätty!");
|
||||
$scope.applGetFunction();
|
||||
},
|
||||
function(response) {
|
||||
noty({
|
||||
text: "Epäonnistui",
|
||||
layout: "bottomRight",
|
||||
type: "success",
|
||||
timeout: 10000
|
||||
});
|
||||
notyError("Hakemuksen hylkäys epäonnistui");
|
||||
$scope.applGetFunction();
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
app.controller("editController",editor("/list"));
|
||||
app.controller("appleditController", editor("/applications"));
|
||||
|
||||
Reference in New Issue
Block a user