XFormsModel.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231
  1. XFormsModel.prototype = new XFormsElement;
  2. function XFormsModel (strParentId, bAutodata, strID, strTag)
  3. {
  4. if (!strID)
  5. {
  6. return;
  7. }
  8. XFormsElement.call(this, strParentId, strID, strTag);
  9. // Attribute
  10. this.attribute["autocdata"] = bAutodata = false;
  11. // Property
  12. this.autocdata;
  13. this.instances = new Collection();
  14. this.property = new Hashtable();
  15. this.propertyReg;
  16. this.registry;
  17. this.m_objTabIndex = new Array();
  18. this.m_objHttpClient = new HttpClient();
  19. this.m_objCurrentSubmission;
  20. this.m_bDoneUnload = false;
  21. this.m_hmInstanceData = null;
  22. this.m_bHasUploadFile = false;
  23. this.m_strSessionId = "";
  24. this.m_resetRoot = null;
  25. };
  26. XFormsModel.prototype.getId = function ()
  27. {
  28. return this.id;
  29. };
  30. XFormsModel.prototype.addLog = function ()
  31. {
  32. //TODO
  33. window.alert("model.addLog() is not avilable.");
  34. };
  35. XFormsModel.prototype.addScript = function (strScript)
  36. {
  37. // <script> Element 를 생성한다.
  38. var heScript = document.createElement("script");
  39. heScript.setAttribute("type", "text/javascript");
  40. // 스크립트 내용을 쓴다.
  41. heScript.text = strScript;
  42. // HEAD에 스크립트를 추가한다.
  43. var heHead = document.firstChild.firstChild;
  44. heHead.appendChild(heScript);
  45. };
  46. XFormsModel.prototype.alert = function (strMessage, strTitle, nType)
  47. {
  48. //TODO
  49. window.alert(strMessage);
  50. };
  51. XFormsModel.prototype.base64decode = function (strData)
  52. {
  53. return Base64.decode(strData);
  54. };
  55. XFormsModel.prototype.base64decodefile = function ()
  56. {
  57. window.alert("model.base64decodefile() is not available.");
  58. };
  59. XFormsModel.prototype.base64encode = function (strData)
  60. {
  61. return Base64.encode(strData);
  62. };
  63. XFormsModel.prototype.base64encodefile = function ()
  64. {
  65. window.alert("model.base64encodefile() is not available.");
  66. };
  67. XFormsModel.prototype.close = function ()
  68. {
  69. window.close();
  70. };
  71. XFormsModel.prototype.copyNode = function (strDest, strSource)
  72. {
  73. var xnDest = null;
  74. if ("string" == typeof(strDest))
  75. {
  76. xnDest = this.getInstanceSinglePart(null, strDest);
  77. }
  78. else
  79. {
  80. // String이 아니면 Node가 바로 들어 올 수 있다.
  81. xnDest = strDest;
  82. }
  83. var xnSource = null;
  84. if ("string" == typeof(strSource))
  85. {
  86. xnSource = this.getInstanceSinglePart(null, strSource);
  87. }
  88. else
  89. {
  90. // String이 아니면 Node가 바로 들어 올 수 있다.
  91. xnSource = strSource;
  92. }
  93. if (null != xnDest && null != xnSource)
  94. {
  95. // Dest의 자식을 모두 지운다.
  96. var xlChild = xnDest.childNodes;
  97. if (null != xlChild)
  98. {
  99. for (var i=xlChild.length-1; i>=0; i--)
  100. {
  101. var xnChild = xlChild[i];
  102. if (null != xnChild)
  103. {
  104. xnDest.removeChild(xlChild[i]);
  105. }
  106. }
  107. }
  108. // Source의 자식을 Clone 하여 Dest에 붙인다.
  109. xlChild = xnSource.childNodes;
  110. if (null != xlChild)
  111. {
  112. for (var i=0; i<xlChild.length; i++)
  113. {
  114. var xnChild = xlChild[i];
  115. if (null != xnChild)
  116. {
  117. xnDest.appendChild(xnChild.cloneNode(true));
  118. }
  119. }
  120. }
  121. }
  122. };
  123. XFormsModel.prototype.destroy = function (strTarget)
  124. {
  125. var xnTarget = null;
  126. if ("string" == typeof(strTarget))
  127. {
  128. xnTarget = this.getInstanceSinglePart(null, strTarget);
  129. }
  130. else
  131. {
  132. // String이 아니면 Node가 바로 들어 올 수 있다.
  133. xnTarget = strTarget;
  134. }
  135. if (null != xnTarget)
  136. {
  137. var xnParent = xnTarget.parentNode;
  138. if (null != xnParent)
  139. {
  140. xnParent.removeChild(xnTarget);
  141. }
  142. }
  143. };
  144. XFormsModel.prototype.download = function ()
  145. {
  146. window.alert("model.download() is not available.");
  147. };
  148. XFormsModel.prototype.downloadFile = function (strURL)
  149. {
  150. window.open(strURL, "_blank", "toolbar=no, location=no, resizable=yes, scrollbars=yes, status=no, menubar=no");
  151. };
  152. XFormsModel.prototype.duplicate = function (strRef, strOrigin, strBefore)
  153. {
  154. var xnRef = null;
  155. if ("string" == typeof(strRef))
  156. {
  157. xnRef = this.getInstanceSinglePart(null, strRef);
  158. }
  159. else
  160. {
  161. // String이 아니면 Node가 바로 들어 올 수 있다.
  162. xnRef = strRef;
  163. }
  164. var xnOrigin = null;
  165. if ("string" == typeof(strOrigin))
  166. {
  167. xnOrigin = this.getInstanceSinglePart(null, strOrigin);
  168. }
  169. else
  170. {
  171. // String이 아니면 Node가 바로 들어 올 수 있다.
  172. xnOrigin = strOrigin;
  173. }
  174. if (null != xnRef && null != xnOrigin)
  175. {
  176. var xnClone = xnOrigin.cloneNode(true);
  177. if (null == strBefore || strBefore.isEmpty())
  178. {
  179. xnRef.appendChild(xnClone);
  180. }
  181. else
  182. {
  183. var xnExist = XmlLib.selectSingleNode(xnRef, strBefore);
  184. if (null != xnRef)
  185. {
  186. xnRef.insertBefore(xnClone, xnExist);
  187. }
  188. }
  189. }
  190. };
  191. XFormsModel.prototype.getFocus = function ()
  192. {
  193. return window.getFocus();
  194. };
  195. /**
  196. * ref 에 해당하는 노드 값을 반환한다.
  197. * @return
  198. */
  199. XFormsModel.prototype.getValue = function (strRef)
  200. {
  201. if ("string" == typeof(strRef))
  202. {
  203. //TODO root 로 시작하는지 instance 로 시작하는지 구분해야한다.
  204. //TODO strRef가 "/root/example"일때와 root.exaple일때 구분해야한다.
  205. var objInstance = this.getInstance();
  206. if (null != objInstance)
  207. {
  208. var xnRoot = objInstance.documentElement;
  209. if (null != xnRoot)
  210. {
  211. var xnNode = XmlLib.selectSingleNode(xnRoot, strRef);
  212. if (null != xnNode)
  213. {
  214. return XmlLib.getTextValue(xnNode);
  215. }
  216. }
  217. }
  218. return "";
  219. }
  220. else
  221. {
  222. return XmlLib.getTextValue(strRef);
  223. }
  224. };
  225. XFormsModel.prototype.getXPathValue = function (strOperation)
  226. {
  227. if (is_ie)
  228. {
  229. return xPathOperation(strOperation)
  230. }
  231. else
  232. {
  233. var objXpathResult = instance1.documentElement.evaluate(strOperation,instance1.documentElement,null,XPathResult.STRING_TYPE,null);
  234. return objXpathResult.stringValue;
  235. }
  236. };
  237. XFormsModel.prototype.makeNode = function (strRef)
  238. {
  239. if (null == strRef || "" == strRef)
  240. {
  241. return false;
  242. }
  243. strRef = strRef.trim();
  244. var strInstance = "";
  245. var bInstance = false;
  246. if (0 == strRef.indexOf("instance('"))
  247. {
  248. strInstance = strRef.substr("instance('".length);
  249. var nPos = strInstance.indexOf("'");
  250. if (0 > nPos)
  251. {
  252. return false;
  253. }
  254. strInstance = strInstance.substring(nPos + 1);
  255. bInstance = true;
  256. }
  257. var xnDoc = this.getInstanceDocument();
  258. if (!xnDoc)
  259. {
  260. return false;
  261. }
  262. var xnElement = xnDoc.firstChild;
  263. var xlChild = xnElement.childNodes;
  264. var xnTemp;
  265. var xnSave;
  266. var strElement;
  267. var strXPath = strRef;
  268. var strNodeName = xnElement.nodeName;
  269. if (!bInstance)
  270. {
  271. var nPos = strXPath.indexOf(strNodeName);
  272. if (-1 != nPos)
  273. {
  274. if ('/' == strXPath.charAt(0) && 1 == nPos)
  275. {
  276. var nIndex = 1 + strNodeName.length + 1;
  277. if (strXPath.length <= nIndex)
  278. {
  279. return false;
  280. }
  281. strXPath = strXPath.substr(1 + strNodeName.length + 1);
  282. }
  283. else if ('/' != strXPath.charAt(0) && 0 == nPos)
  284. {
  285. var nIndex = 1 + strNodeName.length;
  286. if (strXPath.length <= nIndex)
  287. {
  288. return false;
  289. }
  290. strXPath = strXPath.substr(strNodeName.length + 1);
  291. }
  292. }
  293. }
  294. if (bInstance)
  295. {
  296. var nPos = strRef.indexOf("/");
  297. if (-1 == nPos)
  298. {
  299. return false;
  300. }
  301. strXPath = strRef.substr(nPos + 1);
  302. }
  303. while (true)
  304. {
  305. var nIndex = strXPath.indexOf("/");
  306. if (-1 == nIndex)
  307. {
  308. if (-1 != strXPath.indexOf("@"))
  309. {
  310. break;
  311. }
  312. var j = strXPath.indexOf(":");
  313. if (j != -1)
  314. {
  315. strXPath = strXPath.substr(j+1);
  316. }
  317. strElement = strXPath;
  318. xnTemp = this.searchNode(xlChild, strXPath);
  319. break;
  320. }
  321. else
  322. {
  323. var strTempPath = strXPath.substring(0, nIndex);
  324. strXPath = strXPath.substr(nIndex + 1);
  325. var nColon = strXPath.indexOf(":");
  326. if (-1 != nColon)
  327. {
  328. strTempPath = strTempPath.substr(nColon + 1);
  329. }
  330. strElement = strTempPath;
  331. xnTemp = this.searchNode(xlChild, strTempPath);
  332. }
  333. if (null == xnTemp)
  334. {
  335. break;
  336. }
  337. else
  338. {
  339. xlChild = xnTemp.childNodes;
  340. xnSave = xnTemp;
  341. }
  342. }
  343. if (null == xnTemp)
  344. {
  345. var xnNew;
  346. var nStartBracket = strElement.indexOf("[");
  347. if (-1 != nStartBracket)
  348. {
  349. var nIndex = nStartBracket + 1;
  350. var nLastIndex = strElement.indexOf("]");
  351. if (isFinite(strElement.substring(nIndex,nLastIndex)))
  352. {
  353. strElement = strElement.substr(0,nStartBracket);
  354. }
  355. //TODO
  356. }
  357. var strMakeName = "";
  358. var strPrefix = "";
  359. var nIndex = strRef.indexOf(":" + strElement);
  360. if (-1 < nIndex)
  361. {
  362. // TODO
  363. }
  364. if (!strPrefix.isEmpty())
  365. {
  366. strPrefix = strPrefix + ":" + strElement;
  367. }
  368. else
  369. {
  370. strPrefix = strElement;
  371. }
  372. if (null == xnSave)
  373. {
  374. if (null != xnElement)
  375. {
  376. xnNew = XmlLib.createChild(xnElement, strPrefix);
  377. this.makeNode(strRef);
  378. }
  379. }
  380. else
  381. {
  382. xnNew = XmlLib.createChild(xnSave, strPrefix);
  383. this.makeNode(strRef);
  384. }
  385. return true;
  386. }
  387. return true;
  388. };
  389. XFormsModel.prototype.searchNode = function (xlNodeList, strElement)
  390. {
  391. var nNodeCount = null;
  392. if (!xlNodeList)
  393. {
  394. return null;
  395. }
  396. if (-1 != strElement.indexOf("["))
  397. {
  398. var nFristIndex = strElement.indexOf("[");
  399. var nLastIndex = strElement.indexOf("]");
  400. if (isFinite(strElement.substring(nFristIndex+1,nLastIndex)))
  401. {
  402. nNodeCount = Number(strElement.substring(nFristIndex+1,nLastIndex));
  403. strElement = strElement.substr(0,nFristIndex);
  404. }
  405. }
  406. var ntempCount = 0;
  407. for (var i=0; i<xlNodeList.length; i++)
  408. {
  409. var xnNode = xlNodeList.item(i);
  410. if (null != xnNode && strElement == xnNode.nodeName)
  411. {
  412. ntempCount++;
  413. if (null == nNodeCount)
  414. {
  415. return xnNode;
  416. }
  417. else
  418. {
  419. if (ntempCount == nNodeCount)
  420. {
  421. return xnNode;
  422. }
  423. }
  424. }
  425. }
  426. return null;
  427. };
  428. XFormsModel.prototype.makeValue = function (strRef, strValue, bCData)
  429. {
  430. var bCreateNode = this.makeNode(strRef);
  431. if (bCreateNode)
  432. {
  433. this.setValue(strRef, strValue, bCData);
  434. }
  435. };
  436. XFormsModel.prototype.propertynames = function (strSep)
  437. {
  438. var strPropertyNames = "";
  439. if (null == strSep)
  440. {
  441. strSep = "";
  442. }
  443. var nLength = 0;
  444. for(var strName in this.property)
  445. {
  446. strPropertyNames += (strName + strSep);
  447. nLength++;
  448. }
  449. if (0 < nLength)
  450. {
  451. strPropertyNames = strPropertyNames.substr(0, strPropertyNames.length - strSep.length);
  452. }
  453. return strPropertyNames;
  454. };
  455. XFormsModel.prototype.refreshCurrentModel = function (bAutoRefresh)
  456. {
  457. if (null == bAutoRefresh)
  458. {
  459. bAutoRefresh = true;
  460. }
  461. if(bAutoRefresh)
  462. {
  463. this.dispatch("xforms-recalculate");
  464. // TODO xforms-revalidate 미구현
  465. this.dispatch("xforms-refresh");
  466. }
  467. else
  468. {
  469. this.refresh();
  470. }
  471. };
  472. /**
  473. * 모든 bind의 수식을 다시 계산하여 인스턴스에 적용한다
  474. * @return
  475. */
  476. XFormsModel.prototype.recalculate = function ()
  477. {
  478. var arKeyset = this.children.keys();
  479. for (var i=0; i<arKeyset.length; i++)
  480. {
  481. var strChildName = arKeyset[i];
  482. var objChild = this.children.item(strChildName);
  483. if (objChild instanceof XFormsBind)
  484. {
  485. objChild.bindExecute();
  486. }
  487. }
  488. };
  489. /**
  490. * 인스턴스에 저장되어 있는 모든 데이터를 실제 맵핑된 컨트롤에 반영한다.
  491. * @return
  492. */
  493. XFormsModel.prototype.refresh = function ()
  494. {
  495. // model의 자식들을 refresh 한다.
  496. var arKeyset = this.children.keys();
  497. for (var i=0; i<arKeyset.length; i++)
  498. {
  499. var strId = arKeyset[i];
  500. var objControl = this.children.item(strId);
  501. if (null != objControl)
  502. {
  503. if (objControl.refresh)
  504. {
  505. objControl.refresh();
  506. }
  507. }
  508. }
  509. // body의 자식들을 refresh 한다.
  510. var objBody = body;
  511. if (null == objBody)
  512. {
  513. objBody = document.allElement("body");
  514. }
  515. if (null != objBody)
  516. {
  517. objBody.refresh();
  518. }
  519. };
  520. XFormsModel.prototype.refreshpart = function ()
  521. {
  522. //TODO
  523. if (null != window.console)
  524. {
  525. console.log("Unimplemented refreshpart()");
  526. }
  527. };
  528. XFormsModel.prototype.removenode = function (strRef)
  529. {
  530. this.removeNode(strRef);
  531. };
  532. XFormsModel.prototype.removeNode = function (strRef)
  533. {
  534. var xnDoc = this.getInstanceDocument();
  535. if (null != xnDoc)
  536. {
  537. var xnNode = XmlLib.selectSingleNode(xnDoc, strRef);
  538. if (null != xnNode)
  539. {
  540. var xnParentNode = xnNode.parentNode;
  541. if (null != xnParentNode)
  542. {
  543. xnParentNode.removeChild(xnNode);
  544. }
  545. }
  546. }
  547. };
  548. XFormsModel.prototype.removeNodeset = function (strRef)
  549. {
  550. var xnDoc = this.getInstanceDocument();
  551. if (null != xnDoc)
  552. {
  553. var xlNode = XmlLib.selectNodes(xnDoc, strRef);
  554. for (var i=0; i<xlNode.length; i++)
  555. {
  556. var xnNode = xlNode.item(i);
  557. if (null != xnNode)
  558. {
  559. var xnParentNode = xnNode.parentNode;
  560. if (null != xnParentNode)
  561. {
  562. xnParentNode.removeChild(xnNode);
  563. }
  564. }
  565. }
  566. }
  567. };
  568. XFormsModel.prototype.removeRegistry = function ()
  569. {
  570. window.alert("model.removeRegistry() is not available.");
  571. };
  572. XFormsModel.prototype.reset = function ()
  573. {
  574. if (null != instance1)
  575. {
  576. instance1.documentElement.removeChild(instance1.root);
  577. instance1.documentElement.appendChild(this.m_resetRoot.cloneNode(true));
  578. }
  579. };
  580. XFormsModel.prototype.resetInstanceNode = function (strRef)
  581. {
  582. var xnDoc = this.getInstanceDocument();
  583. if (null != xnDoc)
  584. {
  585. var xnParentNode;
  586. var xnNewNode;
  587. var xlNode = XmlLib.selectNodes(xnDoc, strRef);
  588. for (var i=0; i<xlNode.length; i++)
  589. {
  590. var xnNode = xlNode.item(i);
  591. if (null != xnNode)
  592. {
  593. if (0 == i)
  594. {
  595. //xnNewNode = xnNode.cloneNode(true);
  596. var strCloneNode = XmlLib.serializeToString(xnNode);
  597. strCloneNode = strCloneNode.match(/\<(\/|)(([ㄱ-ㅎ가-힣]|\w|\_|\.)*)(\/|)\>/g).join("");
  598. xnNewNode = XmlLib.loadXMLFromString(strCloneNode);
  599. if (null != xnNewNode)
  600. {
  601. xnNewNode = XmlLib.getRootElementNode(xnNewNode);
  602. }
  603. }
  604. xnParentNode = xnNode.parentNode;
  605. if (null != xnParentNode)
  606. {
  607. xnParentNode.removeChild(xnNode);
  608. }
  609. }
  610. }
  611. if (null != xnParentNode && null != xnNewNode)
  612. {
  613. xnParentNode.appendChild(xnNewNode.cloneNode(true));
  614. }
  615. }
  616. };
  617. XFormsModel.prototype.getAttribute = function (strKey)
  618. {
  619. if ("id" != strKey)
  620. {
  621. this.getProperty(strKey);
  622. }
  623. };
  624. XFormsModel.prototype.setAttribute = function (strKey, strValue)
  625. {
  626. this.setProperty(strKey,strValue);
  627. };
  628. XFormsModel.prototype.getProperty = function (strKey)
  629. {
  630. if ((is_ie6 || is_ie7 || is_chromeFrame) && (!is_smartphone))
  631. {
  632. return model.m_objHttpClient.post(window.getTrustFormURL()+ "/SessionStorageManager.tfs?Soonsu_ServiceName=GetProperty", strKey, false, "text/xml", "UTF-8");
  633. }
  634. else
  635. {
  636. var strGetPpy = sessionStorage.getItem(strKey);
  637. strGetPpy = null != strGetPpy ? strGetPpy : "";
  638. return strGetPpy;
  639. }
  640. };
  641. XFormsModel.prototype.setProperty = function (strKey, strValue)
  642. {
  643. if ((is_ie6 || is_ie7 || is_chromeFrame) && (!is_smartphone))
  644. {
  645. var strParam = strKey + "#&" + strValue;
  646. model.m_objHttpClient.post(window.getTrustFormURL()+ "/SessionStorageManager.tfs?Soonsu_ServiceName=SetProperty", strParam, false, "text/xml", "UTF-8");
  647. }
  648. else
  649. {
  650. sessionStorage[strKey] = strValue;
  651. }
  652. };
  653. XFormsModel.prototype.deleteProperty = function (strKey)
  654. {
  655. if ((is_ie6 || is_ie7 || is_chromeFrame) && (!is_smartphone))
  656. {
  657. model.m_objHttpClient.post(window.getTrustFormURL()+ "/SessionStorageManager.tfs?Soonsu_ServiceName=DeleteProperty", strKey, false, "text/xml", "UTF-8");
  658. }
  659. else
  660. {
  661. sessionStorage.removeItem(strKey);
  662. }
  663. };
  664. XFormsModel.prototype.resetProperty = function ()
  665. {
  666. if ((is_ie6 || is_ie7 || is_chromeFrame) && (!is_smartphone))
  667. {
  668. model.m_objHttpClient.post(window.getTrustFormURL()+ "/SessionStorageManager.tfs?Soonsu_ServiceName=ResetProperty", null, false, "text/xml", "UTF-8");
  669. }
  670. else
  671. {
  672. sessionStorage.clear();
  673. }
  674. };
  675. XFormsModel.prototype.revalidate = function ()
  676. {
  677. //TODO
  678. if (null != window.console)
  679. {
  680. console.log("Unimplemented revalidate()");
  681. }
  682. };
  683. XFormsModel.prototype.send = function (strSubmissionID, bRefresh, bThread, bSynch, lTimeout)
  684. {
  685. var objSubmission = this.children.item(strSubmissionID);
  686. if (null != objSubmission && objSubmission instanceof XFormsSubmission)
  687. {
  688. if (null == bRefresh)
  689. {
  690. bRefresh = true;
  691. }
  692. if (null == bThread)
  693. {
  694. bThread = false;
  695. }
  696. if (null == bSynch)
  697. {
  698. bSynch = false;
  699. }
  700. if (null == lTimeout)
  701. {
  702. lTimeout = 0;
  703. }
  704. var strAction = objSubmission.attribute["action"];
  705. var strAdd = objSubmission.attribute["add"];
  706. var strEncoding = objSubmission.attribute["encoding"];
  707. var strMediaType = objSubmission.attribute["mediatype"];
  708. var strMethod = objSubmission.attribute["method"];
  709. var strRef = objSubmission.attribute["ref"];
  710. var strReplace = objSubmission.attribute["replace"];
  711. var strResultRef = objSubmission.attribute["resultref"];
  712. var strType = objSubmission.attribute["type"];
  713. // ref 처리
  714. var strData;
  715. var strBoundary;
  716. if ("application/x-www-form-urlencoded" == strMediaType)
  717. {
  718. strData = this._getPostDataAll(strRef, true, strType, strEncoding, strMediaType);
  719. }
  720. else if ("multipart/form-data" == strMediaType)
  721. {
  722. this.m_hmInstanceData = new Hashtable();
  723. this.m_bHasUploadFile = false;
  724. strData = this._getPostDataAll(strRef, false, strType, strEncoding, strMediaType);
  725. strBoundary = "KKPK" + String(new Date().getTime());
  726. var strBoundarySep = "--" + strBoundary + "\r\n";
  727. var strBoundaryTerm = "--" + strBoundary + "--\r\n";
  728. var arRequestData = ["\r\n"];
  729. for (var strKey in this.m_hmInstanceData)
  730. {
  731. var strValue = this.m_hmInstanceData[strKey];
  732. if (undefined != strValue)
  733. {
  734. arRequestData.push('Content-Disposition: form-data; name="'+strKey+'"\r\n\r\n'+strValue+'\r\n');
  735. }
  736. }
  737. if (this.m_bHasUploadFile)
  738. {
  739. var strHostURL = window.getHostURL();
  740. if (0 != strAction.indexOf(strHostURL) && 0 != strAction.indexOf("http://") && 0 != strAction.indexOf("HTTP://"))
  741. {
  742. strAction = strHostURL + strAction;
  743. }
  744. arRequestData.push('Content-Disposition: form-data; name="__TF_Action"\r\n\r\n'+strAction+'\r\n');
  745. arRequestData.push('Content-Disposition: form-data; name="__TF_Boundary"\r\n\r\n'+strBoundary+'\r\n');
  746. strAction = __getAppName() + "/FileAttach.tfs";
  747. }
  748. strData = arRequestData.join(strBoundarySep) + strBoundaryTerm;
  749. }
  750. else if ("application/xml" == strMediaType || "text/xml" == strMediaType || "application/json" == strMediaType)
  751. {
  752. strData = this._getPostDataXmlAll(strRef);
  753. }
  754. // 비동기 이면 HttpClient에서 ready state 이벤트에 의해 Model.updateDataForAsync() 함수가 호출된다.
  755. if (bSynch)
  756. { // 그때 필요한 정보를 가지고 있는 submission 을 기억한다.
  757. this.m_objCurrentSubmission = objSubmission;
  758. this.m_objCurrentSubmission.m_refresh = bRefresh;
  759. }
  760. //submission 의 type이 custom 일때
  761. if ("custom" == strType)
  762. {
  763. var strTempData = strData;
  764. try
  765. {
  766. strData = onbeforesend(strTempData);
  767. strData = null == strData ? strTempData : strData;
  768. }
  769. catch(err)
  770. {
  771. strData = strTempData;
  772. }
  773. }
  774. var strResult;
  775. if ("get" == strMethod)
  776. {
  777. strResult = this.m_objHttpClient.get(strAction + "?" + strData, bSynch, strMediaType, strEncoding);
  778. }
  779. else if ("post" == strMethod)
  780. {
  781. strResult = this.m_objHttpClient.post(strAction, strData, bSynch, strMediaType, strEncoding, false);
  782. }
  783. else if ("form-data-post" == strMethod)
  784. {
  785. strResult = this.m_objHttpClient.post(strAction, strData, bSynch, strMediaType, strEncoding, true, strBoundary);
  786. }
  787. var xnResultDoc = null;
  788. if (null != strResult && !strResult.isEmpty())
  789. {
  790. // trim을 하지 않으면 Mozilla 계열의 Browser에서 Dom을 이상하게 만든다.
  791. strResult = strResult.trim();
  792. if ("custom" == strType)
  793. {
  794. var strTempResult = strResult;
  795. try
  796. {
  797. strResult = onaftersend(strTempResult);
  798. strResult = null == strResult ? strTempResult : strResult;
  799. }
  800. catch(err)
  801. {
  802. strResult = strTempResult;
  803. }
  804. }
  805. // result 처리
  806. xnResultDoc = XmlLib.loadXMLFromString(strResult);
  807. if (null != xnResultDoc)
  808. {
  809. if (null == xnResultDoc.firstChild || ("root" != xnResultDoc.firstChild.nodeName && "xml" != xnResultDoc.firstChild.nodeName))
  810. {
  811. var objLightGridData = this.makeLightGridObject(strResult, strMediaType);
  812. if (null != objLightGridData)
  813. {
  814. for (var i=0; i<document.controls.length; i++)
  815. {
  816. var objControl = document.controls.item(i);
  817. if (null != objControl && null != objControl.attribute["nodeset"])
  818. {
  819. if(strResultRef == objControl.attribute["nodeset"])
  820. {
  821. objControl.m_objGridData = objLightGridData;
  822. objControl.refresh();
  823. break;
  824. }
  825. }
  826. }
  827. objLightGridData = null;
  828. }
  829. }
  830. else
  831. {
  832. this.updateData(XmlLib.getRootElementNode(xnResultDoc), strResultRef, strAdd, strReplace);
  833. if (bRefresh)
  834. {
  835. model.refreshCurrentModel();
  836. }
  837. }
  838. }
  839. }
  840. //TODO 네이밍 다시
  841. this.setResultKM(xnResultDoc);
  842. return this.m_objHttpClient.status();
  843. }
  844. };
  845. /**
  846. * resultKM 동작을 위한 Function
  847. * @param {XmlNode} xnResultDoc : 결과 노드.
  848. * @memberOf {TypeName}
  849. * TODO error, updateinstance에 관한 스펙 부족. 생략.
  850. */
  851. XFormsModel.prototype.setResultKM = function (xnResultDoc)
  852. {
  853. // resultKM 노드 처리. 2011.09.20. 박현우
  854. // 요청 완료를 하고 회답받은 문자열을 XML 노드로 변경한 후에 실행.
  855. if ("200" == this.m_objHttpClient.status(0) && null!= xnResultDoc)
  856. {
  857. // resultKM 노드가 있을 시.
  858. for (var i=0; i<xnResultDoc.getElementsByTagName("resultKM").length; i++)
  859. {
  860. var xnResultKM = xnResultDoc.getElementsByTagName("resultKM").item(i); // resultKM 노드를 순서대로 검색.
  861. var clAttribute = new Collection();
  862. // 모든 attribute를 받아와 넣는다.
  863. for (var j=0; j<xnResultKM.attributes.length; j++)
  864. {
  865. var xnAttribute = xnResultKM.attributes.item(j);
  866. clAttribute.add(xnAttribute.name, xnAttribute.value);
  867. }
  868. if ("alert" == clAttribute.item("type"))
  869. {
  870. // TODO 원래의 형태는 //////////////////
  871. // Source : a.jsp //
  872. // Description : 경고경고뭐라뭐라 //
  873. // URL : http://www.comsquare.kr //
  874. // 확 인 //
  875. // 이지만 석유공사에서 사용을 위해 단순 alert으로 출력.
  876. alert(clAttribute.item("description"));
  877. }
  878. else
  879. {
  880. this.dispatch("onerror");
  881. }
  882. if ("true" == clAttribute.item("clear"))
  883. {
  884. // 노드 자기 자신 삭제.
  885. // TODO 미구현
  886. }
  887. }
  888. }
  889. };
  890. // TODO Test 필요
  891. XFormsModel.prototype.convertEncoding = function (strText, strEncodingValue)
  892. {
  893. // var nLastIndex = strText.indexOf(strEncodingValue) + strEncodingValue.length;
  894. var strChangeText = strText.replace(strEncodingValue, "UTF-8");
  895. var strUnicode = encodeURIComponent(strChangeText);
  896. strUnicode = decodeURIComponent(strUnicode);
  897. };
  898. function FdecodeURI2(s)
  899. {
  900. var ss = s;
  901. try
  902. {
  903. ss = decodeURI(ss);
  904. ss = ss.replaceAll("+"," ");
  905. ss = ss.replaceAll("%2B","+");
  906. }
  907. catch(e)
  908. {
  909. }
  910. return ss;
  911. }
  912. function FisEncodedString(str)
  913. {
  914. if (FdecodeURI2(str)==str)
  915. {
  916. return false;
  917. }
  918. return true;
  919. };
  920. XFormsModel.prototype.makeLightGridObject = function (strResult, strMediaTypes)
  921. {
  922. try
  923. {
  924. // json 방식일때......는 한줄임.ㅠㅠ
  925. if ("application/json" == strMediaTypes)
  926. {
  927. return jQuery.parseJSON(strResult);
  928. }
  929. var objLightGridData = {status:null, column:null, data:null};
  930. // 배열 들어가는 순서
  931. // 0 : Header 정보
  932. // 1 : col style
  933. // 2~ : data
  934. var arResult = strResult.substring(0, strResult.length-1).split("|"); // 맨마지막이 '|'로 끝나기 때문에 맨마지막 '|'를 삭제해 준다.
  935. // Caption부분 String
  936. var strHeader = arResult[0];
  937. // 구분자 ^로 나눌때 caption의 Col 구분자인 '\^'도 나눠지지 않게 치환.
  938. strHeader = strHeader.replaceAll("\\^", "__TF_CAP_");
  939. // 배열 들어가는 순서
  940. // 0 : T 아무래도 LightGrid라는걸 알려주기 위한 헤더인듯.
  941. // 1 : Row 갯수
  942. // 2 : Col 갯수
  943. // 3 : Caption 이름
  944. // 4 : col width
  945. var arHeader = strHeader.split("^");
  946. // status 값 객체화
  947. objLightGridData.status = {row:parseInt(arHeader[1]), col:parseInt(arHeader[2])};
  948. // Caption영역에 필요한 값들의 배열.
  949. var arCaptionNames = arHeader[3].split("__TF_CAP_"); // caption Name
  950. var arColumnWidths = arHeader[4].split(","); // Column Width
  951. var arColumnTypes = new Array(); // Column Type
  952. var arColumnStyles = new Array(); // Column Style
  953. // Column Style
  954. var arColumnInfo = arResult[1].split("^");
  955. for (var i=0; i<parseInt(arHeader[2]); i++)
  956. {
  957. // Style을 배열로 저장
  958. var strColumnStyle = arColumnInfo[i].split("!")[1];
  959. strColumnStyle = ("" == strColumnStyle && null == strColumnStyle) ? "" : strColumnStyle;
  960. arColumnStyles.push(strColumnStyle);
  961. // Type을 배열로 저장
  962. var strColumnType = arColumnInfo[i].split("!")[0];
  963. strColumnType = ("" == strColumnType && null == strColumnType) ? "" : strColumnType;
  964. arColumnTypes.push(strColumnType);
  965. }
  966. // Colume부분 객체화를 위한 String 만들기
  967. var strCaptionData = "objLightGridData.column = [";
  968. for (var i=0; i<parseInt(arHeader[2]); i++)
  969. {
  970. strCaptionData += "{";
  971. strCaptionData += "width:" + parseInt(arColumnWidths[i]) + ", style:'" + arColumnStyles[i] + "', type:'" + arColumnTypes[i] + "', caption:'" + arCaptionNames[i];
  972. if (i != parseInt(arHeader[2]) - 1)
  973. {
  974. strCaptionData += "'}, ";
  975. }
  976. else
  977. {
  978. strCaptionData += "'}";
  979. }
  980. }
  981. // objLightGridData.column 객체화
  982. eval(strCaptionData + "]");
  983. // Data부분 객체화를 위한 String 만들기
  984. var strBodyData = "objLightGridData.data = [";
  985. for (var i=2; i<arResult.length; i++)
  986. {
  987. var strRowData = arResult[i].substring(0, arResult[i].length-1); // 맨 마지막이 '^'로 끝나기 때문에 마지막 ^를 삭제해 준다.
  988. var arColData = strRowData.split("^");
  989. strBodyData += "[";
  990. for (var j=0; j<parseInt(arHeader[2]); j++)
  991. {
  992. var strColData = ("" == arColData[j] || null == arColData[j]) ? "" : arColData[j];
  993. strBodyData += "{D:'" + strColData;
  994. if (j != parseInt(arHeader[2]) - 1)
  995. {
  996. strBodyData += "'}, ";
  997. }
  998. else
  999. {
  1000. strBodyData += "'}";
  1001. }
  1002. }
  1003. if (i != arResult.length - 1)
  1004. {
  1005. strBodyData += "], ";
  1006. }
  1007. else
  1008. {
  1009. strBodyData += "]";
  1010. }
  1011. }
  1012. // objLightGridData.data 객체화.
  1013. eval(strBodyData += "]");
  1014. // var objLightGridData = {status:null, caption:null, width:null, type:null, style:null, data:null};
  1015. //
  1016. // // 배열 들어가는 순서
  1017. // // 0 : Header 정보
  1018. // // 1 : col style
  1019. // // 2~ : data
  1020. // var arResult = strResult.split("|");
  1021. //
  1022. // // Caption부분 String
  1023. // var strHeader = arResult[0];
  1024. //
  1025. // // 구분자 ^로 나눌때 caption의 Col 구분자인 '\^'도 나눠지지 않게 치환.
  1026. // strHeader = strHeader.replaceAll("\\^", "__TF_CAP_");
  1027. //
  1028. // // 배열 들어가는 순서
  1029. // // 0 : T 아무래도 LightGrid라는걸 알려주기 위한 헤더인듯.
  1030. // // 1 : Row 갯수
  1031. // // 2 : Col 갯수
  1032. // // 3 : Caption 이름
  1033. // // 4 : col width
  1034. // var arHeader = strHeader.split("^");
  1035. //
  1036. // objLightGridData.status = {row:parseInt(arHeader[1]), col:parseInt(arHeader[2])};
  1037. //
  1038. // // caption을 객체화 하기
  1039. // var arCaptionName = arHeader[3].split("__TF_CAP_");
  1040. //
  1041. // var strEvalValue = "objLightGridData.caption = {";
  1042. // for (var i=0; i<parseInt(arHeader[2]); i++)
  1043. // {
  1044. // var strCaptionName = (arCaptionName[i]) ? arCaptionName[i] : "";
  1045. // if (i != parseInt(arHeader[2]) - 1)
  1046. // {
  1047. // strEvalValue += "col"+i+":'" + strCaptionName + "', ";
  1048. // }
  1049. // else
  1050. // {
  1051. // strEvalValue += "col"+i+":'" + strCaptionName + "'";
  1052. // }
  1053. // }
  1054. // eval(strEvalValue + "}");
  1055. //
  1056. // // width를 객체화 하기
  1057. // strEvalValue = "objLightGridData.width = {";
  1058. //
  1059. // var arCaptionWidth = arHeader[4].split(",");
  1060. //
  1061. // for (var i=0; i<parseInt(arHeader[2]); i++)
  1062. // {
  1063. // var strCaptionWidth = arCaptionWidth[i] ? arCaptionWidth[i].trim() : "";
  1064. // if (i != parseInt(arHeader[2]) - 1)
  1065. // {
  1066. // strEvalValue += "col"+i+":" + strCaptionWidth + ", ";
  1067. // }
  1068. // else
  1069. // {
  1070. // strEvalValue += "col"+i+":" + strCaptionWidth;
  1071. // }
  1072. // }
  1073. // eval(strEvalValue + "}");
  1074. //
  1075. // // style, type을 분리하여 객체화 하기
  1076. // strEvalValue = "objLightGridData.style = {";
  1077. //
  1078. // // Type이 함께 있기 때문에 String을 동시에 만들어준다.
  1079. // var strEvalCaptionType = "objLightGridData.type = {";
  1080. //
  1081. // var arCaptionStyle = arResult[1].split("^");
  1082. //
  1083. // for (var i=0; i<parseInt(arHeader[2]); i++)
  1084. // {
  1085. // var strCaptionStyle = arCaptionStyle[i] ? arCaptionStyle[i].trim() : "";
  1086. //
  1087. // var strCaptionType = (null != strCaptionStyle.split("!")[0]) ? strCaptionStyle.split("!")[0] : ""; // caption type 넣기
  1088. // strCaptionStyle = (null != strCaptionStyle.split("!")[1]) ? strCaptionStyle.split("!")[1] : ""; // caption style 넣기
  1089. //
  1090. // if (i != parseInt(arHeader[2]) - 1)
  1091. // {
  1092. // strEvalCaptionType += "col" + i + ":'" +strCaptionType + "', ";
  1093. // strEvalValue += "col"+i+":'" + strCaptionStyle + "', ";
  1094. // }
  1095. // else
  1096. // {
  1097. // strEvalCaptionType += "col" + i + ":'" +strCaptionType + "'";
  1098. // strEvalValue += "col"+i+":'" + strCaptionStyle + "'";
  1099. // }
  1100. // }
  1101. // eval(strEvalValue + "}");
  1102. // eval(strEvalCaptionType + "}");
  1103. //
  1104. // // data를 객체화 하기
  1105. // strEvalValue = "objLightGridData.data = [";
  1106. // for (var i=2; i<arResult.length; i++)
  1107. // {
  1108. // strEvalValue += "{";
  1109. // var strData = arResult[i];
  1110. // var arColData = strData.split("^");
  1111. // for (var j=0; j<parseInt(arHeader[2]);j++)
  1112. // {
  1113. // var strColData = arColData[j] ? arColData[j].trim() : "";
  1114. // if (j != parseInt(arHeader[2]) - 1)
  1115. // {
  1116. // strEvalValue += "col" + j + ":'" + strColData + "', ";
  1117. // }
  1118. // else
  1119. // {
  1120. // strEvalValue += "col" + j + ":'" + strColData + "'";
  1121. // }
  1122. // }
  1123. // if (i != arResult.length-1)
  1124. // {
  1125. // strEvalValue = strEvalValue + "}, ";
  1126. // }
  1127. // else
  1128. // {
  1129. // strEvalValue = strEvalValue + "}";
  1130. // }
  1131. // }
  1132. // eval(strEvalValue + "]");
  1133. return objLightGridData;
  1134. }
  1135. catch (e)
  1136. {
  1137. //TODO 문서구조 오류 로그파일에 추가
  1138. return null;
  1139. }
  1140. };
  1141. /**
  1142. *
  1143. * @param strServerPath xrw파일이 위치하는 폴더명
  1144. * @param strDeployPath html파일로 변환할 폴더명
  1145. * @param strSubDir 서브 폴더가 존재할 때 포함해서 변환할지에 대한 설정(true/false)
  1146. * @return
  1147. */
  1148. XFormsModel.prototype.deployDirectory = function (strServerPath, strDeployPath, strSubDir)
  1149. {
  1150. var strResult;
  1151. var strSubmitData = "ServerPath=" + strServerPath + "&DeployPath=" + strDeployPath + "&SubDir=" + strSubDir +"&";
  1152. strAction = __getAppName() + "/DeploymentPartManager.tfs";
  1153. strResult = this.m_objHttpClient.post(strAction, strSubmitData);
  1154. };
  1155. XFormsModel.prototype.setFocus = function (strId, bEnsureVisible)
  1156. {
  1157. window.setFocus(strId);
  1158. };
  1159. XFormsModel.prototype.setValue = function (strRef, strValue, bCdata)
  1160. {
  1161. //TODO root 로 시작하는지 instance 로 시작하는지 구분해야한다.
  1162. //TODO strRef가 "/root/example"일때와 root.exaple일때 구분해야한다.
  1163. var objInstance = this.getInstance();
  1164. if (null != objInstance)
  1165. {
  1166. var xnRoot = objInstance.documentElement;
  1167. if (null != xnRoot)
  1168. {
  1169. if (typeof(strRef) != "string")
  1170. {
  1171. XmlLib.setTextValue(strRef, strValue);
  1172. objInstance.synchronize();
  1173. }
  1174. else
  1175. {
  1176. var xnNode = XmlLib.selectSingleNode(xnRoot, strRef);
  1177. if (null != xnNode)
  1178. {
  1179. XmlLib.setTextValue(xnNode, strValue);
  1180. objInstance.synchronize();
  1181. }
  1182. }
  1183. }
  1184. }
  1185. };
  1186. XFormsModel.prototype.setXPathValue = function (strRef, strOperation)
  1187. {
  1188. this.setValue(strRef, xPathOperation(strOperation));
  1189. };
  1190. XFormsModel.prototype.toggle = function (strCaseId)
  1191. {
  1192. var arKeyset = document.controls.keys();
  1193. for (var i=0; i<arKeyset.length; i++)
  1194. {
  1195. var strId = arKeyset[i];
  1196. var objChild = document.controls.item(strId);
  1197. if (objChild.id == strCaseId && objChild instanceof XFormsCase)
  1198. {
  1199. objChild.select(true);
  1200. }
  1201. }
  1202. };
  1203. XFormsModel.prototype.urlencode = function (strData, strEncoding)
  1204. {
  1205. return URIEncoder.encode(strData, strEncoding);
  1206. };
  1207. /**
  1208. * Http 통신을 지원하는 모듈을 반환한다.
  1209. * @return
  1210. */
  1211. XFormsModel.prototype.getHttpClient = function ()
  1212. {
  1213. return this.m_objHttpClient;
  1214. };
  1215. XFormsModel.prototype.getSessionId = function ()
  1216. {
  1217. return this.m_strSessionId;
  1218. };
  1219. XFormsModel.prototype.setSessionId = function (strSessionId)
  1220. {
  1221. this.m_strSessionId = strSessionId;
  1222. };
  1223. XFormsModel.prototype.isProcessAutoCdata = function (strValue)
  1224. {
  1225. if(strValue.indexOf("&") > 0 || strValue.indexOf("<") > 0 ||
  1226. strValue.indexOf(">") > 0 || strValue.indexOf("'") > 0 ||
  1227. strValue.indexOf("\"") > 0)
  1228. {
  1229. return true;
  1230. }
  1231. return false;
  1232. };
  1233. XFormsModel.prototype.getInstancePart = function (strInstanceID, strRef)
  1234. {
  1235. //TODO root 로 시작하는지 instance 로 시작하는지 구분해야한다.
  1236. //TODO strRef가 "/root/example"일때와 root.exaple일때 구분해야한다.
  1237. var xnInstansDoc = this.getInstanceDocument(strInstanceID);
  1238. return XmlLib.selectNodes(xnInstansDoc, strRef);
  1239. };
  1240. XFormsModel.prototype.getInstanceSinglePart = function (strInstanceID, strRef)
  1241. {
  1242. //TODO root 로 시작하는지 instance 로 시작하는지 구분해야한다.
  1243. //TODO strRef가 "/root/example"일때와 root.exaple일때 구분해야한다.
  1244. // root 로 시작하고 XPath일때
  1245. var xnInstansDoc = this.getInstanceDocument(strInstanceID);
  1246. if (null != xnInstansDoc)
  1247. {
  1248. var xnNode = XmlLib.selectSingleNode(xnInstansDoc, strRef);
  1249. return xnNode;
  1250. }
  1251. return null;
  1252. };
  1253. /**
  1254. * 인스턴스를 구한다.
  1255. * @return
  1256. */
  1257. XFormsModel.prototype.getInstance = function (strInstanceId)
  1258. {
  1259. var objInstance = null;
  1260. if (0 != this.instances.count())
  1261. {
  1262. // 인자 strInstanceId가 없다면
  1263. if (null == strInstanceId || "" == strInstanceId)
  1264. {
  1265. // 첫 인스턴스를 구한다.
  1266. var arKeyset = this.instances.keys();
  1267. for (var i=0; i<arKeyset.length; i++)
  1268. {
  1269. var strId = arKeyset[i];
  1270. objInstance = this.instances.item(strId);
  1271. if (null != objInstance)
  1272. {
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. // 인자 strInstanceId가 있다면
  1278. else
  1279. {
  1280. // ID 에 맞는 인스턴스를 구한다.
  1281. objInstance = this.instances.item(strInstanceId);
  1282. }
  1283. }
  1284. return objInstance;
  1285. };
  1286. /**
  1287. * 인스턴스의 DocumentElement를 구한다.
  1288. * @param strInstanceID
  1289. * @return
  1290. */
  1291. XFormsModel.prototype.getInstanceDocument = function (strInstanceID)
  1292. {
  1293. var xnDoc = null;
  1294. var objInstance = this.getInstance(strInstanceID);
  1295. // 인스턴스가 있다면
  1296. if (null != objInstance)
  1297. {
  1298. xnDoc = objInstance.documentElement;
  1299. }
  1300. return xnDoc;
  1301. };
  1302. XFormsModel.prototype.initChildren = function ()
  1303. {
  1304. var arKeyset = this.children.keys();
  1305. for (var i=0; i<arKeyset.length; i++)
  1306. {
  1307. var strId = arKeyset[i];
  1308. var objChild = this.children.item(strId);
  1309. if (null != objChild && objChild.init)
  1310. {
  1311. objChild.init();
  1312. }
  1313. }
  1314. XFormsDocument.init();
  1315. };
  1316. XFormsModel.prototype.getTabIndex = function ()
  1317. {
  1318. return this.m_objTabIndex;
  1319. };
  1320. XFormsModel.prototype.initTabIndex = function ()
  1321. {
  1322. for (var i=0; i<this.m_objTabIndex.length; i++)
  1323. {
  1324. if (this.m_objTabIndex[i] && this.m_objTabIndex[i].m_heControl)
  1325. {
  1326. this.m_objTabIndex[i].m_TabIndex = i;
  1327. this.m_objTabIndex[i].m_heControl.tabIndex = i+1;
  1328. }
  1329. }
  1330. };
  1331. XFormsModel.prototype.replaceTabIndex = function (nArrIndex, nTabIndex, objControl)
  1332. {
  1333. this.removeTabIndex(nArrIndex);
  1334. this.addTabIndex(nTabIndex, objControl);
  1335. this.initTabIndex();
  1336. };
  1337. XFormsModel.prototype.removeTabIndex = function (nArrIndex)
  1338. {
  1339. this.m_objTabIndex.splice(nArrIndex, 1);
  1340. };
  1341. XFormsModel.prototype.addTabIndex = function (nTabIndex, objControl)
  1342. {
  1343. if (-1 != nTabIndex)
  1344. {//instance, submission, bind, item 제외
  1345. if (0 == this.m_objTabIndex.length)
  1346. {
  1347. this.m_objTabIndex.push(objControl);
  1348. return;
  1349. }
  1350. for (var i=0; i<this.m_objTabIndex.length; i++)
  1351. {
  1352. if (nTabIndex < this.m_objTabIndex[i].navIndex)
  1353. {
  1354. this.m_objTabIndex.splice(i, 0, objControl);
  1355. return;
  1356. }
  1357. }
  1358. this.m_objTabIndex.push(objControl);
  1359. }
  1360. };
  1361. //////////////////////////////////////////////////////
  1362. //Private 함수
  1363. XFormsModel.prototype._getPostDataXmlAll = function (strRefList)
  1364. {
  1365. var strData = "";
  1366. if (null != strRefList && !strRefList.isEmpty())
  1367. {
  1368. var arRef = strRefList.split(",");
  1369. for (var i=0; i<arRef.length; i++)
  1370. {
  1371. var strRef = arRef[i];
  1372. if (null != strRef && !strRef.isEmpty())
  1373. {
  1374. strRef = strRef.trim();
  1375. var xnRefNode = this.getInstanceSinglePart(null, strRef);
  1376. if (null != xnRefNode)
  1377. {
  1378. strData += XmlLib.serializeToString(xnRefNode);
  1379. }
  1380. }
  1381. }
  1382. }
  1383. return strData;
  1384. };
  1385. /**
  1386. * PostData 전체를 구한다.
  1387. * @param strRef
  1388. * @return
  1389. */
  1390. XFormsModel.prototype._getPostDataAll = function (strRef, bEncoded, strType, strEncoding, strMediaType)
  1391. {
  1392. var strData = "";
  1393. if (null != strRef && "" != strRef)
  1394. {
  1395. // ref 는 ','로 구분되어 다중으로 쓰일 수 있다.
  1396. var arRef = strRef.split(",");
  1397. for (var i=0; i<arRef.length; i++)
  1398. {
  1399. var strSplitRef = arRef[i];
  1400. if (null != strSplitRef && "" != strSplitRef)
  1401. {
  1402. strSplitRef = strSplitRef.trim();
  1403. }
  1404. var strResult = this._getPostData(strSplitRef, bEncoded, strType, strEncoding, strMediaType);
  1405. if ("error" == strResult)
  1406. {
  1407. return strResult;
  1408. }
  1409. strData += strResult;
  1410. }
  1411. }
  1412. return strData;
  1413. };
  1414. /**
  1415. * ref 하나에 대한 PostData를 구한다.
  1416. * @param strRef
  1417. * @param bEncoded
  1418. * @return
  1419. */
  1420. XFormsModel.prototype._getPostData = function (strRef, bEncoded, strType, strEncoding, strMediaType)
  1421. {
  1422. var strData = "";
  1423. if (null != strRef && "" != strRef)
  1424. {
  1425. var xnDoc = this.getInstanceDocument();
  1426. if ("/" == strRef || "." == strRef)
  1427. {
  1428. this._getPostDataNode(xnDoc, bEncoded, strType, strEncoding, strMediaType);
  1429. }
  1430. else
  1431. {
  1432. var xlChild = XmlLib.selectNodes(xnDoc, strRef);
  1433. for (var i=0; i<xlChild.length; i++)
  1434. {
  1435. var xnChild = xlChild.item(i);
  1436. // 하위 노드 얻기
  1437. strData += this._getPostDataNode(xnChild, bEncoded, strType, strEncoding, strMediaType);
  1438. }
  1439. }
  1440. }
  1441. return strData;
  1442. };
  1443. /**
  1444. * Node 하나에 대한 PostData를 구한다.
  1445. * @param xnNode
  1446. * @param bEncoded
  1447. * @return
  1448. */
  1449. XFormsModel.prototype._getPostDataNode = function (xnNode, bEncoded, strType, strEncoding, strMediaType)
  1450. {
  1451. var strData= "";
  1452. if (!XmlLib.hasChildNodesExceptText(xnNode))
  1453. {
  1454. var strNodeName;
  1455. var strNodeValue;
  1456. var nNodeType = xnNode.nodeType;
  1457. if (Node.ELEMENT_NODE == nNodeType)
  1458. {
  1459. strNodeName = xnNode.nodeName;
  1460. strNodeValue = XmlLib.getTextValue(xnNode);
  1461. if (!bEncoded) // endcode 가 아니면 멀티업데이트
  1462. {
  1463. var arLinkedControl = XFormsDocument.getBindControlsByNode(xnNode);
  1464. var objLinkedControl;
  1465. for (var i = 0; i < arLinkedControl.length; i++)
  1466. {
  1467. objLinkedControl = arLinkedControl[i];
  1468. var strTag = objLinkedControl.attribute["tag"];
  1469. if ("xforms:file" == strTag)
  1470. {
  1471. var arTempValue = strNodeValue.split("?");
  1472. var strTempValue = "";
  1473. for (var i = 0; i < arTempValue.length; i++)
  1474. {
  1475. var arTempFileName = arTempValue[i].split("|");
  1476. if (strTempValue != "") strTempValue += "?";
  1477. strTempValue += arTempFileName[0];
  1478. if (arTempFileName[1])
  1479. {
  1480. strTempValue += "|";
  1481. strTempValue += arTempFileName[1];
  1482. this.m_bHasUploadFile = true;
  1483. }
  1484. }
  1485. if (arTempValue.length > 1) this.m_bHasUploadFile = true;
  1486. if (this.m_bHasUploadFile) strNodeName = "__TF_Upload_" + strNodeName;
  1487. strNodeValue = strTempValue;
  1488. break;
  1489. }
  1490. else if ("xforms:img" == strTag && "true" == objLinkedControl.attribute["upload"])
  1491. {
  1492. var arTempValue = strNodeValue.split("|");
  1493. var strTempValue = arTempValue[0];
  1494. if (arTempValue[1])
  1495. {
  1496. strTempValue += "|";
  1497. strTempValue += arTempValue[1];
  1498. this.m_bHasUploadFile = true;
  1499. strNodeName = "__TF_Upload_" + strNodeName;
  1500. }
  1501. strNodeValue = strTempValue;
  1502. break;
  1503. }
  1504. }
  1505. this.m_hmInstanceData[strNodeName] = strNodeValue;
  1506. return "";
  1507. }
  1508. //TODO checkValid
  1509. //TODO checkRequired
  1510. //TODO checkRelevant
  1511. if ("secure" == strType)
  1512. {
  1513. return strNodeName + "=" + strNodeValue+ "&";
  1514. }
  1515. else
  1516. {
  1517. return URIEncoder.encode(strNodeName, strEncoding) + "=" + URIEncoder.encode(strNodeValue, strEncoding)+ "&";
  1518. }
  1519. }
  1520. }
  1521. else
  1522. {
  1523. var xlChild = xnNode.childNodes;
  1524. for (var i=0; i<xlChild.length; i++)
  1525. {
  1526. var xnChild = xlChild[i];
  1527. // 하위 노드 얻기
  1528. var strResult = this._getPostDataNode(xnChild, bEncoded, strType, strEncoding);
  1529. if ("error" == strResult)
  1530. {
  1531. return strResult;
  1532. }
  1533. strData += strResult;
  1534. }
  1535. }
  1536. return strData;
  1537. };
  1538. XFormsModel.prototype.updateDataForASync = function (xnResult)
  1539. {
  1540. if (null != this.m_objCurrentSubmission)
  1541. {
  1542. var strResultRef = this.m_objCurrentSubmission.attribute["resultref"];
  1543. var strAdd = this.m_objCurrentSubmission.attribute["add"];
  1544. var strReplace = this.m_objCurrentSubmission.attribute["replace"];
  1545. this.updateData(xnResult, strResultRef, strAdd, strReplace);
  1546. if (this.m_objCurrentSubmission.m_refresh)
  1547. {
  1548. model.refreshCurrentModel();
  1549. }
  1550. if (-1 != this.m_objCurrentSubmission.attribute["function"].indexOf("("))
  1551. {
  1552. try{window.eval(this.m_objCurrentSubmission.attribute["function"])}catch(e){};
  1553. }
  1554. else
  1555. {
  1556. try{window.eval(this.m_objCurrentSubmission.attribute["function"]+"();")}catch(e){};
  1557. }
  1558. }
  1559. };
  1560. XFormsModel.prototype.updateData = function (xnResult, strResultRef, strAdd, strReplace)
  1561. {
  1562. if (!xnResult)
  1563. {
  1564. return;
  1565. }
  1566. // add = [none, top, bottom]
  1567. if (null == strAdd || "" == strAdd)
  1568. {
  1569. strAdd = "none";
  1570. }
  1571. // replace = [instance, all]
  1572. if (null == strReplace || "" == strReplace)
  1573. {
  1574. strReplace = "instance";
  1575. }
  1576. var xnInstanceDoc = this.getInstanceDocument();
  1577. if (null != xnInstanceDoc)
  1578. {
  1579. var xnTarget = XmlLib.selectSingleNode(xnInstanceDoc, strResultRef);
  1580. var strNodeName;
  1581. var xnParent;
  1582. // target 노드가 있을 때
  1583. if (xnTarget)
  1584. {
  1585. strNodeName = xnTarget.nodeName;
  1586. xnParent = xnTarget.parentNode;
  1587. // none 일때 기존 XPath의 값을 삭제한다.
  1588. if ("top" != strAdd && "bottom" != strAdd)
  1589. {
  1590. var xlChild = xnParent.childNodes;
  1591. var i = 0;
  1592. while(i<xlChild.length)
  1593. {
  1594. var xnChild = xlChild[i];
  1595. if (strNodeName == xnChild.nodeName)
  1596. {
  1597. xnParent.removeChild(xnChild);
  1598. }
  1599. else
  1600. {
  1601. i++;
  1602. }
  1603. }
  1604. // for (var i=0; i<xlChild.length; i++)
  1605. // {
  1606. // var xnChild = xlChild[i];
  1607. // if (strNodeName == xnChild.nodeName)
  1608. // {
  1609. // xnParent.removeChild(xnChild);
  1610. // }
  1611. // }
  1612. }
  1613. }
  1614. // target 노드가 없을 때
  1615. else
  1616. {
  1617. // append 하기위해 XPath 한 단계 위 부모를 찾는다.
  1618. var nPos = strResultRef.lastIndexOf("/");
  1619. strResultRef = strResultRef.substring(0, nPos);
  1620. xnParent = XmlLib.selectSingleNode(xnInstanceDoc, strResultRef);
  1621. }
  1622. var xlResultChild = xnResult.childNodes;
  1623. // 결과가 있다면 (최상위 노드말고 한단계 밑의 노드들을 사용한다. (TF 논리)
  1624. if (xlResultChild && xnParent)
  1625. {
  1626. for (var i=0; i<xlResultChild.length; i++)
  1627. {
  1628. var xnReusltChild = xlResultChild[i];
  1629. if ("top" == strAdd)
  1630. {
  1631. var xnOldFirstChild = xnParent.firstChild;
  1632. xnParent.insertBefore(xnReusltChild.cloneNode(true), xnOldFirstChild);
  1633. }
  1634. else
  1635. {
  1636. xnParent.appendChild(xnReusltChild.cloneNode(true));
  1637. }
  1638. }
  1639. this._synchronizeInstances();
  1640. }
  1641. }
  1642. };
  1643. XFormsModel.prototype._synchronizeInstances = function ()
  1644. {
  1645. // 인스턴스들을 한번씩 초기화 해준다.
  1646. var arKeyset = this.instances.keys();
  1647. for (var i=0; i<arKeyset.length; i++)
  1648. {
  1649. var strName = arKeyset[i];
  1650. var objInstance = this.instances.item(strName);
  1651. if (null != objInstance)
  1652. {
  1653. objInstance.synchronize();
  1654. }
  1655. }
  1656. };
  1657. XFormsModel.prototype.setParentData = function (xnParentData, strTagetRef)
  1658. {
  1659. if (!xnParentData)
  1660. {
  1661. return;
  1662. }
  1663. else
  1664. {
  1665. if (Node.DOCUMENT_NODE == xnParentData.nodeType)
  1666. {
  1667. xnParentData = xnParentData.firstChild;
  1668. }
  1669. }
  1670. var xnInstanceDoc = this.getInstanceDocument();
  1671. if (null != xnInstanceDoc)
  1672. {
  1673. var xnTarget = XmlLib.selectSingleNode(xnInstanceDoc, strTagetRef);
  1674. // target 노드가 있을 때
  1675. if (xnTarget && xnParentData)
  1676. {
  1677. var xlTargetChild = xnTarget.childNodes;
  1678. if (xlTargetChild)
  1679. {
  1680. var nChildNodeCount = xlTargetChild.length;
  1681. for (var i=0; i<nChildNodeCount; i++)
  1682. {
  1683. xnTarget.removeChild(xnTarget.lastChild);
  1684. }
  1685. }
  1686. var xlParentDataChild = xnParentData.childNodes;
  1687. if (xlParentDataChild)
  1688. {
  1689. for (var i=0; i<xlParentDataChild.length; i++)
  1690. {
  1691. var xnReusltChild = xlParentDataChild[i];
  1692. xnTarget.appendChild(xnReusltChild.cloneNode(true));
  1693. }
  1694. this._synchronizeInstances();
  1695. }
  1696. }
  1697. }
  1698. };
  1699. XFormsModel.prototype.cloneInstances = function ()
  1700. {
  1701. if (0 != this.instances.count())
  1702. {
  1703. var arKeyset = this.instances.keys();
  1704. for (var i=0; i<arKeyset.length; i++)
  1705. {
  1706. var strId = arKeyset[i];
  1707. var objInstance = this.instances.item(strId);
  1708. if (null != objInstance)
  1709. {
  1710. objInstance.cloneInstances();
  1711. }
  1712. }
  1713. }
  1714. };
  1715. XFormsModel.prototype.defaultAction = function (strEventName, event)
  1716. {
  1717. switch(strEventName)
  1718. {
  1719. case "xforms-recalculate" :
  1720. {
  1721. this.recalculate(); break;
  1722. }
  1723. case "xforms-revalidate" :
  1724. {
  1725. break;
  1726. }
  1727. case "xforms-refresh" :
  1728. {
  1729. this.refresh(); break;
  1730. }
  1731. case "xforms-compute-exception" :
  1732. {
  1733. break;
  1734. }
  1735. case "xforms-link-exception" :
  1736. {
  1737. break;
  1738. }
  1739. case "xforms-model-construct" :
  1740. {
  1741. break;
  1742. }
  1743. case "xforms-close" :
  1744. {
  1745. break;
  1746. }
  1747. case "xforms-reset" :
  1748. {
  1749. break;
  1750. }
  1751. case "xforms-ready" :
  1752. {
  1753. //this.cloneInstances();
  1754. break;
  1755. }
  1756. case "onredirecthtml" :
  1757. {
  1758. break;
  1759. }
  1760. case "ontimeout" :
  1761. {
  1762. break;
  1763. }
  1764. }
  1765. };
  1766. //////////////////////////////////////////////////////
  1767. // 전역함수
  1768. XFormsModel.onload = function ()
  1769. {
  1770. __initWindow();
  1771. __initDocument();
  1772. // instance, submission, bind 들을 초기화한다.
  1773. __createElements();
  1774. // event들을 element에 연결한다.
  1775. __addEventListener();
  1776. var strSessionId = model.m_objHttpClient.get(window.getTrustFormURL() + "/SessionStorageManager.tfs?Soonsu_ServiceName=SessionId", false, "text/xml", "utf-8", false);
  1777. model.setSessionId(strSessionId);
  1778. // 부모에서 전달한 값을 받는다.
  1779. window.getParentData();
  1780. // var now = new Date();
  1781. // var nStart = now.getTime();
  1782. // 컨트롤들을 초기화한다.
  1783. model.initChildren();
  1784. now = new Date();
  1785. // if (null != window.console)
  1786. // {
  1787. // console.log(((now.getTime()- nStart)/1000)+"초");
  1788. // }
  1789. // 컨트롤의 tabIndex를 멤버변수로 초기화 한다.
  1790. model.initTabIndex();
  1791. if (is_smartphone)
  1792. {
  1793. $("#HE_body").css("-webkit-tap-highlight-color","rgba(0,0,0,0)");
  1794. }
  1795. if ("visible" == body.getAttribute("visibility"))
  1796. {
  1797. document.body.style.visibility = "visible";
  1798. }
  1799. // xforms-model-construct 이벤트
  1800. if (window.xforms_model_construct || window.xforms_model_construct_model)
  1801. {
  1802. var event = XFormsWindow.getCurrentEvent();
  1803. var strOriginEventName = event.name;
  1804. var strOriginTarget = event.target;
  1805. var strOriginCurrentTarget = event.currentTarget;
  1806. var strOriginDescription = event.description;
  1807. var strOriginPropagate = event.propagate;
  1808. var strOriginDefaultAction = event.defaultAction;
  1809. model.dispatch("xforms-model-construct");
  1810. event.name = strOriginEventName;
  1811. event.target = strOriginTarget;
  1812. event.currentTarget = strOriginCurrentTarget;
  1813. event.description = strOriginDescription;
  1814. event.propagate = strOriginPropagate;
  1815. event.defaultAction = strOriginDefaultAction;
  1816. }
  1817. // model 을 refresh 한다.
  1818. model.refreshCurrentModel();
  1819. // xforms-model-construct_done 이벤트
  1820. if (window.xforms_model_construct_done || window.xforms_model_construct_done_model)
  1821. {
  1822. var event = XFormsWindow.getCurrentEvent();
  1823. var strOriginEventName = event.name;
  1824. var strOriginTarget = event.target;
  1825. var strOriginCurrentTarget = event.currentTarget;
  1826. var strOriginDescription = event.description;
  1827. var strOriginPropagate = event.propagate;
  1828. var strOriginDefaultAction = event.defaultAction;
  1829. model.dispatch("xforms-model-construct-done");
  1830. event.name = strOriginEventName;
  1831. event.target = strOriginTarget;
  1832. event.currentTarget = strOriginCurrentTarget;
  1833. event.description = strOriginDescription;
  1834. event.propagate = strOriginPropagate;
  1835. event.defaultAction = strOriginDefaultAction;
  1836. }
  1837. window.m_bReady = true;
  1838. // xforms-ready 이벤트
  1839. if (window.xforms_ready || window.xforms_ready_model)
  1840. {
  1841. var event = XFormsWindow.getCurrentEvent();
  1842. var strOriginEventName = event.name;
  1843. var strOriginTarget = event.target;
  1844. var strOriginCurrentTarget = event.currentTarget;
  1845. var strOriginDescription = event.description;
  1846. var strOriginPropagate = event.propagate;
  1847. var strOriginDefaultAction = event.defaultAction;
  1848. model.dispatch("xforms-ready");
  1849. event.name = strOriginEventName;
  1850. event.target = strOriginTarget;
  1851. event.currentTarget = strOriginCurrentTarget;
  1852. event.description = strOriginDescription;
  1853. event.propagate = strOriginPropagate;
  1854. event.defaultAction = strOriginDefaultAction;
  1855. }
  1856. var collec = new Object();
  1857. if (null != instance1)
  1858. {
  1859. model.m_resetRoot = instance1.root.cloneNode(true);
  1860. }
  1861. };
  1862. XFormsModel.onunload = function ()
  1863. {
  1864. if (!model.m_bDoneUnload)
  1865. {
  1866. // xforms-close 이벤트
  1867. if (window.xforms_close || window.xforms_close_model)
  1868. {
  1869. try
  1870. {
  1871. if (window.xforms_close)
  1872. {
  1873. xforms_close();
  1874. }
  1875. if (window.xforms_close_model)
  1876. {
  1877. xforms_close_model();
  1878. }
  1879. }
  1880. catch (e)
  1881. {
  1882. }
  1883. }
  1884. // 자식윈도우인 경우 부모의 Children 리스트에서 제거 한다.
  1885. if (null != window.opener)
  1886. {
  1887. try
  1888. {
  1889. window.opener.removeChildWindow(window);
  1890. if (window.opener != window.openerTargetWindow)
  1891. {
  1892. if (null != window.opener.m_objModal)
  1893. {
  1894. window.openerTargetWindow.m_objModal = window.opener.m_objModal;
  1895. }
  1896. else
  1897. {
  1898. window.openerTargetWindow.removeBodyHiddenDiv();
  1899. }
  1900. }
  1901. } catch (e) {}
  1902. }
  1903. // xforms-model-destruct 이벤트
  1904. if (window.xforms_model_destruct || window.xforms_model_destruct_model)
  1905. {
  1906. try
  1907. {
  1908. if (window.xforms_model_destruct)
  1909. {
  1910. xforms_model_destruct();
  1911. }
  1912. if (window.xforms_model_destruct_model)
  1913. {
  1914. xforms_model_destruct_model();
  1915. }
  1916. }
  1917. catch (e)
  1918. {
  1919. }
  1920. }
  1921. model.m_bDoneUnload = true;
  1922. }
  1923. for (var i=0; i<window.children.length; i++)
  1924. {
  1925. var objChild = window.children.item(i);
  1926. if (null != objChild)
  1927. {
  1928. objChild.close();
  1929. }
  1930. }
  1931. };
  1932. /**
  1933. * model에 instance를 추가한다.
  1934. * @param strID
  1935. * @param objInstance
  1936. * @return
  1937. */
  1938. XFormsModel.appendInstance = function (strID, objInstance, strParentId)
  1939. {
  1940. var objModel = document.allElement.item(strParentId);
  1941. if (!objModel)
  1942. {
  1943. objModel = model;
  1944. }
  1945. if (objModel.instances.exists(strID))
  1946. {
  1947. // 기존 같은 아이디의 instance
  1948. var objExistedInstance = objModel.instances.item(strID);
  1949. if (null != objExistedInstance)
  1950. {
  1951. var xlChild = objInstance.root.childNodes;
  1952. for (var i=0; i<xlChild.length; i++)
  1953. {
  1954. var xnChild = xlChild[i];
  1955. XmlLib.importChildNode(objExistedInstance.root, xnChild, true);
  1956. }
  1957. }
  1958. }
  1959. else
  1960. {
  1961. objModel.instances.add(strID, objInstance);
  1962. }
  1963. };
  1964. // TODO createChild 구현중 2011. 03. 15. 박현우 /////////////////////////////////////////////////////////////////////////////////////
  1965. //XFormsModel.create = function (strID, clAttribute, strStyle)
  1966. //{
  1967. //// // 메인노드 생성
  1968. //// var xnModel = XFormsModel.createMainNode(clAttribute);
  1969. //// var xnParent = document.getElementById("HE_"+strParentId);
  1970. //// xnParent.appendChild(xnModel);
  1971. ////
  1972. //// xnModel = XFormsModel.createSubNodes(xnModel, clAttribute);
  1973. //// // object 생성
  1974. // return XFormsModel.createObject(strParentId, xnModel, clAttribute, strStyle);
  1975. //};
  1976. //
  1977. //XFormsModel.createObject = function (strParentId, xnModel, clAttribute, strStyle)
  1978. //{
  1979. //// XFormsModel (strParentId, bAutodata, strID, strTag)
  1980. //// var bAutodata = "";
  1981. //// var strId = xnModel.getAttribute("elementid");
  1982. //// var strUserDefineAttrib = "";
  1983. ////
  1984. //// for (var i=0; i<clAttribute.count(); i++)
  1985. //// {
  1986. //// var strAttributeName = clAttribute.keys()[i];
  1987. //// switch (strAttributeName)
  1988. //// {
  1989. //// case "autodata" :
  1990. //// {
  1991. //// if ("true" == clAttribute.item(strAttributeName))
  1992. //// bAutodata = true;
  1993. //// break;
  1994. //// }
  1995. //// default :
  1996. //// {
  1997. //// if (!STYLE_LIST[strAttributeName])
  1998. //// {
  1999. //// strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  2000. //// }
  2001. //// break;
  2002. //// }
  2003. //// }
  2004. //// }
  2005. //// var objModel = new XFormsModel (strParentId, bAutodata, "xforms:model", strUserDefineAttrib);
  2006. //// return objModel;
  2007. //};
  2008. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////