import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal/bs-modal.service';
import { FormBuilder, Validators } from '@angular/forms';
import { FlexTableComponent } from '../../../../shared/common/FlexTable.component';
import { CustomValidators } from 'ng2-validation';
import { FrameValidator } from '../../../../shared/frame/Frame-validator';

@Component({
  selector: 'app-pl-yearcode',
  templateUrl: './pl-yearcode.component.html',
  styleUrls: ['./pl-yearcode.component.scss']
})
export class PlYearcodeComponent extends FlexTableComponent implements OnInit {

  QUERY_URL= "pl/plYearCode/page.htm";
  DELETE_URL= "pl/plYearCode/deleteBatch.htm";
  GET_URL= "pl/plYearCode/get.htm";
  ADD_URL= "pl/plYearCode/add.htm";
  EDIT_URL= "pl/plYearCode/edit.htm";

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) { 
    super();
    this.formModel = fb.group({
      'id': [null],
      'year_code': [null, Validators.compose([Validators.required,Validators.pattern(FrameValidator.pattern_number)])],
      'year': [null, Validators.compose([Validators.required,Validators.pattern(FrameValidator.pattern_number), CustomValidators.rangeLength([1, 6])])],
    });
  }
   

  ngOnInit() {
   
    
  }

  async preGoEditEvent(entity){
    if(entity){
      entity.year_code = entity.year_code +"";
      entity.year = entity.year +"";
    }else{
      entity = {};
      entity.year_code = "";
      entity.year = "";
    }
    return true;
  }

}
