psheet.js 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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: tabs.js
  13. =============================================================
  14. */
  15. _boAllTabs=new Array
  16. // ================================================================================
  17. // ================================================================================
  18. //
  19. // OBJECT newTabWidget (Constructor)
  20. //
  21. // Display a sing tab. It has a selected and an unselected
  22. // State.
  23. //
  24. // ================================================================================
  25. // ================================================================================
  26. function newTabWidget(id,isTop,name,cb,value,icon,iconW,iconH,iconOffX,iconOffY,dblclick,alt)
  27. // id : [String] the tab id for DHTML processing
  28. // isTop : [boolean] change the tab look. true for top tabs
  29. // name : [String] tab label
  30. // cb : [Function] callback pointer, called when clicking on the tab
  31. // value : [String - optional] a value that is used to find it again
  32. // icon : [String - optional] an image URL
  33. // iconW : [int - optional] displayed image width
  34. // iconH : [int - optional] displayed image height
  35. // iconOffX : [int - optional] x offset in the icon (for combined images)
  36. // iconOffY : [int - optional] y offset in the icon (for combined images)
  37. // Return : The new object
  38. {
  39. // Parent class
  40. var o=newWidget(id)
  41. // Members
  42. o.isTop=isTop
  43. o.isSelected=false
  44. // Other layers
  45. o.lnkLayer=null
  46. o.leftImgLayer=null
  47. o.rightImgLayer=null
  48. o.midImgLayer=null
  49. o.imgImgLayer=null
  50. o.iconLayer=null
  51. o.tabBar=null
  52. // Methods
  53. o.getHTML=TabWidget_getHTML
  54. o.select=TabWidget_select
  55. o.change=TabWidget_change
  56. o.changeContent=TabWidget_changeContent
  57. // Set content
  58. o.change(name,cb,value,icon,iconW,iconH,iconOffX,iconOffY,dblclick,alt)
  59. // For further retrieval
  60. _boAllTabs[id]=o
  61. return o
  62. }
  63. // ================================================================================
  64. function TabWidget_getHTML()
  65. // Write the tab widget HTML
  66. // return [String] the HTML
  67. {
  68. var o=this
  69. var y=o.isSelected?0:72
  70. if (!o.isTop)
  71. y+=144
  72. var cls="thumbtxt"+(o.isSelected?"sel":"")
  73. var cb=_codeWinName+".TabWidget_clickCB('"+o.id+"');return false"
  74. var dblcb=_codeWinName+".TabWidget_dblclickCB('"+o.id+"');return false"
  75. var keycb=_codeWinName+".TabWidget_keyDownCB('"+o.id+"',event);"
  76. var menu=_codeWinName+".TabWidget_contextMenuCB('"+o.id+"',event);return false"
  77. var icon=o.icon?o.icon:_skin+"../transp.gif"
  78. var iconTDWidth=o.icon?3:0
  79. return '<table onmouseover="return true" onclick="'+cb+'" id="'+this.id+'" ondblclick="'+dblcb+'" onkeydown="'+keycb+'" oncontextmenu="'+menu+'" id="'+this.id+'" style="cursor:'+_hand+'" cellspacing="0" cellpadding="0" border="0"><tbody><tr valign="middle" height="24">'+
  80. '<td width="15">'+imgOffset(_skin+'tabs.gif',15,24,0,y,"tabWidgetLeft_"+o.id)+'</td>'+
  81. '<td id="tabWidgetImg_'+o.id+'" style="' +(o.isTop?'padding-top:2px;':'padding-bottom:2px;')+ ' padding-right:'+iconTDWidth+'px; '+backImgOffset(_skin+"tabs.gif",0,y+24)+'" width="'+(o.iconW+iconTDWidth)+'" align="left">'+imgOffset(icon,o.iconW,o.iconH,o.iconOffX,o.iconOffY,"tabWidgetIcon_"+o.id,null,o.iconAlt)+'</td>'+
  82. '<td width="50" id="tabWidgetMid_'+o.id+'" style="' +(o.isTop?'padding-top:3px;':'padding-bottom:3px;') +backImgOffset(_skin+"tabs.gif",0,y+24)+'"><span style="white-space:nowrap">'+lnk(convStr(o.name,true),null,cls,"tabWidgetLnk_"+o.id)+'</span></td>'+
  83. '<td width="15">'+imgOffset(_skin+'tabs.gif',15,24,0,y+48,"tabWidgetRight_"+o.id)+'</td>'+
  84. '</tr></tbody></table>'
  85. }
  86. // ================================================================================
  87. function TabWidget_clickCB(id)
  88. // Global function, internal click event handler for the Tab widget. It calls a
  89. // id [String] the tab id
  90. // delayed function for fixing some browers bugs
  91. // return void
  92. {
  93. setTimeout("TabWidget_delayedClickCB('"+id+"')",1)
  94. }
  95. // ================================================================================
  96. function TabWidget_dblclickCB(id)
  97. // id [String] the tab id
  98. // return void
  99. {
  100. setTimeout("TabWidget_delayedDblClickCB('"+id+"')",1)
  101. }
  102. // ================================================================================
  103. function TabWidget_keyDownCB(id,e)
  104. // Global function, internal onkeydown event handler for the Tab widget. It calls a
  105. // id [String] the tab id and event
  106. {
  107. var k=eventGetKey(e);
  108. //be careful ! usefull for dialog box close by Enter ou Escape keypressed
  109. if(eventGetKey(e) == 13)//Enter
  110. {
  111. eventCancelBubble(e);
  112. }
  113. }
  114. // ================================================================================
  115. function TabWidget_contextMenuCB(id,e)
  116. // id [String] the tab id
  117. // e [event] the event
  118. // return void
  119. {
  120. if (_ie)
  121. e=_curWin.event
  122. var tab=_boAllTabs[id], tabbar = tab.tabBar
  123. if ((tab)&&(tab.cb))
  124. tab.cb()
  125. if ((tabbar)&& (tabbar.showMenu))
  126. tabbar.showMenu(e)
  127. }
  128. // ================================================================================
  129. function TabWidget_delayedClickCB(id)
  130. // Global function, internal click event handler for the Tab widget. Calls the
  131. // user defined callback of the TabWidget, if any
  132. // id [String] the tab id
  133. // return void
  134. {
  135. var tab=_boAllTabs[id]
  136. if ((tab)&&(tab.cb))
  137. tab.cb()
  138. }
  139. // ================================================================================
  140. function TabWidget_delayedDblClickCB(id)
  141. // Global function, Delayed internal click event handler for the Tab widget. Calls the
  142. // user defined callback of the TabWidget, if any
  143. // id [String] the tab id
  144. // return void
  145. {
  146. var tab=_boAllTabs[id]
  147. if ((tab)&& (tab.dblclick))
  148. tab.dblclick()
  149. }
  150. // ================================================================================
  151. function TabWidget_changeContent(changeOnlySelection)
  152. // Select or unselects the tab widget
  153. // sel [boolean] : select if true
  154. // return void
  155. {
  156. var o=this
  157. // Get layers
  158. if (o.lnkLayer==null)
  159. {
  160. o.lnkLayer=getLayer("tabWidgetLnk_"+o.id)
  161. o.leftImgLayer=getLayer("tabWidgetLeft_"+o.id)
  162. o.rightImgLayer=getLayer("tabWidgetRight_"+o.id)
  163. o.midImgLayer=getLayer("tabWidgetMid_"+o.id)
  164. o.imgImgLayer=getLayer("tabWidgetImg_"+o.id)
  165. o.iconLayer=getLayer("tabWidgetIcon_"+o.id)
  166. }
  167. // Change icon and text
  168. if (!changeOnlySelection)
  169. {
  170. o.lnkLayer.innerHTML=convStr(o.name,true)
  171. changeOffset(o.iconLayer,o.iconOffX,o.iconOffY,o.icon?o.icon:_skin+"../transp.gif")
  172. o.iconLayer.alt=o.iconAlt
  173. //var parSty=o.iconLayer.parentNode.style
  174. o.iconLayer.style.width=""+o.iconW+"px"
  175. o.iconLayer.style.height=""+o.iconH+"px"
  176. var iconTDWidth=o.icon?3:0,imgL=o.imgImgLayer
  177. imgL.style.paddingRight=""+iconTDWidth+"px"
  178. imgL.style.width=""+(iconTDWidth+(((o.icon!=null)&&(o.iconW!=null))?o.iconW:0))+"px"
  179. if (_moz&&!_saf)
  180. imgL.width=(iconTDWidth+(((o.icon!=null)&&(o.iconW!=null))?o.iconW:0))
  181. }
  182. // Calculate positions
  183. var y=o.isSelected?0:72
  184. if (!o.isTop)
  185. y+=144
  186. changeOffset(o.leftImgLayer,0,y)
  187. changeOffset(o.midImgLayer,0,y+24)
  188. changeOffset(o.imgImgLayer,0,y+24)
  189. changeOffset(o.rightImgLayer,0,y+48)
  190. o.lnkLayer.className="thumbtxt"+(o.isSelected?"sel":"")
  191. }
  192. // ================================================================================
  193. function TabWidget_select(sel)
  194. // Select or unselects the tab widget
  195. // sel [boolean] : select if true
  196. // return : void
  197. {
  198. var o=this
  199. o.isSelected=sel
  200. if (o.layer!=null)
  201. o.changeContent(true)
  202. }
  203. // ================================================================================
  204. function TabWidget_change(name,cb,value,icon,iconW,iconH,iconOffX,iconOffY,dblclick,alt)
  205. // Change the tabs parameters (name, callbacks, icon)
  206. // name : [String] tab label
  207. // cb : [Function] callback pointer, called when clicking on the tab
  208. // value : [String - optional] a value that is used to find it again
  209. // icon : [String - optional] an image URL
  210. // iconW : [int - optional] displayed image width
  211. // iconH : [int - optional] displayed image height
  212. // iconOffX : [int - optional] x offset in the icon (for combined images)
  213. // iconOffY : [int - optional] y offset in the icon (for combined images)
  214. // return : void
  215. {
  216. var o=this
  217. // Set new values
  218. if (name!=null)
  219. o.name=name
  220. if (cb!=null)
  221. o.cb=cb
  222. if (dblclick!=null)
  223. o.dblclick=dblclick
  224. if (value!=null)
  225. o.value=value
  226. if (icon!=null)
  227. o.icon=icon
  228. o.iconW=iconW?iconW:0
  229. o.iconH=iconH?iconH:0
  230. o.iconOffX=iconOffX?iconOffX:0
  231. o.iconOffY=iconOffY?iconOffY:0
  232. if (alt!=null)
  233. o.iconAlt=alt
  234. // If the widget is initialized, update it
  235. if (o.layer!=null)
  236. o.changeContent(false)
  237. }
  238. // ================================================================================
  239. // ================================================================================
  240. //
  241. // OBJECT newTabBarWidget (Constructor)
  242. //
  243. // Display a tabs bar. When using icons, these must be all in the same combined
  244. // image
  245. //
  246. // ================================================================================
  247. // ================================================================================
  248. function newTabBarWidget(id,isTop,cb,st,dblclick,beforeShowMenu,showIcn)
  249. // id : [String] the tab id for DHTML processing
  250. // isTop : [boolean] change the tab look. true for top tabs
  251. // cb : [Function - optional] callback pointer, called when clicking on a tab
  252. // st : [String - optional] additional style in the tag
  253. // showIcn : [boolean] show the navigation icon (default is false)
  254. // Return : The new object
  255. {
  256. // Parent class
  257. var o=newWidget(id)
  258. var t
  259. // Members
  260. o.isTop=isTop
  261. o.cb=cb
  262. o.dblclick=dblclick
  263. o.menu=newMenuWidget("menu_"+id,null,beforeShowMenu)
  264. o.st=st
  265. o.counter=0
  266. o.items=new Array
  267. o.selIndex=-1
  268. o.leftLimit=0
  269. o.trLayer=null
  270. o.showIcn=showIcn==null?false:showIcn
  271. t=o.firstIcn=newIconWidget("firstIcn_"+id,_skin+"scroll_icon.gif",TabBarWidget_firstCB,null,_scroll_first_tab,5,8,0,0,0,8)
  272. t.par=o
  273. t.margin=0
  274. t.allowDblClick=true
  275. t=o.previousIcn=newIconWidget("previousIcn_"+id,_skin+"scroll_icon.gif",TabBarWidget_prevCB,null,_scroll_previous_tab,5,8,7,0,7,8)
  276. t.par=o
  277. t.margin=0
  278. t.allowDblClick=true
  279. t=o.nextIcn=newIconWidget("nextIcn_"+id,_skin+"scroll_icon.gif",TabBarWidget_nextCB,null,_scroll_next_tab,5,8,13,0,13,8)
  280. t.par=o
  281. t.margin=0
  282. t.allowDblClick=true
  283. t=o.lastIcn=newIconWidget("lastIcn_"+id,_skin+"scroll_icon.gif",TabBarWidget_lastCB,null,_scroll_last_tab,5,8,21,0,21,8)
  284. t.par=o
  285. t.margin=0
  286. t.allowDblClick=true
  287. o.showContextMenuAllowed=true
  288. // Methods
  289. o.oldInit=o.init
  290. o.init=TabBarWidget_init
  291. o.getHTML=TabBarWidget_getHTML
  292. o.add=TabBarWidget_add
  293. o.remove=TabBarWidget_remove
  294. o.removeAll=TabBarWidget_removeAll
  295. o.select=TabBarWidget_select
  296. o.getSelection=TabBarWidget_getSelection
  297. o.getMenu=TabBarWidget_getMenu
  298. o.showMenu=TabBarWidget_showMenu
  299. o.showTab=TabBarWidget_showTab
  300. o.getCount=TabBarWidget_getCount
  301. o.oldResize=o.resize
  302. o.resize=TabBarWidget_resize
  303. o.getItemXPos=TabBarWidget_getItemXPos
  304. o.scroll=TabBarWidget_scroll
  305. o.setIconState=TabBarWidget_setIconState
  306. o.setShowContextMenuAllowed=TabBarWidget_setShowContextMenuAllowed
  307. return o
  308. }
  309. // ================================================================================
  310. function TabBarWidget_init()
  311. // init the widget
  312. // return void
  313. {
  314. var o=this,items=o.items
  315. o.oldInit()
  316. if (o.showIcn)
  317. {
  318. o.firstIcn.init()
  319. o.previousIcn.init()
  320. o.nextIcn.init()
  321. o.lastIcn.init()
  322. }
  323. o.trLayer=getLayer("tr_"+o.id)
  324. o.tabsLayer=getLayer("tabs_"+o.id)
  325. for (var i in items)
  326. {
  327. var it=items[i]
  328. it.init()
  329. it.select(i==o.selIndex)
  330. }
  331. }
  332. // ================================================================================
  333. function TabBarWidget_getSelection()
  334. // get the selection
  335. // return an object (or null if no selection). Object fields
  336. // - index [int] : the selection index
  337. // - value [String] : value of the select object
  338. {
  339. var o=this,index=o.selIndex
  340. if (index>=0)
  341. {
  342. var obj=new Object
  343. obj.index=index
  344. obj.valueOf=o.items[index].value
  345. obj.name=o.items[index].name
  346. return obj
  347. }
  348. else
  349. return null
  350. }
  351. // ================================================================================
  352. function TabBarWidget_getHTML()
  353. // Write the tab bar widget HTML
  354. // return [String] the HTML
  355. {
  356. var o=this,items=o.items,len=items.length
  357. var s= '<div id="'+this.id+'" style="height:24px;overflow:hidden;'+(o.st?o.st:'')+'">'
  358. s+='<table cellspacing="0" cellpadding="0" border="0"><tbody><tr valign="top" height="24">'
  359. if (o.showIcn)
  360. {
  361. s+='<td><table class="palette" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'
  362. s+='<td>'+o.firstIcn.getHTML()+'</td>'
  363. s+='<td>'+o.previousIcn.getHTML()+'</td>'
  364. s+='<td>'+o.nextIcn.getHTML()+'</td>'
  365. s+='<td>'+o.lastIcn.getHTML()+'</td>'
  366. s+='</tr></tbody></table></td>'
  367. }
  368. s+='<td><div style="overflow:'+(true?'hidden':'scroll')+'" id="tabs_'+this.id +'"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr id="tr_'+this.id +'">'
  369. for (var i in items)
  370. s+='<td>'+items[i].getHTML()+'</td>'
  371. s+='</tr></tbody></table></div></td>'
  372. s+='</tr></tbody></table></div>'
  373. return s
  374. }
  375. // ================================================================================
  376. function TabBarWidget_select(index)
  377. // Select an elemnt by index
  378. // index : [int] index to select (-1 = last)
  379. // return : void
  380. {
  381. var o=this,items=o.items,len=items.length
  382. if (index==-1) index=len-1
  383. if ((index>=0)&&(index<len))
  384. {
  385. if ((o.selIndex>=0)&&(o.selIndex!=index)&&(o.selIndex<len))
  386. items[o.selIndex].select(false)
  387. o.selIndex=index
  388. items[index].select(true)
  389. o.scroll(o.selIndex)
  390. }
  391. }
  392. // ================================================================================
  393. function TabBarWidget_resize(w,h)
  394. // Resizes the TabBarWidget
  395. // w [int] The new tabBarWidget width
  396. // h [int] The new tabBarWidget height
  397. {
  398. var o=this
  399. var d=isHidden(o.layer)
  400. if (d&_moz&&!_saf)
  401. o.setDisplay(false)
  402. o.oldResize(w,h)
  403. if (w!=null)
  404. o.tabsLayer.style.width=""+Math.max(0,w-54)
  405. if (d&_moz&&!_saf)
  406. o.setDisplay(true)
  407. o.setIconState()
  408. }
  409. // ================================================================================
  410. function TabBarWidget_showTab(index,show)
  411. {
  412. var o=this,items=o.items,len=items.length
  413. if ((index>=0)||(index<len))
  414. items[index].setDisplay(show)
  415. }
  416. // ================================================================================
  417. function TabBarWidget_add(name, value, idx, icon, iconW,iconH,iconOffX,iconOffY,alt)
  418. // Add an element in the tab bar
  419. // name : [String] tab label
  420. // value : [String - optional] a value that is used to find it again
  421. // icon : [String - optional] an image URL
  422. // iconW : [int - optional] displayed image width
  423. // iconH : [int - optional] displayed image height
  424. // iconOffX : [int - optional] x offset in the icon (for combined images)
  425. // iconOffY : [int - optional] y offset in the icon (for combined images)
  426. // Returns : the new TabWidget object
  427. {
  428. var o=this,counter=o.counter++
  429. var obj=newTabWidget(o.id+"_tab"+counter,o.isTop,name,TabBarWidget_itemClick,value,icon,iconW,iconH,iconOffX,iconOffY,TabBarWidget_itemDblClick,alt)
  430. obj.tabBar=o
  431. obj.idx=counter
  432. arrayAdd(o,"items",obj,idx)
  433. var l=o.trLayer
  434. if(l!=null)
  435. {
  436. var node=document.createElement("td")
  437. node.innerHTML=obj.getHTML()
  438. l.appendChild(node)
  439. obj.init()
  440. }
  441. return obj
  442. }
  443. // ================================================================================
  444. function TabBarWidget_remove(idx)
  445. {
  446. var o=this,items=o.items,len=items.length
  447. if ((idx>=0)&&(idx<len))
  448. {
  449. var elem=items[idx]
  450. var l=elem.layer
  451. arrayRemove(o,"items",idx)
  452. items=o.items
  453. len=items.length
  454. if (l!=null)
  455. {
  456. l=l.parentNode
  457. l.parentNode.removeChild(l)
  458. }
  459. if (o.selIndex>idx) o.select(o.selIndex-1)
  460. else if ((o.selIndex==idx) && (len>0))
  461. o.select(Math.min(idx,len-1))
  462. }
  463. }
  464. // ================================================================================
  465. function TabBarWidget_removeAll()
  466. {
  467. var o=this,items=o.items, len= items.length
  468. for (var i=len-1;i>=0;i--)
  469. o.remove(i)
  470. }
  471. // ================================================================================
  472. function TabBarWidget_itemClick()
  473. // Internal callback when an item is selected
  474. // Returns void
  475. {
  476. var o=this.tabBar,items=o.items,len=items.length,index=-1
  477. for (var i=0;i<len;i++)
  478. {
  479. if (items[i].idx==this.idx)
  480. {
  481. o.select(i)
  482. index=i
  483. break
  484. }
  485. }
  486. if (o.cb)
  487. o.cb(index)
  488. }
  489. // ================================================================================
  490. function TabBarWidget_itemDblClick()
  491. // Internal callback when a double click is done
  492. // Returns void
  493. {
  494. var o=this.tabBar,items=o.items,len=items.length,index=-1
  495. for (var i=0;i<len;i++)
  496. {
  497. if (items[i].idx==this.idx)
  498. {
  499. index=i
  500. break
  501. }
  502. }
  503. if (o.dblclick)
  504. o.dblclick(index)
  505. }
  506. // ================================================================================
  507. function TabBarWidget_getMenu()
  508. // get the menu
  509. // return [MenuWidget] the menu
  510. {
  511. return this.menu
  512. }
  513. // ================================================================================
  514. function TabBarWidget_setShowContextMenuAllowed(b)
  515. {
  516. this.showContextMenuAllowed=b
  517. }
  518. // ================================================================================
  519. function TabBarWidget_showMenu(e)
  520. // Show the menu
  521. // e : event
  522. // return void
  523. {
  524. if (this.showContextMenuAllowed==false)
  525. return
  526. if (_ie)
  527. e=event
  528. this.menu.show(true,eventGetX(e),eventGetY(e))
  529. }
  530. // ================================================================================
  531. function TabBarWidget_getCount()
  532. // Get the number of tabs
  533. // return [int] the number of tabs
  534. {
  535. return this.items.length
  536. }
  537. // ================================================================================
  538. function TabBarWidget_scroll(step,destItem)
  539. // Scroll the TabBarWidget in order for the <destIndex> tab to be visible
  540. {
  541. var o=this
  542. if (o.tabsLayer==null)
  543. return
  544. var tabsl=o.tabsLayer
  545. var tabsSL=tabsl.scrollLeft,tabsOW=tabsl.offsetWidth,tabsSW=tabsl.scrollWidth,SLMax=tabsSW-tabsOW
  546. //alert("AVANT scroll\nstep="+step+"\no.leftLimit="+o.leftLimit+"\ntabsSL="+tabsSL+"\nSLMax="+SLMax)
  547. // Scroll
  548. if (step=='first') // go to first tab
  549. {
  550. tabsl.scrollLeft=tabsSL=0
  551. o.leftLimit=0
  552. }
  553. if (step=='previous') // go to previous tab
  554. {
  555. o.leftLimit=o.leftLimit-1
  556. var x=o.getItemXPos(o.leftLimit)
  557. tabsl.scrollLeft=tabsSL=x
  558. }
  559. if (step=='next') // go to next tab
  560. {
  561. if (o.leftLimit>o.getCount()-1)
  562. return
  563. o.leftLimit+=1
  564. var x=o.getItemXPos(o.leftLimit)
  565. if (x<SLMax)
  566. tabsl.scrollLeft=tabsSL=x
  567. else
  568. tabsl.scrollLeft=tabsSL=SLMax
  569. }
  570. if (step=='last') // go to last tab
  571. {
  572. for (var i=0;i<o.getCount();i++)
  573. {
  574. var x=o.getItemXPos(i);
  575. if (x>SLMax)
  576. break;
  577. }
  578. tabsl.scrollLeft=tabsSL=Math.max(0,SLMax)
  579. o.leftLimit=i
  580. }
  581. if (step==null) // go to the specified <destItem>
  582. {
  583. var x=getItemXPos(destItem);
  584. if (x<SLMax)
  585. tabsl.scrollLeft=tabsSL=x
  586. else
  587. tabsl.scrollLeft=tabsSL=SLMax
  588. for (var i=0;i<o.getCount();i++)
  589. {
  590. var x=o.getItemXPos(i)
  591. if (x>SLMax)
  592. break;
  593. }
  594. o.leftLimit=i
  595. }
  596. o.setIconState()
  597. //alert("AVANT scroll\nstep="+step+"\no.leftLimit="+o.leftLimit+"\ntabsSL="+tabsSL+"\nSLMax="+SLMax)
  598. }
  599. // ================================================================================
  600. function TabBarWidget_getItemXPos(index)
  601. // Retrieve the x coordinates of a tab
  602. // index [int] The tab index
  603. // Returns [int] the x coordinates of a the tab
  604. {
  605. var o=this
  606. var x=0
  607. for (var i=0;i<index;i++)
  608. x+=parseInt(o.items[i].getWidth())
  609. return x
  610. }
  611. // ================================================================================
  612. function TabBarWidget_setIconState()
  613. // Enable or disable the navigation icons first, previous, next, last
  614. {
  615. var o=this
  616. if (o.tabsLayer==null)
  617. return
  618. var tabsl=o.tabsLayer
  619. var tabsSL=tabsl.scrollLeft,tabsOW=tabsl.offsetWidth,tabsSW=tabsl.scrollWidth,SLMax=tabsSW-tabsOW
  620. // Enable or disable the navigation icons if no scroll is possible on the
  621. // right
  622. if (tabsSL==SLMax)
  623. {
  624. o.nextIcn.setDisabled(true)
  625. o.lastIcn.setDisabled(true)
  626. }
  627. else
  628. {
  629. o.nextIcn.setDisabled(false)
  630. o.lastIcn.setDisabled(false)
  631. }
  632. // Enable or disable the navigation icons if no scroll is possible on the
  633. // left
  634. if (tabsSL == 0)
  635. {
  636. o.firstIcn.setDisabled(true)
  637. o.previousIcn.setDisabled(true)
  638. }
  639. else
  640. {
  641. o.firstIcn.setDisabled(false)
  642. o.previousIcn.setDisabled(false)
  643. }
  644. }
  645. // ================================================================================
  646. function TabBarWidget_firstCB()
  647. // Callback function called when click on the "first" icon
  648. {
  649. var p=this.par
  650. p.scroll('first')
  651. }
  652. // ================================================================================
  653. function TabBarWidget_prevCB()
  654. // Callback function called when click on the "previous" icon
  655. {
  656. var p=this.par
  657. p.scroll('previous')
  658. }
  659. // ================================================================================
  660. function TabBarWidget_nextCB()
  661. // Callback function called when click on the "next" icon
  662. {
  663. var p=this.par
  664. p.scroll('next')
  665. }
  666. // ================================================================================
  667. function TabBarWidget_lastCB()
  668. // Callback function called when click on the "last" icon
  669. {
  670. var p=this.par
  671. p.scroll('last')
  672. }
  673. // ================================================================================
  674. // ================================================================================
  675. //
  676. // OBJECT newTabbedZone (Constructor)
  677. //
  678. // Display a tabs bar. and a framed zone that display one content by tab
  679. // image
  680. //
  681. // ================================================================================
  682. // ================================================================================
  683. function newTabbedZone(id,cb,w,h)
  684. // id [String] the tab id for DHTML processing
  685. // cb [Function - optional] callback pointer, called when clicking on a tab
  686. // w [int] width
  687. // h [int] height
  688. // Return : The new object
  689. {
  690. var o=newFrameZoneWidget(id,w,h)
  691. o.w=w
  692. o.h=h
  693. o.cb=cb
  694. o.zoneLayers=new Array
  695. o.oldIndex=-1
  696. o.tzOldInit=o.init
  697. o.add=TabbedZoneWidget_add
  698. o.select=TabbedZoneWidget_select
  699. o.getTabCSS=TabbedZoneWidget_getTabCSS
  700. o.init=TabbedZoneWidget_init
  701. o.beginHTML=TabbedZoneWidget_beginHTML
  702. o.oldFrameZoneEndHTML=o.endHTML
  703. o.endHTML=TabbedZoneWidget_endHTML
  704. o.tabs=newTabBarWidget("tzone_tabs_"+id,true,TabbedZone_itemClick)
  705. o.tabs.parentTabbedZone=o
  706. o.beginTabHTML=TabbedZoneWidget_beginTabHTML
  707. o.endTabHTML=TabbedZoneWidget_endTabHTML
  708. o.beginTab=TabbedZoneWidget_beginTab
  709. o.endTab=TabbedZoneWidget_endTab
  710. o.showTab=TabbedZoneWidget_showTab
  711. o.tzOldResize=o.resize
  712. o.resize=TabbedZoneWidget_resize
  713. return o
  714. }
  715. // ================================================================================
  716. function TabbedZone_itemClick()
  717. // Internal callback when an item is selected
  718. // Return void
  719. {
  720. var o=this.parentTabbedZone,i=this.getSelection().index
  721. o.select(i)
  722. if (o.cb)
  723. o.cb(i)
  724. }
  725. // ================================================================================
  726. function TabbedZoneWidget_add(name, value, icon, iconW,iconH,iconOffX,iconOffY)
  727. // Add an element in the tabbed zone
  728. // name : [String] tab label
  729. // value : [String - optional] a value that is used to find it again
  730. // icon : [String - optional] an image URL
  731. // iconW : [int - optional] displayed image width
  732. // iconH : [int - optional] displayed image height
  733. // iconOffX : [int - optional] x offset in the icon (for combined images)
  734. // iconOffY : [int - optional] y offset in the icon (for combined images)
  735. // return [TabWidget] : the new TabWidget object
  736. {
  737. var o=this
  738. o.tabs.add(name, value, -1, icon, iconW,iconH,iconOffX,iconOffY)
  739. o.zoneLayers[o.zoneLayers.length]=null
  740. }
  741. // ================================================================================
  742. function TabbedZoneWidget_init()
  743. // init the widget
  744. // return void
  745. {
  746. var o=this
  747. o.tzOldInit()
  748. o.tabs.init()
  749. o.select(0)
  750. }
  751. // ================================================================================
  752. function TabbedZoneWidget_getTabCSS(index)
  753. // get the tab style
  754. // return [DOM style]
  755. {
  756. var o=this,ls=o.zoneLayers,l=ls[index]
  757. if (l==null)
  758. l=ls[index]=getLayer('tzone_tab_'+index+'_'+o.id)
  759. return l?l.style:null
  760. }
  761. // ================================================================================
  762. function TabbedZoneWidget_showTab(index,show)
  763. // Show/hide a tab
  764. // index [int] the tab index
  765. // show boolean : show/hide
  766. // return void
  767. {
  768. var tab=this.tabs.items[index]
  769. if (tab)
  770. tab.setDisplay(show)
  771. }
  772. // ================================================================================
  773. function TabbedZoneWidget_select(index)
  774. // selects a tab
  775. // index [int] the tab index
  776. // return void
  777. {
  778. var o=this,tabs=o.tabs,sel=tabs.getSelection(),oldIndex=o.oldIndex,c
  779. o.tabs.select(index)
  780. if (oldIndex!=-1)
  781. {
  782. c=o.getTabCSS(oldIndex)
  783. if (c) c.display="none"
  784. }
  785. else
  786. {
  787. var len=o.zoneLayers.length
  788. for (var i=0;i<len;i++)
  789. {
  790. c=o.getTabCSS(i)
  791. if (c) c.display="none"
  792. }
  793. }
  794. o.oldIndex=index
  795. c=o.getTabCSS(index)
  796. if (c)
  797. {
  798. c.display=""
  799. o.resize(o.w, o.h);
  800. }
  801. }
  802. // ================================================================================
  803. function TabbedZoneWidget_beginHTML()
  804. // Write the beginng of the widget HTML
  805. // return [String] the HTML
  806. {
  807. var o=this
  808. return '<table id="'+this.id+'" cellspacing="0" cellpadding="0" border="0"><tbody><tr valign="bottom" height="28">'+
  809. '<td>'+imgOffset(_skin+'dialogframe.gif',5,5,0,0)+'</td>'+
  810. '<td valign="top" align="left" style="'+backImgOffset(_skin+"tabs.gif",0,288)+'">'+o.tabs.getHTML()+'</td>'+
  811. '<td>'+imgOffset(_skin+'dialogframe.gif',5,5,5,0)+'</td></tr>'+
  812. '<tr><td style="'+backImgOffset(_skin+"dialogframeleftright.gif",0,0)+'"></td><td class="dialogzone"><div id="'+o.id+'_container'+'" style="'+sty("width",o.w)+sty("height",o.h)+'">'
  813. }
  814. function TabbedZoneWidget_endHTML()
  815. {
  816. return '</div>'+this.oldFrameZoneEndHTML()
  817. }
  818. // ================================================================================
  819. function TabbedZoneWidget_beginTabHTML(index)
  820. // get the beginning of a tab zone
  821. // index [int] the tab index
  822. // return [String] the HTML
  823. {
  824. var o=this
  825. return '<div id="tzone_tab_'+index+'_'+o.id+'" style="display:none;'+sty("width",o.w)+sty("height",o.h)+'">'
  826. }
  827. // ================================================================================
  828. function TabbedZoneWidget_endTabHTML()
  829. // get the end of a tab zone
  830. // return [String] the HTML
  831. {
  832. return '</div>'
  833. }
  834. // ================================================================================
  835. function TabbedZoneWidget_beginTab(index)
  836. // write in the document the beginning of a tab zone
  837. // return void
  838. {
  839. _curDoc.write(this.beginTabHTML(index))
  840. }
  841. // ================================================================================
  842. function TabbedZoneWidget_endTab()
  843. // write in the document the end of a tab zone
  844. // return void
  845. {
  846. _curDoc.write(this.endTabHTML())
  847. }
  848. // ================================================================================
  849. function TabbedZoneWidget_resize(w, h)
  850. // Resize the tab zone
  851. // w [Int - optional] width
  852. // h [Int - optional] height
  853. // return void
  854. {
  855. var o = this;
  856. if (w != null)
  857. {
  858. o.w = w;
  859. w = w + 10;
  860. }
  861. if (h != null)
  862. {
  863. o.h = h;
  864. h = h + 33;
  865. }
  866. o.tzOldResize(w, h);
  867. var container = getLayer(o.id+'_container');
  868. if (container)
  869. {
  870. container.style.width = o.w + 'px';
  871. container.style.height = o.h + 'px';
  872. }
  873. if (o.oldIndex != null)
  874. {
  875. var tab = getLayer('tzone_tab_'+o.oldIndex+'_'+o.id);
  876. if (tab)
  877. {
  878. tab.style.width = o.w + 'px';
  879. tab.style.height = o.h + 'px';
  880. }
  881. }
  882. }