XFormsCaption.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. XFormsCaption.prototype = new XFormsBindableControl;
  2. function XFormsCaption (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoresize, strBind, strClass, bDisabled, bEllipsis,
  3. strFormat, strId, nNavindex, strRef, strRoundMode, nRoundPosition, strStyle, strTag, 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. strText = strText.split("__TF_STR_N").join("\\n");
  14. strText = strText.split("__TF_STR_T").join("\\t");
  15. strText = strText.split("__TF_STR_R").join("\\r");
  16. strText = strText.split("\_\_TF\_N").join("\n");
  17. strText = strText.split("\_\_TF\_T").join("\t");
  18. strText = strText.split("\_\_TF\_R").join("\r");
  19. this.attribute["text"] = strText;
  20. this.attribute["autoresize"] = String(bAutoresize);
  21. this.attribute["ellipsis"] = String(bEllipsis);
  22. this.attribute["format"] = strFormat;
  23. this.attribute["roundmode"] = strRoundMode;
  24. this.attribute["roundposition"] = String(nRoundPosition);
  25. /**
  26. * Property
  27. */
  28. this.ellipsis = bEllipsis;
  29. this.label = strText;
  30. this.m_heControlText = document.getElementById("HE_" + this.id + "_TEXT");
  31. };
  32. /**
  33. * Attribute 값을 변경시키고 Attribute 값 변화에 맞는 동작을 수행한다.
  34. * @param strAttribute
  35. * @param strValue
  36. * @return
  37. */
  38. XFormsCaption.prototype.init = function ()
  39. {
  40. XFormsBindableControl.prototype.init.call(this);
  41. if ("xforms:caption" == this.attribute["tag"] ||"xforms:output" == this.attribute["tag"])
  42. {
  43. if("true" != this.attribute["autoresize"])
  44. {
  45. this.m_heControlText.style.overflow = "hidden";
  46. // 말줄임 표시(Ellipsis) Attribute 설정
  47. if("" != this.attribute["ellipsis"])
  48. {
  49. this.m_heControlText.style.noWrap = "true";
  50. this.setEllipsis(this.attribute["ellipsis"]);
  51. }
  52. }
  53. else
  54. {
  55. this.m_heControlText.style.overflow = "visible";
  56. }
  57. }
  58. this.resizeControl();
  59. };
  60. XFormsCaption.prototype.getAbility = function ()
  61. {
  62. return EA_CONTROL | EA_HAS_FORMAT | EA_HAS_TEXT;
  63. };
  64. /**
  65. * 인스턴스 데이터를 실제 컨트롤에 반영
  66. * @return
  67. */
  68. XFormsCaption.prototype.refresh = function ()
  69. {
  70. if (null != this.m_heControl)
  71. {
  72. var strValue = "";
  73. if (this.m_bBinded)
  74. {
  75. strValue = this.getValue();
  76. }
  77. else
  78. {
  79. strValue = this.getAttribute("text");
  80. }
  81. var nFormatStatus = formatStatus(this.attribute["format"]);
  82. if (0 != nFormatStatus) // format이 존재한다면
  83. {
  84. if (null == strValue)
  85. {
  86. strValue = "";
  87. }
  88. strValue = strValue.formatting(this.attribute["format"]);
  89. if (4 == nFormatStatus &&
  90. "" != this.attribute["roundmode"] &&
  91. "" != this.attribute["roundposition"])
  92. {//roundmode설정이 정상적으로 있다면 형식대로 처리
  93. strValue = getRoundMode(strValue, this.attribute["roundmode"], this.attribute["roundposition"]);
  94. }
  95. }
  96. if (null != this.m_heControlText)
  97. {
  98. if (null == strValue)
  99. {
  100. strValue = "";
  101. }
  102. strValue = strValue.newlineCharConvert();
  103. this.m_heControlText.innerHTML = strValue;
  104. }
  105. //this.__verticalAlign();
  106. }
  107. };
  108. XFormsCaption.prototype.applyDefaultStyle = function ()
  109. {
  110. XFormsBindableControl.prototype.applyDefaultStyle.call(this);
  111. if (!this.attribute["cursor"])
  112. {
  113. HtmlLib.setStyle(this.m_heControl, "cursor", "default");
  114. }
  115. };
  116. XFormsCaption.prototype.getBindingType = function ()
  117. {
  118. return BT_SINGLE;
  119. };
  120. XFormsCaption.prototype.setText = function (strText)
  121. {
  122. if (null != this.m_heControlText)
  123. {
  124. XFormsBindableControl.prototype.setText.call(this, strText);
  125. if (null == strText)
  126. {
  127. strText = "";
  128. }
  129. this.m_heControlText.innerHTML = strText.newlineCharConvert();
  130. }
  131. };
  132. XFormsCaption.prototype.setAttribute = function (strAttribute, strValue)
  133. {
  134. XFormsBindableControl.prototype.setAttribute.call(this, strAttribute, strValue);
  135. switch (strAttribute)
  136. {
  137. case "text" :
  138. {
  139. if ("xforms:caption" == this.attribute["tag"] ||"xforms:output" == this.attribute["tag"])
  140. {
  141. this.text = strValue;
  142. this.attribute["text"] = strValue;
  143. this.setText(strValue);
  144. break;
  145. }
  146. }
  147. case "autoresize" :
  148. {
  149. if ("true" == strValue)
  150. {
  151. this.attribute["autoresize"] = true;
  152. this.m_heControl.style.overflow = "visible";
  153. }
  154. else if ("false" == strValue)
  155. {
  156. this.attribute["autoresize"] = false;
  157. this.m_heControl.style.overflow = "hidden";
  158. }
  159. break;
  160. }
  161. case "ellipsis" :
  162. {
  163. if ("true" == strValue)
  164. {
  165. this.attribute["ellipsis"] = "true";
  166. this.m_heControl.style.textOverflow = "ellipsis";
  167. this.m_heControl.style.whiteSpace = "nowrap";
  168. }
  169. else if ("false" == strValue)
  170. {
  171. this.attribute["ellipsis"] = "false";
  172. this.m_heControl.style.textOverflow = "clip";
  173. this.m_heControl.style.whiteSpace = "normal";
  174. }
  175. break;
  176. }
  177. case "format" :
  178. {
  179. this.attribute["format"] = strValue;
  180. break;
  181. }
  182. case "roundmode" :
  183. {
  184. this.attribute["roundmode"] = strValue;
  185. break;
  186. }
  187. case "roundposition" :
  188. {
  189. this.attribute["roundposition"] = strValue;
  190. break;
  191. }
  192. }
  193. };
  194. XFormsCaption.prototype.setEllipsis = function (bEllipsis)
  195. {
  196. // Property 변경
  197. this.ellipsis = bEllipsis;
  198. // Attribute 변경
  199. this.attribute["ellipsis"] = bEllipsis;
  200. var strTagName = this.attribute["tag"];
  201. if ("xforms:button" != strTagName)
  202. {
  203. // HTML 적용
  204. if ("true" == bEllipsis)
  205. {
  206. this.m_heControlText.style.textOverflow = "ellipsis";
  207. }
  208. else
  209. {
  210. this.m_heControlText.style.textOverflow = "clip";
  211. }
  212. }
  213. else
  214. {
  215. if ("false" == bEllipsis)
  216. {
  217. this.m_heControl.style.textOverflow = "ellipsis";
  218. }
  219. else
  220. {
  221. this.m_heControl.style.textOverflow = "clip";
  222. }
  223. }
  224. };
  225. XFormsCaption.create = function (strParentId, clAttribute, strStyle)
  226. {
  227. // 메인노드 생성
  228. var xnCaption = XFormsCaption.createMainNode(clAttribute);
  229. var xnParent = document.getElementById("HE_"+strParentId);
  230. xnParent.appendChild(xnCaption);
  231. // 하위노드 생성
  232. xnCaption = XFormsCaption.createSubNodes(xnCaption, clAttribute);
  233. // object 생성
  234. return XFormsCaption.createObject(strParentId, xnCaption, clAttribute, strStyle);
  235. };
  236. XFormsCaption.createMainNode = function (clAttribute)
  237. {
  238. var xnCaption = document.createElement("table");
  239. xnCaption = XFormsCaption.createAttribute(xnCaption, clAttribute);
  240. xnCaption.onclick = function () {};
  241. xnCaption.ondbclick = function () {};
  242. xnCaption.onmousedown = function () {};
  243. xnCaption.onmousemove = function () {};
  244. xnCaption.onmouseup = function () {};
  245. return xnCaption;
  246. };
  247. XFormsCaption.createSubNodes = function (xnCaption, clAttribute)
  248. {
  249. // 상위의 아이디를 가져온다.
  250. var strId = clAttribute.item("id");
  251. var xnCaptionTbody = document.createElement("tbody");
  252. var xnCaptionTR = document.createElement("tr");
  253. var xnCaptionTD = document.createElement("td");
  254. xnCaptionTD.setAttribute("id", "HE_" + strId + "_TEXT");
  255. xnCaptionTD.style.overflow = "hidden";
  256. if (xnCaption.getAttribute("text")) xnCaptionTD.innerHTML = xnCaption.getAttribute("text").newlineCharConvert();
  257. xnCaptionTR.appendChild(xnCaptionTD);
  258. xnCaptionTbody.appendChild(xnCaptionTR);
  259. xnCaption.appendChild(xnCaptionTbody);
  260. return xnCaption;
  261. };
  262. XFormsCaption.createObject = function (strParentId, xnCaption, clAttribute, strStyle)
  263. {
  264. var strAlert = "";
  265. var strHelp = "";
  266. var strHint = "";
  267. var strText = "";
  268. var strAccesskey = "";
  269. var bAutoResize = false;
  270. var strBind = "";
  271. var strClass = "";
  272. var bDisabled = false;
  273. var bEllipsis = false;
  274. var strFormat = "";
  275. var strId = "";
  276. var nNavindex = 9007199254740992;
  277. var strRef = "";
  278. var strRoundMode = "";
  279. var nRoundPosition = 0;
  280. var strVisibility = "visible";
  281. var strUserDefineAttrib = "";
  282. for (var i=0; i<clAttribute.count(); i++)
  283. {
  284. var strAttributeName = clAttribute.keys()[i];
  285. switch (strAttributeName)
  286. {
  287. case "alert" :
  288. {
  289. strAlert = clAttribute.item(strAttributeName);
  290. break;
  291. }
  292. case "help" :
  293. {
  294. strHelp = clAttribute.item(strAttributeName);
  295. break;
  296. }
  297. case "hint" :
  298. {
  299. strHint = clAttribute.item(strAttributeName);
  300. break;
  301. }
  302. case "text" :
  303. {
  304. strText = clAttribute.item(strAttributeName);
  305. break;
  306. }
  307. case "accesskey" :
  308. {
  309. strAccesskey = clAttribute.item(strAttributeName);
  310. break;
  311. }
  312. case "autoreisze" :
  313. {
  314. if ("true" == clAttribute.item(strAttributeName))
  315. {
  316. bAutoResize = true;
  317. }
  318. break;
  319. }
  320. case "bind" :
  321. {
  322. strBind = clAttribute.item(strAttributeName);
  323. break;
  324. }
  325. case "class" :
  326. {
  327. strClass = clAttribute.item(strAttributeName);
  328. break;
  329. }
  330. case "disabled" :
  331. {
  332. if ("true" == clAttribute.item(strAttributeName))
  333. {
  334. bDisabled = true;
  335. }
  336. break;
  337. }
  338. case "ellipsis" :
  339. {
  340. if ("true" == clAttribute.item(strAttributeName))
  341. {
  342. bEllipsis = true;
  343. }
  344. break;
  345. }
  346. case "format" :
  347. {
  348. strFormat = clAttribute.item(strAttributeName);
  349. break;
  350. }
  351. case "id" :
  352. {
  353. strId = clAttribute.item(strAttributeName);
  354. break;
  355. }
  356. case "navindex" :
  357. {
  358. nNavindex = parseInt(clAttribute.item(strAttributeName));
  359. break;
  360. }
  361. case "ref" :
  362. {
  363. strRef = clAttribute.item(strAttributeName);
  364. break;
  365. }
  366. case "roundmode" :
  367. {
  368. strRoundMode = clAttribute.item(strAttributeName);
  369. break;
  370. }
  371. case "roundposition" :
  372. {
  373. nRoundPosition = parseInt(clAttribute.item(strAttributeName));
  374. break;
  375. }
  376. case "visibility" :
  377. {
  378. strVisibility = clAttribute.item(strAttributeName);
  379. break;
  380. }
  381. default :
  382. {
  383. if (!STYLE_LIST[strAttributeName])
  384. {
  385. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  386. }
  387. break;
  388. }
  389. }
  390. }
  391. var objCaption = new XFormsCaption (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoResize, strBind, strClass, bDisabled, bEllipsis, strFormat, strId, nNavindex, strRef, strRoundMode, nRoundPosition, strStyle, "xforms:caption", strVisibility, strUserDefineAttrib);
  392. return objCaption;
  393. };
  394. XFormsCaption.createAttribute = function (xnHtmlNode, clAttribute)
  395. {
  396. xnHtmlNode = XFormsBindableControl.createAttribute(xnHtmlNode, clAttribute);
  397. xnHtmlNode.cellSpacing = 0;
  398. xnHtmlNode.cellPadding = 0;
  399. xnHtmlNode.style.tableLayout = "fixed";
  400. return xnHtmlNode;
  401. };