123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- XFormsFile.prototype = new XFormsGroup;
- function XFormsFile (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, strBind, strClass, bDisabled, strId, strItemMargin, nNavindex,
- strOverflow, bPopup, strRef, strScroll, strShowEffect, bShowList, strStyle, strTag, strVisibility, strUserDefineAttrib)
- {
- if (!strId)
- {
- return;
- }
- XFormsGroup.call(this, strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strClass, bDisabled, strId, nNavindex, strOverflow, bPopup, strRef, strScroll, strShowEffect, strStyle, strTag, strVisibility, strUserDefineAttrib);
- this.m_nAttachHeight;
- this.m_nAttachWidth;
- /**
- * Attribute
- */
- this.attribute["text"] = strText;
- this.attribute["itemmargin"] = strItemMargin;
- this.attribute["showlist"] = String(bShowList);
-
- /**
- * Property
- */
- };
- XFormsFile.prototype.init = function ()
- {
- XFormsGroup.prototype.init.call(this);
-
- var xnFrame = document.getElementById("HE___TF_UploadFrame");
- if (xnFrame)
- {
- if (xnFrame.attachEvent)
- {
- xnFrame.attachEvent("onload", XFormsFile.uploadTempComplete);
- }
- else
- {
- xnFrame.addEventListener("load", XFormsFile.uploadTempComplete, false);
- }
- }
-
- var objAttach = new XFormsButton(this.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".attach", -1, "", "", -1, false, "", "xforms:button", "visible");
- objAttach.init();
- this.m_nAttachHeight = objAttach.m_heControl.offsetHeight;
- this.m_nAttachWidth = objAttach.m_heControl.offsetWidth;
- objAttach.m_heControl.style.marginTop = "-"+(this.m_nAttachHeight/2)+"px";
- if (this.attribute["showlist"] == "false")
- objAttach.m_heControl.style.marginLeft = "-"+(this.m_nAttachWidth/2)+"px";
- if (objAttach.m_heControl.style.borderStyle || objAttach.m_heControl.style.backgroundColor || objAttach.m_heControl.style.backgroundImage)
- {
- var xnVitualButton = document.getElementById("HE_"+this.id+".virtual");
- xnVitualButton.style.borderStyle = "none";
- }
-
- var nItemMargin = parseInt(this.attribute["itemmargin"].replace("px","").replace("%",""));
-
- if (this.attribute["showlist"] == "true")
- {
- var xnFileList = document.createElement("div");
- xnFileList.id = "HE_"+this.id+".list";
- xnFileList.style.position = "absolute";
- xnFileList.style.border = "1px solid #000000";
- xnFileList.style.backgroundColor = "#FFFFFF";
- xnFileList.style.left = nItemMargin+"px";
- xnFileList.style.top = nItemMargin+"px";
- xnFileList.style.wordWrap = "break-word";
- xnFileList.style.overflowX = "hidden";
- xnFileList.style.overflowY = "auto";
- this.m_heControl.appendChild(xnFileList);
- this.resizeList();
- var objList = new XFormsGroup(this.id, "", "", "", "", "", "", false, this.id+".list", -1, "scroll", false, "", "auto", "blend 300", "", "xforms:group", "visible");
- objList.init();
- }
-
- this.createRealButton();
- };
- XFormsFile.prototype.applyDefaultStyle = function ()
- {
- XFormsGroup.prototype.applyDefaultStyle.call(this);
-
- if (!this.attribute["border-style"])
- {
- this.m_heControl.style.borderStyle = "solid";
- }
- };
- XFormsFile.prototype.createRealButton = function ()
- {
- var xnFileButtonReal = document.createElement("input");
- xnFileButtonReal.id = "HE_"+this.id+".button";
- xnFileButtonReal.name = "HE_"+this.id+".button";
- xnFileButtonReal.type = "file";
- xnFileButtonReal.onchange = function ()
- {
- var objParent = document.controls.item(this.id.substring(3, this.id.lastIndexOf(".")));
- document.getElementById("HE___TF_UploadForm").appendChild(this);
- document.getElementById("HE___TF_UploadForm").submit();
- this.parentNode.removeChild(this);
- objParent.createRealButton();
- };
- xnFileButtonReal.style.position = "absolute";
- document.getElementById("HE_"+this.id).appendChild(xnFileButtonReal);
-
- this.resizeRealButton ();
- };
- XFormsFile.prototype.setAttachedFile = function (strFileName, strTempName)
- {
- if (this.attribute["ref"] != "")
- {
- var strInstance = model.getValue(this.attribute["ref"]);
- if (strInstance != "") strInstance += "?";
- strInstance += strFileName;
- strInstance += "|";
- strInstance += strTempName;
- model.setValue(this.attribute["ref"], strInstance);
- this.refresh();
- }
- };
- XFormsFile.prototype.resizeRealButton = function ()
- {
- var xnFileButtonReal = document.getElementById("HE_"+this.id+".button");
- var heAttach = document.getElementById("HE_"+this.id+".attach");
-
- xnFileButtonReal.style.filter = "alpha(opacity=0)";
- xnFileButtonReal.style.opacity = 0;
- xnFileButtonReal.style.height = this.m_nAttachHeight + "px";
- xnFileButtonReal.style.top = heAttach.style.top;
- xnFileButtonReal.style.right = heAttach.style.right;
- xnFileButtonReal.style.width = heAttach.style.width;
- xnFileButtonReal.style.marginTop = heAttach.style.marginTop;
- };
-
- XFormsFile.prototype.resizeList = function ()
- {
- var xnFileList = document.getElementById("HE_"+this.id+".list");
- var nCurrentWidth = this.m_heControl.clientWidth;
- var nCurrentHeight = this.m_heControl.clientHeight;
-
- var nItemMargin = parseInt(this.attribute["itemmargin"].replace("px","").replace("%",""));
-
- xnFileList.style.width = (nCurrentWidth-(nItemMargin*3)-this.m_nAttachWidth)+"px";
- xnFileList.style.height = (nCurrentHeight-(nItemMargin*2))+"px";
-
- };
- XFormsFile.prototype.refresh = function ()
- {
-
- };
- XFormsFile.prototype.refresh = function ()
- {
- if (this.attribute["showlist"] == "true")
- {
- var objList = document.controls.item(this.id+".list");
- var clListChildren = objList.children;
- var nListChildrenCount = clListChildren.length;
-
- for (var i = 0; i < nListChildrenCount; i++)
- {
- var objChild = clListChildren.item(0);
- objList.removeChild(objChild.id);
- }
-
- var strAttachedFile = model.getValue(this.attribute["ref"]);
- if (strAttachedFile != "")
- {
- var arAttachedFile = strAttachedFile.split("?");
-
- for (var i = 0; i < arAttachedFile.length; i++)
- {
- var arFileName = arAttachedFile[i].split("|");
- var strFileName = arFileName[0];
-
- var xnListItem = document.createElement("span");
- xnListItem.id = "HE_"+this.id+".item"+i;
- xnListItem.innerHTML = i == 0 ? "<span id=\"HE_"+this.id+".item"+i+"_TEXT\">"+strFileName+" </span>" :"<span id=\"HE_"+this.id+".item"+i+"_TEXT\"> "+ strFileName+" </span>";
- xnListItem.style.cursor = "default";
- objList.m_heControl.appendChild(xnListItem);
- var objListItem = new XFormsCaption(objList.id, "", "", "", strFileName, "", false, "", "", false, false, "", this.id+".item"+i, -1, "", "", 0, "", "xforms:caption", "visible");
- objListItem.init();
-
- var xnListItemDetach = document.createElement("button");
- xnListItemDetach.id = "HE_"+this.id+".detach"+i;
- xnListItemDetach.style.width = "12px";
- xnListItemDetach.style.height = "12px";
- xnListItemDetach.style.backgroundColor = "transparent";
- xnListItemDetach.style.backgroundImage = "url(" + __getAppName() + "/kr/comsquare/image/file/detach.gif)";
- xnListItemDetach.style.backgroundRepeat = "no-repeat";
- xnListItemDetach.style.borderStyle = "none";
- xnListItemDetach.style.verticalAlign = "middle";
- xnListItemDetach.onclick = function ()
- {
- var nIndex = parseInt(this.id.substring(this.id.lastIndexOf(".")+7, this.id.length));
- var strObjId = this.id.substring(3, this.id.lastIndexOf("."));
- document.controls.item(strObjId).detachFile(nIndex);
- };
- objList.m_heControl.appendChild(xnListItemDetach);
-
- var objListItemDetach = new XFormsButton(objList.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".detach"+i, -1, "", "", -1, false, "", "xforms:button", "visible");
- objListItemDetach.init();
- }
- }
- }
- };
- XFormsFile.prototype.detachFile = function (nIndex)
- {
- var strInstance = model.getValue(this.attribute["ref"]);
- var arInstance = strInstance.split("?");
- strInstance = "";
-
- for (var i = 0; i < arInstance.length; i++)
- {
- if (nIndex == i) continue;
-
- if (strInstance != "")
- {
- strInstance += "?";
- }
- strInstance += arInstance[i];
- }
- model.setValue(this.attribute["ref"], strInstance);
- this.refresh();
- this.dispatch("onfiledeselected");
-
- };
-
- XFormsFile.prototype.getBindingType = function ()
- {
- return BT_SINGLE;
- };
- XFormsFile.uploadTempComplete = function ()
- {
- var xnFrameDoc = document.getElementById("HE___TF_UploadFrame").contentWindow.document;
- var strReturnXML;
- 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"))
- {
- var xnTagName = xnReturn.selectSingleNode("/root/tagName");
- var xnFileName = xnReturn.selectSingleNode("/root/fileName");
- var xnTempName = xnReturn.selectSingleNode("/root/tempName");
- var xnFilePath = xnReturn.selectSingleNode("/root/filePath");
- var strTagName = XmlLib.getTextValue(xnTagName);
- var strFileName = XmlLib.getTextValue(xnFileName);
- var strTempName = XmlLib.getTextValue(xnTempName).replaceAll(XmlLib.getTextValue(xnFilePath), "");
-
- var objFile = document.controls.item(strTagName.substring(3,strTagName.lastIndexOf(".")));
- objFile.setAttachedFile(strFileName, strTempName);
- }
- objFile.dispatch("onfileselected");
- }
- };
|