APS_FORM_INTERVIEW_DHAS_DEPT.Controller.js 11.9 KB
Newer Older
peema_phongam committed
1 2
'use strict'

peema_phongam committed
3
angular.module('APS_INTERVIEW').controller('APS_FORM_INTERVIEW_DHAS_DEPT', ['$scope', '$http', '$sce', 'InterviewcandidateCtrl', 'RecService', function($scope, $http, $sce, InterviewcandidateCtrl, RecService){
peema_phongam committed
4 5
  $scope.candidateid = $('input[name="candidateid"]').val()
  $scope.committeeid = $('input[name="committeeid"]').val()
peema_phongam committed
6
  $scope.judge = $('input[name="judge"]').val()
peema_phongam committed
7 8 9
  $scope.notedit = ($('input[name="notedit"]').val() == 'true')
  $scope.lang = $('input[name="lang"]').val()
  $scope.contextPath = ''
10
  $scope.candidate = {}
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  $scope.headdata = {
    fullname: '',
    job: '',
    status: 0,
    committee_fullname: '',
    apsdate: '',
    jobrouter: ''
  }
  $scope.formdata = {
    form: '',
    comment: '',
    job_other: '',
    appropriate: '',
    apsdate: '',
    status: 0,
  }
peema_phongam committed
27
  $scope.previous = []
peema_phongam committed
28 29 30 31 32
  let question = new Question()
  $scope.examdata = {}
  $scope.score2 = ''
  $scope.score3 = ''
  $scope.score4 = ''
peema_phongam committed
33
  $scope.isReady = false
peema_phongam committed
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

  let DocumentContainer
  let WindowObject

  $scope.comment = [{
    comment:'',
    appropriate:0
  }]
  $scope.apsform = [{
    topic : "บุคลิคลักษณะ กิริยามารยาท การแต่งกาย",
    score : 0
  },{
    topic : "มนุษย์สัมพันธ์",
    score : 0
  },{
    topic : "การสื่อข้อความ การตอบคำถาม การใช้คำพูด",
    score : 0
  },{
    topic : "ประวัติการศึกษา และการฝึกอบรม",
    score : 0
  },{
    topic : "ภูมิหลัง และสถานภาพทางครอบครัว",
    score : 0
  },{
    topic : "ประสบการณ์ ลักษณะงานที่ผ่านมา",
    score : 0
  },{
    topic : "ความรอบรู้เรื่องในงานที่สมัคร ความรู้ทางเทคนิค และวิธีปฏิบัติ",
    score : 0
  },{
    topic : "ความสามารถพิเศษที่เอื้อต่องานที่สมัคร",
    score : 0
  },{
    topic : "สติปัญญา ความคิดริเริ่ม ความคิดเห็น ไหวพริบ การแก้ปัญหาเหตุผล",
    score : 0
  },{
    topic : "ทัศนคติดความมุ่งหมายในชีวิต การงาน และสังคมรอบข้าง",
    score : 0
  }]

  $scope.myparam = {
    candidateid: $scope.candidateid,
peema_phongam committed
76 77
    committeeid: $scope.committeeid,
    judge: $scope.judge
peema_phongam committed
78 79 80 81
  };
  InterviewcandidateCtrl.manageInterviewForm.query($scope.myparam).$promise.then(function(data){
    $scope.headdata = data.header
    $scope.formdata = data.apsform
peema_phongam committed
82
    $scope.previous = data.previous
peema_phongam committed
83
    setFormAPS()
peema_phongam committed
84
    $scope.isReady = true
peema_phongam committed
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  RecService.RestMcandidate.getQuery({id: $scope.candidateid}).$promise.then(function (data){
    $scope.candidate = data.result;
    setExamData1()
    setExamScore2()
    setExamScore3()
    setExamScore4()
    setExamScore5()
  })


  let  setExamData1 = () => {
    let data = $scope.candidate.jobrouter
    let router = {}
    let isReady = false

    for(let x=0;x<data.length;x++){
      if(data[x].examdata != null){
        if(data[x].examdata.topic.tha.includes("Personality") ||
            data[x].examdata.topic.eng.includes("Personality")){
          router = data[x]
          isReady = true
        }
      }
    }
    if(isReady){
      $scope.examdata = question.getDHASPIT(router)
    }
  }
  let setExamScore2 = () => {
    let data = $scope.candidate.jobrouter
    let router = {}
    let isReady = false

    for(let x=0;x<data.length;x++){
      if(data[x].examdata != null){
        if(data[x].examdata.topic.tha.includes("ความพร้อมหัวหน้างาน") ||
            data[x].examdata.topic.eng.includes("ความพร้อมหัวหน้างาน")){
          router = data[x]
          isReady = true
        }
      }
    }
    if(isReady){
      $scope.score2 = question.getRealScore(router.question)
    }
  }

  let setExamScore3 = () => {
    let data = $scope.candidate.jobrouter
    let router = {}
    let isReady = false

    for(let x=0;x<data.length;x++){
      if(data[x].examdata != null){
        if(data[x].examdata.topic.tha.includes("ความถนัดเชิงเหตุผลนามธรรม") ||
            data[x].examdata.topic.eng.includes("ความถนัดเชิงเหตุผลนามธรรม")){
          router = data[x]
          isReady = true
        }
      }
    }
    if(isReady){
      $scope.score3 = question.getRealScore(router.question)
    }
  }

  let setExamScore4 = () => {
    let data = $scope.candidate.jobrouter
    let router = {}
    let isReady = false

    for(let x=0;x<data.length;x++){
      if(data[x].examdata != null){
        if(data[x].examdata.topic.tha.includes("ADVANCE ENGLISH") ||
            data[x].examdata.topic.eng.includes("ADVANCE ENGLISH")){
          router = data[x]
          isReady = true
        }
      }
    }
    if(isReady){
      $scope.score4 = question.getRealScore(router.question)
    }
  }

  let setExamScore5 = () => {
    let data = $scope.candidate.jobrouter
    let router = {}
    let isReady = false

    for(let x=0;x<data.length;x++){
      if(data[x].examdata != null){
        if(data[x].examdata.topic.tha.includes("คณิตศาสตร์") ||
            data[x].examdata.topic.eng.includes("คณิตศาสตร์")){
          router = data[x]
          isReady = true
        }
      }
    }
    if(isReady){
      $scope.score5 = question.getRealScore(router.question)
    }
  }
peema_phongam committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

  let setFormAPS = () => {
    if($scope.formdata.form == ''){
      $scope.formdata.form = $scope.apsform
    }else {
      $scope.formdata.form = jQuery.parseJSON($scope.formdata.form)
    }
    if($scope.formdata.comment == ''){
      $scope.formdata.comment = $scope.comment
    }else {
      $scope.formdata.comment = jQuery.parseJSON($scope.formdata.comment)
    }
  }

  $scope.getSumScore = () => {
    let result = 0
    if($scope.formdata.form != undefined){
      for(var i = 0; i <$scope.formdata.form.length; i++){
        let form = $scope.formdata.form[i];
        result += parseInt(form.score)
      }
    }
212
    return (result / 50).toFixed(2)
peema_phongam committed
213 214
  }

peema_phongam committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  $scope.getSumScoreByForm = ($form) => {
    let result = 0
    if($form != undefined){
      for(var i = 0; i < $form.length; i++){
        let sform = $form[i];
        result += parseInt(sform.score)
      }
    }
    return (result / 50).toFixed(2);
  }

  $scope.getSumScoreByScoreForm = ($form, score) => {
    let result = 0
    if($form != undefined){
      for(var i = 0; i < $form.length; i++){
        let sform = $form[i];
        if(sform.score == score){
          result += parseInt(sform.score)
        }
      }
    }
    return (result / 50).toFixed(2);
  }

peema_phongam committed
239 240 241 242 243 244 245 246 247 248
  $scope.getSumScoreByScore = (score) => {
    let result = 0
    if($scope.formdata.form != undefined){
      for(var i = 0; i <$scope.formdata.form.length; i++){
        let form = $scope.formdata.form[i];
        if(form.score == score){
          result += parseInt(form.score)
        }
      }
    }
249
    return (result / 50).toFixed(2)
peema_phongam committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
  }

  $scope.addComment = () => {
    let data = {
      comment : ''
    }
    $scope.formdata.comment.push(data)
  }
  $scope.delComment = () => {
    $scope.formdata.comment.pop()
  }

  $scope.saveDraff = () => {
    if (confirm(MyCode[1])){
      $scope.sendparam = $scope.sendparam = setParam('0')
      InterviewcandidateCtrl.manageInterviewForm.save(JSON.stringify($scope.sendparam))
          .$promise.then(function(){
        alert(MyCode[18]);
        window.opener.location.reload();
      });
    }
  }

  $scope.save = () => {
    if(chkData()){
      if (confirm(MyCode[1])){
        $scope.sendparam = setParam('1')
        InterviewcandidateCtrl.manageInterviewForm.save(JSON.stringify($scope.sendparam))
            .$promise.then(function(){
          alert(MyCode[18]);
          window.opener.location.reload();
        });
      }
    }else{
      alert('กรุณากรอกข้อมูลให้ครบถ้วน')
    }
  }

  let setParam = (type) => {
    let param = {
      headdata: $scope.headdata
      ,apsform: $scope.formdata
      ,savetype: type
    }
    return param
  }

  let chkData = () => {
    let result = true
    let objlist = $scope.formdata.form.filter((form) => form.score == 0)
    if (objlist.length>0){
      result = false
    }
    let objlist2 = $scope.formdata.comment.filter((comment) => comment.comment == 0)
    if (objlist2.length>0){
      result = false
    }
peema_phongam committed
307 308 309 310 311
    // let objlist3 = $scope.formdata.comment.filter((appropriate) => appropriate.appropriate == 0)
    // if (objlist3.length>0){
    //   result = false
    // }
    // console.log(objlist, objlist2, objlist3)
peema_phongam committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
    return result
  }

  $scope.goprint = function(){
    hidelement();
    promisePrint().then((obj) => {
      WindowObject.focus();
      console.log(WindowObject);
      // window.close();
      WindowObject.print();
    })
  }

  function promisePrint(){
    return new Promise((resolve, reject) => {
      DocumentContainer = document.getElementById('target_warpper');
      WindowObject = window.open('', 'PrintWindow', 'width=1200,height=666,top=10,right=10,toolbars=no,scrollbars=no,status=no,resizable=yes,scale=98%');
      WindowObject.document.writeln('<!DOCTYPE html>');
      WindowObject.document.writeln('<html><head><title></title>');
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/EMPVIEW/css/APP_UP/style_apsup.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/EMPVIEW/css/APS_Interview/style_printInterview.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/Bootstrap/css/bootstrap.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/EMPVIEW_LAYOUT.min.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/font-awesome.css">`);
      WindowObject.document.writeln('</head><body>');
      WindowObject.document.writeln(DocumentContainer.innerHTML);
      WindowObject.document.writeln('</body></html>');
      WindowObject.document.close();
      setTimeout(() => resolve(WindowObject), 1000)
    })
  }

  function hidelement(){
    let txt = ''
    let chk = false

    $(".score1").each(function(){
      if($(this).hasClass("ng-hide")){
        $(this).hide()
      }
    });

    $(".score2").each(function(){
      chk = $(this).prop('checked');
      if(chk){
        $(this).parents("td").append("<i class='fa fa-check-square-o right dis-block'></i>");
      }
      else{
        $(this).parents("td").append("<i class='fa fa-square-o right dis-block'></i>");
      }
      $(this).hide();
    });

    $(".score3").each(function(){
      chk = $(this).prop('checked');
      if(chk){
        $(this).parents(".chk").append("<i class='fa fa-check-square-o right dis-block'></i>");
      }
      else{
        $(this).parents(".chk").append("<i class='fa fa-square-o right dis-block'></i>");
      }
      $(this).hide();
    });


    $("textarea").each(function(){
      txt = $(this).val()
      if(txt ==''){
        $(this).parents(".showtxt").find("label").removeClass('hide')
        $(this).parents(".showtxt").find("label").clone().appendTo($(this).parents(".showtxt"))
      }else{
        $(this).parents(".showtxt").find("label").removeClass('txt-underline hide')
        $(this).parents(".showtxt").find("label").addClass('txt-underline2')
        $(this).parents(".showtxt").find("label").text(txt)
      }
      $(this).hide()
    });

    $('.btn').hide()
    $('.icon-btn').hide()

  }

}]);