Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. angular.module('portalApp')
  4.     .controller('DepartmentController', function ($scope, Department) {
  5.         $scope.departments = [];
  6.         $scope.positions = [];
  7.  
  8.         $scope.loadAll = function () {
  9.             Department.query(function (result) {
  10.                 $scope.departments = result;
  11.             });
  12.         };
  13.         $scope.loadAll();
  14.  
  15.         $scope.create = function () {
  16.             Department.update($scope.department,
  17.                 function () {
  18.                     $scope.loadAll();
  19.                     $('#saveDepartmentModal').modal('hide');
  20.                     $scope.clear();
  21.                 });
  22.         };
  23.  
  24.         $scope.update = function (id) {
  25.             Department.get({id: id}, function (result) {
  26.                 $scope.department = result;
  27.                 $('#saveDepartmentModal').modal('show');
  28.             });
  29.         };
  30.  
  31.         $scope.delete = function (id) {
  32.             $scope.hasDepartmentsLink = false;
  33.             $scope.hasPositionsLink = false;
  34.             if ($scope.departments) {
  35.                 for (var i = 0; i < $scope.departments.length; i++) {
  36.                     if ($scope.departments[i].parentId == id) {
  37.                         $scope.hasDepartmentsLink = true;
  38.                         $('#deleteDepartmentWarning').modal('show');
  39.                         return;
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             Department.hasPositions({id: id}, function (result) {
  45.                 if (result.hasPositions) {
  46.                     $scope.hasPositionsLink = true;
  47.                     $('#deleteDepartmentWarning').modal('show');
  48.                 }
  49.                 else {
  50.                     $('#deleteDepartmentConfirmation').modal('show');
  51.                 }
  52.             });
  53.         };
  54.  
  55.         $scope.confirmDelete = function (id) {
  56.             Department.delete({id: id},
  57.                 function () {
  58.                     $scope.loadAll();
  59.                     $('#deleteDepartmentConfirmation').modal('hide');
  60.                     $scope.clear();
  61.                 });
  62.         };
  63.  
  64.         $scope.clear = function () {
  65.             // "virtual: false" that set default virtual false for cresting departments
  66.             $scope.department = {title: null, weight: null, description: null, id: null, virtual: false, hidden: false};
  67.             $scope.editForm.$setPristine();
  68.             $scope.editForm.$setUntouched();
  69.         };
  70.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement