'use strict'
angular.module("Training").controller('ShowDemo',['$scope', '$http', function($scope, $http){
   $scope.tmplog = 1;
   $scope.langdata = "";
   $scope.formData = {};
   $scope.questionData = [];
   $scope.tmpradio = "";
   $scope.questionType=[{
      "id" : "1",
      "name" : "Textbox"
   },{
      "id" : "2",
      "name" : "Single choice"
   },{
      "id" : "3",
      "name" : "Multi choice"
   },{
      "id" : "4",
      "name" : "Table single choice"
   },{
      "id" : "5",
      "name" : "Table multi choice"
   },{
      "id" : "6",
      "name" :"Sub Question"
   }];
   $scope.allitem = {};

   $scope.initForm = function(){
      if ($scope.tmplog == 1){
         $scope.allitem = JSON.parse(document.body.children[0].value);

         $scope.formData = $scope.allitem.formData;
         $scope.questionData = $scope.allitem.questionData;
      }
      $scope.tmplog++;
   }

   $scope.initLang = function($p_lang){
      $scope.langdata = $p_lang;
   }

   $scope.checkQuestion = function(){
      console.log($scope.questionData);
   }

   $scope.getFormData = function($p_object){
      if ($scope.langdata == "eng"){
         return $scope.formData[$p_object].eng;
      }else{
         return $scope.formData[$p_object].tha;
      }
   }

   $scope.getQuestionData = function($p_object){
      if ($scope.langdata == "eng"){
         return $p_object["eng"];
      }else{
         return $p_object["tha"];
      }
   }
}])
.directive('showtext', function(){
   return {
      templateUrl: '../EMPVIEW/SHOWTEXTQUESTION.html'
   };
})
.directive('showchoice', function(){
   return {
      templateUrl: '../EMPVIEW/SHOWCHOICEQUESTION.html'
   };
})
.directive('showsubquestion', function(){
   return {
      templateUrl: '../EMPVIEW/SHOWSUBQUESTION.html'
   };
})
.directive('showtable', function(){
   return {
      templateUrl: '../EMPVIEW/SHOWTABLEQUESTION.html'
   };
});