XFormsBind.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. XFormsBind.prototype = new XFormsElement;
  2. function XFormsBind (strParentId, strId, strTag, strRef, strCalculate, strConstraint, strReadonly, strRelevant, strRequired, strType, strScript)
  3. {
  4. if (!strId)
  5. {
  6. return;
  7. }
  8. XFormsElement.call(this, strParentId, strId, strTag);
  9. /**
  10. * Attribute
  11. */
  12. this.attribute["ref"] = strRef;
  13. this.attribute["calculate"] = strCalculate;
  14. this.attribute["constraint"] = strConstraint;
  15. this.attribute["readonly"] = strReadonly;
  16. this.attribute["relevant"] = strRelevant;
  17. this.attribute["required"] = strRequired;
  18. this.attribute["type"] = strType;
  19. this.attribute["script"] = strScript;
  20. this.bindExecute();
  21. };
  22. /**
  23. * bind 수식을 실행한다
  24. * @return
  25. */
  26. XFormsBind.prototype.bindExecute = function ()
  27. {
  28. if ("" != this.attribute["ref"])
  29. {
  30. var strBaseRef = this.attribute["ref"];
  31. var xlRefNode = model.getInstancePart(null, strBaseRef);
  32. if (null != xlRefNode)
  33. {
  34. for (var i=0; i<xlRefNode.length; i++)
  35. {
  36. if ("" != this.attribute["calculate"]) // calculate
  37. {
  38. if(1 == xlRefNode.length)
  39. {
  40. model.setValue(this.attribute["ref"], String(this.bindCalculate(this.transRefDot("calculate"))));
  41. }
  42. else
  43. {
  44. XmlLib.setTextValue(xlRefNode.item(i), String(this.bindCalculate(this.attribute["calculate"], xlRefNode.item(i))));
  45. }
  46. }
  47. if ("" != this.attribute["constraint"]) // constraint
  48. {
  49. var nConstraintValue;
  50. if( 1 == xlRefNode.length)
  51. {
  52. var nConstraintValue = this.bindCalculate(this.transRefDot("calculate"));
  53. }
  54. else
  55. {
  56. var nConstraintValue = this.bindCalculate(this.attribute["calculate"], xlRefNode.item(i));
  57. }
  58. var bBindBoolValue = ("0" != nConstraintValue && "false" != nConstraintValue && "" != nReadonlyValue) ? true : false;
  59. if (bBindBoolValue)
  60. {
  61. var arKeyset = document.allElement.keys();
  62. for (var j=0; j<arKeyset; j++)
  63. {
  64. var strChildName = arKeyset[j];
  65. var objChild = document.allElement.item(strChildName);
  66. if (!(objChild instanceof XFormsBind))
  67. {
  68. if (this.attribute["ref"] == objChild.attribute["ref"])
  69. {
  70. if (this.booleanCheckType(this.attribute["type"], this.attribute["ref"]))
  71. {
  72. objChild.dispatch("xforms-valid");
  73. }
  74. else
  75. {
  76. objChild.dispatch("xforms-invalid");
  77. }
  78. }
  79. }
  80. }
  81. }
  82. else
  83. {
  84. var arKeyset = document.allElement.keys();
  85. for (var j=0; j<arKeyset.length; j++)
  86. {
  87. var strChildName = arKeyset[j];
  88. var objChild = document.allElement.item(strChildName);
  89. if (!(objChild instanceof XFormsBind))
  90. {
  91. if (this.attribute["ref"] == objChild.attribute["ref"])
  92. {
  93. objChild.dispatch("xforms-invalid");
  94. }
  95. }
  96. }
  97. }
  98. }
  99. if ("" != this.attribute["readonly"]) // readonly
  100. {
  101. var nReadonlyValue;
  102. if( 1 == xlRefNode.length)
  103. {
  104. var nReadonlyValue = this.bindCalculate(this.transRefDot("readonly"));
  105. }
  106. else
  107. {
  108. var nReadonlyValue = this.bindCalculate(this.attribute["readonly"], xlRefNode.item(i));
  109. }
  110. if ("0" != nReadonlyValue && "false" != nReadonlyValue && "" != nReadonlyValue)
  111. {
  112. var arKeyset = document.allElement.keys();
  113. for (var j=0; j<arKeyset.length; j++)
  114. {
  115. var strChildName = arKeyset[j];
  116. var objChild = document.allElement.item(strChildName);
  117. if (!(objChild instanceof XFormsBind))
  118. {
  119. if (this.attribute["ref"] == objChild.attribute["ref"])
  120. {
  121. objChild.dispatch("xforms-readonly");
  122. objChild.setDisabled(true);
  123. }
  124. }
  125. }
  126. }
  127. else
  128. {
  129. var arKeyset = document.allElement.keys();
  130. for (var j=0; j<arKeyset.length; j++)
  131. {
  132. var strChildName = arKeyset[j];
  133. var objChild = document.allElement.item(strChildName);
  134. if (!(objChild instanceof XFormsBind))
  135. {
  136. if (this.attribute["ref"] == objChild.attribute["ref"])
  137. {
  138. objChild.dispatch("xforms-readwrite");
  139. objChild.setDisabled(false);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. if ("" != this.attribute["relevant"]) //relevant
  146. {
  147. var nRelevantValue;
  148. if( 1 == xlRefNode.length)
  149. {
  150. var nRelevantValue = this.bindCalculate(this.transRefDot("relevant"));
  151. }
  152. else
  153. {
  154. var nRelevantValue = this.bindCalculate(this.attribute["relevant"], xlRefNode.item(i));
  155. }
  156. if ("0" != nRelevantValue && "false" != nRelevantValue && "" != nReadonlyValue)
  157. {
  158. var arKeyset = document.allElement.keys();
  159. for (var j=0; j<arKeyset.length; j++)
  160. {
  161. var strChildName = arKeyset[j];
  162. var objChild = document.allElement.item(strChildName);
  163. if (!(objChild instanceof XFormsBind))
  164. {
  165. if (this.attribute["ref"] == objChild.attribute["ref"])
  166. {
  167. objChild.setVisible(true);
  168. }
  169. }
  170. }
  171. }
  172. else
  173. {
  174. var arKeyset = document.allElement.keys();
  175. for (var j=0; j<arKeyset.length; j++)
  176. {
  177. var strChildName = arKeyset[j];
  178. var objChild = document.allElement.item(strChildName);
  179. if (!(objChild instanceof XFormsBind))
  180. {
  181. if (this.attribute["ref"] == objChild.attribute["ref"])
  182. {
  183. objChild.setVisible(false);
  184. }
  185. }
  186. }
  187. }
  188. }
  189. if ("" != this.attribute["required"]) // required
  190. {
  191. var nRequiredValue;
  192. if( 1 == xlRefNode.length)
  193. {
  194. var nRequiredValue = this.bindCalculate(this.transRefDot("required"));
  195. }
  196. else
  197. {
  198. var nRequiredValue = this.bindCalculate(this.attribute["required"], xlRefNode.item(i));
  199. }
  200. var bBindBoolValue = ("0" != nRequiredValue && "false" != nRequiredValue && "" != nReadonlyValue) ? true : false;
  201. if (bBindBoolValue)
  202. {
  203. var arKeyset = document.allElement.keys();
  204. for (var j=0; j<arKeyset.length; j++)
  205. {
  206. var strChildName = arKeyset[j];
  207. var objChild = document.allElement.item(strChildName);
  208. if (!(objChild instanceof XFormsBind))
  209. {
  210. if (this.attribute["ref"] == objChild.attribute["ref"])
  211. {
  212. if (null != objChild.attribute["required"] && objChild.attribute["required"])
  213. {
  214. objChild.dispatch("xforms-required");
  215. }
  216. else if (null != objChild.attribute["required"] && !objChild.attribute["required"])
  217. {
  218. objChild.dispatch("xforms-optional");
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. this.attribute["ref"] = strBaseRef;
  228. if ("" != this.attribute["script"]) //script
  229. {
  230. try
  231. {
  232. window.eval(this.attribute["script"]);
  233. }
  234. catch (e)
  235. {
  236. return ;
  237. }
  238. }
  239. }
  240. };
  241. XFormsBind.prototype.transRefDot = function (strBindAttribute)
  242. {
  243. var strRef = this.attribute["ref"];
  244. var strBindValue = this.attribute[strBindAttribute];
  245. strRef = strRef.substring(0, strRef.lastIndexOf("/")+1);
  246. strBindValue = strBindValue.replace(/\.\.\//g, strRef);
  247. return strBindValue;
  248. };
  249. /**
  250. * Calculate 함수 구현
  251. * @return
  252. */
  253. XFormsBind.prototype.bindCalculate = function (strBindAttribute, xnNode)
  254. {
  255. return xPathOperation(strBindAttribute, xnNode);
  256. };
  257. XFormsBind.prototype.booleanCheckType = function (strType, strRef)
  258. {
  259. var strValue = model.getValue(strRef);
  260. switch (strType)
  261. {
  262. case "xsd:anyURI":
  263. {
  264. return true;
  265. break;
  266. }
  267. case "xsd:base64Binary":
  268. {
  269. break;
  270. }
  271. case "xsd:boolean":
  272. {
  273. if ("true" == strValue || "1" == strValue)
  274. {
  275. return true;
  276. }
  277. else
  278. {
  279. return false;
  280. }
  281. break;
  282. }
  283. case "xsd:byte":
  284. {
  285. if ("" != strValue)
  286. {
  287. return true;
  288. }
  289. else
  290. {
  291. return false;
  292. }
  293. break;
  294. }
  295. case "xsd:date":
  296. {
  297. break;
  298. }
  299. case "xsd:dateTime":
  300. {
  301. break;
  302. }
  303. case "xsd:decimal":
  304. {
  305. break;
  306. }
  307. case "xsd:double":
  308. {
  309. if (Number (strValue))
  310. {
  311. return true;
  312. }
  313. else
  314. {
  315. return false;
  316. }
  317. break;
  318. }
  319. case "xsd:float":
  320. {
  321. if (Number (strValue))
  322. {
  323. return true;
  324. }
  325. else
  326. {
  327. return false;
  328. }
  329. break;
  330. }
  331. case "xsd:gDay":
  332. {
  333. break;
  334. }
  335. case "xsd:gMonth":
  336. {
  337. break;
  338. }
  339. case "xsd:gMonthDay":
  340. {
  341. break;
  342. }
  343. case "xsd:gYear":
  344. {
  345. break;
  346. }
  347. case "xsd:gYearMonth":
  348. {
  349. break;
  350. }
  351. case "xsd:hexBinary":
  352. {
  353. break;
  354. }
  355. case "xsd:int":
  356. {
  357. if (Number (strValue))
  358. {
  359. return true;
  360. }
  361. else
  362. {
  363. return false;
  364. }
  365. break;
  366. }
  367. case "xsd:integer":
  368. {
  369. if (Number (strValue))
  370. {
  371. return true;
  372. }
  373. else
  374. {
  375. return false;
  376. }
  377. break;
  378. }
  379. case "xsd:long":
  380. {
  381. if (Number (strValue))
  382. {
  383. return true;
  384. }
  385. else
  386. {
  387. return false;
  388. }
  389. break;
  390. }
  391. case "xsd:negativeInteger":
  392. {
  393. break;
  394. }
  395. case "xsd:nonNegativeInteger":
  396. {
  397. break;
  398. }
  399. case "xsd:nonPositiveInteger":
  400. {
  401. break;
  402. }
  403. case "xsd:positiveInteger":
  404. {
  405. break;
  406. }
  407. case "xsd:short":
  408. {
  409. break;
  410. }
  411. case "xsd:string":
  412. {
  413. if ("" != String(strValue))
  414. {
  415. if (!Number (strValue))
  416. {
  417. return true;
  418. }
  419. else
  420. {
  421. return false;
  422. }
  423. }
  424. else
  425. {
  426. return false;
  427. }
  428. break;
  429. }
  430. case "xsd:time":
  431. {
  432. break;
  433. }
  434. case "xsd:unsignedByte":
  435. {
  436. break;
  437. }
  438. case "xsd:unsignedInt":
  439. {
  440. break;
  441. }
  442. case "xsd:unsignedLong":
  443. {
  444. break;
  445. }
  446. case "xsd:unsignedShort":
  447. {
  448. break;
  449. }
  450. default :
  451. {
  452. return true;
  453. break;
  454. }
  455. }
  456. };
  457. XFormsBind.prototype.setAttribute = function (strName, objValue)
  458. {
  459. XFormsElement.prototype.setAttribute.call(this, strName, objValue);
  460. switch (strName)
  461. {
  462. case "ref":
  463. {
  464. this.attribute["ref"] = objValue;
  465. break;
  466. }
  467. case "calculate":
  468. {
  469. this.attribute["calculate"] = objValue;
  470. break;
  471. }
  472. case "constraint":
  473. {
  474. this.attribute["constraint"] = objValue;
  475. break;
  476. }
  477. case "readonly":
  478. {
  479. this.attribute["readonly"] = objValue;
  480. break;
  481. }
  482. case "relevant":
  483. {
  484. this.attribute["relevant"] = objValue;
  485. break;
  486. }
  487. case "required":
  488. {
  489. this.attribute["required"] = objValue;
  490. break;
  491. }
  492. case "type":
  493. {
  494. this.attribute["type"] = objValue;
  495. break;
  496. }
  497. case "script":
  498. {
  499. this.attribute["script"] = objValue;
  500. break;
  501. }
  502. }
  503. };
  504. // TODO createChild 구현중 2011. 03. 15. 박현우 /////////////////////////////////////////////////////////////////////////////////////
  505. XFormsBind.create = function (strParentId, clAttribute, strStyle)
  506. {
  507. // // 메인노드 생성
  508. // var objBind = XFormsModel.createMainNode(clAttribute);
  509. // var xnParent = document.getElementById("HE_"+strParentId);
  510. // xnParent.appendChild(objBind);
  511. //
  512. // objBind = XFormsModel.createSubNodes(objBind, clAttribute);
  513. // // object 생성
  514. var xnBind = null;
  515. return XFormsBind.createObject(strParentId, xnBind, clAttribute, strStyle);
  516. };
  517. XFormsBind.createObject = function (strParentId, xnBind, clAttribute, strStyle)
  518. {
  519. var strId = "";
  520. var strTag = "xforms:bind";
  521. var strCalculate = "";
  522. var strConstraint = "";
  523. var strReadOnly = "";
  524. var strRef = "";
  525. var strRelevant = "";
  526. var strType = "";
  527. var strScript = "";
  528. var strUserDefineAttrib = "";
  529. for (var i=0; i<clAttribute.count(); i++)
  530. {
  531. var strAttributeName = clAttribute.keys()[i];
  532. switch (strAttributeName)
  533. {
  534. case "id" :
  535. {
  536. strId = clAttribute.item(strAttributeName);
  537. break;
  538. }
  539. case "calculate" :
  540. {
  541. strCalculate = clAttribute.item(strAttributeName);
  542. break;
  543. }
  544. case "constraint" :
  545. {
  546. strConstraint = clAttribute.item(strAttributeName);
  547. break;
  548. }
  549. case "readonly" :
  550. {
  551. strReadOnly = clAttribute.item(strAttributeName);
  552. break;
  553. }
  554. case "ref" :
  555. {
  556. strRef = clAttribute.item(strAttributeName);
  557. break;
  558. }
  559. case "relevant" :
  560. {
  561. strRelevant = clAttribute.item(strAttributeName);
  562. break;
  563. }
  564. case "type" :
  565. {
  566. strType = clAttribute.item(strAttributeName);
  567. break;
  568. }
  569. case "script" :
  570. {
  571. strScript = clAttribute.item(strAttributeName);
  572. break;
  573. }
  574. default :
  575. {
  576. if (!STYLE_LIST[strAttributeName])
  577. {
  578. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  579. }
  580. break;
  581. }
  582. }
  583. }
  584. var objBind = new XFormsBind(strParentId, strId, strTag, strRef, strCalculate, strConstraint, strReadOnly, strRelevant, strRequired, strType, strScript, strUserDefineAttrib);
  585. return objBind;
  586. };
  587. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////