dialog.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. // <script>
  2. /*
  3. =============================================================
  4. WebIntelligence(r) Report Panel
  5. Copyright(c) 2001-2003 Business Objects S.A.
  6. All rights reserved
  7. Use and support of this software is governed by the terms
  8. and conditions of the software license agreement and support
  9. policy of Business Objects S.A. and/or its subsidiaries.
  10. The Business Objects products and technology are protected
  11. by the US patent number 5,555,403 and 6,247,008
  12. File: dialog.js
  13. Dialog boxes
  14. =============================================================
  15. */
  16. DialogBoxWidget_modals=new Array;
  17. DialogBoxWidget_instances=new Array
  18. DialogBoxWidget_current=null
  19. _promptDlgInfo=0
  20. _promptDlgWarning=1
  21. _promptDlgCritical=2
  22. // ================================================================================
  23. // ================================================================================
  24. //
  25. // OBJECT newDialogBoxWidget (Constructor)
  26. //
  27. // Class for dialog box
  28. //
  29. // ================================================================================
  30. // ================================================================================
  31. function newDialogBoxWidget(id,title,width,height,defaultCB,cancelCB,noCloseButton)
  32. // CONSTRUCTOR
  33. // id [String] the id for DHTML processing
  34. // title [String] the caption dialog text
  35. // width [int optional] dialog box width
  36. // height [int optional] dialog box height
  37. // defaultCB [Function optional] callback when enter key is hit
  38. // cancelCB [Function optional] callback when esc key is hit or close button pushed
  39. // noCloseButton [Boolean optional] if true no close (on top right) button is displayed
  40. {
  41. var o=newWidget(id)
  42. o.title=title
  43. o.width=width
  44. o.height=height
  45. o.defaultCB=defaultCB
  46. o.cancelCB=cancelCB
  47. o.noCloseButton=noCloseButton?noCloseButton:false
  48. o.resizeable=false
  49. o.oldMouseDown=null
  50. o.oldCurrent=null
  51. o.modal=null
  52. o.hiddenVis=new Array
  53. o.lastLink=null
  54. o.firstLink=null
  55. o.titleLayer = null
  56. o.defaultBtn=null
  57. o.divLayer=null
  58. o.oldInit=o.init
  59. o.oldShow=o.show
  60. o.init=DialogBoxWidget_init
  61. o.setResize=DialogBoxWidget_setResize
  62. o.beginHTML=DialogBoxWidget_beginHTML
  63. o.endHTML=DialogBoxWidget_endHTML
  64. o.show=DialogBoxWidget_Show
  65. o.center=DialogBoxWidget_center
  66. o.focus=DialogBoxWidget_focus
  67. o.setTitle=DialogBoxWidget_setTitle
  68. o.getContainerWidth=DialogBoxWidget_getContainerWidth
  69. o.getContainerHeight=DialogBoxWidget_getContainerHeight
  70. DialogBoxWidget_instances[id]=o
  71. o.modal=newWidget('modal_'+id)
  72. o.placeIframe=DialogBoxWidget_placeIframe
  73. o.oldResize=o.resize
  74. o.resize=DialogBoxWidget_resize
  75. o.attachDefaultButton=DialogBoxWidget_attachDefaultButton
  76. o.unload=DialogBoxWidget_unload
  77. if (!_ie)
  78. {
  79. if (o.width!=null) o.width=Math.max(0,width+4)
  80. if (o.height!=null) o.height=Math.max(0,height+4)
  81. }
  82. return o
  83. }
  84. // ================================================================================
  85. function DialogBoxWidget_setResize(resizeCB,minWidth,minHeight,noResizeW,noResizeH)
  86. // Allow the dialog box to be resized
  87. // resizeCB [Function] callback for resize
  88. // minWidth [int] minimum dialog width
  89. // minHeight [int] minimum dialog height
  90. // noResizeW [boolean] disable vertical resizing
  91. // noResizeH [boolean] disable horizontal resizing
  92. {
  93. var o=this;
  94. o.resizeable=true
  95. o.resizeCB=resizeCB
  96. o.minWidth=minWidth?minWidth:50
  97. o.minHeight=minHeight?minHeight:50
  98. o.noResizeW=noResizeW
  99. o.noResizeH=noResizeH
  100. }
  101. // ================================================================================
  102. function DialogBoxWidget_setTitle(title)
  103. // Change the dialog title
  104. // title [String] the new title
  105. {
  106. var o=this
  107. o.title=title
  108. if (o.titleLayer == null)
  109. o.titleLayer = getLayer('titledialog_'+this.id);
  110. o.titleLayer.innerHTML=convStr(title)
  111. }
  112. // ================================================================================
  113. function DialogBoxWidget_setCloseIcon(lyr,isActive)
  114. // PRIVATE
  115. {
  116. changeOffset(lyr,0,(isActive==1?0:18))
  117. }
  118. // ================================================================================
  119. function DialogBoxWidget_beginHTML()
  120. // Get the widget beginning HTML
  121. // Returns : [String] the HTML
  122. {
  123. with (this)
  124. {
  125. var moveableCb=' onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.DialogBoxWidget_down(event,\''+id+'\',this,false);return false;" '
  126. var mdl='<div onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.eventCancelBubble(event)" border="0" hspace="0" vspace="0" src="'+_skin+'../transp.gif" id="modal_'+id+'" style="position:absolute;top:0px;left:0px;width:1px;height:1px">'+(_ie?img(_skin+'../transp.gif','100%','100%',null):'')+'</div>'
  127. var titleBG="background-image:url("+_skin+"dialogtitle.gif)"
  128. return mdl+
  129. '<a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="firstLink_'+this.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.DialogBoxWidget_keepFocus(\''+this.id+'\');return false;" ></a>'+
  130. '<table dir="ltr" border="0" cellspacing="0" cellpadding="2" id="'+id+'" style="display:none;padding:0px;visibility:'+_hide+';position:absolute;'+sty("width",width?(""+width+"px"):null)+sty("height",height?(""+height+"px"):null)+'"><tr><td id="td_dialog_'+id+'" onresize="'+_codeWinName+'.DialogBoxWidget_resizeIframeCB(\''+id+'\',this)" class="dialogbox" valign="top">'+
  131. '<table width="100%" style="margin-bottom:4px" border="0" cellspacing="0" cellpadding="0"><tr valign="top">'+
  132. '<td '+moveableCb+' style="cursor:move;'+titleBG+'" class="titlezone">'+getSpace(5,18)+'</td>'+
  133. '<td '+moveableCb+' style="cursor:move;'+titleBG+'" class="titlezone" width="100%" valign="middle" align="left"><nobr><span id="titledialog_'+id+'" tabIndex="0" class="titlezone">'+convStr(title)+'</span></nobr></td>'+
  134. '<td class="titlezone" style="'+titleBG+'">'+
  135. (noCloseButton?'':'<a href="javascript:void(0)" onclick="'+_codeWinName+'.DialogBoxWidget_close(\''+id+'\');return false;" title="'+ _closeDialog +'">'+imgOffset(_skin+'dialogelements.gif',18,18,0,18,'dialogClose_'+this.id,'onmouseover="'+_codeWinName+'.DialogBoxWidget_setCloseIcon(this,1)" onmouseout="'+_codeWinName+'.DialogBoxWidget_setCloseIcon(this,0)" ',_closeDialog,'cursor:'+_hand)+'</a>')+
  136. '</td>'+
  137. '</tr></table><div id="div_dialog_'+id+'">'
  138. }
  139. }
  140. /*
  141. function DialogBoxWidget_beginHTML()
  142. // Get the widget beginning HTML
  143. // Returns : [String] the HTML
  144. {
  145. with (this)
  146. {
  147. var moveableCb=' onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.DialogBoxWidget_down(event,\''+id+'\',this,false);return false;" '
  148. var mdl='<div onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.eventCancelBubble(event)" border="0" hspace="0" vspace="0" src="'+_skin+'../transp.gif" id="modal_'+id+'" style="position:absolute;top:0px;left:0px;width:1px;height:1px">'+(_ie?img(_skin+'../transp.gif','100%','100%',null):'')+'</div>'
  149. var titleBG="background-image:url("+_skin+"dialogtitle.gif)"
  150. return mdl+
  151. '<a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="firstLink_'+this.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.DialogBoxWidget_keepFocus(\''+this.id+'\');return false;" ></a>'+
  152. '<table border="0" cellspacing="0" cellpadding="2" id="'+id+'" style="display:none;padding:0px;visibility:'+_hide+';position:absolute;top:-2000px;left:-2000px;'+sty("width",width?(""+width+"px"):null)+sty("height",height?(""+height+"px"):null)+'"><tr><td id="td_dialog_'+id+'" onresize="'+_codeWinName+'.DialogBoxWidget_resizeIframeCB(\''+id+'\',this)" class="dialogbox" valign="top">'+
  153. '<table width="100%" style="margin-bottom:4px" border="0" cellspacing="0" cellpadding="0"><tr valign="top">'+
  154. '<td '+moveableCb+' style="cursor:move;'+titleBG+'" class="titlezone">'+getSpace(5,18)+'</td>'+
  155. '<td '+moveableCb+' style="cursor:move;'+titleBG+'" class="titlezone" width="100%" valign="middle" align="left"><nobr><span id="titledialog_'+id+'" tabIndex="0" class="titlezone">'+convStr(title)+'</span></nobr></td>'+
  156. '<td class="titlezone" style="'+titleBG+'">'+
  157. (noCloseButton?'':'<a href="javascript:void(0)" onclick="'+_codeWinName+'.DialogBoxWidget_close(\''+id+'\');return false;" title="'+ _closeDialog +'">'+imgOffset(_skin+'dialogelements.gif',18,18,0,18,'dialogClose_'+this.id,'onmouseover="'+_codeWinName+'.DialogBoxWidget_setCloseIcon(this,1)" onmouseout="'+_codeWinName+'.DialogBoxWidget_setCloseIcon(this,0)" ',_closeDialog,'cursor:'+_hand)+'</a>')+
  158. '</td>'+
  159. '</tr></table>'
  160. }
  161. }
  162. */
  163. // ================================================================================
  164. function DialogBoxWidget_endHTML()
  165. // Get the widget end HTML
  166. // Returns : [String] the HTML
  167. {
  168. //var moveableCb=' onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.DialogBoxWidget_down(event,\''+this.id+'\',this,true);return false;" '
  169. //var resz=this.resizeable?('<tr onselectstart="return false" height="18" valign="bottom" align="right"><td>'+img(_skin+"resize.gif",14,14,null, moveableCb + ' style="cursor:NW-resize" ')+'</td></tr>'):''
  170. return '</div></td></tr></table><a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="lastLink_'+this.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.DialogBoxWidget_keepFocus(\''+this.id+'\');return false;" ></a>'
  171. }
  172. // ================================================================================
  173. function DialogBoxWidget_getContainerWidth()
  174. // Get the width of the container
  175. // Returns : [int] the width
  176. {
  177. var o=this
  178. return o.width-(2+2)
  179. }
  180. // ================================================================================
  181. function DialogBoxWidget_getContainerHeight()
  182. // Get the height of the container
  183. // Returns : [int] the height
  184. {
  185. var o=this
  186. return o.height-(2+18+2+2+2)
  187. }
  188. // ================================================================================
  189. function DialogBoxWidget_close(id)
  190. // PRIVATE
  191. {
  192. var o=DialogBoxWidget_instances[id]
  193. if (o)
  194. {
  195. o.show(false)
  196. if(o.cancelCB!=null) o.cancelCB()
  197. }
  198. }
  199. // ================================================================================
  200. function DialogBoxWidget_resizeIframeCB(id,lyr)
  201. {
  202. DialogBoxWidget_instances[id].placeIframe()
  203. }
  204. // ================================================================================
  205. function DialogBoxWidget_placeIframe()
  206. {
  207. var o=this
  208. if (o.iframe)
  209. {
  210. var lyr=o.td_lyr
  211. if (lyr==null)
  212. {
  213. o.td_lyr=lyr=getLayer("td_dialog_"+o.id)
  214. }
  215. o.iframe.resize(lyr.offsetWidth,lyr.offsetHeight)
  216. o.iframe.move(o.layer.offsetLeft,o.layer.offsetTop)
  217. }
  218. }
  219. // ================================================================================
  220. //use when resize dialogbox by code (exemple: variableEditorDialog.html)
  221. function DialogBoxWidget_resize(w,h)
  222. {
  223. var o=this;
  224. o.oldResize(w,h);
  225. if (o.iframe)
  226. {
  227. o.iframe.resize(w,h);
  228. }
  229. }
  230. // ================================================================================
  231. function DialogBoxWidget_init()
  232. // Init the widget layers
  233. // Return [void]
  234. {
  235. if (this.layer!=null)
  236. return
  237. var o=this
  238. o.oldInit();
  239. o.modal.init();
  240. o.lastLink=newWidget("lastLink_"+o.id)
  241. o.firstLink=newWidget("firstLink_"+o.id)
  242. o.lastLink.init()
  243. o.firstLink.init()
  244. if (!o.noCloseButton)
  245. {
  246. o.closeButton=getLayer('dialogClose_'+o.id)
  247. DialogBoxWidget_setCloseIcon(o.closeButton,false)
  248. }
  249. }
  250. // ================================================================================
  251. function DialogBoxWidget_attachDefaultButton(btn)
  252. // Attach a default button to the dialogbox
  253. //the callback of this button will be call by Enter action
  254. {
  255. this.defaultBtn=btn;
  256. this.defaultBtn.setDefaultButton();
  257. }
  258. // ================================================================================
  259. _theLYR=null
  260. _dlgResize=null
  261. function DialogBoxWidget_down(e,id,obj,isResize)
  262. // PRIVATE
  263. {
  264. _dlgResize=isResize
  265. var o=DialogBoxWidget_instances[id],lyr=o.layer,mod=o.modal.layer
  266. lyr.onmousemove=mod.onmousemove=eval('_curWin.'+_codeWinName+'.DialogBoxWidget_move')
  267. lyr.onmouseup=mod.onmouseup=eval('_curWin.'+_codeWinName+'.DialogBoxWidget_up')
  268. lyr.dlgStartPosx=mod.dlgStartPosx=parseInt(lyr.style.left)
  269. lyr.dlgStartPosy=mod.dlgStartPosy=parseInt(lyr.style.top)
  270. lyr.dlgStartx=mod.dlgStartx=eventGetX(e)
  271. lyr.dlgStarty=mod.dlgStarty=eventGetY(e)
  272. lyr.dlgStartw=mod.dlgStartw=o.getWidth()
  273. lyr.dlgStarth=mod.dlgStarth=o.getHeight()
  274. lyr._widget=mod._widget=o.widx
  275. _theLYR=lyr
  276. eventCancelBubble(e)
  277. if (lyr.setCapture)
  278. lyr.setCapture(true)
  279. }
  280. // ================================================================================
  281. function DialogBoxWidget_move(e)
  282. // PRIVATE
  283. {
  284. var o=_theLYR,dlg=getWidget(o)
  285. if (_dlgResize)
  286. {
  287. var newW=Math.max(dlg.minWidth,o.dlgStartw+eventGetX(e)-o.dlgStartx)
  288. var newH=Math.max(dlg.minHeight,o.dlgStarth+eventGetY(e)-o.dlgStarty)
  289. dlg.resize(dlg.noResizeW?null:newW,dlg.noResizeH?null:newH)
  290. if (dlg.firstTR)
  291. {
  292. if (!dlg.noResizeW)
  293. dlg.firstTR.style.width=newW-4
  294. if (!dlg.noResizeH)
  295. dlg.secondTR.style.height=newH-44
  296. }
  297. if (dlg.resizeCB)
  298. dlg.resizeCB(newW,newH)
  299. }
  300. else
  301. {
  302. var x=Math.max(0,o.dlgStartPosx-o.dlgStartx+eventGetX(e))
  303. var y=Math.max(0,o.dlgStartPosy-o.dlgStarty+eventGetY(e))
  304. //x = Math.min( Math.max(10,winWidth()-10), x)
  305. //y = Math.min( Math.max(10,winHeight()-18), y)
  306. dlg.iframe.move(x,y)
  307. dlg.move(x,y)
  308. }
  309. eventCancelBubble(e)
  310. return false
  311. }
  312. // ================================================================================
  313. function DialogBoxWidget_up(e)
  314. // PRIVATE
  315. {
  316. var o=getWidget(_theLYR),lyr=o.layer,mod=o.modal.layer;
  317. lyr.onmousemove=mod.onmousemove=null;
  318. lyr.onmouseup=mod.onmouseup=null;
  319. if (lyr.releaseCapture)
  320. lyr.releaseCapture();
  321. _theLYR=null
  322. }
  323. // ================================================================================
  324. function DialogBoxWidget_keypress(e)
  325. // PRIVATE
  326. {
  327. eventCancelBubble(e)
  328. var dlg=DialogBoxWidget_current
  329. if (dlg!=null)
  330. {
  331. switch( eventGetKey(e))
  332. {
  333. case 13://enter
  334. if(dlg.yes && !dlg.no) //old code ???
  335. {
  336. if (dlg.defaultCB) dlg.defaultCB();return false;
  337. }
  338. //Behavior is different from textArea and textField with the Enter action
  339. if(isTextArea(_ie?_curWin.event:e)) return true;
  340. if(dlg.defaultBtn!=null && !dlg.defaultBtn.isDisabled())
  341. {
  342. dlg.defaultBtn.executeCB(); return false;
  343. }
  344. break;
  345. case 27://cancel
  346. dlg.show(false)
  347. hideBlockWhileWaitWidget()
  348. if (dlg.cancelCB!=null) dlg.cancelCB()
  349. return false;
  350. break;
  351. case 8: //back space
  352. return isTextInput(_ie?_curWin.event:e);
  353. break;
  354. }
  355. }
  356. }
  357. // ================================================================================
  358. function DialogBoxWidgetResizeModals(e)
  359. // PRIVATE
  360. {
  361. for (var i in DialogBoxWidget_modals)
  362. {
  363. m_sty=DialogBoxWidget_modals[i]
  364. m_sty.width=documentWidth() + 'px';
  365. m_sty.height=documentHeight() + 'px';
  366. }
  367. }
  368. // ================================================================================
  369. function DialogBoxWidget_center()
  370. {
  371. var o=this;
  372. var defaults = {modalDisplay : o.modal.css.display, layerDisplay : o.css.display};
  373. o.modal.css.display = "none";
  374. o.css.display = "none";
  375. var scrY=getScrollY(),scrX=getScrollX();
  376. o.modal.css.display = defaults.modalDisplay;
  377. o.css.display = "block";
  378. var height = o.layer.offsetHeight, width = o.layer.offsetWidth;
  379. o.css.display = defaults.layerDisplay;
  380. var yOffset = (winHeight()- height)/2;
  381. yOffset = (yOffset < 0) ? 0 : yOffset;
  382. var xOffset = (winWidth()- width)/2;
  383. xOffset = (xOffset < 0) ? 0 : xOffset;
  384. o.move(Math.max(0,scrX + xOffset),Math.max(0,scrY + yOffset));
  385. o.placeIframe()
  386. }
  387. function DialogBoxWidget_Show(sh)
  388. // Show or Hide the dialog
  389. // sh [boolean] if true show
  390. {
  391. with (this)
  392. {
  393. m_sty=modal.css
  394. l_sty=css
  395. if (sh)
  396. {
  397. if (!this.iframe)
  398. {
  399. this.iframe=newWidget(getDynamicBGIFrameLayer().id)
  400. this.iframe.init()
  401. }
  402. oldCurrent=DialogBoxWidget_current
  403. DialogBoxWidget_current=this
  404. if (_ie)
  405. {
  406. layer.onkeydown=eval('_curWin.'+_codeWinName+'.DialogBoxWidget_keypress')
  407. modal.layer.onkeydown=eval('_curWin.'+_codeWinName+'.DialogBoxWidget_keypress')
  408. }
  409. else
  410. {
  411. _curDoc.addEventListener("keydown", eval('_curWin.'+_codeWinName+'.DialogBoxWidget_keypress'), false)
  412. }
  413. oldMouseDown=_curDoc.onmousedown
  414. _curDoc.onmousedown=null
  415. hideBlockWhileWaitWidget()
  416. }
  417. else
  418. {
  419. DialogBoxWidget_current=oldCurrent
  420. oldCurrent=null
  421. if (_ie)
  422. {
  423. layer.onkeydown=null
  424. modal.layer.onkeydown=null
  425. }
  426. else
  427. {
  428. _curDoc.removeEventListener("keydown", eval('_curWin.'+_codeWinName+'.DialogBoxWidget_keypress'), false)
  429. }
  430. _curDoc.onmousedown=oldMouseDown
  431. }
  432. var sameState=(layer.isShown==sh)
  433. if (sameState)
  434. return
  435. layer.isShown=sh
  436. if (sh)
  437. {
  438. if (_curWin.DialogBoxWidget_zindex==null)
  439. _curWin.DialogBoxWidget_zindex=1000;
  440. this.iframe.css.zIndex=_curWin.DialogBoxWidget_zindex++;
  441. m_sty.zIndex=_curWin.DialogBoxWidget_zindex++;
  442. l_sty.zIndex=_curWin.DialogBoxWidget_zindex++;
  443. DialogBoxWidget_modals[DialogBoxWidget_modals.length]=m_sty
  444. m_sty.display=''
  445. l_sty.display='block'
  446. this.iframe.setDisplay(true)
  447. holdBGIFrame(this.iframe.id);
  448. DialogBoxWidgetResizeModals()
  449. this.height=layer.offsetHeight;
  450. this.width=layer.offsetWidth;
  451. //add scroll bar for small resolution 800*600
  452. //do the resize action before the center
  453. if(_small && height)
  454. {
  455. if(divLayer == null)
  456. divLayer=getLayer("div_dialog_"+id);
  457. if(divLayer)
  458. {
  459. divLayer.style.overflow="auto";
  460. divLayer.style.height = (winHeight()< height)? (winHeight()-40) : getContainerHeight();
  461. divLayer.style.width = (_moz?width+20:getContainerWidth());
  462. }
  463. resize(null,((winHeight()< height)? (winHeight()-10):null));
  464. }
  465. if (isHidden(layer))
  466. {
  467. this.center()
  468. }
  469. if (!_small && this.resizeCB)
  470. this.resizeCB(width,height)
  471. }
  472. else
  473. {
  474. var l=DialogBoxWidget_modals.length=Math.max(0,DialogBoxWidget_modals.length-1)
  475. m_sty.width='1px'
  476. m_sty.height='1px'
  477. m_sty.display='none'
  478. l_sty.display='none'
  479. if (this.iframe != null) {
  480. this.iframe.setDisplay(false)
  481. releaseBGIFrame(this.iframe.id)
  482. }
  483. }
  484. modal.show(sh);
  485. firstLink.show(sh)
  486. lastLink.show(sh)
  487. oldShow(sh);
  488. if (DialogBoxWidget_current!=null && sh==true)
  489. DialogBoxWidget_current.focus();
  490. }
  491. }
  492. // must be called to release bg iframe
  493. function DialogBoxWidget_unload()
  494. {
  495. if (this.iframe) {
  496. releaseBGIFrame(this.iframe.id)
  497. }
  498. }
  499. // ================================================================================
  500. function DialogBoxWidget_keepFocus(id)
  501. // PRIVATE
  502. {
  503. var o=DialogBoxWidget_instances[id];
  504. if (o) o.focus();
  505. }
  506. // ================================================================================
  507. function DialogBoxWidget_focus()
  508. // apply focus on the dialog box
  509. {
  510. with (this)
  511. {
  512. if (titleLayer == null)
  513. titleLayer = getLayer('titledialog_'+id);
  514. if (titleLayer.focus) titleLayer.focus();
  515. }
  516. }
  517. // ================================================================================
  518. // ================================================================================
  519. //
  520. // OBJECT newAlertDialog (Constructor)
  521. //
  522. // Class for alert dialog box
  523. //
  524. // ================================================================================
  525. // ================================================================================
  526. /*
  527. function newAlertDialog(id,title,text,okLabel,promptType,yesCB)
  528. // id [String] the id for DHTML processing
  529. // title [String] the caption dialog text
  530. // text [String] the alert text
  531. // okLabel [String] label for the OK button
  532. // promptType [_promptDlgInfo | _promptDlgWarning=1 | _promptDlgCritical]
  533. // yesCB [Function optional] callback when clicking on OK
  534. {
  535. return newPromptDialog(id,title,text,okLabel,null,promptType,yesCB,null,true)
  536. }
  537. */
  538. // ================================================================================
  539. // ================================================================================
  540. //
  541. // OBJECT newPromptDialog (Constructor)
  542. //
  543. // Class for prompt dialog box
  544. //
  545. // ================================================================================
  546. // ================================================================================
  547. function newPromptDialog(id,title,text,okLabel,cancelLabel,promptType,yesCB,noCB,noCloseButton)
  548. // id [String] the id for DHTML processing
  549. // title [String] the caption dialog text
  550. // text [String] the alert text
  551. // okLabel [String] label for the OK button
  552. // cancelLabel [String] label for the Cancel button
  553. // promptType [_promptDlgInfo | _promptDlgWarning=1 | _promptDlgCritical]
  554. // yesCB [String or Function optional] callback when clicking on Yes
  555. // noCB [String or Function optional] callback when clicking on No
  556. {
  557. var o=newDialogBoxWidget(id,title,300,null,PromptDialog_defaultCB,PromptDialog_cancelCB,noCloseButton)
  558. o.text=text
  559. o.getHTML=PromptDialog_getHTML
  560. o.yes=okLabel?newButtonWidget(id+"_yesBtn",okLabel,'PromptDialog_yesCB(\"'+o.id+'\")',70):null
  561. o.no=cancelLabel?newButtonWidget(id+"_noBtn",cancelLabel,'PromptDialog_noCB(\"'+o.id+'\")',70):null
  562. o.yesCB=yesCB
  563. o.noCB=noCB
  564. o.promptType=promptType
  565. o.txtLayer = null
  566. o.imgLayer = null
  567. o.setPromptType=PromptDialog_setPromptType
  568. o.setText=PromptDialog_setText
  569. //attach default button for prompt dialog
  570. if(o.yes) o.attachDefaultButton(o.yes)
  571. else if(o.no) o.attachDefaultButton(o.no)
  572. return o
  573. }
  574. // ================================================================================
  575. function PromptDialog_getimgPath(promptType)
  576. // PRIVATE
  577. {
  578. var imgPath=_skin
  579. switch(promptType)
  580. {
  581. case _promptDlgInfo: imgPath+='information_icon.gif';break
  582. case _promptDlgWarning: imgPath+='warning_icon.gif';break
  583. default: imgPath+='critical_icon.gif';break
  584. }
  585. return imgPath
  586. }
  587. // ================================================================================
  588. function PromptDialog_getimgAlt(promptType)
  589. // PRIVATE
  590. {
  591. var imgAlt=''
  592. /*
  593. switch(promptType)
  594. {
  595. case _promptDlgInfo: imgAlt=_topfs._labImgInfo;break
  596. case _promptDlgWarning: imgAlt=_topfs._labImgWarning;break
  597. default: imgAlt=_topfs._labImgError;break
  598. }
  599. */
  600. return imgAlt
  601. }
  602. // ================================================================================
  603. function PromptDialog_setPromptType(promptType)
  604. // Change the prompt icon
  605. // promptType [_promptDlgInfo | _promptDlgWarning=1 | _promptDlgCritical]
  606. {
  607. var o=this
  608. if (o.imgLayer == null)
  609. o.imgLayer = getLayer("dlg_img_"+o.id)
  610. o.imgLayer.src=PromptDialog_getimgPath(promptType)
  611. o.imgLayer.alt=PromptDialog_getimgAlt(promptType)
  612. }
  613. // ================================================================================
  614. function PromptDialog_setText(text)
  615. // Change the prompt text
  616. // text [String] the prompt text
  617. {
  618. var o=this
  619. o.text=text
  620. if (o.txtLayer == null)
  621. o.txtLayer = getLayer("dlg_txt_"+o.id)
  622. o.txtLayer.innerHTML=convStr(text,false,true)
  623. }
  624. // ================================================================================
  625. function PromptDialog_getHTML()
  626. // Get the widget HTML
  627. // Returns : [String] the HTML
  628. {
  629. var o=this
  630. var imgPath=PromptDialog_getimgPath(o.promptType)
  631. var imgAlt=PromptDialog_getimgAlt(o.promptType)
  632. return o.beginHTML()+
  633. '<table class="dialogzone" width="290" cellpadding="0" cellspacing="5" border="0">'+
  634. '<tr><td>'+
  635. '<table class="dialogzone" cellpadding="5" cellspacing="0" border="0">'+
  636. '<tr><td align="right" width="32" >'+img(imgPath,32,32,null,'id="dlg_img_'+o.id+'"',imgAlt)+'</td><td></td><td id="dlg_txt_'+o.id+'" align="left" tabindex="0">'+convStr(o.text,false,true)+'</td></tr>'+
  637. '</table>'+
  638. '</td></tr>'+
  639. '<tr><td>'+getSep()+'</td></tr>'+
  640. '<tr><td align="right">'+
  641. '<table cellpadding="5" cellspacing="0" border="0">'+
  642. '<tr>'+
  643. (o.yes?'<td>'+o.yes.getHTML()+'</td>':'')+
  644. (o.no?'<td>'+o.no.getHTML()+'</td>':'')+
  645. '</tr>'+
  646. '</table>'+
  647. '</td></tr>'+
  648. '</table>'+
  649. o.endHTML()
  650. }
  651. // ================================================================================
  652. function PromptDialog_defaultCB()
  653. // PRIVATE
  654. {
  655. var o=this
  656. if (o.yesCB)
  657. {
  658. if (typeof o.yesCB!="string")
  659. o.yesCB()
  660. else
  661. eval(o.yesCB)
  662. }
  663. /*
  664. if (this.yesCB)
  665. this.yesCB()
  666. */
  667. this.show(false)
  668. }
  669. // ================================================================================
  670. function PromptDialog_cancelCB()
  671. // PRIVATE
  672. {
  673. var o=this
  674. if (o.noCB)
  675. {
  676. if (typeof o.noCB!="string")
  677. o.noCB()
  678. else
  679. eval(o.noCB)
  680. }
  681. /*
  682. if (this.noCB)
  683. this.noCB()
  684. */
  685. this.show(false)
  686. }
  687. // ================================================================================
  688. function PromptDialog_yesCB(id)
  689. // PRIVATE
  690. {
  691. DialogBoxWidget_instances[id].defaultCB()
  692. }
  693. // ================================================================================
  694. function PromptDialog_noCB(id)
  695. // PRIVATE
  696. {
  697. DialogBoxWidget_instances[id].cancelCB()
  698. }