|
|
|
@@ -1,7 +1,8 @@
|
|
|
|
|
// helpers
|
|
|
|
|
/* Controllers for member register views */
|
|
|
|
|
|
|
|
|
|
function notyfication(type,timeout){
|
|
|
|
|
return function(msg){
|
|
|
|
|
/* Generator function to create a "noty" notification function */
|
|
|
|
|
function notyfication(type, timeout) {
|
|
|
|
|
return function(msg) {
|
|
|
|
|
noty({
|
|
|
|
|
'text': msg,
|
|
|
|
|
'layout': "bottomRight",
|
|
|
|
@@ -10,10 +11,15 @@ function notyfication(type,timeout){
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
var notyError = notyfication('error',2500);
|
|
|
|
|
var notySuccess = notyfication('success',2500);
|
|
|
|
|
|
|
|
|
|
function editor(returnpath){
|
|
|
|
|
/* Create functions to show error and success notifications in the bottom
|
|
|
|
|
* right corner of the viewport
|
|
|
|
|
*
|
|
|
|
|
* These functions take a single message string as a parameter */
|
|
|
|
|
var notyError = notyfication('error', 2500);
|
|
|
|
|
var notySuccess = notyfication('success', 2500);
|
|
|
|
|
|
|
|
|
|
function memberDataEditor(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) {
|
|
|
|
@@ -34,14 +40,12 @@ function editor(returnpath){
|
|
|
|
|
app.directive('ngConfirmClick', [ function() { return {
|
|
|
|
|
link: function (scope, element, attr) {
|
|
|
|
|
var clickAction = attr.confirmedClick;
|
|
|
|
|
element.bind('click',function (event) {
|
|
|
|
|
element.bind('click', function (event) {
|
|
|
|
|
noty( {
|
|
|
|
|
text: 'Oletko aivan varma? T. Lasse Lehtinen',
|
|
|
|
|
layout: 'bottomRight',
|
|
|
|
|
buttons: [ {
|
|
|
|
|
addClass: 'btn btn-danger', text: 'Kyllä', onClick: function($noty) {
|
|
|
|
|
// this = button element
|
|
|
|
|
// $noty = $noty element
|
|
|
|
|
$noty.close();
|
|
|
|
|
scope.$eval(clickAction)
|
|
|
|
|
}
|
|
|
|
@@ -120,64 +124,14 @@ app.controller("getController", function($scope, $document, $http, $window, $loc
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Filter in only those members whose 'created' field comes
|
|
|
|
|
* before the specified date */
|
|
|
|
|
$scope.filterByAddedBeforeDate = function(members) {
|
|
|
|
|
if ($scope.addedBeforeDatePicker == null) {
|
|
|
|
|
$scope.filterByDateComparison = function(members, datePicker, comparison) {
|
|
|
|
|
if (datePicker == null) {
|
|
|
|
|
return members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < members.length; i++) {
|
|
|
|
|
if (moment(members[i].created) <= $scope.addedBeforeDatePicker) {
|
|
|
|
|
result.push(members[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Filter in only those members whose 'created' field comes
|
|
|
|
|
* after the specified date */
|
|
|
|
|
$scope.filterByAddedAfterDate = function(members) {
|
|
|
|
|
if ($scope.addedAfterDatePicker == null) {
|
|
|
|
|
return members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < members.length; i++) {
|
|
|
|
|
if (moment(members[i].created) > $scope.addedAfterDatePicker) {
|
|
|
|
|
result.push(members[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Filter in only those members whose 'paid' field comes
|
|
|
|
|
* before the specified date */
|
|
|
|
|
$scope.filterByPaidBeforeDate = function(members) {
|
|
|
|
|
if ($scope.paidBeforeDatePicker == null) {
|
|
|
|
|
return members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < members.length; i++) {
|
|
|
|
|
if (moment(members[i].paid) <= $scope.paidBeforeDatePicker) {
|
|
|
|
|
result.push(members[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Filter in only those members whose 'paid' field comes
|
|
|
|
|
* after the specified date */
|
|
|
|
|
$scope.filterByPaidAfterDate = function(members) {
|
|
|
|
|
if ($scope.paidAfterDatePicker == null) {
|
|
|
|
|
return members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < members.length; i++) {
|
|
|
|
|
if (moment(members[i].paid) > $scope.paidAfterDatePicker) {
|
|
|
|
|
if (comparison(members[i], datePicker)) {
|
|
|
|
|
result.push(members[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -217,10 +171,14 @@ app.controller("getController", function($scope, $document, $http, $window, $loc
|
|
|
|
|
/* Run all filters on the members list */
|
|
|
|
|
$scope.doFilter = function() {
|
|
|
|
|
var result = $scope.members;
|
|
|
|
|
result = $scope.filterByAddedBeforeDate(result);
|
|
|
|
|
result = $scope.filterByAddedAfterDate(result);
|
|
|
|
|
result = $scope.filterByPaidBeforeDate(result);
|
|
|
|
|
result = $scope.filterByPaidAfterDate(result);
|
|
|
|
|
result = $scope.filterByDateComparison(result, $scope.addedBeforeDatePicker, function(member, date) {
|
|
|
|
|
return moment(member.created) < date });
|
|
|
|
|
result = $scope.filterByDateComparison(result, $scope.addedAfterDatePicker, function(member, date) {
|
|
|
|
|
return moment(member.created) >= date });
|
|
|
|
|
result = $scope.filterByDateComparison(result, $scope.paidBeforeDatePicker, function(member, date) {
|
|
|
|
|
return moment(member.paid) < date });
|
|
|
|
|
result = $scope.filterByDateComparison(result, $scope.paidAfterDatePicker, function(member, date) {
|
|
|
|
|
return moment(member.paid) >= date });
|
|
|
|
|
result = $scope.filterBySearch(result);
|
|
|
|
|
|
|
|
|
|
$scope.shown_members = result;
|
|
|
|
@@ -251,7 +209,7 @@ app.controller("postController", function($scope, $http, $location) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.controller("applController", function($scope, $http, $route, $routeParams, $window, $location){
|
|
|
|
|
$scope.applGetFunction = function() {
|
|
|
|
|
$scope.applUpdateAll = function() {
|
|
|
|
|
$http.get("/members/api/requests").then(function(response){
|
|
|
|
|
$scope.applications = response.data;
|
|
|
|
|
_.each($scope.applications, function(a){
|
|
|
|
@@ -260,35 +218,35 @@ app.controller("applController", function($scope, $http, $route, $routeParams, $
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
$scope.applGetFunction();
|
|
|
|
|
$scope.send_appl = function(id) {
|
|
|
|
|
$scope.applUpdateAll();
|
|
|
|
|
$scope.sendAppl = function(id) {
|
|
|
|
|
$http.post("/members/api/request/" + id).then(
|
|
|
|
|
function(response) {
|
|
|
|
|
notySuccess("Hakemus hyväksytty");
|
|
|
|
|
$scope.applGetFunction();
|
|
|
|
|
$scope.applUpdateAll();
|
|
|
|
|
},
|
|
|
|
|
function(response) {
|
|
|
|
|
notyError("Hakemuksen hyväksyminen epäonnistui");
|
|
|
|
|
$scope.applGetFunction();
|
|
|
|
|
$scope.applUpdateAll();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
$scope.delete_appl = function(id) {
|
|
|
|
|
$scope.deleteAppl = function(id) {
|
|
|
|
|
$http.delete("/members/api/request/" + id).then(
|
|
|
|
|
function(response) {
|
|
|
|
|
notySuccess("Hakemus hylätty!");
|
|
|
|
|
$scope.applGetFunction();
|
|
|
|
|
$scope.applUpdateAll();
|
|
|
|
|
},
|
|
|
|
|
function(response) {
|
|
|
|
|
notyError("Hakemuksen hylkäys epäonnistui");
|
|
|
|
|
$scope.applGetFunction();
|
|
|
|
|
$scope.applUpdateAll();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.controller("editController",editor("/list"));
|
|
|
|
|
app.controller("appleditController", editor("/applications"));
|
|
|
|
|
app.controller("editController", memberDataEditor("/list"));
|
|
|
|
|
app.controller("applEditController", memberDataEditor("/applications"));
|
|
|
|
|
|
|
|
|
|
app.controller("addManyController", function($scope, $http, $window) {
|
|
|
|
|
$scope.memberData = '';
|
|
|
|
|