Clean up code style in controllers and templates

This commit is contained in:
Jan Tuomi
2017-01-19 14:47:51 +02:00
parent c6a2ed38b1
commit 16a3d03a32
4 changed files with 38 additions and 80 deletions
+2 -2
View File
@@ -21,8 +21,8 @@
</div>
<div class="row">
<div class="col-sm-4">
<input type="button" value="Hyväksy" class="btn btn-success" confirmed-click="send_appl(x.id)" ng-confirm-click="Oletko varma, että haluat hyväksyä?"/>
<input type="button" value="Hylkää" class="btn btn-danger" confirmed-click="delete_appl(x.id)" ng-confirm-click="Oletko varma, että haluat hylätä hakemuksen?"/>
<input type="button" value="Hyväksy" class="btn btn-success" confirmed-click="sendAppl(x.id)" ng-confirm-click="Oletko varma, että haluat hyväksyä?"/>
<input type="button" value="Hylkää" class="btn btn-danger" confirmed-click="deleteAppl(x.id)" ng-confirm-click="Oletko varma, että haluat hylätä hakemuksen?"/>
<a href="#/applications/edit/{{x.member.id}}"<input type="button" value="Edit" class="btn btn-info">Muokkaa</input></a>
</div>
</div>
+1 -1
View File
@@ -53,7 +53,7 @@
<td class="table-button-column">
<input type="button" value="Päivitä maksu" class="table-button btn btn-success" ng-click="updatePayment(x.id)" />
<a href="#/edit/{{x.id}}"<input type="button" value="Edit" class="table-button btn btn-info">Muokkaa</input></a>
<input type="button" value="Poista" class="table-button btn btn-danger" confirmed-click="delete_member(x.id)" ng-confirm-click="Are you sure?"/>
<input type="button" value="Poista" class="table-button btn btn-danger" confirmed-click="deleteMember(x.id)" ng-confirm-click="Are you sure?"/>
</td>
</tr>
</tbody>
+34 -76
View File
@@ -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 = '';
+1 -1
View File
@@ -22,7 +22,7 @@ app.config(['$routeProvider', function($routeProvider){
})
.when('/applications/edit/:id',{
templateUrl:"/static/html/muokkaa_jasenta.html",
controller:'appleditController',
controller:'applEditController',
})
.when('/addmany/',{
templateUrl:"/static/html/lisaa_jasenia.html",