REC_CANDIDATE.Controller.js 4.93 KB
Newer Older
1 2 3 4 5
/**
 * Created by PPMaj on 11/24/2016.
 */

'use strict'
6
recModule.controller('REC_CANDIDATE', ['$scope', '$mdDialog', 'RecService', function ($scope, $mdDialog, RecService) {
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  $scope.isReady = false
  $scope.lang = getLang();
  $scope.now = ''
  $scope.userJobid = ''
  $scope.userBu3 = ''
  $scope.userBu2 = ''
  $scope.isActPosition = ''
  $scope.employeeid = ''
  $scope.applicants = []
  $scope.jobs = []
  $scope.basicConfig = {}
  $scope.propertyNameIn = ''
  $scope.reverseIn = true
  $scope.propertyNameEx = ''
  $scope.reverseEx = true
  $scope.openReqs = []
  $scope.buFilter = {}
  let cscForm = document.cscform
  
  RecService.RestMrequest.getManPowerRequest().$promise.then(function (data) {
    $scope.openReqs = data.result.filter((item) => {
      return item.requestStatus === "2"
    })
  })


  let jobSetOne = ['S1001', 'S2001', 'O1001', 'O2001', 'O3001', 'O4001', 'E1001',' M1002']
  let jobSetTwo = ['M2002', 'M1003', 'M2001', 'E2001', 'M2003']
  let jobSetThree = ['T1001', 'T1002']
  $scope.filterDirector = ($item) => {
    if (jobSetOne.includes($item.jobid)) {
      if ($scope.userJobid === 'M1003' || $scope.userJobid === 'M2002' || $scope.userJobid === 'M2001') {
        return $item.bu3.idFromMreq === $scope.userBu3
      } else {
        return false
      }
    } else if (jobSetTwo.includes($item.jobid)) {
      return $scope.isActPosition === '1'
    } else if (jobSetThree.includes($item.jobid)) {
      return $scope.userJobid === 'V0001'
    } else {
      return false
    }
  }
  
  // $scope.$watch('user', ($res) => {
  //   if ($res !== '') {
  //     RecService.RestEmpCenter.getQuery({usernameid: $res}).$promise.then(function ($data) {
  //       if ($data.result.length > 0) {
  //         let data = $data.result[0]
  //         for (let i = 1; i <= 4; i++) {
  //           $scope.buFilter.viewAll = data.isviewall == '1'
  //           let currentBu = $scope.buFilter['bu'+i] = {}
  //           currentBu.active = data['isbu'+i] == '1'
  //           currentBu.show = data['bu'+i+'status'] == '1'
  //           currentBu.list = (data['bu'+i+'list'] != '') ? data['bu'+i+'list'].split(',') : []
  //         }
  //       }
  //     })
  //   }
  // })
  // $scope.filterBu = ($item) => {
  //   let chkBu = ($index) => {
  //     if ($index && !angular.equals($scope.buFilter, {})) {
  //       if ($scope.buFilter['bu'+$index].active) {
  //         if ($scope.buFilter['bu'+$index].list.length > 0) {
  //           if ($scope.buFilter['bu'+$index].show) {
  //             return $scope.buFilter['bu'+$index].list.includes($item['bu'+$index].id)
  //           } else {
  //             return !$scope.buFilter['bu'+$index].list.includes($item['bu'+$index].id)
  //           }
  //         } else {
  //           return true
  //         }
  //       } else {
  //         return true
  //       }
  //     }
  //   }
  //   if ($scope.buFilter.viewAll) {
  //     return true
  //   } else {
  //     return chkBu(1) && chkBu(2) && chkBu(3) && chkBu(4) && chkBu(5)
  //   }
  // }
  
  $scope.goPages = ($candidateid) => {
    cscForm.action = "../RECRUIT/FillFormApplicant.jsp"
    cscForm.__candidateid.value = $candidateid
    cscForm.target = "_blank"
    cscForm.submit()
  }
  
  $scope.sortByIn = function(propertyName) {
    $scope.reverseIn = ($scope.propertyNameIn  === propertyName) ? !$scope.reverseIn : false;
    $scope.propertyNameIn = propertyName;
  }
  
  $scope.sortByEx = function(propertyName) {
    $scope.reverseEx = ($scope.propertyNameEx === propertyName) ? !$scope.reverseEx : false;
    $scope.propertyNameEx = propertyName;
  }
  
  $scope.availableRequest = ($app) => {
    let result = false
    const exist = $scope.openReqs.find(($item) => {
      return $app.requestid === $item.requestid
    })
    if (exist) {
      let today = new Date($scope.now);
      let endDate = new Date(exist.lastDate)
      result = daysBetween(today, endDate) >= 0
    }
    return result
  }
  
  RecService.RestMcandidate.getQuery().$promise.then(function ($res) {
    $scope.applicants = $res.result
    // console.log($res.result);
    $scope.isReady = true
  })
  
  RecService.ManageConfig.query({cname: 'BASIC'}).$promise.then(function (data) {
    $scope.basicConfig = data.result.object
  })
  
  $scope.updateWantInterview = ($applicantid, $event) => {
    RecService.RestMapplicant.updateWantInterview({applicantid: $applicantid, wantinterview: $event.target.value}).$promise.then(function ($res) {
    
    })
  }
  
  $scope.filterConditions = ($app) => {
    return $app.applicantid === $scope.conditions.filter.applicantid &&
      ($app.personal.fname === $scope.conditions.filter.name || $app.personal.fname == $scope.conditions.filter.name) &&
      $app.jobid === $scope.conditions.filter.jobid &&
      $app.wantinterview === $scope.conditions.filter.wantinterview
  }
  
  $scope.filterInternal = ($app) => {
    return $app.internal == '1'
  }
  
  $scope.filterExternal = ($app) => {
    return $app.internal == '0'
    
  }
  
  
  // Jquery
  
  
}
])