Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('portalApp')
- .controller('DepartmentController', function ($scope, Department) {
- $scope.departments = [];
- $scope.positions = [];
- $scope.loadAll = function () {
- Department.query(function (result) {
- $scope.departments = result;
- });
- };
- $scope.loadAll();
- $scope.create = function () {
- Department.update($scope.department,
- function () {
- $scope.loadAll();
- $('#saveDepartmentModal').modal('hide');
- $scope.clear();
- });
- };
- $scope.update = function (id) {
- Department.get({id: id}, function (result) {
- $scope.department = result;
- $('#saveDepartmentModal').modal('show');
- });
- };
- $scope.delete = function (id) {
- $scope.hasDepartmentsLink = false;
- $scope.hasPositionsLink = false;
- if ($scope.departments) {
- for (var i = 0; i < $scope.departments.length; i++) {
- if ($scope.departments[i].parentId == id) {
- $scope.hasDepartmentsLink = true;
- $('#deleteDepartmentWarning').modal('show');
- return;
- }
- }
- }
- Department.hasPositions({id: id}, function (result) {
- if (result.hasPositions) {
- $scope.hasPositionsLink = true;
- $('#deleteDepartmentWarning').modal('show');
- }
- else {
- $('#deleteDepartmentConfirmation').modal('show');
- }
- });
- };
- $scope.confirmDelete = function (id) {
- Department.delete({id: id},
- function () {
- $scope.loadAll();
- $('#deleteDepartmentConfirmation').modal('hide');
- $scope.clear();
- });
- };
- $scope.clear = function () {
- // "virtual: false" that set default virtual false for cresting departments
- $scope.department = {title: null, weight: null, description: null, id: null, virtual: false, hidden: false};
- $scope.editForm.$setPristine();
- $scope.editForm.$setUntouched();
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement