EpayslipSignature.Controller.js 2.42 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
'use strict'

angular.module('Company').controller('EpayslipSignature', ['$scope', '$http', 'ComCtrl', function($scope, $http, ComCtrl){
   $scope.comlist = [];
   $scope.count = 1;

   $scope.comsel = 'All';
   $scope.tmppic = '';
   $scope.tmpforsave = [];

   ComCtrl.manageEpaySignature.query()
   .$promise.then(function(data){
      $scope.comlist = data.result;
      $scope.tmppic = $scope.comlist[0].path;
      if ($scope.tmppic != "" && $('select[name="__branchid"]').val() == "All"){
         console.log('hi');
         $("#signaturePic").attr('src',$scope.tmppic);
      }

   })

   $scope.changePicture = function(){
      var bool = false;
      $scope.comlist.forEach(function(obj){
         if (obj.branchid == $scope.comsel){
            bool = true;
            $scope.tmppic = obj.path;
            if ($scope.tmppic != ""){
               console.log($scope.tmppic);
               $("#signaturePic").attr('src',$scope.tmppic);
            }
         }
      });

      if (bool && $scope.tmppic == ""){
         $("#signaturePic").attr('src',$scope.tmppic);
      }
   }

   $scope.checkData = function(){
      console.log($('select[name="__branchid"]').val());
      var testsub = $("#signaturePic").attr('src');
      testsub = testsub.substring(testsub.indexOf("filename="),testsub.length);
      testsub = testsub.substring(testsub.indexOf("=")+1, testsub.length);
      console.log(testsub);

   }

   $scope.save = function(){
      var srcpath = $("#signaturePic").attr('src');
      srcpath = srcpath.substring(srcpath.indexOf("filename="), srcpath.length);
      srcpath = srcpath.substring(srcpath.indexOf("=")+1, srcpath.length);

      $scope.tmpforsave = [{
         'branchid': $('select[name="__branchid"]').val(),
         'path': srcpath
      }];
      ComCtrl.manageEpaySignature.save($scope.tmpforsave)
      .$promise.then(function(data){
         if (data.result == "success"){
            alert(MyCode[18]);
            $scope.genNewData();
         }
      })
   }

   $scope.delete = function(){
      ComCtrl.manageEpaySignature.delete({branchid: $('select[name="__branchid"]').val()})
      .$promise.then(function(data){
         if (data.result == "success"){
            alert(MyCode[19]);
            window.location.reload();
         }
      });
   }

   $scope.genNewData = function(){
      ComCtrl.manageEpaySignature.query()
      .$promise.then(function(data){
         $scope.comlist = data.result;
      })
   }

}]);