'use strict'

angular.module('RECRUIT').controller('Exam', ['$scope', '$http', 'RecService', function($scope, $http, RecService){
   $scope.examdata = [];
   RecService.ManageExam001.query({examid: '0', querytype: 'ex01all'}).$promise.then(function(data){
      $scope.examdata = data.mquestionset1;
      console.log('DEBUG:: auto query() -> $scope.examdata ->', $scope.examdata);
   });

   $scope.switchDetail = function(p_index){
      if ($scope.examdata[p_index].showdetail == true){
         $scope.examdata[p_index].showdetail = false;
      }else{
         $scope.examdata[p_index].showdetail = true;
      }
   }

   $scope.selectAll = function(){
      $scope.examdata.forEach(function(data){
         data.ischeck = true;
      });
   }

   $scope.unSelectAll = function(){
      $scope.examdata.forEach(function(data){
         data.ischeck = false;
      });
   }

   $scope.checkSelect = function(){
      var result = [];

      $scope.examdata.forEach(function(data){
         if (data.ischeck == true){
            result.push(data);
         }
      });

      window.opener.putNewExam(result);
      window.close();
   }
}]);