import {Component, OnInit} from '@angular/core';
import {FrameDetailComponent} from "../../core/detail/frame.detail";
import {BsModalRef} from "ngx-bootstrap/modal";
import {FormBuilder, Validators} from "@angular/forms";
import {AjaxService} from "../../../../core/service/ajax.service";

@Component({
  selector: 'app-frame-thread-test',
  templateUrl: './frame-thread-test.component.html',
  styleUrls: ['./frame-thread-test.component.scss']
})
export class FrameThreadTestComponent extends FrameDetailComponent implements OnInit {

  callbackTypeArray = [{
    dict_value: 'Swal',
    dict_text: '弹出提示框'
  }, {
    dict_value: 'Download',
    dict_text: '下载文件'
  }];

  openThreadRunningWindow:any;

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'thread_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(128)])],
      'error_flag': [null],
      'callback_type': [null, Validators.compose([Validators.required])],
      'callback_param': [null]
    });
  }

  ngOnInit() {
  }

   initDefautEntity() {
    this.currentEntity.thread_name='测试线程';
    this.currentEntity.error_flag = 'InActive';
    this.currentEntity.callback_type = 'Swal';
  }

  testThread() {
    // 标记所有组件获得过焦点，用于验证判断
    this.detailForm.markAllAsTouched();
    // 如果为验证，提示验证错误信息
    if (!this.validForm()) {
      return;
    }
    AjaxService.requestEntity('frame/thread/test.htm', this.currentEntity, (data) => {
        // 关闭窗口
        this.bsModalRef.hide();
        this.openThreadRunningWindow.call(undefined,data);
    }, {RequestWithLoading: true});


  }

}

