123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- XFormsButton.prototype = new XFormsCaption;
- function XFormsButton (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoresize, strBind, strClass, bDisabled,
- bEllipsis, strFormat, strGroup, strGroupalign, strId, nNavindex, strRef, strRoundmode, nRoundposition, bSelected, strStyle, strTag, strVisibility, strUserDefineAttrib)
- {
- if (!strId)
- {
- return;
- }
-
- XFormsCaption.call(this, strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoresize, strBind, strClass, bDisabled,
- bEllipsis, strFormat, strId, nNavindex, strRef, strRoundmode, nRoundposition, strStyle, strTag, strVisibility, strUserDefineAttrib);
-
- /**
- * Attribute
- */
- this.attribute["group"] = strGroup;
- this.attribute["groupalign"] = strGroupalign;
- this.attribute["selected"] = String(bSelected);
-
- /**
- * Property
- */
- this.selected = bSelected;
- this.m_heControl = document.getElementById("HE_" + this.id);
-
- this.m_strTargetGrid = "";
- this.m_heLodExcelForm = null;
- };
- /**
- * 인스턴스 데이터를 실제 컨트롤에 반영
- * @return
- */
- XFormsButton.prototype.refresh = function ()
- {
- XFormsBindableControl.prototype.refresh.call(this);
- with(this)
- {
- if (null != m_heControl)
- {
- var strRef = attribute["ref"];
- var strValue = (null != strRef && "" != strRef) ? model.getValue(strRef) : getAttribute("text");
- if (null != m_heControlText)
- {
- m_heControlText.innerHTML = strValue.newlineCharConvert();
- }
- }
- }
- };
- XFormsButton.prototype.getBindingType = function ()
- {
- return BT_SINGLE;
- };
- XFormsButton.prototype.init = function ()
- {
- XFormsCaption.prototype.init.call(this);
- if (null != this.m_heControlText)
- {
- var strText = this.getAttribute("text");
- this.m_heControlText.innerHTML = strText.newlineCharConvert();
- }
- if ("xforms:inputbutton" == this.attribute["tag"])
- {
- if (null != this.parent)
- {
- var nControlLeft = Number(this.parent.attribute["left"].split("px")[0]);
- var nControlWidth = this.parent.m_heControl.clientWidth;
- var nControlTargetWidth = 16 > this.m_heControl.clientWidth ? 16 : this.m_heControl.clientWidth;
- this.m_heControl.style.left = (nControlLeft + nControlWidth - nControlTargetWidth) + "px";
- this.m_heControl.style.height = this.parent.m_heControl.clientHeight + "px";
- }
- }
- this.m_strTargetGrid = this.getAttribute("loadexcelgrid");
- if (null != this.m_strTargetGrid && "" != this.m_strTargetGrid)
- {
- this.createExcelButton();
- }
- };
- XFormsButton.prototype.createExcelButton = function ()
- {
- if (null == this.m_heLodExcelForm)
- {
- if (is_ie6 || is_ie7 || is_ie8)
- {
- this.m_heLodExcelForm = document.createElement("<form encType='multipart/form-data'>");
- }
- else
- {
- this.m_heLodExcelForm = document.createElement("form");
- this.m_heLodExcelForm.setAttribute("enctype","multipart/form-data");
- }
- this.m_heLodExcelForm.action = __getAppName () + "/LoadExcel.tfs";
- this.m_heLodExcelForm.method = "post";
- this.m_heLodExcelForm.target = "HE___TF_LoadExcel";
- this.m_heLodExcelForm.style.filter = "alpha(opacity=0)";
- this.m_heLodExcelForm.style.opacity = 0;
- this.m_heLodExcelForm.style.position = "absolute";
- this.m_heLodExcelForm.style.top = this.getAttribute("top");
- this.m_heLodExcelForm.style.left = this.getAttribute("left");
- this.m_heLodExcelForm.style.width = this.getAttribute("width");
- this.m_heLodExcelForm.style.height = this.getAttribute("height");
-
- if (is_ie6 || is_ie7)
- {
- var strTag = "<input type='hidden' name='nodeset'/>";
- strTag += "<input type='file' name='excel' onchange='"+this.id+".loadExcelGrid();' style='top:0px;left:0px;width:100%;height:100%;cursor:hand;' />";
- this.m_heLodExcelForm.innerHTML = strTag;
- }
- else
- {
- var heGridStatus = document.createElement("input");
- heGridStatus.type = "hidden";
- heGridStatus.name = "nodeset";
-
- var heExcelFile = document.createElement("input");
- heExcelFile.type = "file";
- heExcelFile.name = "excel";
- heExcelFile.style.top = "0px";
- heExcelFile.style.left = "0px";
- heExcelFile.style.width = "100%";
- heExcelFile.style.height = "100%";
- heExcelFile.style.cursor = "hand";
- heExcelFile.setAttribute("onchange",this.id + ".loadExcelGrid();");
-
- this.m_heLodExcelForm.appendChild(heGridStatus);
- this.m_heLodExcelForm.appendChild(heExcelFile);
- }
- if (null != this.parent.m_heControl)
- {
- this.parent.m_heControl.appendChild(this.m_heLodExcelForm);
- }
- }
- };
- XFormsButton.prototype.loadExcelGrid = function ()
- {
- var strFileType = this.m_heLodExcelForm.lastChild.value;
- strFileType = strFileType.substring(strFileType.lastIndexOf(".") + 1, strFileType.length);
- if ("xlsx" != strFileType && "xls" != strFileType)
- {
- if (null != window.console)
- {
- console.log("올바른 Excel File 형식이 아닙니다.");
- }
- return;
- }
- var objTargetGrid = document.allElement.item(this.m_strTargetGrid);
- if (null != objTargetGrid)
- {
- var strNodeSet = objTargetGrid.nodeset + "@";
- var bFirst = true;
- for (var i=0; i<objTargetGrid.m_arColumn.length; i++)
- {
- var strRef = objTargetGrid.m_arColumn[i].getAttribute("ref");
- if ("" != strRef.trim())
- {
- if (bFirst)
- {
- strNodeSet += strRef;
- bFirst = false;
- }
- else
- {
- strNodeSet += "," + strRef;
- }
- }
- }
- this.m_heLodExcelForm.firstChild.value = encodeURI(strNodeSet + "@" + strFileType);
- }
- else
- {
- if (null != window.console)
- {
- console.log("Load Excel을 적용할 Target Grid가 존재하지 않습니다.");
- }
- return;
- }
- LOAD_EXCEL_GRID = this.m_strTargetGrid;
- LOAD_EXCEL_BUTTON = this;
- var xnFrame = document.getElementById("HE___TF_LoadExcel");
- if (xnFrame)
- {
- xnFrame.setAttribute("targetGrid", this.m_strTargetGrid);
- if (xnFrame.attachEvent)
- {
- xnFrame.attachEvent("onload", XFormsButton.uploadComplete);
- }
- else
- {
- xnFrame.addEventListener("load", XFormsButton.uploadComplete, false);
- }
- }
- this.m_heLodExcelForm.submit();
- this.m_heLodExcelForm.reset();
- };
- XFormsButton.prototype.isCSSValid = function (strKey)
- {
- var bValid = XFormsCaption.prototype.isCSSValid.call(this);
- if ("background-image" == strKey && !bValid)
- {
- if ("xforms:inputbutton" == this.getTag())
- {
- if ("url("+__getAppName()+"/kr/comsquare/image/input/button.png)" == HtmlLib.getStyle(this.m_heControl, strKey))
- {
- return true;
- }
- }
- else if ("xforms:combobutton" == this.getTag())
- {
- if ("url("+__getAppName()+"/kr/comsquare/image/combo/combo.gif)" == HtmlLib.getStyle(this.m_heControl, strKey))
- {
- return true;
- }
- }
- }
- return bValid;
- };
- XFormsButton.prototype.applyDefaultStyle = function ()
- {
- XFormsCaption.prototype.applyDefaultStyle.call(this);
-
- // 컨트롤 생성당시에 입력된 스타일이 있는지 판단해 원래 스타일로 되돌려준다.
- // if (!this.attribute["background-repeat"])
- // {
- // this.m_heControl.style.backgroundRepeat = "";
- // }
- //
- // // background-color의 존재 여부
- // if (!this.attribute["background-color"])
- // {
- // this.m_heControl.style.backgroundColor = "";
- // }
-
- // 기존 border-style이 없을경우에 border를 지운다.
- if (this.attribute["border-style"])
- {
- if (!this.attribute["border-width"])
- {
- this.m_heControl.style.borderWidth = "1px";
- }
- }
- else
- {
- this.m_heControl.style.borderWidth = "";
- }
- if (null == this.attribute["cursor"])
- {
- this.m_heControl.style.cursor = "hand";
- }
- // 버튼 내용이 흘러 내리는 것을 없애기 위해 "overflow:hidden"을 준다
- this.m_heControl.style.overflow = "hidden";
- };
- XFormsButton.prototype.setAttribute = function (strAttribute, strValue)
- {
- XFormsCaption.prototype.setAttribute.call(this, strAttribute, strValue);
- switch (strAttribute)
- {
- case "text":
- {
- this.attribute["text"] = strValue;
- this.refresh();
- break;
- }
- case "group" :
- {
- this.attribute["group"] = strValue;
- break;
- }
- case "groupalign" :
- {
- this.attribute["groupalign"] = strValue;
- break;
- }
- case "selected" :
- {
- this.attribute["selected"] = strValue;
- break;
- }
- }
- };
- XFormsButton.prototype.onClick = function (event)
- {
- XFormsCaption.prototype.onClick.call(this, event);
-
- if (event.target == this.getId())
- {
- var strGroup = this.getAttribute("group");
- if (!strGroup.isEmpty() && !this.getState(FCS_SELECT))
- {
- this.setState(FCS_SELECT, true, event);
- }
-
- this.dispatch("DOMActivate");
- this.dispatch("xforms-activate");
- }
- };
- XFormsButton.prototype.onKeyPress = function (event)
- {
- XFormsCaption.prototype.onKeyPress.call(this, event);
-
- if (event.target == this.getId() &&
- (TFEvent.ENTER == event.keyCode || TFEvent.SPACE == event.keyCode))
- {
- var strGroup = this.getAttribute("group");
- if (!strGroup.isEmpty() && !this.getState(FCS_SELECT))
- {
- this.setState(FCS_SELECT, true, event);
- }
-
- this.dispatch("DOMActivate");
- this.dispatch("xforms-activate");
- }
- };
- XFormsButton.prototype.onafterloadexcel = function ()
- {
- };
- XFormsButton.create = function (strParentId, clAttribute, strStyle)
- {
- // 메인노드 생성
- var xnButton = XFormsButton.createMainNode(clAttribute);
- var xnParent = document.getElementById("HE_"+strParentId);
- xnParent.appendChild(xnButton);
- // 하위노드 생성
- xnButton = XFormsButton.createSubNodes(xnButton, clAttribute);
- // object 생성
- return XFormsButton.createObject(strParentId, xnButton, clAttribute, strStyle);
- };
- XFormsButton.createMainNode = function (clAttribute)
- {
- var xnButton = document.createElement("button");
- xnButton = XFormsButton.createAttribute(xnButton, clAttribute);
- return xnButton;
- };
- XFormsButton.createSubNodes = function (xnButton, clAttribute)
- {
- var xnButtonText = document.createElement("span");
- if (xnButton.getAttribute("text"))
- {
- xnButton.innerHTML = xnButton.getAttribute("text").newlineCharConvert();
- }
- xnButton.appendChild(xnButtonText);
-
- return xnButton;
- };
- XFormsButton.createObject = function (strParentId, xnButton, clAttribute, strStyle)
- {
- var strAlert = "";
- var strHelp = "";
- var strHint = "";
- var strText = "";
- var strAccesskey = "";
- var strClass = "";
- var bDisabled = false;
- var bEllipsis = false;
- var strGroup = "";
- var strGroupAlign = "";
- var strId = "";
- var nNavindex = 9007199254740992;
- var strRef = "";
- var bSelected = false;
- var strVisibility = "visible";
- var strUserDefineAttrib = "";
-
- for (var i=0; i<clAttribute.count(); i++)
- {
- var strAttributeName = clAttribute.keys()[i];
- switch (strAttributeName)
- {
- case "alert" :
- {
- strAlert = clAttribute.item(strAttributeName);
- break;
- }
- case "help" :
- {
- strHelp = clAttribute.item(strAttributeName);
- break;
- }
- case "hint" :
- {
- strHint = clAttribute.item(strAttributeName);
- break;
- }
- case "text" :
- {
- strText = clAttribute.item(strAttributeName);
- break;
- }
- case "accesskey" :
- {
- strAccesskey = clAttribute.item(strAttributeName);
- break;
- }
- case "class" :
- {
- strClass = clAttribute.item(strAttributeName);
- break;
- }
- case "disabled" :
- {
- if ("true" == clAttribute.item(strAttributeName))
- {
- bDisabled = true;
- }
- break;
- }
- case "ellipsis" :
- {
- if ("true" == clAttribute.item(strAttributeName))
- {
- bEllipsis = true;
- }
- break;
- }
- case "group" :
- {
- strGroup = clAttribute.item(strAttributeName);
- break;
- }
- case "groupalign" :
- {
- strGroupAlign = clAttribute.item(strAttributeName);
- break;
- }
- case "id" :
- {
- strId = clAttribute.item(strAttributeName);
- break;
- }
- case "navindex" :
- {
- nNavindex = parseInt(clAttribute.item(strAttributeName));
- break;
- }
- case "selected" :
- {
- if ("true" == clAttribute.item(strAttributeName))
- {
- bSelected = true;
- }
- break;
- }
- case "visibility" :
- {
- strVisibility = clAttribute.item(strAttributeName);
- break;
- }
-
- default :
- {
- if (!STYLE_LIST[strAttributeName])
- {
- strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
- }
- break;
- }
- }
- }
- var objButton = new XFormsButton (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, false, "", strClass, bDisabled, bEllipsis, "", strGroup, strGroupAlign, strId, nNavindex, strRef, "", -1, bSelected, strStyle, "xforms:button", strVisibility, strUserDefineAttrib);
- return objButton;
- };
- XFormsButton.createAttribute = function (xnHtmlNode, clAttribute)
- {
- xnHtmlNode = XFormsCaption.createAttribute(xnHtmlNode, clAttribute);
- return xnHtmlNode;
- };
- XFormsButton.uploadComplete = function ()
- {
- // var xnFrameDoc = document.getElementById("HE___TF_LoadExcel").contentWindow.document;
- var strReturnXML = document.getElementById("HE___TF_LoadExcel").contentWindow.strLoadXml;
- // if (is_ie)
- // {
- // if (xnFrameDoc.XMLDocument)
- // {
- // strReturnXML = xnFrameDoc.XMLDocument.xml;
- // }
- // else
- // {
- // var serializer = new XMLSerializer();
- // strReturnXML = serializer.serializeToString(xnFrameDoc);
- // }
- // }
- // else
- // {
- // var serializer = new XMLSerializer();
- // strReturnXML = serializer.serializeToString(xnFrameDoc);
- // }
-
- if (strReturnXML)
- {
- var xnReturn = XmlLib.loadXMLFromString(strReturnXML);
- if (!xnReturn.selectSingleNode("/root/TF_EXCEL_ERR"))
- {
- var strExportFalseRows = LOAD_EXCEL_BUTTON.getAttribute("exportfalserows");
- var nExportFalseRows = strExportFalseRows.isEmpty() ? 0 : parseInt(strExportFalseRows);
- var objTargetGrid = document.allElement.item(LOAD_EXCEL_GRID);
- var strTargetNode = objTargetGrid.nodeset.substring(0, objTargetGrid.nodeset.lastIndexOf("/"));
- var strParentTargetNode = objTargetGrid.nodeset;
- if (null != objTargetGrid)
- {
- if (null != model)
- {
- var xnInstanceDoc = model.getInstanceDocument();
- if (null != xnInstanceDoc)
- {
- var xnNewRoot = XmlLib.getRootElementNode(xnReturn);
- var xnParentGridNode = xnInstanceDoc.selectSingleNode(strTargetNode);
- var xlGridItem = XmlLib.selectNodes(xnInstanceDoc, strParentTargetNode);
- var nXlGridItemLen = xlGridItem.length;
- for (var i=0; i<nXlGridItemLen; i++)
- {
- xnParentGridNode.removeChild(xlGridItem.item(i));
- }
- var xnNewGridNode = xnNewRoot.selectSingleNode(strTargetNode);
- var xnNewGridNodeChild= xnNewGridNode.childNodes.item(nExportFalseRows);
- while(xnNewGridNodeChild)
- {
- xnParentGridNode.appendChild(xnNewGridNodeChild.cloneNode(true));
- xnNewGridNodeChild = xnNewGridNodeChild.nextSibling;
- }
-
- }
- }
- objTargetGrid.refresh();
- LOAD_EXCEL_BUTTON.dispatch("onafterloadexcel");
- }
- }
- else
- {
- if(window.console)
- {
- console.log("loadExcel 오류 : 잘못된 타입의 Excel 파일 입니다.");
- }
- }
- }
- };
|