/**
* 빈값일 경우 default value
* <br>
* 빈값일 경우 default value 반환
*
* @method nvl
* @param object
* @return object
* @example
* someFunction: function() {
* var me = this;
* ...
* if (UT.nvl(item.sts, 'C') == 'C') {
* ...
* }
* }
*/
nvl : function(object, defaultValue)
{
if (UT.isEmpty(object))
{
return defaultValue;
}
return object;
},
/**
* 첨부파일 size format
* UT.formatFileSize(data.file_size)
*
*/
formatFileSize : function(fileSize)
{
return Polymer.$UploadUtil.byteToDisplaySize(fileSize, function(size, unit)
{
return SCUtil.String.simpleFormat("{0} {1}", size.toFixed(2), unit);
});
},
/**
* Array에 요소포함여부 체크
* UT.hasInArray(["10", "50"], "10")
*
*/
hasInArray : function(array, item)
{
return (array && Polymer.$Array.find(array, function(_item) {
return _item == item;
}) != null);
},
/**
* 특정화면의 formula 실행
* UT.formula(this.domHost, "isEditable");
*/
formula : function(element, formulaName)
{
if (UT.isFormula(element, formulaName))
{
return element.formula(formulaName);
}
else
{
return false;
}
}
/**
* Formula 여부
*
* @method isFormula
* @param {object} element element
* @param {string} formulaName formula's name
* @return {boolean} true is formula
* @example
* someFunction: function() {
* var me = this;
* if (isFormula(me.domHost, "isEditable")) {
* if (me.domHost.formula("isEditable")) {
* do somthing...
* };
* }
* }
*/
isFormula: function(element, formulaName) {
return UT.isObject(element) && element._formulaReady && UT.isNotEmpty(element.formulas[formulaName]);
},
/**
* message dialog
*
* @method msgBox
* @param {string} title 제목
* @param {string} message 내용
* @param {number} width 넓이
* @param {number} height 높이
* @param {string} button Message dialog에 보여질 버튼명
* @param {function} callback callback function
* @param {Boolean} i18nDisabled 다국어 처리 비활성화 여부 (기본 false:활성화)
* @async
* @example
* UT.msgBox("Notice", "test message", 400, 300, "Yes,No", function(btn)
* {
* if (btn == "yes")
* {
* console.log(btn);
* }
* else
* {
* console.log(btn);
* }
* });
*/
msgBox : function(title, message, width, height, button, callback, i18nDisabled)
{
i18nDisabled = typeof i18nDisabled !== 'undefined' ? i18nDisabled : false;
var _messageBox = new SCMessageBox();
_messageBox.style.width = width + "px";
_messageBox.style.height = height + "px";
_messageBox.show({
title : I18N.translate(UT.nvl(title, "확인")),
message : message,
modal : true,
buttons : button,
handler : callback,
i18nDisabled : i18nDisabled
});
return _messageBox;
},
/**
* return Invalid Element
* @param module
* @param validation group name
* @returns object
* @example
* var _invalidObj = UT.getInvalidElement(me, "validGrpTWC01");
*/
getInvalidElement : function(module, validationGroup)
{
var validationGroup = module.querySelector("[validation-group='" + validationGroup + "']");
var invalids = validationGroup.querySelectorAll("[invalid]");
var el = invalids[0];
if (UT.isNotEmpty(el))
{
validationGroup.collapsed = false;
el.focus();
}
return {validationGroup:validationGroup, invalidElement:el};
},
/**
* iframe을 이용한 파일 다운로드
* UT.fileDownload("/downloadPrfiles.do", {enc_pr_no:data.enc_pr_no, enc_file_name:data.enc_file_name, enc_file_size:data.enc_file_size});
*
*/
fileDownload : function(url, param)
{
var iFrm = window.document.getElementById("fileDownlodFrm");
if (UT.isEmpty(iFrm))
{
iFrm = document.createElement("iframe");
iFrm.id = "fileDownlodFrm";
iFrm.style.display = "none";
document.body.appendChild(iFrm);
}
var form = document.createElement("form");
form.method = "POST";
form.action = url;
form.style.display = "none";
// CSRF
var csrfObj = this.csrf();
csrfObj._csrf = csrfObj.csrf;
var input = document.createElement("input");
input.type = "hidden";
input.id = csrfObj.csrfParameter;
input.name = csrfObj.csrfParameter;
input.value = csrfObj.csrf;
form.appendChild(input);
for(var key in param)
{
input = document.createElement("input");
input.type = "hidden";
input.id = key;
input.name = key;
input.value = param[key];
form.appendChild(input);
}
iFrm.contentWindow.document.body.appendChild(form);
form.submit();
iFrm.contentWindow.document.body.removeChild(form);
},
/**
* POST로 Submit
* UT.postSubmit("/approval.do", {app_id:"ABC", app_nm:"approval"});
*
*/
postSubmit : function(url, param, target, useIframe)
{
var target = target || "_self";
var useIframe = useIframe || false;
var documentBody = null;
if (useIframe)
{
var iFrm = window.document.getElementById("customIframe");
if (UT.isEmpty(iFrm))
{
iFrm = document.createElement("iframe");
iFrm.id = "customIframe";
iFrm.style.display = "none";
document.body.appendChild(iFrm);
}
documentBody = iFrm.contentWindow.document.body;
}
else
{
documentBody = document.body;
}
var form = document.createElement("form");
form.method = "POST";
form.action = url;
form.target = target;
form.style.display = "none";
// CSRF
var csrfObj = this.csrf();
csrfObj._csrf = csrfObj.csrf;
var input = document.createElement("input");
input.type = "hidden";
input.id = csrfObj.csrfParameter;
input.name = csrfObj.csrfParameter;
input.value = csrfObj.csrf;
form.appendChild(input);
for(var key in param)
{
input = document.createElement("input");
input.type = "hidden";
input.id = key;
input.name = key;
input.value = param[key];
form.appendChild(input);
}
iFrm.contentWindow.document.body.appendChild(form);
form.submit();
iFrm.contentWindow.document.body.removeChild(form);
},
validPrecision : function(num, precision, scale)
{
if (UT.isEmpty(num)) return true;
var _num = UT.nvl(num + "", "").replace(/,/, "");
var _intLen = precision - scale;
var _decLen = scale;
var _tempNum = _num.split(".");
return UT.nvl(_tempNum[0], "").length <= _intLen && UT.nvl(_tempNum[1], "").length <= _decLen;
},
/**
* 툴팁
* onmouseover="UT.toolTip(event, this.value)"
*
*/
toolTip : function(event, value)
{
if (UT.isNotEmpty(value))
{
var _elementRect = event.target.getBoundingClientRect();
//console.log(_elementRect);
//console.log(event);
var _div = document.createElement("div");
_div.style.backgroundColor = "#FFFFFF";
_div.style.border = "2px solid gray";
_div.style.borderRadius = "6px";
_div.style.padding = "5px";
_div.style.visibility = "visible";
_div.style.position = "absolute";
_div.style.left = (event.clientX + 10) + "px";
_div.style.top = (_elementRect.top - 40) + "px";
_div.style.zIndex = "999";
var _text = document.createTextNode(value);
_div.appendChild(_text);
document.body.appendChild(_div);
event.target.addEventListener("mouseout", function(event)
{
event.target.removeEventListener(event.type, arguments.callee);
document.body.removeChild(_div);
});
}
}
/**
* 메뉴생성 with 파라메터
*
* @method createWindow
* @param {string} menuId 메뉴아이디
* @param {object} param 파라메터
* @example
* someFunction: function() {
* var me = this;
* }
*/
createWindowByParam: function(menuId, param, callback, regeneration)
{
var regeneration = UT.isBoolean(regeneration) ? regeneration : true;
var windowIndex = SCMdiManager.mdi.$.mdiContent.createdWindows.indexOf(menuId);
var moduleWindow = null;
if (windowIndex > -1 && regeneration)
{
SCMdiManager.removeWindow(menuId);
}
var menuInfo = SCMdiManager.mdi.$.mdiTopMenu.getMenuNode(menuId);
if (UT.isEmpty(menuInfo))
{
// 권한없는 메뉴는 사용할 수 없습니다.
UT.alert("STD.MDI1011");
return;
}
var _paramArray = [];
for (var key in param)
{
if (param.hasOwnProperty(key))
{
_paramArray.push(key + "=" + param[key]);
}
}
var menuUrl = menuInfo.menu_url + (_paramArray.length > 0 ? "?" + _paramArray.join("&") : "");
var moduleWindow = SCMdiManager.createWindow(menuId, menuInfo.menu_nm, menuUrl, {callback: callback});
return moduleWindow;
},