'use strict'

angular.module('APS_INTERVIEW').controller('listcandidate', ['$scope', '$http', '$sce', 'InterviewcandidateCtrl', function($scope, $http, $sce, InterviewcandidateCtrl){
  $scope.lang = $('input[name="lang"]').val()
  $scope.listcandidate = []
  $scope.status_desc = [{
    status: '0',
    desc:{
      tha: 'ยังไม่ได้ประเมิน',
      eng: 'Not Evaluated'
    }
  },{
    status: '1',
    desc:{
      tha: 'บันทึกร่าง',
      eng: 'Save Draff'
    }
  },{
    status: '2',
    desc:{
      tha: 'ประเมินแล้ว',
      eng: 'Success'
    }
  }]

  $scope.p_status_desc = [{
    status: '0',
    desc:{
      tha: 'กรรมการในลำดับก่อนหน้ายังไม่ได้ประเมิน (ไม่มีสิทธิ์ประเมิน)',
      eng: 'Previous Not Approved'
    }
  },{
    status: '1',
    desc:{
      tha: 'กรรมการในลำดับก่อนหน้าประเมินแล้ว',
      eng: 'Previous Approved'
    }
  },{
    status: '2',
    desc:{
      tha: 'คุณเป็นกรรมการชุดแรก',
      eng: "You're First Referees"
    }
  }]

  $scope.ispass_desc = [{
    status: '0',
    desc:{
      tha: 'ผู้สมัครไม่เหมาะสม',
      eng: 'Unqualified'
    }
  },{
    status: '1',
    desc:{
      tha: '',
      eng: ''
    }
  }]

  InterviewcandidateCtrl.managelistcandidate.query().$promise.then(function(data){
    $scope.listcandidate = data.listcandidateData;
    console.log($scope.listcandidate);
    $('.loading-page').css('display', 'none')
  })

  $scope.goPage = function($index){
    if($scope.listcandidate[$index].previous_status != 0){
      $('input[name="candidateid"]').val($scope.listcandidate[$index].candidateid);
      $('form[name="cscform"]').attr('target','myform');
      $('form[name="cscform"]').attr('action','APS_FORM_INTERVIEW_DHAS_EMP.jsp');

      var winopen = window.open('','myform','left=150,top=150,width=2000,height=2000,toolbar=no,status=yes,scrollbars=yes,resizable=yes');
      if (winopen){
        $('form[name="cscform"]').submit();
        winopen.focus();
      }
    }else{
      alert("ยังไม่มีสิทธิ์ประเมิน กรุณารอกรรมการชุดก่อนหน้าประเมินก่อน")
    }
  }
}]);