PageRenderTime 147ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Triad.Controls/tfResources/rel_js/edpopup.js

#
JavaScript | 391 lines | 386 code | 1 blank | 4 comment | 26 complexity | 1e42ed66d9743a9e8df3d7a6c7dc4138 MD5 | raw file
  1. /*
  2. tfpopup.js 1.0.8
  3. handles modal dialog boxes, etc
  4. */
  5. var alertTypes={Error:1,Warning:2,Information:3};
  6. var locTypes={NW:1,N:2,NE:3,E:4,SE:5,S:6,SW:7,W:8,CEN:9};
  7. var contentTypes={iframe:1,html:2,alert:3,MsgBox:4,csMsgBox:5};
  8. var msgboxType={ok:1,yes:2,yesno:3,yesnocancel:4};
  9. var returnFunc={pbContentPage:1,pbPrevDlg:2};
  10. var gTabbableTags=[];
  11. var gTabIndexes=[];
  12. var gIteration=-1;
  13. var gDefaultPage="about:blank";
  14. var iTimeoutID;
  15. var gTabbableTags=["A","BUTTON","TEXTAREA","INPUT","IFRAME"];
  16. function disableTabIndexes(){if(document.all){var i=0;for(var j=0;j<gTabbableTags.length;j++){var tagElements=document.getElementsByTagName(gTabbableTags[j]);for(var k=0;k<tagElements.length;k++){gTabIndexes[i]=tagElements[k].tabIndex;tagElements[k].tabIndex="-1";i++;}}}}
  17. function restoreTabIndexes(){if(document.all){var i=0;for(var j=0;j<gTabbableTags.length;j++){var tagElements=document.getElementsByTagName(gTabbableTags[j]);for(var k=0;k<tagElements.length;k++){tagElements[k].tabIndex=gTabIndexes[i];tagElements[k].tabEnabled=true;i++;}}}}
  18. function getWidth(width){var pWidth;if(width==undefined){width='85%';}if(isNaN(width)){if(width.search(/\%/)!=-1){pWidth=getViewPortWidth()*(width.replace("\%","")/100);}}else{pWidth=width;}return pWidth;}
  19. function getHeight(height){var pHeight;if(height==undefined){height='90%';}if(isNaN(height)){if(height.search(/\%/)!=-1){pHeight=getViewPortHeight()*(height.replace("\%","")/100);}}else{pHeight=height;}return pHeight;}
  20. function getScrollTop(){if(top.pageYOffset){return top.pageYOffset;}else if(top.document.documentElement&&top.document.documentElement.scrollTop){return top.document.documentElement.scrollTop;}else if(top.document.body){return top.document.body.scrollTop;}}
  21. function ModalDlg(options){
  22. var defaultOptions={
  23. id:'',
  24. type:2,
  25. width:600,
  26. height:600,
  27. loc:'CEN',
  28. title:'Dialog',
  29. alertText:g_jsErrorTxt,
  30. alertType:0,
  31. alertTask:'unknown',
  32. msgboxType:0,
  33. msgboxQuestion:'',
  34. URL:'',
  35. HTML:'',
  36. returnFocusID:'',
  37. returnFunc:'',
  38. showClose:false,
  39. autoClose:-1,
  40. modal:false
  41. };
  42. options=options||{};
  43. for(var name in defaultOptions){
  44. if(!options.hasOwnProperty(name)){
  45. options[name]=defaultOptions[name];
  46. }
  47. }
  48. var _me=this;
  49. gIteration++;
  50. _me.iter=gIteration;
  51. _me.id=options.id;
  52. _me.contentType=options.type;
  53. _me.width=options.width;
  54. _me.msgboxQuestion=options.msgboxQuestion;
  55. _me.msgboxType=options.msgboxType;
  56. _me.height=options.height;
  57. _me.loc=options.loc;
  58. _me.title=options.title;
  59. _me.blnClose=options.showClose;
  60. _me.alertText=options.alertText;
  61. _me.alertType=options.alertType;
  62. _me.autoClose=options.autoClose;
  63. _me.setFocusId=options.returnFocusID;
  64. _me.callBackFunc=options.returnFunc;
  65. _me.myHTML=options.HTML;
  66. _me.myURL=options.URL;
  67. _me.sTask=options.alertTask;
  68. _me.isModal=options.modal;
  69. var strType="mdl";
  70. if(_me.contentType!=contentTypes.iframe){
  71. strType="alt";
  72. }
  73. _me.tBody=document.getElementById(strType+'Dialog'+_me.iter);
  74. if(_me.tBody==null){
  75. _me.tBody=document.createElement("div");
  76. _me.tBody.id=strType+"Dialog"+_me.iter;
  77. document.body.appendChild(_me.tBody);
  78. }
  79. _me.Mask=document.createElement("div");
  80. _me.Mask.id=strType+"DlgMask_"+_me.iter;
  81. _me.Mask.className="ModalDlgMask";
  82. _me.Con=document.createElement("div");
  83. _me.Con.id=strType+"DlgContainer_"+_me.iter;
  84. _me.Con.className="ModalDlgContainer";
  85. _me.MDI=document.createElement("div");
  86. _me.MDTB=document.createElement("div");
  87. _me.MDT=document.createElement("div");
  88. _me.MDC=document.createElement("div");
  89. _me.HFLD=document.createElement("INPUT");
  90. _me.Content=null;
  91. _me.arrTemp=[];
  92. _me.setTask=function(sTask){_me.sTask=sTask;};
  93. _me.setType=function(contentType){_me.contentType=contentType;};
  94. _me.setURL=function(sUrl){_me.myURL=sUrl;};
  95. _me.setCallBackFunc=function(callBackFunc){_me.callBackFunc=callBackFunc;};
  96. _me.setFocusOnReturn=function(elId){_me.setFocusId=elId;};
  97. _me.setHTML=function(newHTML){_me.myHTML=newHTML;};
  98. _me.setModal=function(sModal){_me.isModal=sModal;};
  99. _me.setAlertType=function(aType){_me.alertType=aType;};
  100. _me.setTitle=function(sTitle){_me.title=sTitle;};
  101. _me.setLocation=function(locType){_me.loc=locType;};
  102. _me.setAutoClose=function(sSeconds){_me.autoClose=sSeconds*1000;};
  103. _me.init=function(){
  104. var arrTemp=[];
  105. _me.MDI.id="MDI"+_me.iter;
  106. _me.MDTB.id="MDTB"+_me.iter;
  107. _me.MDT.id="MDT"+_me.iter;
  108. _me.MDC.id="MDI"+_me.iter;
  109. _me.HFLD.id="HFLD"+_me.iter;
  110. _me.HFLD.setAttribute("type","button");
  111. var cImg=document.createElement("img");
  112. cImg.id="popCloseBox_"+_me.iter;
  113. switch(_me.contentType){
  114. case contentTypes.MsgBox:case contentTypes.csMsgBox:
  115. var image=edIs;
  116. var cs=_me.contentType==contentTypes.csMsgBox?true:false;
  117. var onClose="javascript:edRaiseEvent('"+_me.id+"','OnClose','~t');";
  118. var strButtons='';
  119. if(_me.id==''){_me.id='msgBoxValue';}
  120. if(_me.callBackFunc==returnFunc.pbContentPage){
  121. onClose+="top.frames['ifMainContent'].__doPostBack('"+_me.id+"','~t');";
  122. }
  123. else if(_me.callBackFunc==returnFunc.pbPrevDlg){
  124. onClose+="javascript:edRaiseEvent('"+_me.id+"','OnClose','~t');postBackbPrevDlg('"+_me.id+"','~t');";
  125. }
  126. _me.returnFunc="";
  127. onClose+="g_MsgBox.hide("+_me.contentType+");";
  128. switch(_me.msgboxType){
  129. case msgboxType.ok:
  130. image=edIs;
  131. strButtons+="<td style='width:50%;'></td>";
  132. strButtons+="<td></td>";
  133. strButtons+="<td><input id='s1' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","ok")+"\" type=button value=OK name=MessageBoxIDYes1 /></td>";
  134. strButtons+="<td></td>";
  135. strButtons+="<td style='width:50%;'>&nbsp;</td>";
  136. break;
  137. case msgboxType.yes:
  138. image=edIs;
  139. strButtons+="<td style='width:50%;'></td>";
  140. strButtons+="<td></td>";
  141. strButtons+="<td><input id='s1' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","yes")+"\" type=button value=OK name=MessageBoxIDYes1 /></td>";
  142. strButtons+="<td></td>";
  143. strButtons+="<td style='width:50%;'></td>";
  144. break;
  145. case msgboxType.yesno:
  146. image=edIs;
  147. strButtons+="<td style='width:50%;'></td>";
  148. strButtons+="<td><input id='s1' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","yes")+"\" type=button value=Yes name=MessageBoxIDYes1 /></td></td>";
  149. strButtons+="<td>&nbsp;&nbsp;&nbsp;</td>";
  150. strButtons+="<td><input id='s2' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","no")+"\" type=button value=No name=MessageBoxIDNo1 /></td></td>";
  151. strButtons+="<td style='width:50%;'></td>";
  152. break;
  153. case msgboxType.yesnocancel:
  154. image=edIs;
  155. strButtons+="<td style='width:50%;'></td>";
  156. strButtons+="<td><input id='s1' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","yes")+"\" type=button value=Yes name=MessageBoxIDYes1 /></td></td>";
  157. strButtons+="<td><input id='s2' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","no")+"\" type=button value=No name=MessageBoxIDNo1 /></td></td>";
  158. strButtons+="<td><input id='s3' style='WIDTH: 50px; CURSOR: hand' onclick=\""+onClose.replaceAll("~t","cancel")+"\" type=button value=Cancel name=MessageBoxIDCancel1 /></td></td>";
  159. strButtons+="<td style='width:50%;'></td>";
  160. break;
  161. }
  162. cImg.setAttribute("src",edXs);
  163. _me.Content=document.createElement("div");
  164. _me.MDI.className="NotifyDlgInner";
  165. _me.MDTB.className="NotifyDlgTitleBar";
  166. _me.MDT.className="NotifyDlgTitle";
  167. _me.MDT.innerHTML=_me.title;
  168. _me.MDC.className="NotifyDlgControls";
  169. _me.Content.setAttribute("style","overflow:auto;");
  170. var strHTML="<table style='width: 100%;text-align:center;background-color: lightgrey;'>";
  171. strHTML+="<tr><td ><img style='border: black 1px solid; height:25px' src='"+image+"' alt='' /></td>";
  172. strHTML+="<td style='text-align:left;padding:5px;' colspan='4'>"+_me.msgboxQuestion+"</td></tr><tr>";
  173. strHTML+=strButtons;
  174. strHTML+="</tr></table></div></div>";
  175. _me.Content.innerHTML=strHTML;
  176. _me.setModal(true);
  177. break;
  178. case contentTypes.html:
  179. var image=edIs;
  180. switch(_me.alertType){
  181. case alertTypes.Error:
  182. _me.autoClose=-1;
  183. top.edNLog.error(g_jsErrorTxt,_me.sTask);
  184. image=edEs;
  185. break;
  186. case alertTypes.Warning:
  187. top.edNLog.warning(g_jsErrorTxt,_me.sTask);
  188. image=edWs;
  189. break;
  190. case alertTypes.Information:
  191. top.edNLog.info(g_jsErrorTxt,_me.sTask);
  192. image=edIs;
  193. break;
  194. }
  195. cImg.setAttribute("src",edXs);
  196. _me.Content=document.createElement("div");
  197. _me.MDI.className="NotifyDlgInner";
  198. _me.MDTB.className="NotifyDlgTitleBar";
  199. _me.MDT.className="NotifyDlgTitle";
  200. _me.MDT.innerHTML=_me.title;
  201. _me.MDC.className="NotifyDlgControls";
  202. _me.Content.setAttribute("style","overflow:auto;");
  203. _me.Content.innerHTML="<table style='width:95%'><tr><td align='center'><img src='"+image+"' alt=''></img></td><td>"+_me.errText+"</td></tr></table></div></div>";
  204. break;
  205. case contentTypes.alert:
  206. var image=edIs;
  207. switch(_me.alertType){
  208. case alertTypes.Error:
  209. _me.autoClose=-1;
  210. top.edNLog.error(g_jsErrorTxt,_me.sTask);
  211. image=edEs;
  212. break;
  213. case alertTypes.Warning:
  214. top.edNLog.warning(g_jsErrorTxt,_me.sTask);
  215. image=edWs;
  216. break;
  217. case alertTypes.Information:
  218. top.edNLog.info(g_jsErrorTxt,_me.sTask);
  219. image=edIs;
  220. break;
  221. }
  222. cImg.setAttribute("src",edXs);
  223. _me.Content=document.createElement("div");
  224. _me.MDI.className="NotifyDlgInner";
  225. _me.MDTB.className="NotifyDlgTitleBar";
  226. _me.MDT.className="NotifyDlgTitle";
  227. _me.MDT.innerHTML=_me.title;
  228. _me.MDC.className="NotifyDlgControls";
  229. _me.Content.setAttribute("style","overflow:auto;");
  230. _me.Content.innerHTML="<table style='width:95%'><tr><td align='center'><img src='"+image+"' alt=''></img></td><td>"+_me.alertText+"</td></tr></table></div></div>";
  231. break;
  232. case contentTypes.iframe:
  233. _me.MDI.className="ModalDlgInner";
  234. _me.MDTB.className="ModalDlgTitleBar";
  235. _me.MDT.className="ModalDlgTitle";
  236. _me.MDT.innerHTML="<img src='"+gsfICON+"' alt=''></img>&nbsp;&nbsp;"+_me.title;
  237. _me.MDC.className="ModalDlgControls";
  238. cImg.setAttribute("src",edX);
  239. _me.Content=document.createElement("iframe");
  240. _me.Content.setAttribute("src",_me.myURL);
  241. _me.Content.setAttribute("style","width:100%;height:100%;background-color:transparent;");
  242. _me.Content.setAttribute("scrolling","auto");
  243. _me.Content.setAttribute("frameborder","0");
  244. _me.Content.setAttribute("allowtransparency","true");
  245. _me.Content.className="ModalDlgFrame";
  246. if(_me.id!=''){
  247. _me.Content.id=_me.id;
  248. _me.Content.setAttribute("name",_me.id);
  249. }
  250. else{
  251. _me.Content.id=strType+"DlgFrame_"+_me.iter;
  252. _me.Content.setAttribute("name",strType+"DlgFrame_"+_me.iter);
  253. }
  254. _me.Content.setAttribute("width","100%");
  255. _me.Content.setAttribute("height","100%");
  256. break;
  257. default:break;
  258. }
  259. _me.MDC.appendChild(cImg);
  260. _me.MDTB.appendChild(_me.MDT);
  261. _me.MDTB.appendChild(_me.MDC);
  262. _me.MDI.appendChild(_me.MDTB);
  263. _me.MDI.appendChild(_me.Content);
  264. _me.Con.appendChild(_me.MDI);
  265. _me.tBody.appendChild(_me.Mask);
  266. _me.tBody.appendChild(_me.Con);
  267. edEnableDrag(_me.Con.id);
  268. edAddEvent(_me.MDC,"click",function(){_me.hide(_me.contentType);});
  269. };
  270. _me.show=function show(){
  271. var pWidth=getWidth(_me.width);
  272. var pHeight=getHeight(_me.height)-30;
  273. _me.init();
  274. var t=getLocationPoint(pWidth,pHeight,_me.loc);
  275. _me.Con.style.left=t.x;
  276. _me.Con.style.top=t.y;
  277. if(_me.alertType>2){_me.autoClose=4000;}
  278. if(_me.isModal){
  279. _me.Mask.style.height=getViewPortHeight();
  280. _me.Mask.style.width=getViewPortWidth();
  281. _me.Mask.style.zIndex=800+(_me.iter*3);
  282. _me.Mask.style.display="block";
  283. }
  284. var titleBarHeight=parseInt(_me.MDTB.offsetHeight,10);
  285. _me.Con.style.width=pWidth+"px";
  286. _me.Con.style.height=(pHeight+titleBarHeight)+"px";
  287. _me.Con.style.zIndex=801+(_me.iter*3);
  288. _me.Con.style.display="block";
  289. if(_me.autoClose>0){setTimeout(_me.hide,_me.autoClose);}
  290. };
  291. _me.destroy=function(){
  292. edRemoveEvent(_me.MDC,"click",function(){_me.hide(_me.contentType);});
  293. edEnableDrag(_me.Con.id,'','','',false);
  294. removeChildSafe(_me.tBody);
  295. gIteration--;
  296. if(gIteration==-1)gIteration=0;
  297. };
  298. _me.hide=function(iType){
  299. if(_me!=null){
  300. if(_me.contentType==iType){
  301. _me.Con.style.display='none';
  302. var fn="";
  303. if(_me.callBackFunc!=null){fn=_me.callBackFunc;}
  304. if(_me.setFocusId!=null&&_me.setFocusId.length>0){fn+=";setFocus("+_me.setFocusId+");";}
  305. if(fn.length>0){setTimeout(fn,10);}
  306. if(_me.isModal){
  307. if(_me.Mask!=undefined){_me.Mask.style.display='none';}
  308. }
  309. setTimeout(_me.destroy,1000);
  310. }
  311. }
  312. };
  313. }
  314. function removeChildSafe(el){
  315. while(el.childNodes.length>0){
  316. if(el.childNodes[el.childNodes.length-1].nodeName=='IFRAME'){
  317. el.childNodes[el.childNodes.length-1].src="javascript:false";
  318. }
  319. removeChildSafe(el.childNodes[el.childNodes.length-1]);
  320. }
  321. el.parentNode.removeChild(el);
  322. }
  323. function getLocationPoint(width,height,loc){
  324. var theBody=document.getElementsByTagName("BODY")[0];
  325. var scTop=parseInt(getScrollTop(),10);
  326. var scLeft=parseInt(theBody.scrollLeft,10);
  327. var titleBarHeight=0;
  328. var fullHeight=getViewPortHeight();
  329. var fullWidth=getViewPortWidth();
  330. var x,y;
  331. switch(loc){
  332. case locTypes.NW:
  333. x="2px";
  334. y="2px";
  335. break;
  336. case locTypes.N:
  337. x=(scLeft+((fullWidth-width)/2))+(10)+"px";
  338. y="2px";
  339. break;
  340. case locTypes.NE:
  341. x=(getViewPortWidth()-width)+"px";
  342. y="2px";
  343. break;
  344. case locTypes.E:
  345. x=(getViewPortWidth()-width)+"px";
  346. y=(scTop+((fullHeight-(height+titleBarHeight))/2))+(10)+"px"
  347. break;
  348. case locTypes.SE:
  349. break;
  350. case locTypes.S:
  351. break;
  352. case locTypes.SW:
  353. break;
  354. case locTypes.W:
  355. x="2px";
  356. y=(scTop+((fullHeight-(height+titleBarHeight))/2))+"px"
  357. break;
  358. case locTypes.CEN:
  359. x=(scLeft+((fullWidth-width)/2))+(10)+"px";
  360. y=(scTop+((fullHeight-(height+titleBarHeight))/2))+"px"
  361. break;
  362. default:break;
  363. }
  364. return{x:x,y:y};
  365. };
  366. function postBackbPrevDlg(eventTarget,eventArg){
  367. var el=xGetElementById("mdlDlgFrame_"+(gIteration-1));
  368. if(el!=null){
  369. top.frames["mdlDlgFrame_"+(gIteration-1)].__doPostBack(eventTarget,eventArg);
  370. }
  371. }
  372. function refreshPrevDlg(dlgId){
  373. if(dlgId!=null){
  374. var el=_gE(dlgId);
  375. }
  376. else{
  377. var el=xGetElementById("mdlDlgFrame_"+(gIteration-1));
  378. }
  379. el.src=el.src;
  380. return;
  381. }
  382. function getPrevDlg(dlgId){
  383. if(dlgId!=null){
  384. var el=top.frames[dlgId].document.parentWindow;
  385. }
  386. else{
  387. var el=top.frames["mdlDlgFrame_"+(gIteration-1)].document.parentWindow;
  388. }
  389. return el;
  390. }