//Grid용 클래스. 블록 처리용 class Tb_class { constructor(){ let _this = this; _this.tblList = ""; _this.ajax_url = "./pdf.ajax.php"; _this.download_url = "/include/getFile.php"; } //리스트 로드 getMainList () { let _this = this; let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력 ajax_json({ url: _this.ajax_url, data: { mode: 'getPdfList' }, success: function (data) { if (data.code) { _this.tblList.setData(data.data.map( v=> {return {...v, reg_date : v.reg_date.date.substr(0,19)}} )); }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_PDF_NM") || ( (data.file_name.toLowerCase()).search(document.getElementById("S_PDF_NM").value.toLowerCase()) !== -1 ) ) ) }, '=', true); }; //Row 추가 addRow(){ let _this = this; } //Cell 클릭 콜백 cellClick (e, tgt){ let _this = this; switch( tgt.getField() ) { case "file_name": let rowData = tgt.getData(); let file_url = _this.download_url + "?gubun=" + rowData['gubun'] + "&nid=" + rowData['nid'] + "&sid=" + rowData['sid']; pop_filedown(file_url, rowData['file_name'].split(".").pop()); break; } }; //Cell 변경 콜백 cellEdited (cell){ let _this = this; }; //등록 putPdf () { let _this = this; let talert = window.setTimeout(function () { Tb_funcs.tblList.alert("Loading ...") }, 0); //1초 이상 지연되면 로딩 출력 let formData = new FormData(document.forms["pdf"]); formData.append("mode","putPdf"); ajax_form({ url: "./pdf.ajax.php", data: formData, success: function(data){ if( data.code ){ _this.tblList.setData(data.data.map( v=> {return {...v, reg_date : v.reg_date.date.substr(0,19)}} )); }else{ kuls_alert(data.mesg); } }, complete: function () { window.clearTimeout(talert); _this.tblList.clearAlert(); Tb_funcs.setFilter(); } }); }; //삭제 delPdf () { let _this = this; let postdata = { 'mode': 'delPdf', 'reqdata': JSON.stringify(_this.tblList.getData("selected")), }; ajax_json({ url: _this.ajax_url, data: postdata, success: function (data) { if (data.code) { _this.getMainList(); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function () { } }); }; //시작 실행 init () { let _this = this; const fields = [ { formatter:"rowSelection", titleFormatter: "rowSelection", width: "4%", minWidth:36, headerSort: false, }, { field: "file_name", title: "파일명", width: "50%", minWidth:300, }, { field: "file_size", title: "파일크기", width: "22%", minWidth:100, formatter: "money", formatterParams: {precision:0}}, { field: "reg_date", title: "등록일", width: "22%", minWidth:100, }, ]; _this.tblList = new Tabulator("#tblPdfList",{ layout: "fitColumns", height: "100%", data: [], //기본 데이터 columns: fields, //컬럼 설정 columnDefaults: { //컬럼 공통 규칙 vertAlign: "middle", hozAlign: "center", resizable: "header",//Resize 는 헤더에서만 가능 headerHozAlign: "center", //헤더 정렬 headerSortTristate: true, //데이터 정렬 => 정/역/초기화 }, headerSortElement: "", //정렬 아이콘 }); _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); }); ['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_PDF_NM").forEach(tgt=>tgt.addEventListener(evt,()=>{_this.setFilter()}))); ['click','keyup'].forEach(evt => document.querySelectorAll("#btnDelPdf").forEach(tgt=>tgt.addEventListener(evt,()=>{ kuls_confirm("파일삭제","정말 파일을 삭제하시겠습니까?", ()=>{ _this.delPdf(); }) }))); ['change'].forEach(evt => document.querySelector("#pdf_file").addEventListener(evt, ()=>{_this.putPdf()})); }; } const Tb_funcs = new Tb_class(); Tb_funcs.init();