123 lines
4.2 KiB
JavaScript
123 lines
4.2 KiB
JavaScript
'use strict';
|
|
|
|
var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'employees', function ($scope, $location, $routeParams, Tokenizer, employees) {
|
|
$scope.search = $routeParams.q || '';
|
|
$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.$watch('search', function (newValue, oldValue) {
|
|
$scope.filterEmployees(newValue);
|
|
}, true);
|
|
|
|
$scope.$on('$destroy', function () {
|
|
Tokenizer.doFilter.cache = {};
|
|
});
|
|
|
|
$scope.searchInfo = {
|
|
comparator: {
|
|
'n': {'Col': 'Name', 'Comparator': 'text'},
|
|
'c': {'Col': 'Code', 'Comparator': 'numeric'},
|
|
's': {'Col': 'Salary', 'Comparator': 'numeric'},
|
|
'a': {'Col': 'IsActive', 'Comparator': 'boolean'},
|
|
'des': {'Col': 'Designation', 'Comparator': 'text'},
|
|
'dep': {'Col': 'CostCenter', 'Comparator': 'text'}
|
|
},
|
|
def: 'n',
|
|
sorter: {
|
|
'n': 'Name',
|
|
'c': 'Code',
|
|
's': 'Salary',
|
|
'a': 'IsActive',
|
|
'des': 'Designation',
|
|
'dep': 'CostCenter'
|
|
}
|
|
};
|
|
$scope.filterEmployees = _.debounce(function (q) {
|
|
if (q !== $scope._search) {
|
|
$scope._search = q;
|
|
if (angular.isUndefined(q) || q === '') {
|
|
$location.path('/Employees').search('q', null).replace();
|
|
} else {
|
|
$location.path('/Employees').search({'q': q}).replace();
|
|
}
|
|
$scope.$apply(function () {
|
|
var matches = Tokenizer.parseFilterString(q, $scope.searchInfo);
|
|
$scope.employees = Tokenizer.doFilter(q, $scope.info, matches);
|
|
|
|
});
|
|
}
|
|
}, 350);
|
|
}];
|
|
|
|
EmployeeListCtrl.resolve = {
|
|
employees: ['Employee', function (Employee) {
|
|
return Employee.query({}).$promise;
|
|
}]
|
|
};
|
|
|
|
var EmployeeCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', '$modal', 'employee', 'costCenters', function ($scope, $routeParams, $location, asDate, $modal, employee, costCenters) {
|
|
$scope.employee = employee;
|
|
|
|
$scope.costCenters = costCenters;
|
|
|
|
$scope.save = function () {
|
|
$scope.employee.JoiningDate = asDate($scope.employee.JoiningDate);
|
|
$scope.employee.LeavingDate = asDate($scope.employee.LeavingDate);
|
|
$scope.employee.$save(function (u, putResponseHeaders) {
|
|
$scope.toasts.push({Type: 'Success', Message: u.Code});
|
|
$location.path('/Employees');
|
|
}, function (data, status) {
|
|
$scope.toasts.push({Type: 'Danger', Message: data.data});
|
|
});
|
|
};
|
|
|
|
$scope.delete = function () {
|
|
$scope.employee.$delete(function (u, putResponseHeaders) {
|
|
$scope.toasts.push({Type: 'Success', Message: ''});
|
|
$location.path('/Employees');
|
|
}, function (data, status) {
|
|
$scope.toasts.push({Type: 'Danger', Message: data.data});
|
|
});
|
|
};
|
|
|
|
$scope.confirm = function () {
|
|
var modalInstance = $modal.open({
|
|
backdrop: true,
|
|
templateUrl: '/template/modal/confirm.html',
|
|
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
|
|
$scope.title = "Delete Account";
|
|
$scope.body = "Are you sure? This cannot be undone.";
|
|
$scope.isDelete = true;
|
|
$scope.ok = function () {
|
|
$modalInstance.close();
|
|
};
|
|
$scope.cancel = function () {
|
|
$modalInstance.dismiss('cancel');
|
|
};
|
|
}]
|
|
});
|
|
modalInstance.result.then(function () {
|
|
$scope.delete();
|
|
});
|
|
};
|
|
|
|
$('#txtName').focus();
|
|
}];
|
|
|
|
EmployeeCtrl.resolve = {
|
|
employee: ['$route', 'Employee', function ($route, Employee) {
|
|
var id = $route.current.params.id;
|
|
return Employee.get({id: id}).$promise;
|
|
}],
|
|
costCenters: ['CostCenter', function (CostCenter) {
|
|
return CostCenter.query({}).$promise;
|
|
}]
|
|
};
|