/**
 * Created by PPMaj on 3/1/2017.
 */
'use strict'

angular.module('RECRUIT').controller('EmailConfig', function ($scope, $mdDialog, RecService, $log, SwapLang) {
  $scope.lang = getLang()
  $scope.clsRecruitmentConfig = new RecruitmentConfig()
  $scope.HrSwlang = SwapLang
  $scope.init = function () {
    RecService.ManageConfig.query({cname: 'EMAIL'}).$promise.then(function (data) {
      $scope.clsRecruitmentConfig.recruitmentConfig = data.result
    })
  }
  $scope.init()

  $scope.submit = function () {
    $scope.HrSwlang.getConfirm(1).then(function () {
      RecService.ManageConfig.save($scope.clsRecruitmentConfig.recruitmentConfig).$promise.then(function () {
        $scope.HrSwlang.getAlert(18).then(function () {
          $scope.init()
        })
      }, function () {
        $scope.HrSwlang.getAlert(17)
      });
    })
  };
  $scope.showEmail = function (event, email) {
    $mdDialog.show({
      controller: DialogController,
      templateUrl: 'DIALOGTEMPLATE/EMAIL_CONF.TMPL.html',
      parent: angular.element(document.body),
      targetEvent: event,
      clickOutsideToClose: true,
      locals: {
        email: email
      }
    })
  }
  function DialogController($scope, $mdDialog, email) {
    $scope.lang = getLang();
    $scope.email = email
    $scope.code = {
      applicant: {
        id : '${CID}',
        name: '${CFNAME}',
        lastname: '${CLNAME}',
        preName: '${CPREFIX+CFNAME}',
        preLastname: '${CPREFIX+CLNAME}',
        nameLastname: '${CFNAME+CLNAME}',
        preNameLastName: '${CFULLNAME}'
      },
      committee: {
        name: '${CMFNAME}',
        lastname: '${CMLNAME}',
        preName: '${CMPREFIX+CMFNAME}',
        preLastname: '${CMPREFIX+CMLNAME}',
        nameLastname: '${CMFNAME+CMLNAME}',
        preNameLastName: '${CMFULLNAME}'
      },
      datetime: {
        day: '${DAY}',
        month: '${MONTH}',
        year: '${YEAR}',
        timestart: '${TIMESTART}',
        timeend: '${TIMEEND}'
      },
      job: '${JOB}',
      place: '${PLACE}'
    }
    $scope.cancel = function () {
      $mdDialog.cancel();
    };
    $scope.save = function () {
      $mdDialog.hide();
    };
  }
})