ApsBuForm.Controller.js 4 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 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
'use strict'
angular.module('APP_BU').controller('ApsBuForm',['$scope', '$http', 'ListBuCtrl', function($scope, $http, ListBuCtrl){
   $scope.apsid = $('input[name="apsid"]').val();
   $scope.apsgroup = $('input[name="apsgroup"]').val();
   $scope.subdata = $('input[name="subdata"]').val();
   $scope.assessordata = {};
   $scope.sequence = '';
   $scope.apsform = [];
   $scope.selectscore = [{
      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: "Don't assess"
      }
   }];
   $scope.mylang = 'eng';

   $scope.myparam = {
      apsid: $scope.apsid
      ,apsgroup: $scope.apsgroup
      ,subdata: $scope.subdata
   };
   ListBuCtrl.manageApsForm.query($scope.myparam)
   .$promise.then(function(data){
      $scope.assessordata = data.header;
      $scope.apsform = data.body;
      $scope.sequence = $scope.assessordata[0].sequence;
   });

   $scope.setMyLang = function($p_lang){
      $scope.mylang = $p_lang;
   }

   $scope.getLabel = function($p_object){
      if ($scope.mylang == 'eng'){
         return $p_object.eng;
      }else if ($scope.mylang == 'tha'){
         return $p_object.tha;
      }
   }
    $scope.saveDraff = function(){
        if ($scope.checkCommnet()){
            alert("กรุณากรอกความคิดเห็นให้ครบถ้วน");
        }else if (confirm(MyCode[1])){
            $scope.sendparam = {
                apsid: $scope.apsid
                ,apsgroup: $scope.apsgroup
                ,subdata: $scope.subdata
                ,apsform: $scope.apsform
                ,sequence: $scope.sequence
                ,savetype: '0'
            }
            ListBuCtrl.manageApsForm.save(JSON.stringify($scope.sendparam))
            .$promise.then(function(){
                alert(MyCode[18]);
            });
        }   
    }
    $scope.save = function(){
        if ($scope.checkScore()){
            alert("กรุณาใส่คะแนนให้ครบถ้วน");
        }else if ($scope.checkCommnet()){
            alert("กรุณากรอกความคิดเห็นให้ครบถ้วน");
        }else if (confirm(MyCode[1])){
            $scope.sendparam = {
                apsid: $scope.apsid
                ,apsgroup: $scope.apsgroup
                ,subdata: $scope.subdata
                ,apsform: $scope.apsform
                ,sequence: $scope.sequence
                ,savetype: '1'
            }
            ListBuCtrl.manageApsForm.save(JSON.stringify($scope.sendparam))
            .$promise.then(function(){
                $scope.assessordata[0].apsstate = 1;
                alert(MyCode[18]);
                closePage();
                window.opener.location.reload();
            });
        }
    }
    $scope.checkCommnet = function(){
        var result = false;
        $scope.apsform.forEach(function(data){
            if((data.score ==5 || data.score ==1 )){
                if(data.comment == undefined){
                    result = true;
                }
            }else{
                if(data.comment != ""){
                    data.comment="";
                }
            }
        });
     return result;
    }
    $scope.checkRequire = function($p_obj){
        var result = '';
        if (($p_obj.score ==5 || $p_obj.score ==1)){
            result = 'required';
        }
        return result;
    }
    $scope.checkScore = function(){
        var result = false;
        $scope.apsform.forEach(function(data){
            if(data.score ==0){
                result = true;
            }
        });
        return result;
    }
}]);