XFormsBool.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. BS_DESELECTED = 0;
  2. BS_SELECTED = 1;
  3. BS_NONESELECTED = 2;
  4. BM_2STATE = 0;
  5. BM_3STATE = 1;
  6. XFormsBool.prototype = new XFormsBindableControl;
  7. function XFormsBool (strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strCheckValue, strClass,
  8. bDisabled, strId, nNavindex, strRef, strStyle, strTag, strVisibility, strUserDefineAttrib)
  9. {
  10. if (!strId)
  11. {
  12. return;
  13. }
  14. XFormsBindableControl.call (this, strParentId, strAlert, strHelp, strHint, strAccesskey, strBind, strClass,
  15. bDisabled, strId, nNavindex, strRef, strStyle, strTag, strVisibility, strUserDefineAttrib);
  16. /**
  17. * Attribute
  18. */
  19. this.attribute["checkvalue"] = strCheckValue;
  20. this.attribute["mode"] = "2state";
  21. /**
  22. * property
  23. */
  24. this.selected = false;
  25. this.m_nState = 0;
  26. this.m_strTrue = "true";
  27. this.m_strFalse = "false";
  28. this.m_strNone;
  29. if (null != strCheckValue && "" != strCheckValue)
  30. {
  31. var arValue = strCheckValue.split(",");
  32. if (null != arValue && 2 == arValue.length) // 2 State
  33. {
  34. this.m_strTrue = arValue[0];
  35. this.m_strFalse = arValue[1];
  36. }
  37. else if (null != arValue && 3 == arValue.length) // 3 State
  38. {
  39. this.m_strTrue = arValue[0];
  40. this.m_strFalse = arValue[1];
  41. this.m_strNone = arValue[2];
  42. this.attribute["mode"] = "3state";
  43. }
  44. }
  45. };
  46. XFormsBool.prototype.init = function ()
  47. {
  48. XFormsBindableControl.prototype.init.call(this);
  49. if (!this.getAttribute("background-image"))
  50. {
  51. this.setAttribute("background-image", __getAppName() + "/kr/comsquare/image/checkbox/uncheck.gif");
  52. }
  53. if (!this.getSelectAttribute("background-image"))
  54. {
  55. this.setSelectAttribute("background-image", __getAppName() + "/kr/comsquare/image/checkbox/check.gif");
  56. }
  57. if (!this.getDisableAttribute("background-image"))
  58. {
  59. this.setDisableAttribute("background-image", __getAppName() + "/kr/comsquare/image/checkbox/disuncheck.gif");
  60. }
  61. if (!this.getDisableAttribute("select.background-image"))
  62. {
  63. this.setDisableAttribute("select.background-image", __getAppName() + "/kr/comsquare/image/checkbox/discheck.gif");
  64. }
  65. this.resizeControl();
  66. };
  67. XFormsBool.prototype.applyDefaultStyle = function ()
  68. {
  69. XFormsBindableControl.prototype.applyDefaultStyle.call(this);
  70. this.m_heControl.style.padding = "";
  71. this.m_heControl.style.paddingLeft = "";
  72. this.m_heControl.style.paddingTop = "";
  73. this.m_heControl.style.paddingRight = "";
  74. this.m_heControl.style.paddingBottom = "";
  75. if (!this.attribute["border-color"])
  76. {
  77. this.m_heControl.style.borderColor = "#000000";
  78. }
  79. };
  80. XFormsBool.prototype.getAbility = function ()
  81. {
  82. return EA_CONTROL;
  83. };
  84. XFormsBool.prototype.getBindingType = function ()
  85. {
  86. return BT_SINGLE;
  87. };
  88. XFormsBool.prototype.getMode = function ()
  89. {
  90. return ("3state" == this.getAttribute("mode")) ? BM_3STATE : BM_2STATE;
  91. };
  92. /**
  93. * 인스턴스 데이터를 실제 컨트롤에 반영
  94. *
  95. * @return
  96. */
  97. XFormsBool.prototype.refresh = function ()
  98. {
  99. var strValue = this.getValue();
  100. if (BM_2STATE == this.getMode())
  101. {
  102. if (this.m_strTrue == strValue)
  103. {
  104. this.setState(FCS_SELECT, true);
  105. this.m_nState = BS_SELECTED;
  106. this.selected = true;
  107. }
  108. else
  109. {
  110. this.setState(FCS_SELECT, false);
  111. this.m_nState = BS_DESELECTED;
  112. this.selected = false;
  113. }
  114. }
  115. else if (BM_3STATE == this.getMode())
  116. {
  117. if (this.m_strTrue == strValue)
  118. {
  119. this.setState(FCS_SELECT, true);
  120. this.m_nState = BS_SELECTED;
  121. this.selected = true;
  122. }
  123. else if (this.m_strNone == strValue)
  124. {
  125. this.setState(FCS_SELECT, true);
  126. this.m_nState = BS_NONESELECTED;
  127. this.selected = true;
  128. }
  129. else
  130. {
  131. this.setState(FCS_SELECT, false);
  132. this.m_nState = BS_DESELECTED;
  133. this.selected = false;
  134. }
  135. }
  136. };
  137. XFormsBool.prototype.setAttribute = function (strAttribute, strValue)
  138. {
  139. XFormsBindableControl.prototype.setAttribute.call(this, strAttribute, strValue);
  140. switch (strAttribute)
  141. {
  142. case "checkvalue" :
  143. {
  144. this.attribute["checkvalue"] = strValue;
  145. if (null != strValue && "" != strValue)
  146. {
  147. var arValue = strValue.split(",");
  148. if (null != arValue && 2 == arValue.length) // 2 State
  149. {
  150. this.m_strTrue = arValue[0];
  151. this.m_strFalse = arValue[1];
  152. }
  153. else if (null != arValue && 3 == arValue.length) // 3 State
  154. {
  155. this.m_strTrue = arValue[0];
  156. this.m_strFalse = arValue[1];
  157. this.m_strNone = arValue[2];
  158. this.attribute["mode"] = "3state";
  159. }
  160. }
  161. break;
  162. }
  163. }
  164. };
  165. XFormsBool.prototype.onClick = function (event)
  166. {
  167. XFormsBindableControl.prototype.onClick.call(this, event);
  168. if (this.disabled)
  169. {
  170. return;
  171. }
  172. var bSelect = this.getState(FCS_SELECT);
  173. if ((bSelect && this.m_nState == BS_DESELECTED) || (!bSelect && this.m_nState != BS_DESELECTED))
  174. {
  175. this.m_nState = bSelect ? BS_SELECTED : BS_DESELECTED;
  176. }
  177. if (BS_SELECTED == this.m_nState)
  178. {
  179. if (BM_2STATE == this.getMode())
  180. {
  181. this.setState(FCS_SELECT, false);
  182. this.m_nState = BS_DESELECTED;
  183. this.selected = false;
  184. this.dispatch("xforms-deselect");
  185. }
  186. else
  187. {
  188. this.setState(FCS_SELECT, true);
  189. this.m_nState = BS_NONESELECTED;
  190. this.selected = true;
  191. this.dispatch("xforms-noneselect");
  192. }
  193. this.dispatch("xforms-value-changed");
  194. }
  195. else if (BS_DESELECTED == this.m_nState)
  196. {
  197. this.setState(FCS_SELECT, true);
  198. this.m_nState = BS_SELECTED;
  199. this.selected = true;
  200. this.dispatch("xforms-select");
  201. this.dispatch("xforms-value-changed");
  202. }
  203. else if (BS_NONESELECTED == this.m_nState)
  204. {
  205. this.setState(FCS_SELECT, false);
  206. this.m_nState = BS_DESELECTED;
  207. this.selected = false;
  208. this.dispatch("xforms-select");
  209. this.dispatch("xforms-value-changed");
  210. }
  211. };
  212. XFormsBool.prototype.onKeyDown = function (event)
  213. {
  214. if (this.disabled)
  215. {
  216. return;
  217. }
  218. switch (event.keyCode)
  219. {
  220. case TFEvent.TAB :
  221. case TFEvent.F1 :
  222. {
  223. XFormsBindableControl.prototype.onKeyDown.call(this, event);
  224. break;
  225. }
  226. case TFEvent.SPACE :
  227. case TFEvent.ENTER :
  228. {
  229. if(BS_SELECTED == this.m_nState)
  230. {
  231. if(BM_2STATE == this.getMode())
  232. {
  233. this.setState(FCS_SELECT, false);
  234. this.m_nState = BS_DESELECTED;
  235. this.selected = false;
  236. this.dispatch("xforms-deselect");
  237. }
  238. else
  239. {
  240. this.setState(FCS_SELECT, true);
  241. this.m_nState = BS_NONESELECTED;
  242. this.selected = true;
  243. this.dispatch("xforms-noneselect");
  244. }
  245. }
  246. else if(BS_NONESELECTED == this.m_nState)
  247. {
  248. this.setState(FCS_SELECT, false);
  249. this.m_nState = BS_DESELECTED;
  250. this.selected = false;
  251. this.dispatch("xforms-deselect");
  252. }
  253. else if(BS_DESELECTED == this.m_nState)
  254. {
  255. if(BM_2STATE == this.getMode())
  256. {
  257. this.setState(FCS_SELECT, true);
  258. this.m_nState = BS_SELECTED;
  259. this.selected = true;
  260. this.dispatch("xforms-select");
  261. }
  262. else
  263. {
  264. this.setState(FCS_SELECT, true);
  265. this.m_nState = BS_SELECTED;
  266. this.selected = true;
  267. this.dispatch("xforms-select");
  268. }
  269. }
  270. this.dispatch("xforms-value-changed");
  271. break;
  272. }
  273. }
  274. };
  275. XFormsBool.prototype.onSelect = function (event)
  276. {
  277. this.setValue(this.m_strTrue);
  278. this.refreshCurrentModel(this.attribute["ref"]);
  279. };
  280. XFormsBool.prototype.onDeSelect = function (event)
  281. {
  282. this.setValue(this.m_strFalse);
  283. this.refreshCurrentModel(this.attribute["ref"]);
  284. };
  285. XFormsBool.prototype.onNoneSelect = function (event)
  286. {
  287. this.setValue(this.m_strNone);
  288. this.refreshCurrentModel(this.attribute["ref"]);
  289. };
  290. XFormsBool.prototype.defaultAction = function (strEventName, event)
  291. {
  292. XFormsBindableControl.prototype.defaultAction.call(this, strEventName, event);
  293. switch(strEventName)
  294. {
  295. case "xforms-select" :
  296. {
  297. this.onSelect(event); break;
  298. }
  299. case "xforms-deselect" :
  300. {
  301. this.onDeSelect(event); break;
  302. }
  303. case "xforms-noneselect" :
  304. {
  305. this.onNoneSelect(event); break;
  306. }
  307. }
  308. };
  309. XFormsBool.create = function (strParentId, clAttribute, strStyle)
  310. {
  311. // 메인노드 생성
  312. var xnBool = XFormsBool.createMainNode(clAttribute);
  313. var xnParent = document.getElementById("HE_"+strParentId);
  314. xnParent.appendChild(xnBool);
  315. // object 생성
  316. return XFormsBool.createObject(strParentId, xnBool, clAttribute, strStyle);
  317. };
  318. XFormsBool.createMainNode = function (clAttribute)
  319. {
  320. var xnBool = document.createElement("div");
  321. xnBool = XFormsBool.createAttribute(xnBool, clAttribute);
  322. xnBool.onclick = function () {};
  323. xnBool.ondbclick = function () {};
  324. xnBool.onmousedown = function () {};
  325. xnBool.onmousemove = function () {};
  326. xnBool.onmouseup = function () {};
  327. return xnBool;
  328. };
  329. XFormsBool.createObject = function (strParentId, xnBool, clAttribute, strStyle)
  330. {
  331. var strAlert = "";
  332. var strHelp = "";
  333. var strHint = "";
  334. var strAccesskey = "";
  335. var strCheckValue = "";
  336. var strClass = "";
  337. var bDisabled = false;
  338. var strId = "";
  339. var nNavindex = 9007199254740992;
  340. var strRef = "";
  341. var strVisibility = "visible";
  342. var strUserDefineAttrib = "";
  343. for (var i=0; i<clAttribute.count(); i++)
  344. {
  345. var strAttributeName = clAttribute.keys()[i];
  346. switch (strAttributeName)
  347. {
  348. case "alert" :
  349. {
  350. strAlert = clAttribute.item(strAttributeName);
  351. break;
  352. }
  353. case "help" :
  354. {
  355. strHelp = clAttribute.item(strAttributeName);
  356. break;
  357. }
  358. case "hint" :
  359. {
  360. strHint = clAttribute.item(strAttributeName);
  361. break;
  362. }
  363. case "accesskey" :
  364. {
  365. strAccesskey = clAttribute.item(strAttributeName);
  366. break;
  367. }
  368. case "checkvalue" :
  369. {
  370. strCheckValue = clAttribute.item(strAttributeName);
  371. break;
  372. }
  373. case "class" :
  374. {
  375. strClass = clAttribute.item(strAttributeName);
  376. break;
  377. }
  378. case "disabled" :
  379. {
  380. if ("true" == clAttribute.item(strAttributeName))
  381. {
  382. bDisabled = true;
  383. }
  384. break;
  385. }
  386. case "id" :
  387. {
  388. strId = clAttribute.item(strAttributeName);
  389. break;
  390. }
  391. case "navindex" :
  392. {
  393. nNavindex = parseInt(clAttribute.item(strAttributeName));
  394. break;
  395. }
  396. case "ref" :
  397. {
  398. strRef = clAttribute.item(strAttributeName);
  399. break;
  400. }
  401. case "visibility" :
  402. {
  403. strVisibility = clAttribute.item(strAttributeName);
  404. break;
  405. }
  406. default :
  407. {
  408. if (!STYLE_LIST[strAttributeName])
  409. {
  410. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  411. }
  412. break;
  413. }
  414. }
  415. }
  416. var objBool = new XFormsBool (strParentId, strAlert, strHelp, strHint, strAccesskey, "", strCheckValue, strClass, bDisabled, strId, nNavindex, strRef, strStyle, "xforms:bool", strVisibility, strUserDefineAttrib);
  417. return objBool;
  418. };
  419. XFormsBool.createAttribute = function (xnHtmlNode, clAttribute)
  420. {
  421. xnHtmlNode.style.backgroundRepeat = "no-repeat";
  422. xnHtmlNode.style.backgroundPosition = "center";
  423. xnHtmlNode.style.backgroundImage = "url(" + __getAppName() + "/kr/comsquare/image/checkbox/uncheck.gif" + ")";
  424. xnHtmlNode = XFormsBindableControl.createAttribute(xnHtmlNode, clAttribute);
  425. return xnHtmlNode;
  426. };