ApsBuData.Controller.js 2.7 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 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
'use strict'

angular.module('APP_BU').controller('ApsBuData', ['$scope', '$http', 'ApsManage', function($scope, $http, ApsManage){
   $scope.apsbudata = [];
   $scope.assdata = [];
   $scope.empdata = 'emp =';
   $scope.allitem = {};
   $scope.selectnumber =[{
      score: "5.00",
      show: {
         tha: 5,
         eng: 5
      }
   },{
      score: "4.00",
      show: {
         tha: 4,
         eng: 4
      }
   },{
      score: "3.00",
      show: {
         tha: 3,
         eng: 3
      }
   },{
      score: "2.00",
      show: {
         tha: 2,
         eng: 2
      }
   },{
      score: "1.00",
      show: {
         tha: 1,
         eng: 1
      }
   },{
      score: "0.00",
      show: {
         tha: '-',
         eng: '-'
      }
   }];

   $scope.getApsData = function($empid){

      $scope.empdata = $scope.empdata+" "+$empid;
      ApsManage.manageAps360.query({employeeid: $empid})
      .$promise.then(function(data){
         $scope.apsbudata = data.tasdata;
         $scope.assdata = data.assessdata;
         //console.log($scope.apsbudata);
      })
   }

    $scope.getLabel = function($p_obj){
      if (lang == 'eng'){
         return $p_obj.eng;
      }else if (lang == 'tha'){
         return $p_obj.tha;
      }
   }

   $scope.calScore = function($p_index){
      var tmpscore = 0.00;
      $scope.apsbudata[$p_index].scorelist.forEach(function($data){
         tmpscore += parseFloat($data.score);
      });

      if (tmpscore == 0.00){
         return '-';
      }else{
         return tmpscore;
      }
   }

    $scope.save = function(){
        if($scope.chkcomment()){
            alert("กรุณากรอกความคิดเห็นให้ครบถ้วน");
        }else if (confirm(MyCode[1])){      
            $scope.alldata = $scope.apsbudata;
            $scope.alldata.forEach(function(data){
                 data.scorelist.forEach(function(list){
                    if((list.score !="1.00" && list.score !="5.00") && (list.comment !="")){
                        list.comment ="";
                    }                    
                 });
            });
            $scope.allitem = {budata: $scope.alldata};

            
            ApsManage.manageAps360.save(JSON.stringify($scope.allitem))
            .$promise.then(function(data){
                alert(MyCode[18]);
            });
         }
    }
 
    $scope.chkcomment = function(){
        var result = false;
        $scope.apsbudata.forEach(function(data){
            data.scorelist.forEach(function(list){
                if((list.score =="1.00" || list.score =="5.00") && (list.comment==="")){
                    result = true;
                }
            });
        });
        return result;
    }
}]);