XFormsFile.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. XFormsFile.prototype = new XFormsGroup;
  2. function XFormsFile (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, strBind, strClass, bDisabled, strId, strItemMargin, nNavindex,
  3. strOverflow, bPopup, strRef, strScroll, strShowEffect, bShowList, strStyle, strTag, strVisibility, strUserDefineAttrib)
  4. {
  5. if (!strId)
  6. {
  7. return;
  8. }
  9. XFormsGroup.call(this, strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strClass, bDisabled, strId, nNavindex, strOverflow, bPopup, strRef, strScroll, strShowEffect, strStyle, strTag, strVisibility, strUserDefineAttrib);
  10. this.m_nAttachHeight;
  11. this.m_nAttachWidth;
  12. /**
  13. * Attribute
  14. */
  15. this.attribute["text"] = strText;
  16. this.attribute["itemmargin"] = strItemMargin;
  17. this.attribute["showlist"] = String(bShowList);
  18. /**
  19. * Property
  20. */
  21. };
  22. XFormsFile.prototype.init = function ()
  23. {
  24. XFormsGroup.prototype.init.call(this);
  25. var xnFrame = document.getElementById("HE___TF_UploadFrame");
  26. if (xnFrame)
  27. {
  28. if (xnFrame.attachEvent)
  29. {
  30. xnFrame.attachEvent("onload", XFormsFile.uploadTempComplete);
  31. }
  32. else
  33. {
  34. xnFrame.addEventListener("load", XFormsFile.uploadTempComplete, false);
  35. }
  36. }
  37. var objAttach = new XFormsButton(this.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".attach", -1, "", "", -1, false, "", "xforms:button", "visible");
  38. objAttach.init();
  39. this.m_nAttachHeight = objAttach.m_heControl.offsetHeight;
  40. this.m_nAttachWidth = objAttach.m_heControl.offsetWidth;
  41. objAttach.m_heControl.style.marginTop = "-"+(this.m_nAttachHeight/2)+"px";
  42. if (this.attribute["showlist"] == "false")
  43. objAttach.m_heControl.style.marginLeft = "-"+(this.m_nAttachWidth/2)+"px";
  44. if (objAttach.m_heControl.style.borderStyle || objAttach.m_heControl.style.backgroundColor || objAttach.m_heControl.style.backgroundImage)
  45. {
  46. var xnVitualButton = document.getElementById("HE_"+this.id+".virtual");
  47. xnVitualButton.style.borderStyle = "none";
  48. }
  49. var nItemMargin = parseInt(this.attribute["itemmargin"].replace("px","").replace("%",""));
  50. if (this.attribute["showlist"] == "true")
  51. {
  52. var xnFileList = document.createElement("div");
  53. xnFileList.id = "HE_"+this.id+".list";
  54. xnFileList.style.position = "absolute";
  55. xnFileList.style.border = "1px solid #000000";
  56. xnFileList.style.backgroundColor = "#FFFFFF";
  57. xnFileList.style.left = nItemMargin+"px";
  58. xnFileList.style.top = nItemMargin+"px";
  59. xnFileList.style.wordWrap = "break-word";
  60. xnFileList.style.overflowX = "hidden";
  61. xnFileList.style.overflowY = "auto";
  62. this.m_heControl.appendChild(xnFileList);
  63. this.resizeList();
  64. var objList = new XFormsGroup(this.id, "", "", "", "", "", "", false, this.id+".list", -1, "scroll", false, "", "auto", "blend 300", "", "xforms:group", "visible");
  65. objList.init();
  66. }
  67. this.createRealButton();
  68. };
  69. XFormsFile.prototype.applyDefaultStyle = function ()
  70. {
  71. XFormsGroup.prototype.applyDefaultStyle.call(this);
  72. if (!this.attribute["border-style"])
  73. {
  74. this.m_heControl.style.borderStyle = "solid";
  75. }
  76. };
  77. XFormsFile.prototype.createRealButton = function ()
  78. {
  79. var xnFileButtonReal = document.createElement("input");
  80. xnFileButtonReal.id = "HE_"+this.id+".button";
  81. xnFileButtonReal.name = "HE_"+this.id+".button";
  82. xnFileButtonReal.type = "file";
  83. xnFileButtonReal.onchange = function ()
  84. {
  85. var objParent = document.controls.item(this.id.substring(3, this.id.lastIndexOf(".")));
  86. document.getElementById("HE___TF_UploadForm").appendChild(this);
  87. document.getElementById("HE___TF_UploadForm").submit();
  88. this.parentNode.removeChild(this);
  89. objParent.createRealButton();
  90. };
  91. xnFileButtonReal.style.position = "absolute";
  92. document.getElementById("HE_"+this.id).appendChild(xnFileButtonReal);
  93. this.resizeRealButton ();
  94. };
  95. XFormsFile.prototype.setAttachedFile = function (strFileName, strTempName)
  96. {
  97. if (this.attribute["ref"] != "")
  98. {
  99. var strInstance = model.getValue(this.attribute["ref"]);
  100. if (strInstance != "") strInstance += "?";
  101. strInstance += strFileName;
  102. strInstance += "|";
  103. strInstance += strTempName;
  104. model.setValue(this.attribute["ref"], strInstance);
  105. this.refresh();
  106. }
  107. };
  108. XFormsFile.prototype.resizeRealButton = function ()
  109. {
  110. var xnFileButtonReal = document.getElementById("HE_"+this.id+".button");
  111. var heAttach = document.getElementById("HE_"+this.id+".attach");
  112. xnFileButtonReal.style.filter = "alpha(opacity=0)";
  113. xnFileButtonReal.style.opacity = 0;
  114. xnFileButtonReal.style.height = this.m_nAttachHeight + "px";
  115. xnFileButtonReal.style.top = heAttach.style.top;
  116. xnFileButtonReal.style.right = heAttach.style.right;
  117. xnFileButtonReal.style.width = heAttach.style.width;
  118. xnFileButtonReal.style.marginTop = heAttach.style.marginTop;
  119. };
  120. XFormsFile.prototype.resizeList = function ()
  121. {
  122. var xnFileList = document.getElementById("HE_"+this.id+".list");
  123. var nCurrentWidth = this.m_heControl.clientWidth;
  124. var nCurrentHeight = this.m_heControl.clientHeight;
  125. var nItemMargin = parseInt(this.attribute["itemmargin"].replace("px","").replace("%",""));
  126. xnFileList.style.width = (nCurrentWidth-(nItemMargin*3)-this.m_nAttachWidth)+"px";
  127. xnFileList.style.height = (nCurrentHeight-(nItemMargin*2))+"px";
  128. };
  129. XFormsFile.prototype.refresh = function ()
  130. {
  131. };
  132. XFormsFile.prototype.refresh = function ()
  133. {
  134. if (this.attribute["showlist"] == "true")
  135. {
  136. var objList = document.controls.item(this.id+".list");
  137. var clListChildren = objList.children;
  138. var nListChildrenCount = clListChildren.length;
  139. for (var i = 0; i < nListChildrenCount; i++)
  140. {
  141. var objChild = clListChildren.item(0);
  142. objList.removeChild(objChild.id);
  143. }
  144. var strAttachedFile = model.getValue(this.attribute["ref"]);
  145. if (strAttachedFile != "")
  146. {
  147. var arAttachedFile = strAttachedFile.split("?");
  148. for (var i = 0; i < arAttachedFile.length; i++)
  149. {
  150. var arFileName = arAttachedFile[i].split("|");
  151. var strFileName = arFileName[0];
  152. var xnListItem = document.createElement("span");
  153. xnListItem.id = "HE_"+this.id+".item"+i;
  154. xnListItem.innerHTML = i == 0 ? "<span id=\"HE_"+this.id+".item"+i+"_TEXT\">"+strFileName+"&nbsp;</span>" :"<span id=\"HE_"+this.id+".item"+i+"_TEXT\">&nbsp;&nbsp;"+ strFileName+"&nbsp;</span>";
  155. xnListItem.style.cursor = "default";
  156. objList.m_heControl.appendChild(xnListItem);
  157. var objListItem = new XFormsCaption(objList.id, "", "", "", strFileName, "", false, "", "", false, false, "", this.id+".item"+i, -1, "", "", 0, "", "xforms:caption", "visible");
  158. objListItem.init();
  159. var xnListItemDetach = document.createElement("button");
  160. xnListItemDetach.id = "HE_"+this.id+".detach"+i;
  161. xnListItemDetach.style.width = "12px";
  162. xnListItemDetach.style.height = "12px";
  163. xnListItemDetach.style.backgroundColor = "transparent";
  164. xnListItemDetach.style.backgroundImage = "url(" + __getAppName() + "/kr/comsquare/image/file/detach.gif)";
  165. xnListItemDetach.style.backgroundRepeat = "no-repeat";
  166. xnListItemDetach.style.borderStyle = "none";
  167. xnListItemDetach.style.verticalAlign = "middle";
  168. xnListItemDetach.onclick = function ()
  169. {
  170. var nIndex = parseInt(this.id.substring(this.id.lastIndexOf(".")+7, this.id.length));
  171. var strObjId = this.id.substring(3, this.id.lastIndexOf("."));
  172. document.controls.item(strObjId).detachFile(nIndex);
  173. };
  174. objList.m_heControl.appendChild(xnListItemDetach);
  175. var objListItemDetach = new XFormsButton(objList.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".detach"+i, -1, "", "", -1, false, "", "xforms:button", "visible");
  176. objListItemDetach.init();
  177. }
  178. }
  179. }
  180. };
  181. XFormsFile.prototype.detachFile = function (nIndex)
  182. {
  183. var strInstance = model.getValue(this.attribute["ref"]);
  184. var arInstance = strInstance.split("?");
  185. strInstance = "";
  186. for (var i = 0; i < arInstance.length; i++)
  187. {
  188. if (nIndex == i) continue;
  189. if (strInstance != "")
  190. {
  191. strInstance += "?";
  192. }
  193. strInstance += arInstance[i];
  194. }
  195. model.setValue(this.attribute["ref"], strInstance);
  196. this.refresh();
  197. this.dispatch("onfiledeselected");
  198. };
  199. XFormsFile.prototype.getBindingType = function ()
  200. {
  201. return BT_SINGLE;
  202. };
  203. XFormsFile.uploadTempComplete = function ()
  204. {
  205. var xnFrameDoc = document.getElementById("HE___TF_UploadFrame").contentWindow.document;
  206. var strReturnXML;
  207. if (is_ie)
  208. {
  209. if (xnFrameDoc.XMLDocument)
  210. {
  211. strReturnXML = xnFrameDoc.XMLDocument.xml;
  212. }
  213. else
  214. {
  215. var serializer = new XMLSerializer();
  216. strReturnXML = serializer.serializeToString(xnFrameDoc);
  217. }
  218. }
  219. else
  220. {
  221. var serializer = new XMLSerializer();
  222. strReturnXML = serializer.serializeToString(xnFrameDoc);
  223. }
  224. if (strReturnXML)
  225. {
  226. var xnReturn = XmlLib.loadXMLFromString(strReturnXML);
  227. if (xnReturn.selectSingleNode("/root"))
  228. {
  229. var xnTagName = xnReturn.selectSingleNode("/root/tagName");
  230. var xnFileName = xnReturn.selectSingleNode("/root/fileName");
  231. var xnTempName = xnReturn.selectSingleNode("/root/tempName");
  232. var xnFilePath = xnReturn.selectSingleNode("/root/filePath");
  233. var strTagName = XmlLib.getTextValue(xnTagName);
  234. var strFileName = XmlLib.getTextValue(xnFileName);
  235. var strTempName = XmlLib.getTextValue(xnTempName).replaceAll(XmlLib.getTextValue(xnFilePath), "");
  236. var objFile = document.controls.item(strTagName.substring(3,strTagName.lastIndexOf(".")));
  237. objFile.setAttachedFile(strFileName, strTempName);
  238. }
  239. objFile.dispatch("onfileselected");
  240. }
  241. };