XFormsSwitch.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. XFormsSwitch.prototype = new XFormsControl;
  2. function XFormsSwitch (strParentId, strClass, bDisabled, strId, strStyle, strTag, strVisibility, strUserDefineAttrib)
  3. {
  4. if (!strId)
  5. {
  6. return;
  7. }
  8. XFormsControl.call(this, strParentId, /*strAlert*/"", /*strHelp*/"", /*strHint*/"", /*strAccesskey*/"", strClass, bDisabled, strId, /*nNavindex*/"", strStyle, strTag, strVisibility, strUserDefineAttrib);
  9. /**
  10. * Property
  11. */
  12. this.selected;
  13. this.selectedIndex;
  14. /**
  15. * Method
  16. */
  17. this.m_isChild;
  18. };
  19. XFormsSwitch.prototype.init = function ()
  20. {
  21. XFormsControl.prototype.init.call(this);
  22. var bSelectCase = false;
  23. var strFirstChildId = "";
  24. var nIndex = 0;
  25. var arKeyset = this.children.keys();
  26. for (var i=0; i<arKeyset.length; i++)
  27. {
  28. var strId = arKeyset[i];
  29. var objCase = this.children.item(strId);
  30. if (objCase instanceof XFormsCase)
  31. {
  32. objCase.setIndex(nIndex);
  33. if ("true" == objCase.attribute["selected"])
  34. {
  35. objCase.select("true");
  36. bSelectCase = true;
  37. }
  38. if (0 == nIndex)
  39. {
  40. strFirstChildId = strId;
  41. }
  42. nIndex++;
  43. }
  44. }
  45. if (!bSelectCase && strFirstChildId != "")
  46. {
  47. var objFirstCase = this.children.item(strFirstChildId);
  48. objFirstCase.select("true");
  49. }
  50. this.resizeControl();
  51. };
  52. XFormsSwitch.prototype.applyDefaultStyle = function ()
  53. {
  54. XFormsControl.prototype.applyDefaultStyle.call(this);
  55. if (null == HtmlLib.getStyle(this.m_heControl,"background-color") || "" == HtmlLib.getStyle(this.m_heControl,"background-color"))
  56. {
  57. HtmlLib.setStyle(this.m_heControl, "background-color", "#FFFFFF");
  58. }
  59. };
  60. /**
  61. * 지정한 스타일을 최초 로딩시점과 동일하게 초기화
  62. * @return
  63. */
  64. XFormsSwitch.prototype.initStyle = function ()
  65. {
  66. };
  67. /**
  68. * 인스턴스 데이터를 실제 컨트롤에 반영
  69. * @return
  70. */
  71. XFormsSwitch.prototype.refresh = function ()
  72. {
  73. var arKeyset = this.children.keys();
  74. for (var i=0; i<arKeyset.length; i++)
  75. {
  76. var strId = arKeyset[i];
  77. var objChild = this.children.item(strId);
  78. if (null != objChild && objChild instanceof XFormsElement && objChild.refresh)
  79. {
  80. objChild.refresh();
  81. }
  82. }
  83. };
  84. XFormsSwitch.prototype.setSelectedIndex = function (nIndex)
  85. {
  86. var arKeyset = this.children.keys();
  87. for (var i=0; i<arKeyset.length; i++)
  88. {
  89. var strId = arKeyset[i];
  90. var objCase = this.children.item(strId);
  91. if (objCase instanceof XFormsCase)
  92. {
  93. if (nIndex == objCase.getIndex())
  94. {
  95. objCase.select("true");
  96. }
  97. }
  98. }
  99. };
  100. /**
  101. * ID가 strId인 컨트롤이 Switch의 자식인지 판단한다.
  102. * @param strId 컨트롤의 ID
  103. * @return
  104. */
  105. XFormsSwitch.prototype.isChild = function (strId)
  106. {
  107. var objChild = this.children.item(strId);
  108. if (null != objChild)
  109. {
  110. return true;
  111. }
  112. else
  113. {
  114. return false;
  115. }
  116. };
  117. /**
  118. * ID가 strId인 컨트롤이 Switch의 자손인지 판단한다.
  119. * @param strId 컨트롤의 ID
  120. * @param bIncludeThis Switch 자신을 포함할지 여부
  121. * @return
  122. */
  123. XFormsSwitch.prototype.isDescendants = function(strId, bIncludeThis)
  124. {
  125. if(null == bIncludeThis)
  126. {
  127. bIncludeThis = false;
  128. }
  129. var objChild = document.allElement.item(strId);
  130. if (null != objChild)
  131. {
  132. if (bIncludeThis)
  133. {
  134. if (objChild == this)
  135. {
  136. return true;
  137. }
  138. }
  139. var objParent = objChild.parent;
  140. while(null != objParent)
  141. {
  142. if (objParent == this)
  143. {
  144. return true;
  145. }
  146. objParent = objParent.parent;
  147. }
  148. return false;
  149. }
  150. return false;
  151. };
  152. XFormsSwitch.create = function (strParentId, clAttribute, strStyle)
  153. {
  154. // 메인노드 생성
  155. var xnSwitch = XFormsSwitch.createMainNode(clAttribute);
  156. var xnParent = document.getElementById("HE_"+strParentId);
  157. xnParent.appendChild(xnSwitch);
  158. // 하위노드 생성
  159. xnSwitch = XFormsSwitch.createSubNodes(xnSwitch, clAttribute);
  160. // object 생성
  161. return XFormsSwitch.createObject(strParentId, xnSwitch, clAttribute, strStyle);
  162. };
  163. XFormsSwitch.createMainNode = function (clAttribute)
  164. {
  165. var xnSwitch = document.createElement("div");
  166. xnSwitch = XFormsSwitch.createAttribute(xnSwitch, clAttribute);
  167. return xnSwitch;
  168. };
  169. XFormsSwitch.createSubNodes = function (xnSwitch, clAttribute)
  170. {
  171. return xnSwitch;
  172. };
  173. XFormsSwitch.createObject = function (strParentId, xnSwitch, clAttribute, strStyle)
  174. {
  175. var strClass = "";
  176. var bDisabled = false;
  177. var strId = "";
  178. var strVisibility = "visible";
  179. var strUserDefineAttrib = "";
  180. for (var i=0; i<clAttribute.count(); i++)
  181. {
  182. var strAttributeName = clAttribute.keys()[i];
  183. switch (strAttributeName)
  184. {
  185. case "class" :
  186. {
  187. strClass = clAttribute.item(strAttributeName);
  188. break;
  189. }
  190. case "disabled" :
  191. {
  192. if ("true" == clAttribute.item(strAttributeName))
  193. {
  194. bDisabled = true;
  195. }
  196. break;
  197. }
  198. case "id" :
  199. {
  200. strId = clAttribute.item(strAttributeName);
  201. break;
  202. }
  203. case "visibility" :
  204. {
  205. strVisibility = clAttribute.item(strAttributeName);
  206. break;
  207. }
  208. default :
  209. {
  210. if (!STYLE_LIST[strAttributeName])
  211. {
  212. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  213. }
  214. break;
  215. }
  216. }
  217. }
  218. var objSwitch = new XFormsSwitch(strParentId, strClass, bDisabled, strId, strStyle, "xforms:switch", strVisibility, strUserDefineAttrib);
  219. return objSwitch;
  220. };
  221. XFormsSwitch.createAttribute = function (xnHtmlNode, clAttribute)
  222. {
  223. xnHtmlNode = XFormsControl.createAttribute(xnHtmlNode, clAttribute);
  224. return xnHtmlNode;
  225. };