XFormsImg.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. XFormsImg.prototype = new XFormsBindableControl;
  2. function XFormsImg (strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, bCache, strClass, bDisabled,
  3. bDragMode, bDropMode, strId, nNavindex, strRef, strSrc, strStyle, strTag, bUpload, strVisibility, strUserDefineAttrib)
  4. {
  5. if (!strId)
  6. {
  7. return;
  8. }
  9. XFormsBindableControl.call(this, strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strClass, bDisabled, strId, nNavindex, strRef, strStyle, strTag, strVisibility, strUserDefineAttrib);
  10. /**
  11. * Attribute
  12. */
  13. this.attribute["cache"] = String(bCache);
  14. this.attribute["src"] = strSrc;
  15. this.attribute["upload"] = String(bUpload);
  16. /**
  17. * Property
  18. */
  19. this.src = strSrc;
  20. this.upload = bUpload;
  21. this.m_heUploadUI = null;
  22. this.m_bUploadUIVisible = false;
  23. };
  24. XFormsImg.prototype.getBindingType = function ()
  25. {
  26. return BT_SINGLE;
  27. };
  28. /**
  29. * 인스턴스 데이터를 실제 컨트롤에 반영
  30. * @return
  31. */
  32. XFormsImg.prototype.refresh = function ()
  33. {
  34. if (null != this.m_heControl)
  35. {
  36. var strRef = this.attribute["ref"];
  37. if (null != strRef && "" != strRef)
  38. {
  39. var strValue = this.getValue(strRef);
  40. this.setSrc(strValue);
  41. }
  42. }
  43. };
  44. /**
  45. * Attribute 값을 변경시키고 Attribute 값 변화에 맞는 동작을 수행한다.
  46. * @param strAttribute
  47. * @param strValue
  48. * @return
  49. */
  50. XFormsImg.prototype.init = function ()
  51. {
  52. XFormsBindableControl.prototype.init.call(this);
  53. var xnFrame = document.getElementById("HE___TF_ImageUploadFrame");
  54. if (xnFrame)
  55. {
  56. if (xnFrame.attachEvent)
  57. {
  58. xnFrame.attachEvent("onload", XFormsImg.uploadTempComplete);
  59. }
  60. else
  61. {
  62. xnFrame.addEventListener("load", XFormsImg.uploadTempComplete, false);
  63. }
  64. }
  65. if (this.upload)
  66. {
  67. this.createUploadUI();
  68. }
  69. var nBorderStyle = parseInt((this.m_heControl.style.border).replaceAll("px", ""));
  70. var nBorderLeftStyle = parseInt((this.m_heControl.style.borderLeft).replaceAll("px", ""));
  71. var nBorderTopStyle = parseInt((this.m_heControl.style.borderTop).replaceAll("px", ""));
  72. var nBorderRightStyle = parseInt((this.m_heControl.style.borderRight).replaceAll("px", ""));
  73. var nBorderBottomStyle = parseInt((this.m_heControl.style.borderBottom).replaceAll("px", ""));
  74. if ("" != nBorderStyle && null != nBorderStyle)
  75. {
  76. if ("" != nBorderLeftStyle && null)
  77. {
  78. this.m_heControl.style.borderLeft = nBorderLeftStyle;
  79. }
  80. }
  81. this.resizeControl();
  82. };
  83. XFormsImg.prototype.createUploadUI = function ()
  84. {
  85. this.m_heUploadShadowUI = document.createElement("div");
  86. this.m_heUploadShadowUI.style.position = "absolute";
  87. this.m_heUploadShadowUI.style.backgroundColor = "#FFFFFF";
  88. this.m_heUploadShadowUI.style.visibility = "hidden";
  89. this.m_heUploadShadowUI.style.filter = "alpha(opacity = 50)";
  90. this.m_heUploadShadowUI.style.opacity = 0.5;
  91. this.m_heUploadShadowUI.style.top = this.getAttribute("top");
  92. this.m_heUploadShadowUI.style.left = this.getAttribute("left");
  93. this.m_heUploadShadowUI.style.width = this.getAttribute("width");
  94. this.m_heUploadShadowUI.style.height = this.getAttribute("height");
  95. this.m_heControl.parentNode.appendChild(this.m_heUploadShadowUI);
  96. this.m_heUploadUI = document.createElement("div");
  97. this.m_heUploadUI.setAttribute("id", "HE_" + this.id);
  98. this.m_heUploadUI.style.position = "absolute";
  99. this.m_heUploadUI.style.visibility = "hidden";
  100. this.m_heUploadUI.style.top = this.getAttribute("top");
  101. this.m_heUploadUI.style.left = this.getAttribute("left");
  102. this.m_heUploadUI.style.width = this.getAttribute("width");
  103. this.m_heUploadUI.style.height = this.getAttribute("height");
  104. this.m_heUploadUI.style.overflow = "hidden";
  105. this.m_heControl.parentNode.appendChild(this.m_heUploadUI);
  106. var heDetachButton= document.createElement("button");
  107. heDetachButton.id = "HE_" + this.id + ".detach";
  108. heDetachButton.style.position = "absolute";
  109. heDetachButton.style.right = "4px";
  110. heDetachButton.style.top = "4px";
  111. heDetachButton.style.width = "16px";
  112. heDetachButton.style.height = "16px";
  113. heDetachButton.style.backgroundColor = "transparent";
  114. heDetachButton.style.backgroundImage = "url(" + __getAppName() + "/kr/comsquare/image/img/detach.gif)";
  115. heDetachButton.style.backgroundRepeat = "no-repeat";
  116. heDetachButton.style.backgroundPosition = "center";
  117. heDetachButton.style.borderStyle = "none";
  118. heDetachButton.onclick = function ()
  119. {
  120. XFormsImg.deleteFile(this.id);
  121. };
  122. this.m_heUploadUI.appendChild(heDetachButton);
  123. var objDetach = new XFormsButton(this.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".detach", -1, "", "", -1, false, "", "xforms:button", "visible");
  124. objDetach.init();
  125. var heAttachDiv= document.createElement("div");
  126. heAttachDiv.id = "HE_" + this.id + ".attach";
  127. heAttachDiv.style.position = "absolute";
  128. heAttachDiv.style.left = "50%";
  129. heAttachDiv.style.top = "50%";
  130. heAttachDiv.style.width = "32px";
  131. heAttachDiv.style.height = "32px";
  132. heAttachDiv.style.fontSize = "0pt";
  133. heAttachDiv.style.overflow = "hidden";
  134. heAttachDiv.style.backgroundImage = "url(" + __getAppName() + "/kr/comsquare/image/img/attach.gif)";
  135. heAttachDiv.style.backgroundRepeat = "no-repeat";
  136. heAttachDiv.style.backgroundPosition = "center";
  137. this.m_heUploadUI.appendChild(heAttachDiv);
  138. var objAttach = new XFormsButton(this.id, "", "", "", "", "", false, "", "", false, false, "", "", "", this.id+".attach", -1, "", "", -1, false, "", "xforms:button", "visible");
  139. objAttach.init();
  140. heAttachDiv.style.marginLeft = (heAttachDiv.offsetWidth/-2)+"px";
  141. heAttachDiv.style.marginTop = (heAttachDiv.offsetHeight/-2)+"px";
  142. var heAttachForm = document.createElement("form");
  143. heAttachForm.id = "HE___TF_ImageUploadForm_" + this.id;
  144. heAttachForm.name = "HE___TF_ImageUploadForm_" + this.id;
  145. heAttachForm.action = __getAppName() + "/FileUpload.tfs";
  146. heAttachForm.method = "post";
  147. heAttachForm.encoding = "multipart/form-data";
  148. heAttachForm.enctype = "multipart/form-data";
  149. heAttachForm.target = "HE___TF_ImageUploadFrame";
  150. heAttachForm.style.backgroundColor = "transparent";
  151. heAttachDiv.appendChild(heAttachForm);
  152. this.createUploadFileInput();
  153. };
  154. XFormsImg.prototype.createUploadFileInput = function (heAttachForm)
  155. {
  156. var heAttachForm = document.getElementById("HE___TF_ImageUploadForm_" + this.id);
  157. var heAttachFileOld = document.getElementById("HE_ImageInput_" + this.id);
  158. if (heAttachFileOld) heAttachForm.removeChild(heAttachFileOld);
  159. var heAttachFile = document.createElement("input");
  160. heAttachFile.id = "HE_ImageInput_" + this.id;
  161. heAttachFile.name = "HE_ImageInput_" + this.id;
  162. heAttachFile.type = "file";
  163. heAttachFile.onchange = function ()
  164. {
  165. var strControlId = this.parentNode.id.replace("HE___TF_ImageUploadForm_", "");
  166. XFormsImg.submitFile(strControlId);
  167. document.controls.item(strControlId).createUploadFileInput();
  168. };
  169. heAttachFile.style.position = "absolute";
  170. heAttachForm.appendChild(heAttachFile);
  171. var heAttachDiv= document.getElementById("HE_" + this.id + ".attach");
  172. var nButtonHeight = heAttachDiv.offsetHeight;
  173. var nButtonWidth = heAttachDiv.offsetWidth;
  174. heAttachFile = document.getElementById("HE_ImageInput_" + this.id);
  175. heAttachFile.style.filter = "alpha(opacity = 0)";
  176. heAttachFile.style.opacity = 0;
  177. heAttachFile.style.height = nButtonHeight + "px";
  178. heAttachFile.style.top = ((heAttachDiv.offsetHeight/2)-(heAttachFile.offsetHeight/2))+"px";
  179. if (is_ie)
  180. {
  181. heAttachFile.style.width = "0px";
  182. if (nButtonWidth < 95)
  183. {
  184. heAttachFile.style.left = (nButtonWidth-heAttachFile.offsetWidth)+"px";
  185. }
  186. else
  187. {
  188. heAttachFile.style.left = ((nButtonWidth/2)-heAttachFile.offsetWidth+47)+"px";
  189. }
  190. }
  191. else if (is_firefox)
  192. {
  193. heAttachFile.size = "1";
  194. if (nButtonWidth < 87)
  195. {
  196. heAttachFile.style.left = (nButtonWidth-heAttachFile.offsetWidth)+"px";
  197. }
  198. else
  199. {
  200. heAttachFile.style.left = ((nButtonWidth/2)-heAttachFile.offsetWidth+43)+"px";
  201. }
  202. }
  203. else if (is_opera)
  204. {
  205. heAttachFile.style.width = "57px";
  206. if (nButtonWidth < 58)
  207. {
  208. heAttachFile.style.left = (nButtonWidth-heAttachFile.offsetWidth)+"px";
  209. }
  210. else
  211. {
  212. heAttachFile.style.left = ((nButtonWidth/2)-heAttachFile.offsetWidth+29)+"px";
  213. }
  214. }
  215. else
  216. {
  217. heAttachFile.style.width = nButtonWidth+"px";
  218. heAttachFile.style.left = "0px";
  219. }
  220. };
  221. XFormsImg.prototype.showUploadUI = function ()
  222. {
  223. if (this.upload)
  224. {
  225. this.m_bUploadUIVisible = true;
  226. this.m_heUploadUI.style.visibility = "visible";
  227. this.m_heUploadShadowUI.style.visibility = "visible";
  228. var nTop = this.getAttribute("top");
  229. var nLeft = this.getAttribute("left");
  230. var nWidth = this.getAttribute("width");
  231. var nHeight = this.getAttribute("height");
  232. this.m_heUploadUI.style.top = parseInt(nTop) +"px";
  233. this.m_heUploadUI.style.left = parseInt(nLeft) +"px";
  234. this.m_heUploadUI.style.width = parseInt(nWidth) +"px";
  235. this.m_heUploadUI.style.height = parseInt(nHeight) +"px";
  236. }
  237. };
  238. XFormsImg.prototype.hideUploadUI = function ()
  239. {
  240. if (this.upload)
  241. {
  242. this.m_bUploadUIVisible = false;
  243. this.m_heUploadUI.style.visibility = "hidden";
  244. this.m_heUploadShadowUI.style.visibility = "hidden";
  245. }
  246. };
  247. XFormsImg.prototype.deleteFile = function (strId)
  248. {
  249. if ("" != this.src)
  250. {
  251. this.setSrc("");
  252. model.setValue(this.attribute["ref"], "");
  253. }
  254. };
  255. XFormsImg.prototype.submitFile = function ()
  256. {
  257. var heInput = document.getElementById("HE_ImageInput_" + this.id);
  258. var heForm = document.getElementById("HE___TF_ImageUploadForm_" + this.id);
  259. heForm.submit();
  260. };
  261. XFormsImg.prototype.setAttachedFile = function (strFileName, strTempName)
  262. {
  263. var strImgPath = __getAppName() + "/kr/comsquare/upload/" + model.getSessionId() + "/" + strTempName;
  264. this.setSrc(strImgPath);
  265. this.setValue(strFileName + "|" + strTempName);
  266. };
  267. XFormsImg.prototype.setAttribute = function (strAttribute, strValue)
  268. {
  269. XFormsBindableControl.prototype.setAttribute.call(this, strAttribute, strValue);
  270. switch (strAttribute)
  271. {
  272. case "cache" :
  273. {
  274. this.attribute["cache"] = strValue;
  275. break;
  276. }
  277. case "src" :
  278. {
  279. // Attribute 변경
  280. this.attribute["src"] = strValue;
  281. // Property 변경
  282. this.src = strValue;
  283. // HTML 적용
  284. this.m_heControl.src = strValue;
  285. break;
  286. }
  287. }
  288. };
  289. XFormsImg.prototype.setSrc = function (strSrc)
  290. {
  291. if (this.upload && -1 < strSrc.indexOf("|"))
  292. {
  293. var arImageName = strSrc.split("|");
  294. if (2 == arImageName.length)
  295. {
  296. strSrc = __getAppName() + "/kr/comsquare/upload/" + model.getSessionId() + "/" + arImageName[1];
  297. }
  298. }
  299. if (this.src != strSrc)
  300. {
  301. // Attribute 변경
  302. this.attribute["src"] = strSrc;
  303. // Property 변경
  304. this.src = strSrc;
  305. // HTML 적용
  306. this.m_heControl.src = strSrc;
  307. }
  308. };
  309. XFormsImg.prototype.onClick = function (event)
  310. {
  311. XFormsBindableControl.prototype.onClick.call(this, event);
  312. if (is_smartphone && this.upload)
  313. {
  314. (this.m_bUploadUIVisible) ? this.hideUploadUI() : this.showUploadUI();
  315. }
  316. };
  317. XFormsImg.prototype.onMouseEnter = function (event)
  318. {
  319. XFormsBindableControl.prototype.onMouseEnter.call(this, event);
  320. if (this.upload)
  321. {
  322. this.showUploadUI();
  323. }
  324. };
  325. XFormsImg.prototype.onMouseOut = function (event)
  326. {
  327. XFormsBindableControl.prototype.onMouseOut.call(this, event);
  328. if (this.upload && event.ptarget.parent != this && event.ptarget != this)
  329. {
  330. this.hideUploadUI();
  331. }
  332. };
  333. XFormsImg.deleteFile = function (strId)
  334. {
  335. var objImage = document.controls.item(strId);
  336. if (null != objImage && objImage instanceof XFormsImg)
  337. {
  338. objImage.deleteFile();
  339. }
  340. };
  341. XFormsImg.submitFile = function (strId)
  342. {
  343. var objImage = document.controls.item(strId);
  344. if (null != objImage && objImage instanceof XFormsImg)
  345. {
  346. objImage.submitFile();
  347. }
  348. };
  349. XFormsImg.uploadTempComplete = function ()
  350. {
  351. var xnFrameDoc = document.getElementById("HE___TF_ImageUploadFrame").contentWindow.document;
  352. var strReturnXML;
  353. if (is_ie)
  354. {
  355. if (xnFrameDoc.XMLDocument) strReturnXML = xnFrameDoc.XMLDocument.xml;
  356. }
  357. else
  358. {
  359. var serializer = new XMLSerializer();
  360. strReturnXML = serializer.serializeToString(xnFrameDoc);
  361. }
  362. if (strReturnXML)
  363. {
  364. var xnReturn = XmlLib.loadXMLFromString(strReturnXML);
  365. if (xnReturn.selectSingleNode("/root"))
  366. {
  367. var xnTagName = xnReturn.selectSingleNode("/root/tagName");
  368. var xnFileName = xnReturn.selectSingleNode("/root/fileName");
  369. var xnTempName = xnReturn.selectSingleNode("/root/tempName");
  370. var strTagName = XmlLib.getTextValue(xnTagName);
  371. var strFileName = XmlLib.getTextValue(xnFileName);
  372. var strTempName = XmlLib.getTextValue(xnTempName);
  373. var objImg = document.controls.item(strTagName.substr("HE_ImageInput_".length));
  374. if (null != objImg)
  375. {
  376. objImg.setAttachedFile(strFileName, strTempName);
  377. }
  378. }
  379. }
  380. };
  381. XFormsImg.create = function (strParentId, clAttribute, strStyle)
  382. {
  383. // 메인노드 생성
  384. var xnImg = XFormsImg.createMainNode(clAttribute);
  385. var xnParent = document.getElementById("HE_" + strParentId);
  386. xnParent.appendChild(xnImg);
  387. // 하위노드 생성
  388. xnImg = XFormsImg.createSubNodes(xnImg, clAttribute);
  389. // object 생성
  390. return XFormsImg.createObject(strParentId, xnImg, clAttribute, strStyle);
  391. };
  392. XFormsImg.createMainNode = function (clAttribute)
  393. {
  394. var xnImg = document.createElement("img");
  395. xnImg.setAttribute("alt", this.id);
  396. xnImg = XFormsImg.createAttribute(xnImg, clAttribute);
  397. return xnImg;
  398. };
  399. XFormsImg.createSubNodes = function (xnImg, clAttribute)
  400. {
  401. return xnImg;
  402. };
  403. XFormsImg.createObject = function (strParentId, xnImg, clAttribute, strStyle)
  404. {
  405. var strAlert = "";
  406. var strHelp = "";
  407. var strHint = "";
  408. var strAccesskey = "";
  409. var strBind = "";
  410. var bCache = true;
  411. var strClass = "";
  412. var bDisabled = false;
  413. var bDragMode = false;
  414. var bDropMode = false;
  415. var strId = "";
  416. var nNavindex = 9007199254740992;
  417. var strRef = "";
  418. var strSrc = "";
  419. var bUpload = false;
  420. var strVisibility = "visible";
  421. var strUserDefineAttrib = "";
  422. for (var i=0; i<clAttribute.count(); i++)
  423. {
  424. var strAttributeName = clAttribute.keys()[i];
  425. switch (strAttributeName)
  426. {
  427. case "alert" :
  428. {
  429. strAlert = clAttribute.item(strAttributeName);
  430. break;
  431. }
  432. case "help" :
  433. {
  434. strHelp = clAttribute.item(strAttributeName);
  435. break;
  436. }
  437. case "hint" :
  438. {
  439. strHint = clAttribute.item(strAttributeName);
  440. break;
  441. }
  442. case "accesskey" :
  443. {
  444. strAccesskey = clAttribute.item(strAttributeName);
  445. break;
  446. }
  447. case "bind" :
  448. {
  449. strBind = clAttribute.item(strAttributeName);
  450. break;
  451. }
  452. case "cache" :
  453. {
  454. if ("false" == clAttribute.item(strAttributeName))
  455. {
  456. bCache = false;
  457. }
  458. break;
  459. }
  460. case "class" :
  461. {
  462. strClass = clAttribute.item(strAttributeName);
  463. break;
  464. }
  465. case "disabled" :
  466. {
  467. if ("true" == clAttribute.item(strAttributeName))
  468. {
  469. bDisabled = true;
  470. }
  471. break;
  472. }
  473. case "dragmode" :
  474. {
  475. if ("true" == clAttribute.item(strAttributeName))
  476. {
  477. bDragMode = true;
  478. }
  479. break;
  480. }
  481. case "dropmode" :
  482. {
  483. if ("true" == clAttribute.item(strAttributeName))
  484. {
  485. bDropMode = true;
  486. }
  487. break;
  488. }
  489. case "id" :
  490. {
  491. strId = clAttribute.item(strAttributeName);
  492. break;
  493. }
  494. case "navindex" :
  495. {
  496. nNavindex = parseInt(clAttribute.item(strAttributeName));
  497. break;
  498. }
  499. case "ref" :
  500. {
  501. strRef = clAttribute.item(strAttributeName);
  502. break;
  503. }
  504. case "src" :
  505. {
  506. strSrc = clAttribute.item(strAttributeName);
  507. break;
  508. }
  509. case "visibility" :
  510. {
  511. strVisibility = clAttribute.item(strAttributeName);
  512. break;
  513. }
  514. default :
  515. {
  516. if (!STYLE_LIST[strAttributeName])
  517. {
  518. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  519. }
  520. break;
  521. }
  522. }
  523. }
  524. var objImg = new XFormsImg (strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, bCache, strClass, bDisabled, bDragMode, bDropMode, strId, nNavindex, strRef, strSrc, strStyle, "xforms:img", bUpload, strVisibility, strUserDefineAttrib);
  525. return objImg;
  526. };
  527. XFormsImg.createAttribute = function (xnHtmlNode, clAttribute)
  528. {
  529. xnHtmlNode = XFormsBindableControl.createAttribute(xnHtmlNode, clAttribute);
  530. return xnHtmlNode;
  531. };