forked from HANYANG/HANYANG_MES
174 lines
6.1 KiB
JavaScript
174 lines
6.1 KiB
JavaScript
|
|
//Grid용 클래스. 블록 처리용
|
|
class Tb_class {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.tblList = "";
|
|
_this.ajax_url = "./mofact.ajax.php";
|
|
}
|
|
|
|
//리스트 로드
|
|
getMainList () {
|
|
let _this = this;
|
|
|
|
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: { mode: 'getMofactList' },
|
|
success: function (data) {
|
|
if (data.code) {
|
|
_this.tblList.setData(data.data);
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
window.clearTimeout(talert);
|
|
_this.tblList.clearAlert();
|
|
Tb_funcs.setFilter();
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
setFilter () {
|
|
let _this = this;
|
|
|
|
_this.tblList.setFilter(function(data){ //필터링
|
|
return (
|
|
true
|
|
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
|
|
&& ( !document.getElementById("S_MOF_NM") || ( (data.MOF_NM).search(document.getElementById("S_MOF_NM").value) !== -1 ) )
|
|
&& ( !document.getElementById("S_MOF_CD") ||( (data.MOF_CD).search(document.getElementById("S_MOF_CD").value) !== -1 ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//Row 추가
|
|
addRow(){
|
|
let _this = this;
|
|
_this.tblList.addRow({_STATUS_:'I', USE_FLG:'Y', MOF_ACCNT:'PD', MOF_GRP:'ST', SHAPE_TYPE:'NF'});
|
|
}
|
|
|
|
//Cell 클릭 콜백
|
|
cellClick (e, tgt){
|
|
let _this = this;
|
|
_this.tgt = tgt;
|
|
switch( tgt.getField() ){
|
|
case "USE_FLG":
|
|
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
|
|
break;
|
|
|
|
case "MAJR_EMP_NO":
|
|
popEmployeeList('MAJR_EMP_NO','MAJR_EMP_NM', 'BA01', tgt.getRow()._row);
|
|
break;
|
|
|
|
case "MINR_EMP_NO":
|
|
popEmployeeList('MINR_EMP_NO','MINR_EMP_NM', 'BA01', tgt.getRow()._row);
|
|
break;
|
|
}
|
|
};
|
|
|
|
//Cell 변경 콜백
|
|
cellEdited (cell){
|
|
let _this = this;
|
|
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
|
|
};
|
|
|
|
//등록
|
|
putMofact (){
|
|
let _this = this;
|
|
let pdata = _this.tblList.getData();
|
|
let dupdata = pdata.map( data => data.MOF_CD ).filter( data => data );
|
|
if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){
|
|
kuls_alert("단말기 코드가 중복됩니다.");
|
|
return false;
|
|
}
|
|
let postdata = {
|
|
'mode': 'putMofact',
|
|
'reqdata': JSON.stringify(_this.tblList.getData().filter(row=> row._STATUS_)),
|
|
};
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: postdata,
|
|
success: function (data) {
|
|
if (data.code) {
|
|
kuls_success("적용 되었습니다.");
|
|
_this.getMainList();
|
|
}else{
|
|
Tb_funcs.tblList.getRows().forEach( row => { //일부 적용된 열 update 처리
|
|
if( data.data.includes(row.getData()['MOF_CD']) ){
|
|
row.update({_STATUS_:'U'});
|
|
}
|
|
} );
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
//시작 실행
|
|
init () {
|
|
let _this = this;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "4%", minWidth:60, },
|
|
{ field: "MOF_CD", title: "단말기코드", width: "10%", minWidth:100, editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }, },
|
|
{ field: "MOF_NM", title: "단말기명", width: "20%", minWidth:120, editor:'input', },
|
|
{ field: "MOF_MF", title: "제조사", width: "15%", minWidth:120, editor:'input', },
|
|
{ field: "PUR_NM", title: "반입처", width: "10%", minWidth:120, editor:'input', },
|
|
{ field: "PUR_DATE", title: "등록일", width: "10%", minWidth:120, editor:'date', editorParams: {max:'9999-12-31'}, },
|
|
{ field: "MAJR_EMP_NO", title: "담당자(정)", width: "10%", minWidth:120, cssClass:'user-editable', formatter: function(tgt){ return (tgt.getData()['MAJR_EMP_NM']||''); }, },
|
|
{ field: "MINR_EMP_NO", title: "담당자(부)", width: "10%", minWidth:120, cssClass:'user-editable', formatter: function(tgt){ return (tgt.getData()['MINR_EMP_NM']||''); }, },
|
|
{ field: "USE_FLG", title: "사용", width: "6%", minWidth:80, cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}, },
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblMofactList",{
|
|
layout: "fitColumns",
|
|
height: "100%",
|
|
data: [], //기본 데이터
|
|
columns: fields, //컬럼 설정
|
|
columnDefaults: { //컬럼 공통 규칙
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header",//Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
},
|
|
rowFormatter:function(row){
|
|
if(row.getData().USE_FLG != "Y"){
|
|
row.getElement().classList.add('text-secondary');
|
|
}
|
|
},
|
|
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
|
|
});
|
|
|
|
_this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
|
|
_this.getMainList();
|
|
});
|
|
|
|
_this.tblList.on("cellClick", (e,tgt) => { //Tabulator cell Click
|
|
_this.cellClick && Tb_funcs.cellClick(e,tgt);
|
|
});
|
|
_this.tblList.on("cellEdited", (cell) => { //Tabulator cell Edited
|
|
_this.cellEdited && Tb_funcs.cellEdited(cell);
|
|
});
|
|
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnAddMofact").addEventListener(evt,()=>{_this.addRow()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnPutMofact").addEventListener(evt,()=>{_this.putMofact()}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_MOF_CD, #S_MOF_NM, #S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
|
|
};
|
|
}
|
|
|
|
const Tb_funcs = new Tb_class();
|
|
Tb_funcs.init();
|