import { Component, OnInit } from '@angular/core';
import { FlexTableComponent } from '../../../../../shared/common/FlexTable.component';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FormBuilder, Validators } from '@angular/forms';
import { FrameRequest } from '../../../../../shared/frame/frame-request';

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

  public query = {
    query: ""
  };
  QUERY_URL = "pl/plPjSchool/page.htm";
  ADD_URL = "pl/plPjSchool/add.htm";
  DELETE_URL= "pl/plPjSchool/delete.htm";
  GET_URL= "pl/plPjSchool/get.htm";
  EDIT_URL= "pl/plPjSchool/edit.htm";
  SCHOOL_URL = "cf/cfOrganization/list.htm?org_type=1&status=1";
  GET_SCHOOL_URL = "cf/cfOrganization/get.htm";

  constructor(public bsModalService: BsModalService, fb: FormBuilder) {
    super();
    this.formModel = fb.group({
      id: [null],
      school_code: [null, Validators.required],
      school_name: [null, Validators.required]
    });
   }

  ngOnInit() {
  }

  getSchoolName(org_id : any) {
    if(this.item && org_id && this.item.school_id !== org_id) {
      FrameRequest.requestEntity(this.GET_SCHOOL_URL, {id: org_id}, (entity) => {
        if(entity) {
          this.item.school_name = entity.org_name;
        }
      });
    }
  }



}
