XFormsBindableControl.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. XFormsBindableControl.prototype = new XFormsControl;
  2. function XFormsBindableControl (strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strClass,
  3. bDisabled, strId, nNavindex, strRef, strStyle, strTag, strVisibility, strUserDefineAttrib)
  4. {
  5. if (!strId)
  6. {
  7. return;
  8. }
  9. XFormsControl.call(this, strParentId, strAlert, strHelp, strHint, strAccesskey, strClass,
  10. bDisabled, strId, nNavindex, strStyle, strTag, strVisibility, strUserDefineAttrib);
  11. /**
  12. * Property
  13. */
  14. this.value = "";
  15. /**
  16. * Attribute
  17. */
  18. this.attribute["bind"] = strBind;
  19. this.attribute["ref"] = strRef;
  20. this.attribute["required"] = null;
  21. this.m_xlRefNode = null;
  22. this.m_bBinded = false;
  23. this.m_bCanBind = true;
  24. this.m_bBase64 = false;
  25. var strBind = this.getAttribute("bind");
  26. //bind obj 찾기
  27. if (null != strBind && !strBind.isEmpty())
  28. {
  29. this.m_bBinded = true;
  30. }
  31. var strRef;
  32. if (BT_SINGLE == this.getBindingType())
  33. {
  34. strRef = this.getAttribute("ref");
  35. }
  36. else if (BT_NODESET == this.getBindingType())
  37. {
  38. strRef = this.getAttribute("nodeset");
  39. }
  40. if (null != strRef && !strRef.isEmpty())
  41. {
  42. if (null == REF_ATTRIBUTE[strRef])
  43. {
  44. REF_ATTRIBUTE[strRef] = new Hashtable();
  45. REF_ATTRIBUTE[strRef][this.id] = this;
  46. }
  47. else
  48. {
  49. REF_ATTRIBUTE[strRef][this.id] = this;
  50. }
  51. this.m_bBinded = true;
  52. }
  53. };
  54. XFormsBindableControl.prototype.init = function ()
  55. {
  56. XFormsControl.prototype.init.call(this);
  57. this.m_xlRefNode = this.getControlNodeList();
  58. };
  59. XFormsBindableControl.prototype.refresh = function ()
  60. {
  61. XFormsControl.prototype.refresh.call(this);
  62. this.m_xlRefNode = this.getControlNodeList();
  63. };
  64. XFormsBindableControl.prototype.getRefNode = function ()
  65. {
  66. return this.m_xlRefNode;
  67. };
  68. XFormsBindableControl.prototype.setRefNode = function (xlNode)
  69. {
  70. this.m_xlRefNode = xlNode;
  71. };
  72. XFormsBindableControl.prototype.isBinded = function ()
  73. {
  74. return this.m_bBinded;
  75. };
  76. XFormsBindableControl.prototype.setBinded = function (bBinded)
  77. {
  78. this.m_bBinded = bBinded;
  79. };
  80. XFormsBindableControl.prototype.isCanBind = function ()
  81. {
  82. return this.m_bCanBind;
  83. };
  84. XFormsBindableControl.prototype.setCanBind = function (bCanBind)
  85. {
  86. this.m_bCanBind = bCanBind;
  87. };
  88. XFormsBindableControl.prototype.getValue = function ()
  89. {
  90. // 부모가 그리드, 멀티라인 그리드 일때 처리
  91. if (false/* "datagrid" == this.parent.getElementName */)
  92. {
  93. // return this.parent.getValue();
  94. }
  95. else
  96. {
  97. this.m_xlRefNode = this.getControlNodeList();
  98. if (null != this.m_xlRefNode && 0 < this.m_xlRefNode.length)
  99. {
  100. return XmlLib.getTextValue(this.m_xlRefNode.item(0));
  101. }
  102. // 없을때 처리
  103. if ("xforms:caption" == this.getElementName())
  104. {
  105. return this.getText();
  106. }
  107. else if ("xforms:button" == this.getElementName())
  108. {
  109. return this.getText();
  110. }
  111. else if ("xforms:treeview" == this.getElementName())
  112. {
  113. return this.getText();
  114. }
  115. return "";
  116. }
  117. };
  118. XFormsBindableControl.prototype.setValue = function (strValue)
  119. {
  120. //TODO Parent 부분 처리
  121. if (null != this.m_xlRefNode && 0 < this.m_xlRefNode.length)
  122. {
  123. var xnNode = this.m_xlRefNode.item(0);
  124. // TODO valid check
  125. // TODO CDATA 처리
  126. var bAutoCDATA = model.attribute["autocdata"];
  127. var bProcessCDATA = model.isProcessAutoCdata(strValue);
  128. if (bAutoCDATA && bProcessCDATA)
  129. {
  130. //TODO model 의 autocdata 처리
  131. }
  132. else
  133. {
  134. XmlLib.setTextValue(xnNode, strValue);
  135. }
  136. }
  137. else
  138. {
  139. this.setText(strValue);
  140. }
  141. this.refreshCurrentModel(this.attribute["ref"]);
  142. };
  143. XFormsBindableControl.prototype.getControlNodeList = function ()
  144. {
  145. if (null == model)
  146. {
  147. return null;
  148. }
  149. var strBind = this.getAttribute("bind");
  150. if (null != strBind && !strBind.isEmpty())
  151. {
  152. // TODO bind 처리
  153. this.m_bBinded = true;
  154. }
  155. else
  156. {
  157. var strRef;
  158. if (BT_SINGLE == this.getBindingType())
  159. {
  160. strRef = this.getAttribute("ref");
  161. }
  162. else if (BT_NODESET == this.getBindingType())
  163. {
  164. strRef = this.getAttribute("nodeset");
  165. }
  166. if (null != strRef && !strRef.isEmpty())
  167. {
  168. this.m_bBinded = true;
  169. return model.getInstancePart(null, strRef);
  170. }
  171. }
  172. return null;
  173. };
  174. /**
  175. * Attribute 값을 변경시키고 Attribute 값 변화에 맞는 동작을 수행한다.
  176. * @param strAttribute
  177. * @param strValue
  178. * @return
  179. */
  180. XFormsBindableControl.prototype.setAttribute = function (strAttribute, strValue)
  181. {
  182. XFormsControl.prototype.setAttribute.call(this, strAttribute, strValue);
  183. switch (strAttribute)
  184. {
  185. case "bind" :
  186. {
  187. this.attribute["bind"] = strValue;
  188. break;
  189. }
  190. case "ref" :
  191. {
  192. var strRef = this.attribute["ref"];
  193. if (null != strRef && !strRef.isEmpty())
  194. {
  195. if (null != REF_ATTRIBUTE[strRef])
  196. {
  197. REF_ATTRIBUTE[strRef][this.id] = null;
  198. }
  199. }
  200. this.attribute["ref"] = strValue;
  201. if (null != strValue && !strValue.isEmpty())
  202. {
  203. if (null == REF_ATTRIBUTE[strValue])
  204. {
  205. REF_ATTRIBUTE[strValue] = new Hashtable();
  206. REF_ATTRIBUTE[strValue][this.id] = this;
  207. }
  208. else
  209. {
  210. REF_ATTRIBUTE[strValue][this.id] = this;
  211. }
  212. this.m_bBinded = true;
  213. }
  214. break;
  215. }
  216. }
  217. };
  218. XFormsBindableControl.prototype.isBindControlByNode = function (xnNode)
  219. {
  220. this.m_xlRefNode = this.getControlNodeList();
  221. if (null != this.m_xlRefNode)
  222. {
  223. for (var i=0; i<this.m_xlRefNode.length; i++)
  224. {
  225. var xnRefNode = this.m_xlRefNode.item(i);
  226. if (xnNode == xnRefNode)
  227. {
  228. return true;
  229. }
  230. }
  231. }
  232. return false;
  233. };
  234. XFormsBindableControl.prototype.isBindControlByXPath = function (strXPath)
  235. {
  236. var strRef;
  237. if (BT_SINGLE == this.getBindingType())
  238. {
  239. strRef = this.getAttribute("ref");
  240. }
  241. else if (BT_NODESET == this.getBindingType())
  242. {
  243. strRef = this.getAttribute("nodeset");
  244. }
  245. return (strRef == strXPath);
  246. };
  247. XFormsBindableControl.createAttribute = function (xnHtmlNode, clAttribute)
  248. {
  249. xnHtmlNode = XFormsControl.createAttribute(xnHtmlNode, clAttribute);
  250. return xnHtmlNode;
  251. };