Fix: TryCatch added to Employee.delete view
Feature: Added filtering to employee-list partial
This commit is contained in:
parent
db6b7a4881
commit
d3e3584e9b
@ -1,4 +1,13 @@
|
||||
<h2>Employees <a href="/Employee" class="btn btn-success pull-right">Add <i class="glyphicon glyphicon-plus"></i></a>
|
||||
<h2>Employees
|
||||
<div class="form-group col-md-9 pull-right">
|
||||
<div class="col-md-10">
|
||||
<input type="text" class="form-control" placeholder="Search" ng-model="search">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<a href="/Employee" class="btn btn-success btn-block">Add <i
|
||||
class="glyphicon glyphicon-plus"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</h2>
|
||||
<table id="gvGrid" class="table table-condensed table-bordered table-striped">
|
||||
<thead>
|
||||
@ -14,7 +23,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbodyMain">
|
||||
<tr ng-repeat="item in info">
|
||||
<tr ng-repeat="item in getEmployees(search)">
|
||||
<td>{{item.Code}}</td>
|
||||
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
|
||||
<td>{{item.Designation}}</td>
|
||||
|
@ -2,7 +2,68 @@
|
||||
|
||||
var EmployeeListCtrl = ['$scope', 'employees', function ($scope, employees) {
|
||||
$scope.info = employees;
|
||||
}]
|
||||
var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
|
||||
|
||||
$scope.isTrue = function (value) {
|
||||
value = value.toLowerCase();
|
||||
return !_.any(['f', 'fa', 'fal', 'fals', 'false', 'n', 'no', '0'], function (item) {
|
||||
return item === value;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.getEmployees = _.memoize(function (q) {
|
||||
var matches = [], i, len;
|
||||
if (angular.isUndefined(q) || q === '') {
|
||||
return $scope.info;
|
||||
}
|
||||
var m = q.match(re);
|
||||
_.forEach(m, function (item) {
|
||||
item = item.toLowerCase();
|
||||
if (item.indexOf(':') === -1) {
|
||||
matches.push({'key': 'n', 'value': item});
|
||||
} else {
|
||||
var key = item.substr(0, item.indexOf(':')).toLowerCase();
|
||||
var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
|
||||
if (value.indexOf("'") === 0 || value.indexOf('"') === 0) {
|
||||
value = value.substring(1, value.length - 2);
|
||||
}
|
||||
if (key !== '' && value !== '' && _.any(['w', 'dep', 'des', 'c'], function (item) {
|
||||
return item === key;
|
||||
})) {
|
||||
matches.push({'key': key, 'value': value});
|
||||
}
|
||||
}
|
||||
});
|
||||
return _.filter($scope.info, function (item) {
|
||||
len = matches.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
var match = matches[i];
|
||||
if (match.key === 'n') {
|
||||
if (item.Name.toLowerCase().indexOf(match.value) === -1) {
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'w') {
|
||||
if (item.IsActive !== $scope.isTrue(match.value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'dep') {
|
||||
if (item.CostCenter.toLowerCase().indexOf(match.value) === -1) {
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'des') {
|
||||
if (item.Designation.toLowerCase().indexOf(match.value) === -1) {
|
||||
return false;
|
||||
}
|
||||
} else if (match.key === 'c') {
|
||||
if (item.Code.toString().indexOf(match.value) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}];
|
||||
|
||||
EmployeeListCtrl.resolve = {
|
||||
employees: ['$q', '$route', 'Employee', function ($q, $route, Employee) {
|
||||
|
@ -62,6 +62,7 @@ def update(request):
|
||||
|
||||
|
||||
@view_config(request_method='DELETE', route_name='api_employee_id', renderer='json', permission='Employees')
|
||||
@TryCatchFunction
|
||||
def delete(request):
|
||||
employee = Employee.by_id(uuid.UUID(request.matchdict['id']))
|
||||
can_delete, reason = employee.can_delete('Advanced Delete' in groupfinder(authenticated_userid(request), request))
|
||||
|
Loading…
Reference in New Issue
Block a user