You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
359 lines
11 KiB
JavaScript
359 lines
11 KiB
JavaScript
if(window.help !== undefined){
|
|
help.prototype.list.push("AppSupport 클래스 : 웹프로젝트 내에서 공통적으로 사용할 수 있는 기능 지원");
|
|
}
|
|
|
|
class AppSupport {
|
|
|
|
static help(){
|
|
console.log("initDatepicker(초기화영역) : 특정 영역의 datepicker를 초기화한다.");
|
|
console.log("initDetailSearchButton(초기화영역) : 특정 영역의 상세조회 버튼을 초기화한다.");
|
|
console.log("getLastOpenDialog() : 마지막으로 열린 다이얼로그 영역을 반환한다.");
|
|
console.log("getLastDialog() : 마지막으로 생성된 다이얼로그 영역을 반환한다.");
|
|
console.log("setDialogZindex() : 모달창 z-index 초기화");
|
|
console.log("focusClose() : 모달창 닫기 버튼에 포커스");
|
|
console.log("focusOK() : 모달창 확인 버튼에 포커스");
|
|
console.log("customValidate(제이쿼리객체) : 커스텀 발리데이션");
|
|
console.log("getCellDefs(th제이쿼리객체, td제이쿼리객체, [컬럼명 구하는 메소드]) : 엑셀 파일 정보 생성");
|
|
console.log("sleep(마이크로초) : 지연 처리 함수");
|
|
|
|
}
|
|
|
|
/**************************************************************************
|
|
* 특정 영역의 datepicker를 초기화한다.
|
|
**************************************************************************/
|
|
static initDatepicker(elementEl){
|
|
var executionArea;
|
|
if(typeof elementEl == "string"){
|
|
executionArea = $("#"+elementEl);
|
|
} else {
|
|
executionArea = $(elementEl);
|
|
}
|
|
|
|
executionArea.find(".form-date").datePicker();
|
|
}
|
|
|
|
/**************************************************************************
|
|
* 특정 영역의 상세조회 버튼을 초기화한다.
|
|
**************************************************************************/
|
|
static initDetailSearchButton(elementId){
|
|
|
|
var executionArea;
|
|
if(typeof elementId == "string"){
|
|
executionArea = $("#"+elementId);
|
|
} else {
|
|
executionArea = $(elementId);
|
|
}
|
|
|
|
/*--------------------- 상세검색 버튼 제어 ---------------------*/
|
|
executionArea.find(".btn-open-detail").on("click", function() {
|
|
$(this).find('i').toggleClass('bx-chevron-down');
|
|
$(this).find('i').toggleClass('bx-chevron-up');
|
|
});
|
|
|
|
}
|
|
|
|
//마지막으로 열린 다이얼로그 영역을 반환한다.
|
|
static getLastOpenDialog(){
|
|
return $("div.modal.show").last()[0];
|
|
}
|
|
//마지막으로 생성된 다이얼로그 영역을 반환환다.
|
|
static getLastDialog(){
|
|
return $("div.modal").last()[0];
|
|
}
|
|
static getSecondDialogFromLast(){
|
|
var dialogCount = $("div.modal").length;
|
|
if(dialogCount >= 2){
|
|
return $("div.modal").eq(dialogCount - 2)[0];
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
/**************************************************************************
|
|
* 모달창 z-index 초기화
|
|
**************************************************************************/
|
|
static setDialogZindex(){
|
|
var parentDialog = AppSupport.getSecondDialogFromLast();
|
|
var childDialog = AppSupport.getLastDialog();
|
|
|
|
if(parentDialog == null){
|
|
return;
|
|
}
|
|
if(parentDialog == childDialog){
|
|
return;
|
|
}
|
|
|
|
var parentZ = $(parentDialog).css("z-index");
|
|
$(childDialog).css("z-index", Number(parentZ)+10);
|
|
|
|
var dNext = $(childDialog).next();
|
|
|
|
if(dNext.prop("tagName") == "SCRIPT"){
|
|
var dNextNext = $(childDialog).next().next();
|
|
dNextNext.css("z-index", Number(parentZ)+9);
|
|
} else if(dNext.hasClass("modal-backdrop")){
|
|
dNext.css("z-index", Number(parentZ)+9);
|
|
};
|
|
}
|
|
|
|
/**************************************************************************
|
|
* 모달창 닫기 버튼 포커스
|
|
**************************************************************************/
|
|
static focusClose() {
|
|
$(document).find("div.modal").last().on('shown.bs.modal', function () {
|
|
$(this).find(".btn-close").trigger('focus');
|
|
});
|
|
}
|
|
|
|
/**************************************************************************
|
|
* 모달창 확인 버튼 포커스
|
|
**************************************************************************/
|
|
static focusOK() {
|
|
$(document).find("div.modal").last().on('shown.bs.modal', function () {
|
|
$(this).find(".modal-footer").find("button").each(function(){
|
|
if($(this).text() == "확인"){
|
|
$(this).trigger('focus');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* validation
|
|
**************************************************************************/
|
|
static customValidate(targetArr) {
|
|
|
|
var handler = validationFailureHandler();
|
|
handler.notice = function(msg, input) {
|
|
dialog.alert({
|
|
content:msg,
|
|
onClose:function(){input.focus();},
|
|
init: function(){
|
|
AppSupport.setDialogZindex();
|
|
}
|
|
});
|
|
};
|
|
|
|
for(var i=0;i<targetArr.length;i++){
|
|
var input = targetArr[i];
|
|
|
|
if(!validInput(input, handler)){
|
|
return false;
|
|
}
|
|
|
|
if(!input.required && input.value == ""){
|
|
continue;
|
|
}
|
|
|
|
//입력값의 최대 바이트 수 체크
|
|
if(input.dataset.maxlengthb){
|
|
if(!StringSupport.isMaxByte(input.value, input.dataset.maxlengthb)){
|
|
handler.tooLong(input);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//입력값의 포맷형식 체크
|
|
if(input.dataset.fmtType){
|
|
if(input.dataset.fmtType == "day"){
|
|
if(!StringSupport.isDate(input.value)){
|
|
handler.typeMismatch(input);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if(input.dataset.fmtType == "time"){
|
|
if(!StringSupport.isTime(input.value)){
|
|
handler.typeMismatch(input);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if(input.dataset.fmtType == "zeroLpadNumber"){
|
|
if(!StringSupport.isDigitString(input.value)){
|
|
handler.typeMismatch(input);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* 엑셀 파일 작성 정보 생성
|
|
**************************************************************************/
|
|
static getCellDefs($ths, $tds, fieldGetterOption){
|
|
var cellDefs = [];
|
|
|
|
for(var i=0; i < $ths.length; i++){
|
|
|
|
var label = $ths.eq(i).text();
|
|
label = label.replace("\n", "");
|
|
label = label.replace("\t", "");
|
|
label = label.replace(" ", "");
|
|
|
|
if(label != ""){
|
|
|
|
var width = $ths.eq(i).outerWidth();
|
|
width = Math.ceil(width/10) + 2;
|
|
|
|
var field = "";
|
|
if(fieldGetterOption != null){
|
|
field = fieldGetterOption($tds.eq(i));
|
|
} else {
|
|
field = $tds.eq(i).text();
|
|
}
|
|
|
|
field = field.replace("{", "");
|
|
field = field.replace("}", "");
|
|
field = field.replace("\n", "");
|
|
field = field.replace("\t", "");
|
|
field = field.replace(" ", "");
|
|
|
|
var cellDef = {
|
|
label : label,
|
|
width : width,
|
|
field : field
|
|
};
|
|
|
|
cellDefs.push(cellDef);
|
|
}
|
|
|
|
}
|
|
|
|
return JSON.stringify(cellDefs);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* 지연
|
|
**************************************************************************/
|
|
static sleep(ms) {
|
|
return new Promise((r) => setTimeout(r, ms));
|
|
}
|
|
|
|
/**************************************************************************
|
|
* PDF파일 미리보기 창 열기
|
|
**************************************************************************/
|
|
static openPDF(blob, windowName){
|
|
let wctxpath = wctx.path;
|
|
|
|
var popup = window.open(
|
|
wctx.url("/webjars/applib/html/pdf.html")+"?wctxpath="+wctxpath
|
|
,windowName
|
|
,'top=10, left=10'
|
|
);
|
|
popup.onload = () => {
|
|
|
|
popup.makePdfFromBlob(blob);
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* 전역함수
|
|
**************************************************************************/
|
|
/**************************************************************************
|
|
* 동기식 대화상자
|
|
**************************************************************************/
|
|
async function confirm2(msg){
|
|
return await dialog2(msg, "confirm");
|
|
}
|
|
|
|
async function alert2(msg){
|
|
return await dialog2(msg, "alert");
|
|
}
|
|
|
|
async function prompt2(msg){
|
|
return await dialog2(msg, "prompt");
|
|
}
|
|
|
|
async function dialog2(msg, type, buttons){
|
|
var dlgId = "dlg-" + uuid();
|
|
var resp = await fetch(wctx.url("/webjars/html/dialog.html"));
|
|
var template = await resp.text();
|
|
var container = "<div class='container-fluid text-center fs-4'>{content}</div>";
|
|
if(type == "prompt"){
|
|
var rsn = '<br/><textarea type="text" id="rsn" class="form-control w-100"></textarea>';
|
|
content = container.replace(/{content}/g, msg + rsn);
|
|
} else {
|
|
content = container.replace(/{content}/g, msg);
|
|
}
|
|
var backdropID = dlgId + "-backdrop";
|
|
var tmpl = template.replace(/{id}/g, dlgId).replace(/{title}/g, "").replace(/{size}/, "").replace("","");
|
|
tmpl = tmpl.replace("modal-dialog", "modal-dialog-centered modal-dialog");
|
|
tmpl = tmpl.replace("data-bs-backdrop=\"static\"", "data-bs-backdrop=\"static\" data-bs-keyboard=\"false\"");
|
|
tmpl = tmpl.replace("text-end hidden","text-end");
|
|
tmpl = tmpl.replace("btn-primary","btn-primary btn-ok");
|
|
var dlg = $(tmpl).appendTo("body");
|
|
if(type == "confirm" || type == "alert" || type == "prompt"){
|
|
if(type == "confirm" || type == "prompt"){
|
|
dlg.find(".modal-footer").append('<button type="button" class="btn btn-primary btn-cancel">취소</button>');
|
|
}
|
|
} else {
|
|
dlg.find(".modal-footer").find(".btn-ok").remove();
|
|
|
|
for(var i=0; i < buttons.length; i++){
|
|
dlg.find(".modal-footer").append(
|
|
'<button type="button" class="btn btn-primary btn-custom" data-key="'+buttons[i].key+'" >'
|
|
+buttons[i].value
|
|
+'</button>');
|
|
}
|
|
|
|
}
|
|
|
|
dlg.find(".modal-header").remove();
|
|
dlg.find(".modal-body").html(content).fadeIn();
|
|
dlg.on("hidden.bs.modal", function() {
|
|
$("#" + dlgId +",#" + backdropID).remove();
|
|
});
|
|
dlg.modal("show");
|
|
$(".modal-backdrop").each(function() {
|
|
var backdrop = $(this);
|
|
if (!backdrop.prop("id")){
|
|
backdrop.prop("id", backdropID);
|
|
}
|
|
});
|
|
|
|
AppSupport.setDialogZindex();
|
|
|
|
return new Promise(resolve => {
|
|
if(type == "confirm" || type == "alert" || type == "prompt"){
|
|
if(type == "prompt"){
|
|
dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
|
|
dlg.modal("hide");
|
|
resolve($("#rsn").val());
|
|
});
|
|
} else {
|
|
dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
|
|
dlg.modal("hide");
|
|
resolve(true);
|
|
});
|
|
}
|
|
|
|
if(type == "confirm"){
|
|
dlg[0].querySelector(".btn-cancel").addEventListener("click", () => {
|
|
dlg.modal("hide");
|
|
resolve(false);
|
|
});
|
|
}
|
|
if(type == "prompt"){
|
|
dlg[0].querySelector(".btn-cancel").addEventListener("click", () => {
|
|
dlg.modal("hide");
|
|
resolve(null);
|
|
});
|
|
}
|
|
} else {
|
|
dlg.find(".btn-custom").each(function(){
|
|
this.addEventListener("click", () => {
|
|
dlg.modal("hide");
|
|
resolve(this.dataset.key);
|
|
});
|
|
});
|
|
}
|
|
|
|
});
|
|
} |