XFormsButton.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. XFormsButton.prototype = new XFormsCaption;
  2. function XFormsButton (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoresize, strBind, strClass, bDisabled,
  3. bEllipsis, strFormat, strGroup, strGroupalign, strId, nNavindex, strRef, strRoundmode, nRoundposition, bSelected, strStyle, strTag, strVisibility, strUserDefineAttrib)
  4. {
  5. if (!strId)
  6. {
  7. return;
  8. }
  9. XFormsCaption.call(this, strParentId, strAlert, strHelp, strHint, strText, strAccesskey, bAutoresize, strBind, strClass, bDisabled,
  10. bEllipsis, strFormat, strId, nNavindex, strRef, strRoundmode, nRoundposition, strStyle, strTag, strVisibility, strUserDefineAttrib);
  11. /**
  12. * Attribute
  13. */
  14. this.attribute["group"] = strGroup;
  15. this.attribute["groupalign"] = strGroupalign;
  16. this.attribute["selected"] = String(bSelected);
  17. /**
  18. * Property
  19. */
  20. this.selected = bSelected;
  21. this.m_heControl = document.getElementById("HE_" + this.id);
  22. this.m_strTargetGrid = "";
  23. this.m_heLodExcelForm = null;
  24. };
  25. /**
  26. * 인스턴스 데이터를 실제 컨트롤에 반영
  27. * @return
  28. */
  29. XFormsButton.prototype.refresh = function ()
  30. {
  31. XFormsBindableControl.prototype.refresh.call(this);
  32. with(this)
  33. {
  34. if (null != m_heControl)
  35. {
  36. var strRef = attribute["ref"];
  37. var strValue = (null != strRef && "" != strRef) ? model.getValue(strRef) : getAttribute("text");
  38. if (null != m_heControlText)
  39. {
  40. m_heControlText.innerHTML = strValue.newlineCharConvert();
  41. }
  42. }
  43. }
  44. };
  45. XFormsButton.prototype.getBindingType = function ()
  46. {
  47. return BT_SINGLE;
  48. };
  49. XFormsButton.prototype.init = function ()
  50. {
  51. XFormsCaption.prototype.init.call(this);
  52. if (null != this.m_heControlText)
  53. {
  54. var strText = this.getAttribute("text");
  55. this.m_heControlText.innerHTML = strText.newlineCharConvert();
  56. }
  57. if ("xforms:inputbutton" == this.attribute["tag"])
  58. {
  59. if (null != this.parent)
  60. {
  61. var nControlLeft = Number(this.parent.attribute["left"].split("px")[0]);
  62. var nControlWidth = this.parent.m_heControl.clientWidth;
  63. var nControlTargetWidth = 16 > this.m_heControl.clientWidth ? 16 : this.m_heControl.clientWidth;
  64. this.m_heControl.style.left = (nControlLeft + nControlWidth - nControlTargetWidth) + "px";
  65. this.m_heControl.style.height = this.parent.m_heControl.clientHeight + "px";
  66. }
  67. }
  68. this.m_strTargetGrid = this.getAttribute("loadexcelgrid");
  69. if (null != this.m_strTargetGrid && "" != this.m_strTargetGrid)
  70. {
  71. this.createExcelButton();
  72. }
  73. };
  74. XFormsButton.prototype.createExcelButton = function ()
  75. {
  76. if (null == this.m_heLodExcelForm)
  77. {
  78. if (is_ie6 || is_ie7 || is_ie8)
  79. {
  80. this.m_heLodExcelForm = document.createElement("<form encType='multipart/form-data'>");
  81. }
  82. else
  83. {
  84. this.m_heLodExcelForm = document.createElement("form");
  85. this.m_heLodExcelForm.setAttribute("enctype","multipart/form-data");
  86. }
  87. this.m_heLodExcelForm.action = __getAppName () + "/LoadExcel.tfs";
  88. this.m_heLodExcelForm.method = "post";
  89. this.m_heLodExcelForm.target = "HE___TF_LoadExcel";
  90. this.m_heLodExcelForm.style.filter = "alpha(opacity=0)";
  91. this.m_heLodExcelForm.style.opacity = 0;
  92. this.m_heLodExcelForm.style.position = "absolute";
  93. this.m_heLodExcelForm.style.top = this.getAttribute("top");
  94. this.m_heLodExcelForm.style.left = this.getAttribute("left");
  95. this.m_heLodExcelForm.style.width = this.getAttribute("width");
  96. this.m_heLodExcelForm.style.height = this.getAttribute("height");
  97. if (is_ie6 || is_ie7)
  98. {
  99. var strTag = "<input type='hidden' name='nodeset'/>";
  100. strTag += "<input type='file' name='excel' onchange='"+this.id+".loadExcelGrid();' style='top:0px;left:0px;width:100%;height:100%;cursor:hand;' />";
  101. this.m_heLodExcelForm.innerHTML = strTag;
  102. }
  103. else
  104. {
  105. var heGridStatus = document.createElement("input");
  106. heGridStatus.type = "hidden";
  107. heGridStatus.name = "nodeset";
  108. var heExcelFile = document.createElement("input");
  109. heExcelFile.type = "file";
  110. heExcelFile.name = "excel";
  111. heExcelFile.style.top = "0px";
  112. heExcelFile.style.left = "0px";
  113. heExcelFile.style.width = "100%";
  114. heExcelFile.style.height = "100%";
  115. heExcelFile.style.cursor = "hand";
  116. heExcelFile.setAttribute("onchange",this.id + ".loadExcelGrid();");
  117. this.m_heLodExcelForm.appendChild(heGridStatus);
  118. this.m_heLodExcelForm.appendChild(heExcelFile);
  119. }
  120. if (null != this.parent.m_heControl)
  121. {
  122. this.parent.m_heControl.appendChild(this.m_heLodExcelForm);
  123. }
  124. }
  125. };
  126. XFormsButton.prototype.loadExcelGrid = function ()
  127. {
  128. var strFileType = this.m_heLodExcelForm.lastChild.value;
  129. strFileType = strFileType.substring(strFileType.lastIndexOf(".") + 1, strFileType.length);
  130. if ("xlsx" != strFileType && "xls" != strFileType)
  131. {
  132. if (null != window.console)
  133. {
  134. console.log("올바른 Excel File 형식이 아닙니다.");
  135. }
  136. return;
  137. }
  138. var objTargetGrid = document.allElement.item(this.m_strTargetGrid);
  139. if (null != objTargetGrid)
  140. {
  141. var strNodeSet = objTargetGrid.nodeset + "@";
  142. var bFirst = true;
  143. for (var i=0; i<objTargetGrid.m_arColumn.length; i++)
  144. {
  145. var strRef = objTargetGrid.m_arColumn[i].getAttribute("ref");
  146. if ("" != strRef.trim())
  147. {
  148. if (bFirst)
  149. {
  150. strNodeSet += strRef;
  151. bFirst = false;
  152. }
  153. else
  154. {
  155. strNodeSet += "," + strRef;
  156. }
  157. }
  158. }
  159. this.m_heLodExcelForm.firstChild.value = encodeURI(strNodeSet + "@" + strFileType);
  160. }
  161. else
  162. {
  163. if (null != window.console)
  164. {
  165. console.log("Load Excel을 적용할 Target Grid가 존재하지 않습니다.");
  166. }
  167. return;
  168. }
  169. LOAD_EXCEL_GRID = this.m_strTargetGrid;
  170. LOAD_EXCEL_BUTTON = this;
  171. var xnFrame = document.getElementById("HE___TF_LoadExcel");
  172. if (xnFrame)
  173. {
  174. xnFrame.setAttribute("targetGrid", this.m_strTargetGrid);
  175. if (xnFrame.attachEvent)
  176. {
  177. xnFrame.attachEvent("onload", XFormsButton.uploadComplete);
  178. }
  179. else
  180. {
  181. xnFrame.addEventListener("load", XFormsButton.uploadComplete, false);
  182. }
  183. }
  184. this.m_heLodExcelForm.submit();
  185. this.m_heLodExcelForm.reset();
  186. };
  187. XFormsButton.prototype.isCSSValid = function (strKey)
  188. {
  189. var bValid = XFormsCaption.prototype.isCSSValid.call(this);
  190. if ("background-image" == strKey && !bValid)
  191. {
  192. if ("xforms:inputbutton" == this.getTag())
  193. {
  194. if ("url("+__getAppName()+"/kr/comsquare/image/input/button.png)" == HtmlLib.getStyle(this.m_heControl, strKey))
  195. {
  196. return true;
  197. }
  198. }
  199. else if ("xforms:combobutton" == this.getTag())
  200. {
  201. if ("url("+__getAppName()+"/kr/comsquare/image/combo/combo.gif)" == HtmlLib.getStyle(this.m_heControl, strKey))
  202. {
  203. return true;
  204. }
  205. }
  206. }
  207. return bValid;
  208. };
  209. XFormsButton.prototype.applyDefaultStyle = function ()
  210. {
  211. XFormsCaption.prototype.applyDefaultStyle.call(this);
  212. // 컨트롤 생성당시에 입력된 스타일이 있는지 판단해 원래 스타일로 되돌려준다.
  213. // if (!this.attribute["background-repeat"])
  214. // {
  215. // this.m_heControl.style.backgroundRepeat = "";
  216. // }
  217. //
  218. // // background-color의 존재 여부
  219. // if (!this.attribute["background-color"])
  220. // {
  221. // this.m_heControl.style.backgroundColor = "";
  222. // }
  223. // 기존 border-style이 없을경우에 border를 지운다.
  224. if (this.attribute["border-style"])
  225. {
  226. if (!this.attribute["border-width"])
  227. {
  228. this.m_heControl.style.borderWidth = "1px";
  229. }
  230. }
  231. else
  232. {
  233. this.m_heControl.style.borderWidth = "";
  234. }
  235. if (null == this.attribute["cursor"])
  236. {
  237. this.m_heControl.style.cursor = "hand";
  238. }
  239. // 버튼 내용이 흘러 내리는 것을 없애기 위해 "overflow:hidden"을 준다
  240. this.m_heControl.style.overflow = "hidden";
  241. };
  242. XFormsButton.prototype.setAttribute = function (strAttribute, strValue)
  243. {
  244. XFormsCaption.prototype.setAttribute.call(this, strAttribute, strValue);
  245. switch (strAttribute)
  246. {
  247. case "text":
  248. {
  249. this.attribute["text"] = strValue;
  250. this.refresh();
  251. break;
  252. }
  253. case "group" :
  254. {
  255. this.attribute["group"] = strValue;
  256. break;
  257. }
  258. case "groupalign" :
  259. {
  260. this.attribute["groupalign"] = strValue;
  261. break;
  262. }
  263. case "selected" :
  264. {
  265. this.attribute["selected"] = strValue;
  266. break;
  267. }
  268. }
  269. };
  270. XFormsButton.prototype.onClick = function (event)
  271. {
  272. XFormsCaption.prototype.onClick.call(this, event);
  273. if (event.target == this.getId())
  274. {
  275. var strGroup = this.getAttribute("group");
  276. if (!strGroup.isEmpty() && !this.getState(FCS_SELECT))
  277. {
  278. this.setState(FCS_SELECT, true, event);
  279. }
  280. this.dispatch("DOMActivate");
  281. this.dispatch("xforms-activate");
  282. }
  283. };
  284. XFormsButton.prototype.onKeyPress = function (event)
  285. {
  286. XFormsCaption.prototype.onKeyPress.call(this, event);
  287. if (event.target == this.getId() &&
  288. (TFEvent.ENTER == event.keyCode || TFEvent.SPACE == event.keyCode))
  289. {
  290. var strGroup = this.getAttribute("group");
  291. if (!strGroup.isEmpty() && !this.getState(FCS_SELECT))
  292. {
  293. this.setState(FCS_SELECT, true, event);
  294. }
  295. this.dispatch("DOMActivate");
  296. this.dispatch("xforms-activate");
  297. }
  298. };
  299. XFormsButton.prototype.onafterloadexcel = function ()
  300. {
  301. };
  302. XFormsButton.create = function (strParentId, clAttribute, strStyle)
  303. {
  304. // 메인노드 생성
  305. var xnButton = XFormsButton.createMainNode(clAttribute);
  306. var xnParent = document.getElementById("HE_"+strParentId);
  307. xnParent.appendChild(xnButton);
  308. // 하위노드 생성
  309. xnButton = XFormsButton.createSubNodes(xnButton, clAttribute);
  310. // object 생성
  311. return XFormsButton.createObject(strParentId, xnButton, clAttribute, strStyle);
  312. };
  313. XFormsButton.createMainNode = function (clAttribute)
  314. {
  315. var xnButton = document.createElement("button");
  316. xnButton = XFormsButton.createAttribute(xnButton, clAttribute);
  317. return xnButton;
  318. };
  319. XFormsButton.createSubNodes = function (xnButton, clAttribute)
  320. {
  321. var xnButtonText = document.createElement("span");
  322. if (xnButton.getAttribute("text"))
  323. {
  324. xnButton.innerHTML = xnButton.getAttribute("text").newlineCharConvert();
  325. }
  326. xnButton.appendChild(xnButtonText);
  327. return xnButton;
  328. };
  329. XFormsButton.createObject = function (strParentId, xnButton, clAttribute, strStyle)
  330. {
  331. var strAlert = "";
  332. var strHelp = "";
  333. var strHint = "";
  334. var strText = "";
  335. var strAccesskey = "";
  336. var strClass = "";
  337. var bDisabled = false;
  338. var bEllipsis = false;
  339. var strGroup = "";
  340. var strGroupAlign = "";
  341. var strId = "";
  342. var nNavindex = 9007199254740992;
  343. var strRef = "";
  344. var bSelected = false;
  345. var strVisibility = "visible";
  346. var strUserDefineAttrib = "";
  347. for (var i=0; i<clAttribute.count(); i++)
  348. {
  349. var strAttributeName = clAttribute.keys()[i];
  350. switch (strAttributeName)
  351. {
  352. case "alert" :
  353. {
  354. strAlert = clAttribute.item(strAttributeName);
  355. break;
  356. }
  357. case "help" :
  358. {
  359. strHelp = clAttribute.item(strAttributeName);
  360. break;
  361. }
  362. case "hint" :
  363. {
  364. strHint = clAttribute.item(strAttributeName);
  365. break;
  366. }
  367. case "text" :
  368. {
  369. strText = clAttribute.item(strAttributeName);
  370. break;
  371. }
  372. case "accesskey" :
  373. {
  374. strAccesskey = clAttribute.item(strAttributeName);
  375. break;
  376. }
  377. case "class" :
  378. {
  379. strClass = clAttribute.item(strAttributeName);
  380. break;
  381. }
  382. case "disabled" :
  383. {
  384. if ("true" == clAttribute.item(strAttributeName))
  385. {
  386. bDisabled = true;
  387. }
  388. break;
  389. }
  390. case "ellipsis" :
  391. {
  392. if ("true" == clAttribute.item(strAttributeName))
  393. {
  394. bEllipsis = true;
  395. }
  396. break;
  397. }
  398. case "group" :
  399. {
  400. strGroup = clAttribute.item(strAttributeName);
  401. break;
  402. }
  403. case "groupalign" :
  404. {
  405. strGroupAlign = clAttribute.item(strAttributeName);
  406. break;
  407. }
  408. case "id" :
  409. {
  410. strId = clAttribute.item(strAttributeName);
  411. break;
  412. }
  413. case "navindex" :
  414. {
  415. nNavindex = parseInt(clAttribute.item(strAttributeName));
  416. break;
  417. }
  418. case "selected" :
  419. {
  420. if ("true" == clAttribute.item(strAttributeName))
  421. {
  422. bSelected = true;
  423. }
  424. break;
  425. }
  426. case "visibility" :
  427. {
  428. strVisibility = clAttribute.item(strAttributeName);
  429. break;
  430. }
  431. default :
  432. {
  433. if (!STYLE_LIST[strAttributeName])
  434. {
  435. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  436. }
  437. break;
  438. }
  439. }
  440. }
  441. var objButton = new XFormsButton (strParentId, strAlert, strHelp, strHint, strText, strAccesskey, false, "", strClass, bDisabled, bEllipsis, "", strGroup, strGroupAlign, strId, nNavindex, strRef, "", -1, bSelected, strStyle, "xforms:button", strVisibility, strUserDefineAttrib);
  442. return objButton;
  443. };
  444. XFormsButton.createAttribute = function (xnHtmlNode, clAttribute)
  445. {
  446. xnHtmlNode = XFormsCaption.createAttribute(xnHtmlNode, clAttribute);
  447. return xnHtmlNode;
  448. };
  449. XFormsButton.uploadComplete = function ()
  450. {
  451. // var xnFrameDoc = document.getElementById("HE___TF_LoadExcel").contentWindow.document;
  452. var strReturnXML = document.getElementById("HE___TF_LoadExcel").contentWindow.strLoadXml;
  453. // if (is_ie)
  454. // {
  455. // if (xnFrameDoc.XMLDocument)
  456. // {
  457. // strReturnXML = xnFrameDoc.XMLDocument.xml;
  458. // }
  459. // else
  460. // {
  461. // var serializer = new XMLSerializer();
  462. // strReturnXML = serializer.serializeToString(xnFrameDoc);
  463. // }
  464. // }
  465. // else
  466. // {
  467. // var serializer = new XMLSerializer();
  468. // strReturnXML = serializer.serializeToString(xnFrameDoc);
  469. // }
  470. if (strReturnXML)
  471. {
  472. var xnReturn = XmlLib.loadXMLFromString(strReturnXML);
  473. if (!xnReturn.selectSingleNode("/root/TF_EXCEL_ERR"))
  474. {
  475. var strExportFalseRows = LOAD_EXCEL_BUTTON.getAttribute("exportfalserows");
  476. var nExportFalseRows = strExportFalseRows.isEmpty() ? 0 : parseInt(strExportFalseRows);
  477. var objTargetGrid = document.allElement.item(LOAD_EXCEL_GRID);
  478. var strTargetNode = objTargetGrid.nodeset.substring(0, objTargetGrid.nodeset.lastIndexOf("/"));
  479. var strParentTargetNode = objTargetGrid.nodeset;
  480. if (null != objTargetGrid)
  481. {
  482. if (null != model)
  483. {
  484. var xnInstanceDoc = model.getInstanceDocument();
  485. if (null != xnInstanceDoc)
  486. {
  487. var xnNewRoot = XmlLib.getRootElementNode(xnReturn);
  488. var xnParentGridNode = xnInstanceDoc.selectSingleNode(strTargetNode);
  489. var xlGridItem = XmlLib.selectNodes(xnInstanceDoc, strParentTargetNode);
  490. var nXlGridItemLen = xlGridItem.length;
  491. for (var i=0; i<nXlGridItemLen; i++)
  492. {
  493. xnParentGridNode.removeChild(xlGridItem.item(i));
  494. }
  495. var xnNewGridNode = xnNewRoot.selectSingleNode(strTargetNode);
  496. var xnNewGridNodeChild= xnNewGridNode.childNodes.item(nExportFalseRows);
  497. while(xnNewGridNodeChild)
  498. {
  499. xnParentGridNode.appendChild(xnNewGridNodeChild.cloneNode(true));
  500. xnNewGridNodeChild = xnNewGridNodeChild.nextSibling;
  501. }
  502. }
  503. }
  504. objTargetGrid.refresh();
  505. LOAD_EXCEL_BUTTON.dispatch("onafterloadexcel");
  506. }
  507. }
  508. else
  509. {
  510. if(window.console)
  511. {
  512. console.log("loadExcel 오류 : 잘못된 타입의 Excel 파일 입니다.");
  513. }
  514. }
  515. }
  516. };