XFormsControl.js 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. // Form Control State
  2. FCS_NORMAL = 0x00000000;
  3. FCS_FOCUS = 0x00000001; // focus
  4. FCS_SELECT = 0x00000002; // select
  5. FCS_HOVER = 0x00000004; // hover
  6. FCS_DOWN = 0x00000008; // down
  7. FCS_DISABLE = 0x00000010; // disable
  8. FCS_ACTIVE = 0x00000020; // active
  9. // Binding Type
  10. BT_NONE = 0;
  11. BT_SINGLE = 1;
  12. BT_NODESET = 2;
  13. XFormsControl.prototype = new XFormsElement;
  14. function XFormsControl (strParentId, strAlert, strHelp, strHint, strAccesskey, strClass,
  15. bDisabled, strId, nNavindex, strStyle, strTag, strVisibility, strUserDefineAttrib)
  16. {
  17. if (!strId)
  18. {
  19. return;
  20. }
  21. XFormsElement.call(this, strParentId, strId, strTag);
  22. /**
  23. * Attribute
  24. */
  25. this.attribute["alert"] = strAlert;
  26. this.attribute["help"] = strHelp;
  27. this.attribute["hint"] = strHint;
  28. this.attribute["accesskey"] = strAccesskey;
  29. this.attribute["class"] = strClass;
  30. this.attribute["disabled"] = String(bDisabled);
  31. this.attribute["id"] = strId;
  32. this.attribute["navindex"] = String(nNavindex);
  33. this.attribute["tag"] = strTag;
  34. this.attribute["visibility"] = strVisibility;
  35. /**
  36. * Property
  37. */
  38. this.disabled = bDisabled;
  39. this.hint = strHint;
  40. this.navIndex = nNavindex;
  41. this.visible = ("visible" == strVisibility) ? true : false;
  42. /**
  43. * html Element
  44. */
  45. this.m_heControl;
  46. /**
  47. * Style
  48. */
  49. this.m_strStyle = strStyle;
  50. /**
  51. * User Define Attribute
  52. */
  53. this.m_strUserDefineAttrib = strUserDefineAttrib;
  54. /**
  55. * Event State 관련
  56. */
  57. this.m_bDown = false;
  58. this.m_bDragStart = false;
  59. this.m_bLButtonDown = false;
  60. this.m_dwState = 0;
  61. /**
  62. * 컨트롤이 가져야 할 index 멤버변수
  63. */
  64. this.m_TabIndex;
  65. /**
  66. * 컨트롤 안에 존재하는 새부적인 컨트롤일 경우 true (ex> combo.input , combo.button)
  67. */
  68. this.m_bDependentCtl = false;
  69. /**
  70. * 도큐먼트에 컨트롤을 추가한다.
  71. */
  72. if ("xforms:col" != this.attribute["tag"])
  73. {
  74. XFormsDocument.appendControl(strId, this);
  75. }
  76. /**
  77. * 탭인덱스를 추가한다.
  78. */
  79. model.addTabIndex(nNavindex, this);
  80. };
  81. XFormsControl.prototype.init = function ()
  82. {
  83. this.m_heControl = document.getElementById("HE_" + this.id);
  84. var bIsControl = null != this.m_heControl ? true : false;
  85. this.setStyleToAttribute();
  86. this.setUserDefineAttribute();
  87. if (!bIsControl)
  88. {//물리적인 tag가 존재하지 않을 때 부모의 style을 상속받는다.
  89. // this.setNotObjToChildStyle();
  90. }
  91. else if (bIsControl && this.m_bDependentCtl)
  92. {//물리적인 tag가 존재하지만 컨트롤의 문서상에서 style을 변경할수 없는 자식들의 style을 넣어준다.
  93. //ex)combo.input , combo.buttom
  94. // this.setChildStyle();
  95. }
  96. if (null != g_objStyleSheet)
  97. {
  98. g_objStyleSheet.applyCSS(this);
  99. }
  100. if (bIsControl)
  101. {
  102. if (!this.m_bDependentCtl)
  103. {//앞에서 적용하였기 때문에 생략한다.
  104. // this.setChildStyle();
  105. }
  106. this.applyDefaultStyle();
  107. // this.adjustDIVSize();
  108. this.m_heControl.title = this.hint;
  109. if (1 == this.navIndex)
  110. {
  111. window.setTimeout("window.setFocus('" + this.id + "');", 0);
  112. }
  113. if(!this.visible)
  114. {
  115. this.m_heControl.style.visibility = "hidden";
  116. }
  117. }
  118. this.disabled = false;
  119. };
  120. XFormsControl.prototype.setStyleToAttribute = function ()
  121. {
  122. if (null != this.m_strStyle && "" != this.m_strStyle)
  123. {
  124. this.m_strStyle = this.m_strStyle.trim();
  125. if (";" == this.m_strStyle.charAt(this.m_strStyle.length - 1))
  126. {
  127. this.m_strStyle = this.m_strStyle.substring(0, this.m_strStyle.length - 1);
  128. }
  129. var arStyle = this.m_strStyle.split(";");
  130. for (var i=0; i<arStyle.length; i++)
  131. {
  132. if (null != arStyle[i] && "" != arStyle[i])
  133. {
  134. var arStyleUnit = arStyle[i].split(":");
  135. this.attribute[arStyleUnit[0].trim()] = arStyleUnit[1].trim();
  136. }
  137. }
  138. }
  139. };
  140. XFormsControl.prototype.setUserDefineAttribute = function ()
  141. {
  142. if (null != this.m_strUserDefineAttrib && "" != this.m_strUserDefineAttrib)
  143. {
  144. this.m_strUserDefineAttrib = this.m_strUserDefineAttrib.trim();
  145. if (";" == this.m_strUserDefineAttrib.charAt(this.m_strUserDefineAttrib.length - 1))
  146. {
  147. this.m_strUserDefineAttrib = this.m_strUserDefineAttrib.substring(0, this.m_strUserDefineAttrib.length - 1);
  148. }
  149. var arAttrib = this.m_strUserDefineAttrib.split(";");
  150. for (var i=0; i<arAttrib.length; i++)
  151. {
  152. if (null != arAttrib[i] && "" != arAttrib[i])
  153. {
  154. var arAttribUnit = arAttrib[i].split(":");
  155. this.attribute[arAttribUnit[0].trim()] = arAttribUnit[1].trim();
  156. }
  157. }
  158. }
  159. };
  160. XFormsControl.prototype.isIndepandent = function ()
  161. {
  162. return true;
  163. };
  164. XFormsControl.prototype.getAbility = function ()
  165. {
  166. return EA_CONTROL;
  167. };
  168. XFormsControl.prototype.isEnable = function ()
  169. {
  170. var objControl = this;
  171. while (null != objControl && (EA_CONTROL_BASE & objControl.getAbility()))
  172. {
  173. if (objControl.getState(FCS_DISABLE))
  174. {
  175. return false;
  176. }
  177. objControl = objControl.parent;
  178. }
  179. return true;
  180. };
  181. XFormsControl.prototype.setRefElement = function (objElementBase)
  182. {
  183. XFormsElement.prototype.setRefElement.call(this, objElementBase);
  184. this.m_heControl = objElementBase.getHtmlElement();
  185. };
  186. XFormsControl.prototype.getClass = function ()
  187. {
  188. return this.attribute["class"];
  189. };
  190. XFormsControl.prototype.getHtmlElement = function ()
  191. {
  192. return this.m_heControl;
  193. };
  194. XFormsControl.prototype.setHtmlElement = function (heElement)
  195. {
  196. this.m_heControl = heElement;
  197. };
  198. XFormsControl.prototype.refresh = function ()
  199. {
  200. if ("true" == this.attribute["disabled"])
  201. {
  202. this.setDisabled(true);
  203. }
  204. };
  205. /**
  206. * 컨트롤의 IE 이외의 브라우저에서 DIV border를 밖에 그리는 문제때문에 border 사이즈와 width, height를 조절한다.
  207. * DIV로 싸여있는 컨트롤은 이 함수를 init()에서 호출하자.
  208. * @return
  209. */
  210. XFormsControl.prototype.adjustDIVSize = function ()
  211. {
  212. if (!is_ie && this.m_heControl && this.m_heControl.tagName.toLowerCase() == "div")
  213. {
  214. var strWidth = this.attribute["width"];
  215. if (strWidth && strWidth.lastIndexOf("%") < 0)
  216. {
  217. var nWidth = parseInt(this.attribute["width"].replace("px",""));
  218. var nDifference = this.m_heControl.offsetWidth - this.m_heControl.clientWidth;
  219. this.m_heControl.style.width = (nWidth - nDifference) + "px";
  220. }
  221. var strHeight = this.attribute["height"];
  222. if (strHeight && strHeight.lastIndexOf("%") < 0)
  223. {
  224. var nHeight = parseInt(this.attribute["height"].replace("px",""));
  225. var nDifference = this.m_heControl.offsetHeight - this.m_heControl.clientHeight;
  226. this.m_heControl.style.height = (nHeight - nDifference) + "px";
  227. }
  228. }
  229. };
  230. XFormsControl.prototype.getBindingType = function ()
  231. {
  232. return BT_NONE;
  233. };
  234. XFormsControl.prototype.setDisabled = function (bDisabled, bParentDis)
  235. {
  236. if (null == bParentDis && this.disabled == bDisabled)
  237. {
  238. return;
  239. }
  240. if (null == bParentDis)
  241. {
  242. this.m_bThisDisabled = bDisabled;
  243. }
  244. if (null == bParentDis && !bDisabled)
  245. {
  246. this.m_bThisDisabled = null;
  247. }
  248. if (this.m_bThisDisabled && bParentDis && !bDisabled)
  249. {
  250. return;
  251. }
  252. this.disabled = bDisabled;
  253. // Attribute 변경
  254. this.attribute["disabled"] = String(bDisabled);
  255. // HTML 적용
  256. if (null != this.m_heControl)
  257. {
  258. this.m_heControl.disabled = bDisabled;
  259. }
  260. // 상태 변경
  261. this.setState(FCS_DISABLE, bDisabled);
  262. this.m_strPDisabled = bDisabled ? this.id : null;
  263. for (var i=0; i<this.children.length; i++)
  264. {
  265. var objChild = this.children.item(i);
  266. var strElementName = objChild.elementName;
  267. if (objChild instanceof XFormsControl)
  268. {
  269. if ( -1 != objChild.id.indexOf("fixed-cell"))
  270. {
  271. continue;
  272. }
  273. objChild.setDisabled(bDisabled , true);
  274. }
  275. }
  276. };
  277. XFormsControl.prototype.setHint = function (strHint)
  278. {
  279. // Attribute 변경
  280. this.attribute["hint"] = strHint;
  281. // Property 변경
  282. this.hint = strHint;
  283. // HTML 적용
  284. this.m_heControl.title = strHint;
  285. };
  286. XFormsControl.prototype.setNavIndex = function (nNavindex)
  287. {
  288. if (this.navIndex == nNavindex)
  289. {
  290. return;
  291. }
  292. else
  293. {
  294. model.replaceTabIndex(this.m_TabIndex, nNavindex, this);
  295. // Property 변경
  296. this.navIndex = nNavindex;
  297. // Attribute 변경
  298. this.attribute["navindex"] = String(nNavindex);
  299. }
  300. };
  301. XFormsControl.prototype.setVisible = function (bVisible)
  302. {
  303. // Property 적용
  304. this.visible = bVisible;
  305. if (bVisible)
  306. {
  307. // Attribute 적용
  308. this.attribute["visibility"] = "visible";
  309. // HTML 적용
  310. this.m_heControl.style.visibility = "visible";
  311. }
  312. else
  313. {
  314. // Attribute 적용
  315. this.attribute["visibility"] = "hidden";
  316. // HTML 적용
  317. this.m_heControl.style.visibility = "hidden";
  318. }
  319. };
  320. XFormsControl.prototype.refreshCurrentModel = function (strObj)
  321. {
  322. if (__useBinding)
  323. {
  324. var bAutoRefresh = (null == strObj || -1 != strObj.indexOf("/")) ? true: false;
  325. if (null == bAutoRefresh)
  326. {
  327. bAutoRefresh = true;
  328. }
  329. if(bAutoRefresh)
  330. {
  331. model.dispatch("xforms-recalculate");
  332. // TODO xforms-revalidate 미구현
  333. model.dispatch("xforms-refresh");
  334. }
  335. else
  336. {
  337. model.refresh();
  338. }
  339. }
  340. else
  341. {
  342. var strRef = strObj;
  343. if (null != strRef && !strRef.isEmpty())
  344. {
  345. if (null != REF_ATTRIBUTE[strRef])
  346. {
  347. for (strHtKey in REF_ATTRIBUTE[strRef])
  348. {
  349. REF_ATTRIBUTE[strRef][strHtKey].refresh();
  350. }
  351. return;
  352. }
  353. this.refresh();
  354. }
  355. else
  356. {
  357. this.refresh();
  358. }
  359. }
  360. };
  361. XFormsControl.prototype.setPosition = function (rectControl)
  362. {
  363. this.m_heControl.style.top = rectControl.getY() + "px";
  364. this.m_heControl.style.left = rectControl.getX() + "px";
  365. this.m_heControl.style.width = rectControl.getWidth() + "px";
  366. this.m_heControl.style.height = rectControl.getHeight() + "px";
  367. };
  368. XFormsControl.prototype.resizeControl = function ()
  369. {
  370. if (this.attribute["height"])
  371. {
  372. HtmlLib.setStyle(this.m_heControl, "height", this.attribute["height"]);
  373. }
  374. if (this.attribute["width"])
  375. {
  376. HtmlLib.setStyle(this.m_heControl, "width", this.attribute["width"]);
  377. }
  378. };
  379. XFormsControl.prototype.clientToControl = function (ptClient)
  380. {
  381. // ptClient.m_nX +=
  382. };
  383. XFormsControl.prototype.focus = function ()
  384. {
  385. try
  386. {//컨트롤의 상태가 disabled 일때 사용불가능
  387. this.m_heControl.focus();
  388. }
  389. catch(e)
  390. {
  391. }
  392. };
  393. /**
  394. * Attribute 값을 변경시키고 Attribute 값 변화에 맞는 동작을 수행한다.
  395. * @param strAttribute
  396. * @param strValue
  397. * @return
  398. */
  399. XFormsControl.prototype.setAttribute = function (strAttribute, strValue)
  400. {
  401. XFormsElement.prototype.setAttribute.call(this, strAttribute, strValue);
  402. switch (strAttribute)
  403. {
  404. case "alert" :
  405. {
  406. this.attribute["alert"] = strValue;
  407. break;
  408. }
  409. case "help" :
  410. {
  411. this.attribute["help"] = strValue;
  412. break;
  413. }
  414. case "hint" :
  415. {
  416. this.attribute["hint"] = strValue;
  417. this.setHint(strValue);
  418. break;
  419. }
  420. case "accesskey" :
  421. {
  422. this.attribute["accesskey"] = strValue;
  423. this.m_heControl.accessKey = strValue;
  424. break;
  425. }
  426. case "class" :
  427. {
  428. this.attribute["class"] = strValue;
  429. this.init();
  430. break;
  431. }
  432. case "disabled" :
  433. {
  434. if ("true" == strValue)
  435. {
  436. this.setDisabled (true);
  437. }
  438. else if ("false" == strValue)
  439. {
  440. this.setDisabled (false);
  441. }
  442. break;
  443. }
  444. case "navindex" :
  445. {
  446. this.setNavIndex(parseInt(strValue));
  447. break;
  448. }
  449. case "visibility" :
  450. {
  451. if ("visible" == strValue)
  452. {
  453. this.visible = true;
  454. this.attribute["visibility"] = strValue;
  455. this.m_heControl.style.visibility = "visible";
  456. }
  457. else if ("hidden" == strValue)
  458. {
  459. this.visible = false;
  460. this.attribute["visibility"] = strValue;
  461. this.m_heControl.style.visibility = "hidden";
  462. }
  463. break;
  464. }
  465. }
  466. };
  467. XFormsControl.prototype.onFocus = function (event)
  468. {
  469. if (!this.getState(FCS_ACTIVE))
  470. {
  471. this.setState(FCS_ACTIVE, true, event);
  472. this.dispatch("onactivate");
  473. }
  474. if (event.target == this.getId())
  475. {
  476. this.setState(FCS_FOCUS, true, event);
  477. if (null != this.m_heControl)
  478. {
  479. if (this.isFocusValid())
  480. {
  481. this.focus();
  482. }
  483. }
  484. }
  485. };
  486. XFormsControl.prototype.onBlur = function (event)
  487. {
  488. if (this.getState(FCS_ACTIVE))
  489. {
  490. this.setState(FCS_ACTIVE, false, event);
  491. this.dispatch("ondeactivate");
  492. }
  493. if (event.target == this.getId())
  494. {
  495. this.setState(FCS_FOCUS, false, event);
  496. }
  497. event.focus = "";
  498. };
  499. XFormsControl.prototype.onClick = function (event)
  500. {
  501. if (null == window.m_nDelayTime)
  502. {
  503. window.m_nDelayTime = window.setTimeout("var objCtrl = document.controls.m_htCollection['"+ this.id +"'];" +
  504. "if(null != objCtrl)" +
  505. "{" +
  506. "objCtrl.dispatch(\"ondelayclick\");" +
  507. "}",500);
  508. }
  509. };
  510. XFormsControl.prototype.onDelayClick = function (event)
  511. {
  512. window.clearTimeout(window.m_nDelayTime);
  513. window.m_nDelayTime = null;
  514. };
  515. XFormsControl.prototype.onCursor = function (event)
  516. {
  517. };
  518. XFormsControl.prototype.onDblClick = function (event)
  519. {
  520. window.clearTimeout(window.m_nDelayTime);
  521. window.m_nDelayTime = null;
  522. if (TFEvent.BUTTON_LEFT == event.button)
  523. {
  524. this.setState(FCS_DOWN, true, event);
  525. m_bDown = 0;
  526. }
  527. };
  528. XFormsControl.prototype.onKeyDown = function (event)
  529. {
  530. if (event.target == this.getId())
  531. {
  532. if (!event.ctrlKey && TFEvent.TAB == event.keyCode)
  533. {
  534. if (!event.shiftKey)
  535. {
  536. if (event.defaultAction != "cancle")
  537. {
  538. this.dispatch("onnext");
  539. }
  540. event.defaultAction = "cancle";
  541. }
  542. else
  543. {
  544. this.dispatch("onprevious");
  545. event.defaultAction = "cancle";
  546. }
  547. }
  548. else if (TFEvent.F1 == event.keyCode)
  549. {
  550. this.dispatch("xforms-help");
  551. }
  552. }
  553. };
  554. XFormsControl.prototype.onKeyUp = function (event)
  555. {
  556. };
  557. XFormsControl.prototype.onKeyPress = function (event)
  558. {
  559. };
  560. XFormsControl.prototype.onMouseDown = function (event)
  561. {
  562. if (is_ie)
  563. {
  564. var arOmitFormtags=["input", "textarea"];
  565. arOmitFormtags=arOmitFormtags.join("|");
  566. if (arOmitFormtags.indexOf(m_event.m_browserEvent.srcElement.tagName.toLowerCase())==-1)
  567. {
  568. body.m_heControl.onselectstart = new Function("return false");
  569. }
  570. else
  571. {
  572. body.m_heControl.onselectstart = new Function("return true");
  573. }
  574. }
  575. //combo control의 스크롤이 존재할 때 이벤트 처리
  576. //TODO 경북대병원 (is_smartphone 부분을 주석처리하고 줌 오류부분 파악불가)
  577. if(!is_smartphone)
  578. {
  579. var heElementName = is_firefox ? event.m_browserEvent.target : event.m_browserEvent.srcElement;
  580. if ("combo" == heElementName.getAttribute("U_D_C_S"))
  581. {
  582. heElementName = null;
  583. return;
  584. }
  585. }
  586. if (event.target == this.getId())
  587. {
  588. if (TFEvent.BUTTON_LEFT == event.button)
  589. {
  590. this.setState(FCS_DOWN, true, event);
  591. this.m_bDown = true;
  592. }
  593. window.setFocus(this.getId(), event);
  594. }
  595. this.m_bDragStart = false;
  596. };
  597. XFormsControl.prototype.onMouseEnter = function (event)
  598. {
  599. };
  600. XFormsControl.prototype.onMouseUp = function (event)
  601. {
  602. if (window.bDragDrop)
  603. {
  604. window.bDragDrop = false;
  605. var objControl = null;
  606. for (var i=0; i< document.controls.length; i++)
  607. {
  608. objControl = document.controls.item(i);
  609. if (TAG_LIST[objControl.getAttribute("tag")])
  610. {
  611. objControl.setAttribute("cursor", objControl.getAttribute("cursor"));
  612. }
  613. }
  614. this.dispatch("ondrop");
  615. }
  616. if (TFEvent.BUTTON_LEFT == event.button)
  617. {
  618. var bDown = (event.down == this.getId()) && this.m_bDown;
  619. if (this.getState(FCS_DOWN) && this.m_bDown)
  620. {
  621. this.setState(FCS_DOWN, false, event);
  622. this.m_bDown = false;
  623. }
  624. if (event.target == this.getId() && bDown)
  625. {
  626. this.dispatch("onclick");
  627. }
  628. }
  629. };
  630. XFormsControl.prototype.onMouseMove = function (event)
  631. {
  632. if (!event.capture.isEmpty())
  633. {
  634. return;
  635. }
  636. if (null != this.m_heControl)
  637. {
  638. if (event.down && window.bDragDrop)
  639. {//drap 상태
  640. if (TAG_LIST[this.getAttribute("tag")])
  641. {
  642. this.m_heControl.style.cursor = "pointer";
  643. }
  644. }
  645. }
  646. // TODO Viewer들의 hover 상태를 비운다. onChangedHover();
  647. if (event.target == this.getId())
  648. {
  649. // 이전 over가 자신이 아니면
  650. if (event.hover != this.getId())
  651. {
  652. // 이전 over는 mouseout
  653. if (!event.hover.isEmpty())
  654. {
  655. this.dispatch("onmouseenter");
  656. var objOldOver = document.allElement.item(event.hover);
  657. if (null != objOldOver)
  658. {
  659. objOldOver = objOldOver.getElement();
  660. objOldOver.dispatch("onmouseout");
  661. }
  662. }
  663. this.dispatch("onmouseover");
  664. // TODO IFrame 대응
  665. }
  666. }
  667. };
  668. XFormsControl.prototype.onMouseOut = function (event)
  669. {
  670. if (event.target == this.getId() && this.getState(FCS_HOVER))
  671. {
  672. this.setState(FCS_HOVER, false, event);
  673. }
  674. };
  675. XFormsControl.prototype.onMouseOver = function (event)
  676. {
  677. if (event.target == this.getId())
  678. {
  679. if (window.bDragDrop)
  680. {
  681. this.dispatch("ondragover");
  682. }
  683. this.dispatch("oncursor");
  684. if (!this.getState(FCS_HOVER))
  685. {
  686. this.setState(FCS_HOVER, true, event);
  687. }
  688. }
  689. };
  690. XFormsControl.prototype.onNext = function (event)
  691. {
  692. if (event.target == this.getId())
  693. {
  694. var arTabIndex = model.getTabIndex();
  695. var nIndex = arTabIndex.find(this);
  696. if (0 > nIndex)
  697. {
  698. if (null != this.parent)
  699. {
  700. nIndex = arTabIndex.find(this.parent);
  701. }
  702. }
  703. if (-1 <= nIndex)
  704. {
  705. var objNext;
  706. if (nIndex + 1 < arTabIndex.length)
  707. {
  708. objNext = arTabIndex[nIndex + 1];
  709. }
  710. else
  711. {
  712. objNext = arTabIndex[0];
  713. }
  714. if (null != objNext && (objNext.id != event.target))
  715. {
  716. window.setFocus(objNext.id);
  717. }
  718. else
  719. {
  720. window.setFocus("body");
  721. }
  722. }
  723. // 실제 브라우저 이벤트를 막는다.
  724. if (event.m_browserEvent.cancelable === undefined)
  725. {
  726. event.m_browserEvent.returnValue = false;
  727. }
  728. else
  729. {
  730. if (event.m_browserEvent.cancelable)
  731. {
  732. event.m_browserEvent.preventDefault ();
  733. }
  734. }
  735. this.dispatch("xforms-next");
  736. }
  737. };
  738. XFormsControl.prototype.onPrevious = function (event)
  739. {
  740. if (event.target == this.getId())
  741. {
  742. var arTabIndex = model.getTabIndex();
  743. var nIndex = arTabIndex.find(this);
  744. if (0 > nIndex)
  745. {
  746. if (null != this.parent)
  747. {
  748. nIndex = arTabIndex.find(this.parent);
  749. }
  750. }
  751. var objPrev;
  752. if (0 <= nIndex - 1)
  753. {
  754. objPrev = arTabIndex[nIndex - 1];
  755. }
  756. else if (0 <= arTabIndex.length - 1)
  757. {
  758. objPrev = arTabIndex[arTabIndex.length - 1];
  759. }
  760. if (null != objPrev && (objPrev.id != event.target))
  761. {
  762. window.setFocus(objPrev.id);
  763. }
  764. else
  765. {
  766. window.setFocus("body");
  767. }
  768. // 실제 브라우저 이벤트를 막는다.
  769. if (event.m_browserEvent.cancelable === undefined)
  770. {
  771. event.m_browserEvent.returnValue = false;
  772. }
  773. else
  774. {
  775. if (event.m_browserEvent.cancelable)
  776. {
  777. event.m_browserEvent.preventDefault ();
  778. }
  779. }
  780. this.dispatch("xforms-previous");
  781. }
  782. };
  783. XFormsControl.prototype.onScroll = function (event)
  784. {
  785. };
  786. XFormsControl.prototype.onScrollDown = function (event)
  787. {
  788. };
  789. XFormsControl.prototype.onScrollUp = function (event)
  790. {
  791. };
  792. XFormsControl.prototype.onMouseWheel = function (event)
  793. {
  794. };
  795. XFormsControl.prototype.onInvalid = function (event)
  796. {
  797. };
  798. XFormsControl.prototype.onOptional = function (event)
  799. {
  800. };
  801. XFormsControl.prototype.onReadonly = function (event)
  802. {
  803. };
  804. XFormsControl.prototype.onReadWrite = function (event)
  805. {
  806. };
  807. XFormsControl.prototype.onRequired = function (event)
  808. {
  809. };
  810. XFormsControl.prototype.onvalid = function (event)
  811. {
  812. };
  813. XFormsControl.prototype.onDragStart = function (event)
  814. {
  815. if ("false" != this.getAttribute("dragmode"))
  816. {
  817. event.drag = this.getId();
  818. if (event.target == event.currentTarget)
  819. {
  820. }
  821. }
  822. };
  823. XFormsControl.prototype.onDragEnter = function (event)
  824. {
  825. };
  826. XFormsControl.prototype.onDragOver = function (event)
  827. {
  828. };
  829. XFormsControl.prototype.onDragLeave = function (event)
  830. {
  831. };
  832. XFormsControl.prototype.onDrop = function (event)
  833. {
  834. };
  835. XFormsControl.prototype.setState = function (nState, bSet, event, bRedraw, bCallChange)
  836. {
  837. if (bSet)
  838. {
  839. switch(nState)
  840. {
  841. case FCS_HOVER : event.hover = this.getId(); this.setAttribute("hover", true); break;
  842. case FCS_DOWN : event.down = this.getId(); this.setAttribute("down", true); break;
  843. case FCS_FOCUS : event.focus = this.getId(); this.setAttribute("focus", true); break;
  844. case FCS_SELECT : this.attribute["select"] = "true"; break;
  845. case FCS_DISABLE : this.attribute["disable"] = "true"; break;
  846. }
  847. this.m_dwState |= nState;
  848. }
  849. else
  850. {
  851. switch(nState)
  852. {
  853. case FCS_HOVER : event.hover = ""; this.setAttribute("hover", false); break;
  854. case FCS_DOWN : event.down = ""; this.setAttribute("down", false); break;
  855. case FCS_FOCUS : event.focus = ""; this.setAttribute("focus", false); break;
  856. case FCS_SELECT : this.attribute["select"] = "false"; break;
  857. case FCS_DISABLE : this.attribute["disable"] = "false"; break;
  858. }
  859. this.m_dwState &= ~nState;
  860. }
  861. this.resetStyle(nState, bSet);
  862. if (bCallChange)
  863. {
  864. this.onStateChange(nState, bSet);
  865. }
  866. };
  867. XFormsControl.prototype.resetStyle = function (nState, bSet)
  868. {
  869. var htStyle = null;
  870. if (FCS_NORMAL == nState)
  871. {
  872. htStyle = this.attribute;
  873. }
  874. else
  875. {
  876. if (nState & FCS_DISABLE)
  877. {
  878. if (nState & FCS_SELECT)
  879. {
  880. htStyle = this.m_htSelectStyle;
  881. }
  882. if (nState & FCS_DISABLE)
  883. {
  884. htStyle = this.m_htDisableStyle;
  885. }
  886. }
  887. else
  888. {
  889. if (nState & FCS_HOVER)
  890. {
  891. htStyle = this.m_htHoverStyle;
  892. }
  893. if (nState & FCS_SELECT)
  894. {
  895. htStyle = this.m_htSelectStyle;
  896. }
  897. if (nState & FCS_FOCUS)
  898. {
  899. htStyle = this.m_htFocusStyle;
  900. }
  901. if (nState & FCS_DOWN)
  902. {
  903. htStyle = this.m_htDownStyle;
  904. }
  905. }
  906. }
  907. if (null != htStyle)
  908. {
  909. for (var strKey in htStyle)
  910. {
  911. var strValue = htStyle[strKey];
  912. if (!bSet)
  913. {
  914. strValue = this.attribute[strKey];
  915. }
  916. if (STYLE_LIST[strKey])
  917. {
  918. HtmlLib.setStyle(this.m_heControl, strKey, strValue);
  919. }
  920. }
  921. }
  922. else
  923. {
  924. if (null != this.m_heControl)
  925. {
  926. if (nState & FCS_DISABLE)
  927. {
  928. var nConStatus = this.getEditControls();
  929. if (1 == nConStatus)
  930. {
  931. if (!bSet)
  932. {
  933. this.m_heControl.style.backgroundColor = null != this.attribute["background-color"] ?this.attribute["background-color"] : "#ffffff";
  934. }
  935. else
  936. {
  937. this.m_heControl.style.backgroundColor = null != this.attribute["disable.background-color"] ? this.attribute["disable.background-color"] : "#EBEBE4";
  938. }
  939. }
  940. else if (2 == nConStatus)
  941. {
  942. if (!bSet)
  943. {
  944. this.m_heControl.style.color = null != this.attribute["color"] ?this.attribute["color"] : "#000000";
  945. }
  946. else
  947. {
  948. this.m_heControl.style.color = null != this.attribute["disable.background-color"] ? this.attribute["disable.background-color"] : "#EBEBE4";
  949. }
  950. }
  951. }
  952. }
  953. }
  954. };
  955. XFormsControl.prototype.getState = function (nState)
  956. {
  957. return this.m_dwState & nState;
  958. };
  959. XFormsControl.prototype.isFocusValid = function (nState)
  960. {
  961. var heParent = this.m_heControl;
  962. while (null != heParent && "HE_body" != heParent.id)
  963. {
  964. if ("hidden" == heParent.style.visibility || "none" == heParent.style.display || true == heParent.disabled)
  965. {
  966. return false;
  967. }
  968. if (is_firefox)
  969. {
  970. heParent = heParent.parentNode;
  971. }
  972. else
  973. {
  974. heParent = heParent.parentElement;
  975. }
  976. }
  977. return true;
  978. };
  979. XFormsControl.prototype.getEditControls = function ()
  980. {
  981. // CON_TPYE_EDIT = 1;
  982. //CON_TPYE_VIEW = 2;
  983. //CON_TPYE_BUTTON = 3;
  984. var strElementName = this.elementName;
  985. if ("xforms:input" == strElementName || "xforms:comboinput" == strElementName ||
  986. "xforms:output" == strElementName || "xforms:secret" == strElementName ||
  987. "xforms:textarea" == strElementName)
  988. {
  989. strElementName = null;
  990. return CON_TPYE_EDIT;
  991. }
  992. else if ("xforms:select1" == strElementName || "minimal" == this.attribute["appearance"])
  993. {
  994. strElementName = null;
  995. return CON_TPYE_EDIT;
  996. }
  997. else if ("xforms:button" == strElementName)
  998. {
  999. strElementName = null;
  1000. return CON_TPYE_BUTTON;
  1001. }
  1002. else
  1003. {
  1004. strElementName = null;
  1005. return CON_TPYE_VIEW;
  1006. }
  1007. };
  1008. XFormsControl.prototype.defaultAction = function (strEventName, event)
  1009. {
  1010. if("onaccesskey" == strEventName)
  1011. {
  1012. this.dispatch("DOMActivate");
  1013. this.dispatch("xforms-activate");
  1014. }
  1015. if (!this.isEnable())
  1016. {
  1017. return;
  1018. }
  1019. switch(strEventName)
  1020. {
  1021. case "onmouseactivate" : this.onMouseActivate(event); break;
  1022. case "onmousemove" : this.onMouseMove(event); break;
  1023. case "onmousedown" : this.onMouseDown(event); break;
  1024. case "onmouseenter" : this.onMouseEnter(event); break;
  1025. case "onmouseup" : this.onMouseUp(event); break;
  1026. case "oncursor" : this.onCursor(event); break;
  1027. case "onmouseover" : this.onMouseOver(event); break;
  1028. case "onmouseout" : this.onMouseOut(event); break;
  1029. case "onclick" : this.onClick(event); break;
  1030. case "ondelayclick" : this.onDelayClick(event); break;
  1031. case "ondblclick" : this.onDblClick(event); break;
  1032. case "onfocus" : this.onFocus(event); break;
  1033. case "onblur" : this.onBlur(event); break;
  1034. case "onkeypress" : this.onKeyPress(event); break;
  1035. case "onkeydown" : this.onKeyDown(event); break;
  1036. case "onkeyup" : this.onKeyUp(event); break;
  1037. case "onscrolldown" : this.onScrollDown(event); break;
  1038. case "onscrollup" : this.onScrollUp(event); break;
  1039. case "onscrollpagedown" : this.onScrollPageDown(event); break;
  1040. case "onscrollpageup" : this.onScrollPageUp(event); break;
  1041. case "onscrollpos" : this.onScrollPos(event); break;
  1042. case "onscrolltrack" : this.onScrollTrack(event); break;
  1043. case "onscrolltrackdown": this.onScrollTrackDown(event);break;
  1044. case "onscrolltrackup" : this.onScrollTrackUp(event); break;
  1045. case "onscroll" : this.onScroll(event); break;
  1046. case "onmousewheel" : this.onMouseWheel(event); break;
  1047. case "ontimer" : this.onTimer(event); break;
  1048. case "onnext" : this.onNext(event); break;
  1049. case "onprevious" : this.onPrevious(event); break;
  1050. case "xforms-invalid" : this.onInvalid(event); break;
  1051. case "xforms-optional" : this.onOptional(event); break;
  1052. case "xforms-readonly" : this.onReadonly(event); break;
  1053. case "xforms-readwrite" : this.onReadWrite(event); break;
  1054. case "xforms-required" : this.onRequired(event); break;
  1055. case "xforms-valid" : this.onvalid(event); break;
  1056. case "xforms-enabled" : this.onEnabled(event); break;
  1057. case "xforms-disabled" : this.onDisabled(event); break;
  1058. case "ondragenter" : this.onDragEnter(event); break;
  1059. case "ondragleave" : this.onDragLeave(event); break;
  1060. case "ondrop" : this.onDrop(event); break;
  1061. case "ondragover" : this.onDragOver(event); break;
  1062. case "ondragstart" : this.onDragStart(event); break;
  1063. case "onscrollmax" : this.onScrollMax(event); break;
  1064. case "onscrollmin" : this.onScrollMin(event); break;
  1065. }
  1066. };
  1067. XFormsControl.prototype.getClientLeft = function (bCalcScroll)
  1068. {
  1069. var nClientLeft = 0;
  1070. var heOffsetParent = this.m_heControl;
  1071. while (null != heOffsetParent)
  1072. {
  1073. nClientLeft += heOffsetParent.offsetLeft;
  1074. if (heOffsetParent != this.m_heControl )
  1075. {
  1076. nClientLeft += heOffsetParent.clientLeft;
  1077. }
  1078. if (bCalcScroll && heOffsetParent != document.body)
  1079. {
  1080. nClientLeft -= (is_android ? 0 : heOffsetParent.scrollLeft);
  1081. }
  1082. heOffsetParent = heOffsetParent.offsetParent;
  1083. }
  1084. return nClientLeft;
  1085. };
  1086. XFormsControl.prototype.getClientTop = function (bCalcScroll)
  1087. {
  1088. var nClientTop = 0;
  1089. var heOffsetParent = this.m_heControl;
  1090. while (null != heOffsetParent)
  1091. {
  1092. nClientTop += heOffsetParent.offsetTop;
  1093. if (heOffsetParent != this.m_heControl)
  1094. {
  1095. nClientTop += heOffsetParent.clientTop;
  1096. }
  1097. if (bCalcScroll&& heOffsetParent != document.body)
  1098. {
  1099. nClientTop -= (is_android ? 0 : heOffsetParent.scrollTop);
  1100. }
  1101. heOffsetParent = heOffsetParent.offsetParent;
  1102. }
  1103. return nClientTop;
  1104. };
  1105. XFormsControl.prototype.preTranslateEvent = function (event)
  1106. {
  1107. var nScrolledTargetX = event.targetX;
  1108. var nScrolledTargetY = event.targetY;
  1109. var heOffsetParent = null;
  1110. var clAllItem = document.allElement;
  1111. if (null != clAllItem.item(event.target))
  1112. {
  1113. //컨트롤의 존재 유무를 제어한다.
  1114. heOffsetParent = clAllItem.item(event.target).m_heControl;
  1115. }
  1116. var strParentId = null != heOffsetParent ? heOffsetParent.getAttribute("id") : null;
  1117. if (strParentId)
  1118. {
  1119. strParentId = strParentId.replace("HE_", "");
  1120. }
  1121. while (null != heOffsetParent && strParentId != event.currentTarget)
  1122. {
  1123. nScrolledTargetX += heOffsetParent.offsetLeft;
  1124. nScrolledTargetY += heOffsetParent.offsetTop;
  1125. if (strParentId != event.target)
  1126. {
  1127. nScrolledTargetX = nScrolledTargetX + heOffsetParent.clientLeft - heOffsetParent.scrollLeft;
  1128. nScrolledTargetY = nScrolledTargetY + heOffsetParent.clientLeft - heOffsetParent.scrollTop;
  1129. }
  1130. heOffsetParent = heOffsetParent.offsetParent;
  1131. if (heOffsetParent)
  1132. {
  1133. strParentId = heOffsetParent.getAttribute("id");
  1134. if (strParentId)
  1135. {
  1136. strParentId = strParentId.replace("HE_", "");
  1137. }
  1138. }
  1139. }
  1140. if (null != heOffsetParent && event.target != event.currentTarget)
  1141. {
  1142. nScrolledTargetX -= heOffsetParent.scrollLeft;
  1143. nScrolledTargetY -= heOffsetParent.scrollTop;
  1144. }
  1145. event.x = nScrolledTargetX;
  1146. event.y = nScrolledTargetY;
  1147. };
  1148. /**
  1149. * jquery Effects hide()
  1150. */
  1151. XFormsControl.prototype.hide = function ()
  1152. {
  1153. var arArg = arguments;
  1154. switch (arArg.length)
  1155. {
  1156. case 1:
  1157. {
  1158. $(this.m_heControl).hide(arArg[0]);
  1159. break;
  1160. }
  1161. case 2:
  1162. {
  1163. $(this.m_heControl).hide(arArg[0] ,arArg[1]);
  1164. break;
  1165. }
  1166. case 3:
  1167. {
  1168. $(this.m_heControl).hide(arArg[0], arArg[1], arArg[2]);
  1169. break;
  1170. }
  1171. default:
  1172. {
  1173. $(this.m_heControl).hide();
  1174. break;
  1175. }
  1176. }
  1177. };
  1178. /**
  1179. * jquery Effects show()
  1180. */
  1181. XFormsControl.prototype.show = function ()
  1182. {
  1183. var arArg = arguments;
  1184. switch (arArg.length)
  1185. {
  1186. case 1:
  1187. {
  1188. $(this.m_heControl).show(arArg[0]);
  1189. break;
  1190. }
  1191. case 2:
  1192. {
  1193. $(this.m_heControl).show(arArg[0] ,arArg[1]);
  1194. break;
  1195. }
  1196. case 3:
  1197. {
  1198. $(this.m_heControl).show(arArg[0], arArg[1], arArg[2]);
  1199. break;
  1200. }
  1201. default:
  1202. {
  1203. $(this.m_heControl).show();
  1204. break;
  1205. }
  1206. }
  1207. };
  1208. /**
  1209. * jquery Effects animate()
  1210. */
  1211. XFormsControl.prototype.animate = function ()
  1212. {
  1213. var arArg = arguments;
  1214. switch (arArg.length)
  1215. {
  1216. case 1:
  1217. {
  1218. $(this.m_heControl).animate(arArg[0]);
  1219. break;
  1220. }
  1221. case 2:
  1222. {
  1223. $(this.m_heControl).animate(arArg[0] ,arArg[1]);
  1224. break;
  1225. }
  1226. case 3:
  1227. {
  1228. $(this.m_heControl).animate(arArg[0], arArg[1], arArg[2]);
  1229. break;
  1230. }
  1231. case 4:
  1232. {
  1233. $(this.m_heControl).animate(arArg[0], arArg[1], arArg[2], arArg[3]);
  1234. break;
  1235. }
  1236. default:
  1237. {
  1238. $(this.m_heControl).animate();
  1239. break;
  1240. }
  1241. }
  1242. };
  1243. XFormsControl.createAttribute = function (xnHtmlNode, clAttribute)
  1244. {
  1245. for (var strKey in clAttribute.m_htCollection)
  1246. {
  1247. if (strKey == "id")
  1248. {
  1249. xnHtmlNode.setAttribute("id", "HE_" + clAttribute.item("id"));
  1250. }
  1251. else if (strKey == "disabled")
  1252. {
  1253. continue;
  1254. }
  1255. else if (strKey == "clsid")
  1256. {
  1257. xnHtmlNode.setAttribute("CLASSID", "clsid:" + clAttribute.item("clsid"));
  1258. }
  1259. else
  1260. {
  1261. if (STYLE_LIST[strKey])
  1262. {
  1263. HtmlLib.setStyle(xnHtmlNode, strKey, clAttribute.item(strKey));
  1264. }
  1265. else
  1266. {
  1267. xnHtmlNode.setAttribute(strKey, clAttribute.item(strKey));
  1268. }
  1269. }
  1270. }
  1271. xnHtmlNode.style.position = "absolute";
  1272. xnHtmlNode = XFormsElement.createAttribute(xnHtmlNode, clAttribute);
  1273. return xnHtmlNode;
  1274. };