treeview.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986
  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: treeview.js
  13. Custom treeview control
  14. =============================================================
  15. */
  16. _trIndent=18
  17. // ================================================================================
  18. // ================================================================================
  19. //
  20. // OBJECT newIconListWidget (Constructor)
  21. //
  22. // List box with icons, based on tree widget
  23. //
  24. // ================================================================================
  25. // ================================================================================
  26. /*
  27. function newIconListWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass)
  28. // CONSTRUCTOR
  29. // id [String] the id for DHTML processing
  30. // w [int] the tree wiew frame width in pixels
  31. // h [int] the tree wiew frame height in pixels
  32. // icn [String] the combined icon URL
  33. // clickCB [Function] callback called when clicking on an item
  34. // doubleClickCB [Function] callback called when double clicking on an item
  35. {
  36. var o=newTreeWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass)
  37. o.select=IconListWidget_select
  38. o.getSelection=IconListWidget_getSelection
  39. o.initialIndent=-_trIndent+3
  40. return o
  41. }
  42. // ================================================================================
  43. function IconListWidget_select(pos,setFocus,ev,noSendClickCB,isFromKeyArrow)
  44. // Select by position
  45. // pos [int] : the position
  46. // returns [void]
  47. {
  48. if ((pos>=0) && (pos<this.sub.length)) {
  49. this.sub[pos].select(setFocus,ev,noSendClickCB,isFromKeyArrow)
  50. }
  51. }
  52. // ================================================================================
  53. function IconListWidget_getSelection()
  54. // Get selction
  55. // returns [object] index, value
  56. {
  57. var sel=this.getSelectedItem()
  58. if (sel)
  59. {
  60. if (sel.elemPos==-1) this.buildElems()
  61. var selection=new Object
  62. selection.index=sel.elemPos
  63. selection.value=sel.userData
  64. return selection
  65. }
  66. return null
  67. }
  68. // ================================================================================
  69. // ================================================================================
  70. //
  71. // OBJECT newIconListPopupWidget (Constructor)
  72. //
  73. // List box with icons, based on tree widget show in popup like a menu
  74. //
  75. // ================================================================================
  76. // ================================================================================
  77. function newIconListPopupWidget(id,w,h,icns,clickCB,doubleClickCB)
  78. // CONSTRUCTOR
  79. // id [String] the id for DHTML processing
  80. // w [int] the tree wiew frame width in pixels
  81. // h [int] the tree wiew frame height in pixels
  82. // icn [String] the combined icon URL
  83. // clickCB [Function] callback called when clicking on an item
  84. // doubleClickCB [Function] callback called when double clicking on an item
  85. {
  86. var o=newWidget(id)
  87. o.iconList=newIconListWidget("list_"+id,w,h,icns,clickCB,doubleClickCB,"treeNoBorder")
  88. o.getList=IconListPopupWidget_getList
  89. //o.init=IconListPopupWidget_init
  90. o.getHTML=IconListPopupWidget_getHTML
  91. o.justInTimeInit=IconListPopupWidget_justInTimeInit
  92. o.getShadowHTML=IconListPopupWidget_getShadowHTML
  93. o.show=IconListPopupWidget_show
  94. o.captureClicks=IconListPopupWidget_captureClicks
  95. o.releaseClicks=IconListPopupWidget_releaseClicks
  96. o.getSelection=IconListPopupWidget_getSelection
  97. // Click capture
  98. o.clickCB=new Array
  99. o.clickCBDocs=new Array
  100. //cancelCB
  101. o.cancelCB=null;
  102. return o
  103. }
  104. // ================================================================================
  105. function IconListPopupWidget_init()
  106. {
  107. var o=this
  108. o.iconList.init();
  109. o.init();
  110. }
  111. // ================================================================================
  112. function IconListPopupWidget_getList()
  113. {
  114. return this.iconList;
  115. }
  116. // ================================================================================
  117. function IconListPopupWidget_getSelection()
  118. {
  119. }
  120. // ================================================================================
  121. function IconListPopupWidget_getShadowHTML()
  122. // Displays the shadow of the IconListPopup
  123. // Return [void]
  124. {
  125. return getBGIframe('menuIframe_'+this.id)
  126. }
  127. // ================================================================================
  128. function IconListPopupWidget_getHTML()
  129. // Return [string] the HTML sorce of this widget
  130. {
  131. var o=this
  132. var keyCB=' onkeydown="'+_codeWinName+'.IconListPopupWidget_keyDown(\''+o.id+'\',event)" onkeypress=" return '+_codeWinName+'.IconListPopupWidget_keyPress(\''+o.id+'\',event)" onkeyup="'+_codeWinName+'.IconListPopupWidget_keyUp(\''+o.id+'\',event)"';
  133. var s=''
  134. s+=o.getShadowHTML()
  135. s+='<table id="'+o.id+'" style="display:none;" class="menuFrame" cellspacing="0" cellpadding="0" border="0" '+keyCB+'><tbody>'
  136. s+='<tr><td align="center">'+o.iconList.getHTML()+'</td></tr>'
  137. s+='</tbody></table>'
  138. return s
  139. }
  140. // ================================================================================
  141. function IconListPopupWidget_justInTimeInit()
  142. // Initialization called just before showing scrollMenu for the first time
  143. // Return [void]
  144. {
  145. var o=this
  146. o.layer=getLayer(o.id)
  147. if (o.layer==null)
  148. {
  149. targetApp(o.getHTML())
  150. o.layer=getLayer(o.id)
  151. }
  152. o.layer._widget=o.widx
  153. o.css=o.layer.style
  154. o.css.visibility="hidden"
  155. o.iframeLyr=getLayer("menuIframe_"+o.id)
  156. o.iframeCss=o.iframeLyr.style
  157. o.iconList.init()
  158. o.iconList.layer.onmousedown=IconListPopupWidget_clickNoBubble
  159. }
  160. // ================================================================================
  161. function IconListPopupWidget_show(show,x,y)
  162. // show [boolean] if true shows the menu, otherwise hide it
  163. // x [int] menu abscissa (may be changed if the menu is outside the window)
  164. // y [int] menu ordinate (may be changed if the menu is outside the window)
  165. // Return [void]
  166. {
  167. var o=this
  168. if (o.layer==null)
  169. o.justInTimeInit()
  170. var css=o.css,iCss=o.iframeCss
  171. if (show)
  172. {
  173. o.captureClicks()
  174. // Show and place menu
  175. css.display='block'
  176. //css.zIndex=(o.zIndex+1)
  177. css.zIndex=4000
  178. css.visibility="hidden"
  179. css.left="-1000px"
  180. css.top="-1000px"
  181. var w=o.getWidth()
  182. var h=o.getHeight()
  183. if (o.alignLeft)
  184. x-=w
  185. // Change coordinates if the menu is out of the window
  186. var x2=x+w+4,y2=y+h+4
  187. if (x2>winWidth())
  188. x=Math.max(0,x-4-w)
  189. if (y2>winHeight())
  190. y=Math.max(0,y-4-h)
  191. css.left=""+x+"px"
  192. css.top=""+y+"px"
  193. //hideAllInputs(x,y,w+4,h+4)
  194. css.visibility="visible"
  195. // Show and place menu shadow
  196. iCss.left=""+x+"px"
  197. iCss.top=""+y+"px"
  198. iCss.width=""+w+"px"
  199. iCss.height=""+h+"px"
  200. iCss.zIndex=3998
  201. iCss.display='block'
  202. if (_ie)
  203. {
  204. y-=2
  205. x-=2
  206. }
  207. }
  208. else
  209. {
  210. css.display='none'
  211. iCss.display='none'
  212. o.releaseClicks()
  213. }
  214. }
  215. // ================================================================================
  216. function IconListPopupWidget_captureClicks(w)
  217. // capture click in current frame and sub-frame, so when the users clicks outside
  218. // the menu, the menu is closed. Eventual click handlers are stored.
  219. // Use releaseClicks() to restore previous click handlers
  220. // Returns [void]
  221. {
  222. var o=this
  223. if (o.par==null)
  224. {
  225. if (w==null)
  226. {
  227. _globMenuCaptured=o
  228. o.clickCB.length=0
  229. o.clickCBDocs.length=0
  230. w=_curWin
  231. }
  232. //_excludeFromFrameScan variable is set by a frame that does not want to
  233. // be scaned, when the frame is used to download document for instance.
  234. if (canScanFrames(w))
  235. {
  236. if (_moz)
  237. {
  238. _oldErrHandler=window.onerror
  239. window.onerror=localErrHandler
  240. }
  241. try
  242. {
  243. d=w.document
  244. o.clickCB[o.clickCB.length]=d.onmousedown
  245. o.clickCBDocs[o.clickCBDocs.length]=d
  246. d.onmousedown=IconListPopupWidget_globalClick
  247. var fr=w.frames,len=fr.length
  248. for (var i=0;i<len;i++)
  249. o.captureClicks(fr[i])
  250. }
  251. catch(expt)
  252. {
  253. }
  254. if (_moz)
  255. window.onerror=_oldErrHandler
  256. }
  257. }
  258. }
  259. // ================================================================================
  260. function IconListPopupWidget_globalClick()
  261. // PRIVATE
  262. // Click handler that close the menu if the user clicks outside the menu
  263. // Also call releaseClicks() to restore previous click handlers
  264. {
  265. var o=_globMenuCaptured
  266. if (o!=null)
  267. {
  268. _globMenuCaptured=null
  269. o.releaseClicks()
  270. o.show(false)
  271. }
  272. }
  273. // ================================================================================
  274. function IconListPopupWidget_releaseClicks()
  275. // Restore click handlers overrided by captureClicks()
  276. // Returns [void]
  277. {
  278. var o=this
  279. if (o.par==null)
  280. {
  281. var len=o.clickCB.length
  282. for (var i=0;i<len;i++)
  283. {
  284. o.clickCBDocs[i].onmousedown=o.clickCB[i]
  285. o.clickCB[i]=null
  286. o.clickCBDocs[i]=null
  287. }
  288. o.clickCB.length=0
  289. o.clickCBDocs.length=0
  290. }
  291. }
  292. // ================================================================================
  293. function IconListPopupWidget_clickNoBubble(e)
  294. {
  295. eventCancelBubble(e)
  296. }
  297. // ================================================================================
  298. //NOTE: these 3 functions are usefull to do not propagate the return carriage for textarea (variableeditordialog.html)
  299. function IconListPopupWidget_keyDown(id,e)
  300. {
  301. var o=getWidget(getLayer(id))
  302. var key=eventGetKey(e)
  303. if(key == 27)
  304. {
  305. if(o && o.cancelCB)
  306. o.cancelCB(e)
  307. }
  308. if(key == 13)
  309. {
  310. eventCancelBubble(e)
  311. return false
  312. }
  313. }
  314. function IconListPopupWidget_keyPress(id,e)
  315. {
  316. var o=getWidget(getLayer(id))
  317. var key=eventGetKey(e)
  318. if(key == 13 || key == 27)
  319. {
  320. eventCancelBubble(e)
  321. return false
  322. }
  323. }
  324. function IconListPopupWidget_keyUp(id,e)
  325. {
  326. var key=eventGetKey(e)
  327. if(key == 13 || key == 27)
  328. {
  329. eventCancelBubble(e)
  330. return false
  331. }
  332. }
  333. */
  334. // ================================================================================
  335. // ================================================================================
  336. //
  337. // OBJECT newTreeWidget (Constructor)
  338. //
  339. // Tree view class
  340. //
  341. // ================================================================================
  342. // ================================================================================
  343. function newTreeWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass,expandCB,collapseCB,deleteCB,minIcon,plusIcon)
  344. // CONSTRUCTOR
  345. // id [String] the id for DHTML processing
  346. // w [int] the tree wiew frame width in pixels
  347. // h [int] the tree wiew frame height in pixels
  348. // icn [String] the combined icon URL, null if tree without icons
  349. // clickCB [Function] callback called when clicking on an item
  350. // doubleClickCB [Function] callback called when double clicking on an item
  351. // bgClass [String - optional] CSS class for tree background and frame
  352. // minIcon [String - optional] URL to min.gif
  353. // plusIcon [String - optional] URL to plus.gif
  354. {
  355. var o=newScrolledZoneWidget(id,2,4,w,h,bgClass)
  356. o.icns=icns
  357. o.sub = new Array
  358. o.clickCB=clickCB
  359. o.doubleClickCB=doubleClickCB
  360. o.expandCB=expandCB
  361. o.collapseCB=collapseCB
  362. o.deleteCB=deleteCB
  363. o.minIcon = minIcon
  364. o.plusIcon = plusIcon
  365. o.mouseOverCB=null
  366. o.rightClickMenuCB=null // need to call setRightClickMenu method
  367. o.mouseOverTooltip=false
  368. o.dragDrop=null
  369. o.oldInit=o.init
  370. o.init=TreeWidget_init
  371. o.getHTML=TreeWidget_getHTML
  372. o.getSelections=TreeWidget_getSelections
  373. // deprecated use getSelections()
  374. o.getSelectedItem=TreeWidget_getSelectedItem
  375. o.getSelectedItems=TreeWidget_getSelectedItems
  376. o.getCheckedItems=TreeWidget_getCheckedItems
  377. o.setDragDrop=TreeWidget_setDragDrop
  378. o.setFocus=TreeWidget_setFocus
  379. o.add=TreeWidget_add
  380. o.setRightClickMenuCB=TreeWidget_setRightClickMenuCB
  381. o.findByData=TreeWidget_findByData
  382. o.findById=TreeWidget_findById
  383. o.findInName=TreeWidget_findInName
  384. o.selectByData=TreeWidget_selectByData
  385. o.selectById=TreeWidget_selectById
  386. o.unselect=TreeWidget_unselect
  387. o.search=TreeWidget_search
  388. o.treeLyr=null
  389. o.elems=new Array
  390. o.elemCount=0
  391. o.selId=-1;
  392. o.selIds=new Array;
  393. o.multiSelection=false;
  394. o.hlPath=false; //highlight path
  395. o.hlElems=new Array;
  396. o.iconOrientVertical=true
  397. o.deleteAll=TreeWidget_deleteAll
  398. o.rebuildHTML=TreeWidget_rebuildHTML
  399. o.iconW=16
  400. o.iconH=16
  401. o.initialIndent=0
  402. o.buildElems=TreeWidget_buildElems
  403. o.getCount=TreeWidget_getCount
  404. if (window._TreeWidgetElemInstances==null)
  405. window._TreeWidgetElemInstances=new Array
  406. o.dispIcnFuncName="dispIcn"
  407. o.setTooltipOnMouseOver=TreeWidget_setTooltipOnMouseOver
  408. o.setMouseOverCB=TreeWidget_setMouseOverCB
  409. o.setMultiSelection=TreeWidget_setMultiSelection
  410. o.setHighlightPath=TreeWidget_setHighlightPath
  411. o.highlightPath=TreeWidget_highlightPath
  412. o.unhlPath=TreeWidget_unhlPath
  413. return o
  414. }
  415. // ================================================================================
  416. function TreeWidget_unselect()
  417. // Unselect in the tree view
  418. {
  419. var o=this
  420. if (o.selId>=0)
  421. {
  422. var prev=_TreeWidgetElemInstances[o.selId]
  423. prev.unselect()
  424. o.selId=-1
  425. }
  426. if(o.multiSelection)
  427. {
  428. var len=o.selIds.length, id;
  429. for(var i=len-1;i>=0;i--)
  430. {
  431. var prev=_TreeWidgetElemInstances[o.selIds[i]]
  432. if(prev) prev.unselect()
  433. }
  434. o.selIds.length=0;
  435. o.layer._BOselIds="";
  436. }
  437. //unhighligh if necessary
  438. o.unhlPath()
  439. }
  440. // ================================================================================
  441. function TreeWidget_selectByData(data,setFocus)
  442. // Select an item that matches the data parameter
  443. // data [Variant] the item data to find
  444. // id [setFocus - Optional] Scroll to the item & set the focus on it
  445. // return void
  446. {
  447. var o=this,item=o.findByData(data)
  448. if (item)
  449. {
  450. item.select(setFocus)
  451. }
  452. }
  453. // ================================================================================
  454. function TreeWidget_selectById(id,setFocus)
  455. // Select an item that matches the id parameter
  456. // id [String] the item id to find
  457. // id [setFocus - Optional] Scroll to the item & set the focus on it
  458. // return void
  459. {
  460. var o=this,item=o.findById(id)
  461. if (item)
  462. {
  463. item.select(setFocus)
  464. }
  465. }
  466. // ================================================================================
  467. function TreeWidget_findByData(data)
  468. {
  469. var o=this,sub=o.sub,item=null
  470. for (var i in sub)
  471. {
  472. item=sub[i].findByData(data)
  473. if (item)
  474. return item
  475. }
  476. return null
  477. }
  478. // ================================================================================
  479. function TreeWidget_findById(id)
  480. {
  481. var o=this,sub=o.sub,item=null
  482. for (var i in sub)
  483. {
  484. item=sub[i].findById(id)
  485. if (item)
  486. return item
  487. }
  488. return null
  489. }
  490. // ================================================================================
  491. function TreeWidget_findInName(text,matchCase,matchWholeW,startFrom,next,starWith,visible)
  492. //text [String] text to search in treeview
  493. //matchCase [Boolean - Optional] if null or false then case is no sensitive
  494. //matchWholeW [Boolean - Optional] if null or false then no match whole word
  495. //startFrom [String - Optional] 2 options "begin" "end", by default we start from the first selection and ignore this parameter, if no selection then this parameter is used
  496. //next [Boolean - Optional] search next or previous, by default it is next
  497. //starWith [Boolean - Optional] search object begenning with this text, by default it is false
  498. //visible [Boolean - Optional] search object in the deployed node (not in the hidden nodes), by default the search is performed in the entire tree even in hidden nodes
  499. {
  500. //safe test
  501. if(text=="" || text==null) return null;
  502. var o=this,item=null,elem=null,hidden=false;
  503. var startPos=0,newPos=0;
  504. var bMatchCase=matchCase?matchCase:false;
  505. var bMatchWW=matchWholeW?matchWholeW:false;
  506. var bNext=(!next)?next:true;
  507. var bVisible=visible?visible:false;
  508. var len=o.elems.length;
  509. if(len == 0)
  510. {
  511. o.buildElems();
  512. len=o.elems.length;
  513. if( len == 0) return;
  514. }
  515. //get the position of the selection
  516. var arr = o.getSelections();
  517. if(arr.length>0)
  518. {
  519. startPos=arr[0].elemPos+(bNext?1:-1);
  520. //verify that the start position is good
  521. if((startPos<0) &&! bNext )
  522. startPos=len-1;
  523. if((startPos==len) && bNext )
  524. startPos=0;
  525. }
  526. else if(startFrom=="begin")
  527. {
  528. startPos=0;
  529. }
  530. else if(startFrom=="end")
  531. {
  532. startPos=len-1;
  533. }
  534. newPos=startPos;
  535. while ((newPos>=0)&&(newPos<len))
  536. {
  537. elem=o.elems[newPos];
  538. hidden=elem.getHiddenParent();//not visible item
  539. if((bVisible && !hidden) || (!bVisible))
  540. item=elem.findInName(text,bMatchCase,bMatchWW,bNext,starWith);
  541. if(item!=null) break;
  542. newPos=newPos+(bNext?1:-1);
  543. if((newPos<0) && !bNext )
  544. newPos=len-1;
  545. if((newPos==len) && bNext )
  546. newPos=0;
  547. if(newPos==startPos) break;
  548. }
  549. return item;
  550. }
  551. // ================================================================================
  552. function TreeWidget_search(text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
  553. //text [String] text to search in treeview
  554. //matchCase [Boolean - Optional] if null or false then case is no sensitive
  555. //matchWholeW [Boolean - Optional] if null or false then no match whole word
  556. //startFrom [String - Optional] 2 options "begin" "end", by default we start from the first selection and ignore this parameter, if no selection then this parameter is used
  557. //next [Boolean - Optional] search next or previous, by default it is next
  558. //notFoundCB [Callback - Optional] call when no occurence is found
  559. //starWith [Boolean - Optional] search object begenning with this text, by default it is false
  560. //visible [Boolean - Optional] search object in the deployed node (not in the hidden nodes), by default the search is performed in the entire tree even in hidden nodes
  561. //setFocus [Boolean - Optional] set the focus to the found item, by default it is false
  562. {
  563. var o=this,item=null;
  564. if(text=="" || text==null) return ;
  565. item = o.findInName(text,matchCase,matchWholeW,startFrom,next,starWith,visible);
  566. if(item)
  567. {
  568. o.unselect();
  569. item.select(setFocus);
  570. }
  571. else if(notFoundCB)
  572. {
  573. notFoundCB();
  574. }
  575. }
  576. // ================================================================================
  577. function TreeWidget_add(elem,extraIndent)
  578. // Add an item in the tree
  579. // elem [TreeWidgetElem] the tree view elemnt to add
  580. // extraIndent [int - optional] the element additional indent
  581. // returns [TreeWidgetElem] elem
  582. {
  583. var o=this,sub=o.sub,len=sub.length
  584. elem.treeView=o
  585. sub[len]=elem
  586. elem.expanded=(len==0)
  587. if (extraIndent)
  588. elem.extraIndent=extraIndent
  589. return elem
  590. }
  591. // ================================================================================
  592. function TreeWidget_getHTML()
  593. // get the widget HTML
  594. // returns [String] the HTML
  595. {
  596. var o=this,sub=o.sub,len=sub.length,a=new Array(len+3),j=0
  597. //l.onkeydown=TreeWidget_keyDownCB;
  598. //l.onkeypress=TreeWidget_keyPressCB;
  599. a[j++]= o.beginHTML()+'<span id="treeCont_'+o.id+'" onkeydown="return '+_codeWinName+'.TreeWidget_keyDownCB(this,event)" >'
  600. for (var i in sub)
  601. a[j++]=sub[i].getHTML(o.initialIndent,i==0)
  602. a[j++]='</span>'+o.endHTML()
  603. return a.join("")
  604. }
  605. // ================================================================================
  606. function TreeWidget_deleteAll()
  607. // returns [void]
  608. {
  609. var sub=this.sub
  610. for (var i in sub)
  611. {
  612. sub[i].deleteAll()
  613. sub[i]=null
  614. }
  615. sub.length=0
  616. if (this.elems)
  617. this.elems.length=0
  618. }
  619. // ================================================================================
  620. function TreeWidget_rebuildHTML()
  621. // Rebuild completly the tree view
  622. // returns [void]
  623. {
  624. var o=this,sub=o.sub,len=sub.length,a=new Array(len),j=0,idt=o.initialIndent
  625. for (var i in sub)
  626. a[j++]=sub[i].getHTML(idt,i==0)
  627. o.treeLyr.innerHTML=a.join("")
  628. o.selId=-1
  629. o.layer._BOselId=-1
  630. //multi selection init
  631. o.selIds.length=0
  632. o.layer._BOselIds=""
  633. this.buildElems()
  634. }
  635. // ================================================================================
  636. function TreeWidget_init()
  637. // Standard init function
  638. // returns [void]
  639. {
  640. this.oldInit();
  641. var l=this.treeLyr=getLayer('treeCont_'+this.id);
  642. //l.onkeydown=TreeWidget_keyDownCB;
  643. //l.onkeypress=TreeWidget_keyPressCB;
  644. if (this.dragDrop)
  645. this.dragDrop.attachCallbacks(this.layer)
  646. var oldSel = this.layer._BOselId
  647. if (oldSel!=null)
  648. this.selId=oldSel
  649. //multi selection init
  650. var oldArraySel = this.layer._BOselIds; //string
  651. if (oldArraySel!=null && oldArraySel!="")
  652. {
  653. this.selIds.length=0;
  654. this.selIds=oldArraySel.split(";");
  655. }
  656. var sub=this.sub
  657. }
  658. // ================================================================================
  659. function TreeWidget_buildElems(elem)
  660. {
  661. with (this)
  662. {
  663. if (elem==null)
  664. elem=this;
  665. else
  666. {
  667. var pos=elems.length;
  668. elems[pos]=elem;
  669. elem.elemPos=pos;
  670. }
  671. var subArr=elem.sub,len=subArr.length;
  672. for (var i=0;i<len;i++)
  673. buildElems(subArr[i]);
  674. }
  675. }
  676. // ================================================================================
  677. function TreeWidget_getSelectedItem()
  678. // deprecated use getSelections()
  679. // Get the selected item
  680. // Returns [TreeWidgetElem] the selected itel (null if no selection)
  681. {
  682. var id=this.selId
  683. return (id>=0)?_TreeWidgetElemInstances[id]:null
  684. }
  685. // ================================================================================
  686. function TreeWidget_getSelections()
  687. //unify interface for multi or single selection in treeview
  688. {
  689. var o=this;
  690. if(o.multiSelection)
  691. {
  692. return o.getSelectedItems();
  693. }
  694. else
  695. {
  696. var sel=o.getSelectedItem(),arrSel=new Array;
  697. if(sel!=null) arrSel[0]=sel;
  698. return arrSel;
  699. }
  700. }
  701. // ================================================================================
  702. function TreeWidget_setFocus(index)
  703. {
  704. var elem=_TreeWidgetElemInstances[index]
  705. if(elem!=null)
  706. {
  707. elem.init()
  708. safeSetFocus(elem.domElem)
  709. }
  710. }
  711. // ================================================================================
  712. function TreeWidget_keyPressCB(lay,e)
  713. // Internal key press event callback
  714. // Internal Note: Do not forget to fix a bug in single and multi selection functions.
  715. {
  716. //multi selection treeview
  717. if(getWidget(lay).multiSelection)
  718. {
  719. return TreeWidget_multiSelKeyPress(lay,e);
  720. }
  721. //mono selection treeview
  722. var id=getWidget(lay).selId;
  723. if (id>=0)
  724. {
  725. var elem=_TreeWidgetElemInstances[id]
  726. var treeView=elem.treeView
  727. var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  728. //_ie?_curWin.event.srcElement.id:e.target.id
  729. var k=eventGetKey(e) , ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey
  730. //window.status='press touche '+k + '('+ (t) +')'; t=t+1;
  731. if( k==13 )
  732. {
  733. //if(source!=_codeWinName+"trLstElt"+id) //select the item if not selected
  734. if(source!=id) //select the item if not selected
  735. {
  736. TreeWidget_clickCB(source,false,null);
  737. TreeWidgetElem_UpdateTooltip(source,true);
  738. }
  739. //else if ((source==_codeWinName+"trLstElt"+id)&&(treeView.doubleClickCB))
  740. else if ((source==id)&&(treeView.doubleClickCB))
  741. treeView.doubleClickCB(elem.userData);
  742. }
  743. if((k==10) && ctrl &&(source==_codeWinName+"trLstElt"+id))
  744. {
  745. if(elem.sub.length>0)
  746. {
  747. TreeWidget_toggleCB(id);
  748. TreeWidgetElem_UpdateTooltip(source);
  749. }
  750. if (elem.isIncomplete&&elem.querycompleteCB)
  751. {
  752. elem.querycompleteCB()
  753. TreeWidgetElem_UpdateTooltip(source);
  754. }
  755. return false
  756. }
  757. }
  758. else //no selection in tree view
  759. {
  760. //var source =_ie?_curWin.event.srcElement.id:e.target.id
  761. var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  762. var k=eventGetKey(e);
  763. if( k==13 )
  764. {
  765. TreeWidget_clickCB(source,false,null);
  766. TreeWidgetElem_UpdateTooltip(source,true);
  767. }
  768. }
  769. }
  770. // ================================================================================
  771. function TreeWidget_multiSelKeyPress(o,e)
  772. {
  773. //multi selection treeview
  774. var treeView = getWidget(o);
  775. var len = treeView.selIds.length;
  776. if (len>0) //already has selection
  777. {
  778. //var source =_ie?_curWin.event.srcElement.id:e.target.id
  779. var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  780. var k=eventGetKey(e) , ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey
  781. //find the source in the selected items
  782. var elem = null;
  783. for(var i=0; i<len;i++)
  784. {
  785. var id = treeView.selIds[i];
  786. //if (source==_codeWinName+"trLstElt"+id)
  787. if (source==id)
  788. {
  789. elem = _TreeWidgetElemInstances[id];
  790. break;
  791. }
  792. }
  793. //IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  794. //doubleClickCB will only send userData of the elem where the action is performed
  795. //code must be added by the user in the doubleClickCB to manage the action for all the selected items
  796. //please refer to sample treeview.html for more details
  797. if( k==13 )//enter
  798. {
  799. //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,null);
  800. if(elem == null)
  801. {
  802. //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,_ie?_curWin.event:e);
  803. TreeWidget_clickCB(source,false,_ie?_curWin.event:e);
  804. TreeWidgetElem_UpdateTooltip(source,true);
  805. }
  806. else if (elem &&(treeView.doubleClickCB))
  807. treeView.doubleClickCB(elem.userData);
  808. }
  809. if((k==10) && ctrl && elem) //ctrl+enter
  810. {
  811. if(elem.sub.length>0)
  812. {
  813. TreeWidget_toggleCB(id);
  814. TreeWidgetElem_UpdateTooltip(source);
  815. }
  816. if (elem.isIncomplete&&elem.querycompleteCB)
  817. {
  818. elem.querycompleteCB()
  819. TreeWidgetElem_UpdateTooltip(source);
  820. }
  821. return false
  822. }
  823. }
  824. else //no selection in tree view
  825. {
  826. //var source =_ie?_curWin.event.srcElement.id:e.target.id
  827. var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  828. var k=eventGetKey(e);
  829. if( k==13 )
  830. {
  831. //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,null);
  832. TreeWidget_clickCB(source,false,null);
  833. TreeWidgetElem_UpdateTooltip(source,true);
  834. }
  835. }
  836. return true;
  837. }
  838. // ================================================================================
  839. t=0
  840. function TreeWidget_keyDownCB(lay,e)
  841. // Internal key down event callback
  842. // Internal Note: Do not forget to fix a bug in single and multi selection functions.
  843. {
  844. //multi selection treeview
  845. if(getWidget(lay).multiSelection)
  846. {
  847. return TreeWidget_multiSelKeyDown(lay,e);
  848. }
  849. //mono selection treeview
  850. var id=getWidget(lay).selId;
  851. var k=eventGetKey(e);
  852. if (id>=0)
  853. {
  854. var elem=_TreeWidgetElemInstances[id]
  855. if (elem!=null)
  856. {
  857. var treeView=elem.treeView
  858. //var source=_ie?_curWin.event.srcElement.id:e.target.id;
  859. var source=TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  860. switch(k)
  861. {
  862. case 107:
  863. case 39:
  864. if ((elem.sub.length>0)&&(!elem.expanded))
  865. {
  866. TreeWidget_toggleCB(id);
  867. TreeWidgetElem_UpdateTooltip(source);
  868. }
  869. if (elem.isIncomplete&&elem.querycompleteCB)
  870. {
  871. elem.querycompleteCB()
  872. TreeWidgetElem_UpdateTooltip(source);
  873. }
  874. break;
  875. case 109:
  876. case 37:
  877. if ((elem.sub.length>0)&&(elem.expanded))
  878. {
  879. TreeWidget_toggleCB(id);
  880. TreeWidgetElem_UpdateTooltip(source);
  881. }
  882. break;
  883. case 40:
  884. case 38:
  885. var nElt=elem.getNextPrev(k==40?1:-1);if (nElt!=null){nElt.select(null,null,null,true);safeSetFocus(nElt.domElem)}
  886. return false
  887. break;
  888. case 46: //remove
  889. if(treeView.deleteCB)
  890. treeView.deleteCB(elem.userData)
  891. break;
  892. default:
  893. //key is alpha numerique, select the first occurence that starts with this character from the current position
  894. var c = String.fromCharCode(k);
  895. if(c)//text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
  896. {
  897. treeView.search(c,false,false,null,true,null,true,true,true);
  898. }
  899. break
  900. }
  901. }
  902. }
  903. //To implement default action in dialog box with the key Enter
  904. //we should cancel the bubble for treeview because Enter should not execute
  905. //the default action in dialog box when it is done on a treview item.
  906. if(k == 13)
  907. {
  908. eventCancelBubble(e);
  909. }
  910. }
  911. // ================================================================================
  912. function TreeWidget_multiSelKeyDown(o,e)
  913. {
  914. //multi selection treeview
  915. var treeView = getWidget(o);
  916. var len = treeView.selIds.length;
  917. var k=eventGetKey(e);
  918. if (len>0) //already has selection
  919. {
  920. var ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey;
  921. var shift=_ie?_curWin.event.shiftKey:e.shiftKey;
  922. //var source=_ie?_curWin.event.srcElement.id:e.target.id;
  923. var source=TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
  924. //find the source in the selected items
  925. var elem = null, id;
  926. for(var i=0; i<len;i++)
  927. {
  928. id = treeView.selIds[i];
  929. //if (source==_codeWinName+"trLstElt"+id)
  930. if (source==id)
  931. {
  932. elem = _TreeWidgetElemInstances[id];
  933. break;
  934. }
  935. }
  936. if(elem)
  937. {
  938. switch(k)
  939. {
  940. case 107: //+ ou ->
  941. case 39:
  942. //no change for multi selection
  943. if ((elem.sub.length>0)&&(!elem.expanded))
  944. {
  945. TreeWidget_toggleCB(id);
  946. TreeWidgetElem_UpdateTooltip(source);
  947. }
  948. if (elem.isIncomplete&&elem.querycompleteCB)
  949. {
  950. elem.querycompleteCB()
  951. TreeWidgetElem_UpdateTooltip(source);
  952. }
  953. break;
  954. case 109: //- ou <-
  955. case 37:
  956. //no change for multi selection
  957. if ((elem.sub.length>0)&&(elem.expanded))
  958. {
  959. TreeWidget_toggleCB(id);
  960. TreeWidgetElem_UpdateTooltip(source);
  961. }
  962. break;
  963. case 40: //up or down arrow
  964. case 38:
  965. //var nElt=elem.getNextPrev(k==40?1:-1);if (nElt!=null){nElt.select(null,null,null,true);safeSetFocus(nElt.domElem)} return false;
  966. var nElt=elem.getNextPrev(k==40?1:-1);
  967. if (nElt!=null)
  968. {
  969. nElt.select(null,_ie?_curWin.event:e,null,true);
  970. safeSetFocus(nElt.domElem)
  971. }
  972. return false
  973. break;
  974. case 46: //remove
  975. //IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  976. //deleteCB will only send userData of the elem where the action is performed
  977. //code must be added by the user in the deleteCB to manage the action for all the selected items
  978. //please refer to sample treeview.html for more details
  979. if(treeView.deleteCB)
  980. treeView.deleteCB(elem.userData)
  981. break;
  982. default:
  983. //key is alpha numerique, select the first occurence that starts with this character from the current position
  984. var c = String.fromCharCode(k);
  985. if(c)//text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
  986. {
  987. treeView.search(c,false,false,null,true,null,true,true,true);
  988. }
  989. break
  990. }
  991. }
  992. }
  993. //To implement default action in dialog box with the key Enter
  994. //we should cancel the bubble for treeview because Enter should not execute
  995. //the default action in dialog box when it is done on a treview item.
  996. if(k == 13)
  997. {
  998. eventCancelBubble(e);
  999. }
  1000. }
  1001. // ================================================================================
  1002. function TreeWidget_setDragDrop(dragCB,acceptDropCB,dropCB,dragEndCB)
  1003. // Add drag & drop behaviour to the tree view
  1004. // dragCB (source) : triggered when beginning D&D
  1005. // acceptDropCB (source, target, ctrl, shift) : return boolean if D&D is accepted
  1006. // dropCB (source, target,ctrl, shift) : triggered when ending D&D
  1007. {
  1008. this.dragCB=dragCB
  1009. this.acceptDropCB=acceptDropCB
  1010. this.dropCB=dropCB
  1011. this.dragEndCB=dragEndCB
  1012. this.dragDrop=newDragDropData(this,TreeWidget_dragStartCB,TreeWidget_dragCB,TreeWidget_dragEndCB,TreeWidget_acceptDropCB,TreeWidget_leaveDropCB,TreeWidget_dropCB)
  1013. }
  1014. // ================================================================================
  1015. function TreeWidget_dragStartCB(src)
  1016. // Internal
  1017. // src : widget that started the drag&drop action
  1018. {
  1019. //var item=src.getSelectedItem(),vert=src.iconOrientVertical
  1020. var items=src.getSelections(),vert=src.iconOrientVertical
  1021. src.dragCB(src)
  1022. if (items && items.length==1 )
  1023. {
  1024. var item=items[0]; //display the tooltip of one selection
  1025. var idx=item.iconId
  1026. newTooltipWidget().show
  1027. (
  1028. true,
  1029. item.getDragTooltip(),//item.name,
  1030. idx>=0?src.icns:null,
  1031. src.iconW,
  1032. src.iconH,
  1033. vert?0:src.iconW*idx,
  1034. vert?src.iconH*idx:0
  1035. )
  1036. }
  1037. }
  1038. // ================================================================================
  1039. //this function must be called before the construction of HTML
  1040. function TreeWidget_setRightClickMenuCB(rightClickMenuCB)
  1041. {
  1042. this.rightClickMenuCB=rightClickMenuCB
  1043. }
  1044. // ================================================================================
  1045. // ================================================================================
  1046. function TreeWidget_getCount()
  1047. {
  1048. var o=this
  1049. if (o.sub != null)
  1050. return o.sub.length
  1051. else
  1052. return 0;
  1053. }
  1054. // ================================================================================
  1055. //this function must be called before the construction of HTML
  1056. function TreeWidget_setTooltipOnMouseOver(catchMouseOver)
  1057. {
  1058. this.mouseOverTooltip=catchMouseOver
  1059. }
  1060. // ================================================================================
  1061. function TreeWidget_setMouseOverCB(mouseOverCB)
  1062. {
  1063. this.mouseOverCB=mouseOverCB
  1064. }
  1065. // ================================================================================
  1066. function TreeWidget_dragCB(src)
  1067. {
  1068. newTooltipWidget().setPos();
  1069. }
  1070. // ================================================================================
  1071. function TreeWidget_dragEndCB(src) {
  1072. newTooltipWidget().show(false);
  1073. if (src.dragEndCB) src.dragEndCB()
  1074. }
  1075. // added for inside tree D&D
  1076. function TreeWidget_dragOverEnterCB(lyr,elemId)
  1077. {
  1078. var e=_TreeWidgetElemInstances[elemId]
  1079. if (lyr.ondrop==null) // layer
  1080. {
  1081. e.treeView.dragDrop.attachCallbacks(lyr,true)
  1082. lyr.domEltID=elemId
  1083. }
  1084. var o=_ddData[lyr._dragDropData],e=_curWin.event
  1085. e.dataTransfer.dropEffect=e.ctrlKey?'copy':'move'
  1086. if (o.acceptDropCB(window._globalDDD,o.widget,e.ctrlKey,e.ctrlKey?false:e.shiftKey,lyr,false))
  1087. e.returnValue=false
  1088. e.cancelBubble=true
  1089. }
  1090. // ================================================================================
  1091. function TreeWidget_acceptDropCB(src,target,ctrl,shift,layer)
  1092. {
  1093. return target.acceptDropCB(src,target,ctrl,shift,layer)// the callback defined by the client
  1094. }
  1095. // ================================================================================
  1096. function TreeWidget_leaveDropCB(src,target,ctrl,shift)
  1097. {
  1098. if (target.dropWidget && target.dropWidget.layer) {
  1099. //window.status="leave: " + target.dropWidget.layer.id
  1100. if (target.dropWidget.layer.className != target.dropWidget.nonselectedClass) {
  1101. target.dropWidget.layer.className = target.dropWidget.nonselectedClass
  1102. }
  1103. //target.dropWidget = null
  1104. }
  1105. }
  1106. // ================================================================================
  1107. function TreeWidget_dropCB(src,target,ctrl,shift,layer,enter)
  1108. {
  1109. newTooltipWidget().show(false);
  1110. // added for inside tree D&D
  1111. //target.dropWidget=_TreeWidgetElemInstances[layer.domEltID]
  1112. //target.dropWidget.layer.className = target.dropWidget.nonselectedClass
  1113. //
  1114. target.dropCB(src,target,ctrl,shift);
  1115. }
  1116. // ================================================================================
  1117. //set multi selection in treeview
  1118. function TreeWidget_setMultiSelection(multi)
  1119. {
  1120. //clean the selection structure before start new selection mode
  1121. if((!this.multiSelection && multi)||(this.multiSelection && !multi))
  1122. this.unselect();
  1123. //set selection mode
  1124. this.multiSelection = multi;
  1125. }
  1126. // ================================================================================
  1127. function TreeWidget_getSelectedItems()
  1128. // deprecated use getSelections()
  1129. // Get the selected items
  1130. // Returns an array of [TreeWidgetElem] selected (empty if no selection)
  1131. {
  1132. var arrSel=new Array;
  1133. var len = this.selIds.length, id, cpt=0;
  1134. for(var i=0; i< len; i++)
  1135. {
  1136. id = this.selIds[i];
  1137. if(id>=0)
  1138. {
  1139. arrSel[cpt]=_TreeWidgetElemInstances[id];
  1140. cpt++;
  1141. }
  1142. //arrSel[i]= (id>=0)?_TreeWidgetElemInstances[id]:null;
  1143. }
  1144. return arrSel;
  1145. }
  1146. // ================================================================================
  1147. function TreeWidget_getCheckedItems()
  1148. // Get the checked items
  1149. // Returns an array of [TreeWidgetElem] selected (empty if no selection)
  1150. {
  1151. var arrChecked=new Array;
  1152. var len = _TreeWidgetElemInstances.length, cpt=0;
  1153. for (var i=0; i < len; i++)
  1154. {
  1155. elem = _TreeWidgetElemInstances[i]
  1156. if (elem.isChecked())
  1157. {
  1158. arrChecked[cpt]=elem;
  1159. cpt++;
  1160. }
  1161. }
  1162. return arrChecked;
  1163. }
  1164. // ================================================================================
  1165. //set highlight path parameter in treeview
  1166. function TreeWidget_setHighlightPath(hl)
  1167. {
  1168. this.hlPath=hl;
  1169. if(!hl)
  1170. this.unhlPath();
  1171. }
  1172. // ================================================================================
  1173. function TreeWidget_unhlPath()
  1174. {
  1175. var o=this, len = o.hlElems.length;
  1176. var elem, de;
  1177. if(len>0)//unhighlight previous elems
  1178. {
  1179. for(var i=0;i<len;i++)
  1180. {
  1181. elem = o.hlElems[i];
  1182. elem.init();
  1183. de =elem.domElem;
  1184. if( de == null) return;//safe test
  1185. if(elem.isSelected())
  1186. de.className=elem.selectedClass;
  1187. else
  1188. de.className=elem.nonselectedClass;
  1189. }
  1190. o.hlElems.length=0;
  1191. }
  1192. }
  1193. //highlight path of the selected item
  1194. function TreeWidget_highlightPath(elemId)
  1195. {
  1196. var o=this;
  1197. if(!o.hlPath) return ; //safe test
  1198. o.unhlPath();
  1199. var elem = _TreeWidgetElemInstances[elemId];
  1200. //highlight and select item
  1201. o.hlElems[o.hlElems.length]=elem;
  1202. elem.domElem.className=elem.selectedClass;
  1203. if(elem.elemPos == -1) o.buildElems();
  1204. //highlight parents
  1205. var papa = elem.par;
  1206. while(papa)
  1207. {
  1208. papa.init();
  1209. papa.domElem.className=papa.hlClass;
  1210. o.hlElems[o.hlElems.length]=papa;
  1211. papa = papa.par;
  1212. }
  1213. //highlight children
  1214. if(elem.isNode())
  1215. hlVisibleChildren(elem,o.hlElems);
  1216. }
  1217. function hlVisibleChildren(node,arr)
  1218. {
  1219. if(node.expanded && !node.isIncomplete)
  1220. {
  1221. var len = node.sub.length;
  1222. for(var i=0;i<len;i++)
  1223. {
  1224. var sub = node.sub[i];
  1225. arr[arr.length]=sub;
  1226. sub.init();
  1227. sub.domElem.className=sub.hlClass;
  1228. if(sub.isNode())
  1229. hlVisibleChildren(sub,arr);
  1230. }
  1231. }
  1232. }
  1233. // ================================================================================
  1234. // ================================================================================
  1235. //
  1236. // OBJECT newTreeWidgetElem (Constructor)
  1237. //
  1238. // Tree view element class
  1239. //
  1240. // ================================================================================
  1241. // ================================================================================
  1242. function newTreeWidgetElem(iconId,name,userData,help,iconSelId,tooltip,iconAlt,textClass,textSelectedClass)
  1243. // CONSTRUCTOR
  1244. // iconId [int] the index of the icon in the combined image, -1 if no icon
  1245. // name [String] name of the elem
  1246. // userData [Optional]user data
  1247. // help [Optional]help of the elem (tooltip ???)
  1248. // iconSelId [int Optional] the index of the icon in the combined image when elem is selected
  1249. // tooltip [Optional]tooltip of the elem
  1250. // iconAlt [Optional]tooltip of icon
  1251. // Return [newTreeWidgetElem] the instance
  1252. // to not encode the elemen content, set isHTML to true
  1253. {
  1254. var o=new Object
  1255. // Data
  1256. o.elemPos=-1
  1257. if (window._TreeWidgetElemInstances==null)
  1258. window._TreeWidgetElemInstances=new Array
  1259. o.expanded=false
  1260. o.generated=false
  1261. o.iconId=iconId
  1262. o.iconSelId=iconSelId?iconSelId:iconId
  1263. o.tooltip=tooltip
  1264. o.customTooltip=false
  1265. o.iconAlt=iconAlt
  1266. o.isHTML=false
  1267. // Check box
  1268. o.isCheck=false
  1269. o.checked=false
  1270. o.check=TreeWidgetElem_check
  1271. o.isChecked=TreeWidgetElem_isChecked
  1272. o.checkCB=null
  1273. o.name=name
  1274. o.par=null
  1275. o.userData=userData
  1276. o.sub=new Array
  1277. o.treeView=null
  1278. o.id=_TreeWidgetElemInstances.length
  1279. // Layers
  1280. o.layer=null
  1281. o.plusLyr=null
  1282. o.icnLyr=null
  1283. o.checkElem=null
  1284. o.domElem=null
  1285. o.toggleLyr=null
  1286. o.blackTxt=(textClass)?textClass:'treeNormal'
  1287. o.grayTxt='treeGray'
  1288. o.selectedClass=(textSelectedClass)?textSelectedClass:'treeSelected'
  1289. o.nonselectedClass=o.blackTxt
  1290. o.feedbackDDClass='treeFeedbackDD'
  1291. o.hlClass='treeHL' //hl=highlight
  1292. o.help=help
  1293. _TreeWidgetElemInstances[o.id]=o
  1294. // Methods
  1295. o.getHTML=TreeWidgetElem_getHTML
  1296. o.init=TreeWidgetElem_init
  1297. o.add=TreeWidgetElem_add;
  1298. o.select=TreeWidgetElem_select
  1299. o.unselect=TreeWidgetElem_unselect
  1300. o.getNextPrev=TreeWidgetElem_getNextPrev
  1301. o.getHiddenParent=TreeWidgetElem_getHiddenParent
  1302. o.nodeIndent=0
  1303. o.getTooltip=TreeWidgetElem_getTooltip
  1304. o.getDragTooltip=TreeWidgetElem_getDragTooltip
  1305. o.change=TreeWidgetElem_change
  1306. o.deleteAll=TreeWidget_deleteAll
  1307. o.setGrayStyle=TreeWidgetElem_setGrayStyle
  1308. o.isGrayStyle=TreeWidgetElem_isGrayStyle
  1309. o.findByData=TreeWidgetElem_findByData
  1310. o.findById=TreeWidgetElem_findById
  1311. o.findInName=TreeWidgetElem_findInName
  1312. o.isIncomplete=false
  1313. o.querycompleteCB=null
  1314. o.setIncomplete=TreeWidgetElem_setIncomplete
  1315. o.finishComplete=TreeWidgetElem_finishComplete
  1316. o.setEditable=TreeWidgetElem_setEditable
  1317. o.showEditInput=TreeWidgetElem_showEditInput
  1318. o.isLeaf=TreeWidgetElem_isLeaf
  1319. o.isNode=TreeWidgetElem_isNode
  1320. o.isSelected=TreeWidgetElem_isSelected
  1321. o.htmlWritten=false
  1322. o.showCustomTooltipCB=null
  1323. o.hideCustomTooltipCB=null
  1324. return o
  1325. }
  1326. // ================================================================================
  1327. function TreeWidgetElem_checkCB(elem, id)
  1328. // PRIVATE
  1329. {
  1330. var o=_TreeWidgetElemInstances[id]
  1331. o.checked=elem.checked
  1332. if (o.checkCB)
  1333. o.checkCB(o, id)
  1334. }
  1335. // ================================================================================
  1336. function TreeWidgetElem_isChecked()
  1337. // Test is the element is checked (works if the TreeWidgetElem is a checkbox)
  1338. // Return boolean
  1339. {
  1340. var o=this
  1341. return (o.isCheck ? o.checked : false)
  1342. }
  1343. // ================================================================================
  1344. function TreeWidgetElem_check(checked)
  1345. // check or uncheck the element (works if the TreeWidgetElem is a checkbox)
  1346. // checked [boolean - Mandatory]
  1347. {
  1348. var o=this
  1349. if (o.isCheck)
  1350. {
  1351. o.checked = checked
  1352. if (o.htmlWritten)
  1353. {
  1354. o.init()
  1355. o.checkElem.checked = checked
  1356. }
  1357. }
  1358. }
  1359. // ================================================================================
  1360. function TreeWidgetElem_EditNormalBehaviour(e)
  1361. // PRIVATE
  1362. {
  1363. eventCancelBubble(e)
  1364. return true
  1365. }
  1366. // ================================================================================
  1367. function TreeWidgetElem_EditBlurCB()
  1368. // PRIVATE
  1369. {
  1370. setTimeout("TreeWidgetElem_EditKeyCancel("+this.widID+")",1)
  1371. }
  1372. // ================================================================================
  1373. _globTreeTxtvalue=""
  1374. function TreeWidgetElem_EditKeyDown(e)
  1375. // PRIVATE
  1376. {
  1377. eventCancelBubble(e); //do not fire the event in TreeWidgetElem
  1378. var k=eventGetKey(e),o=_TreeWidgetElemInstances[this.widID]
  1379. if (k==27) // Escape
  1380. {
  1381. setTimeout("TreeWidgetElem_EditKeyCancel("+this.widID+")",1)
  1382. }
  1383. else if (k==13) // Enter
  1384. {
  1385. _globTreeTxtvalue=this.value
  1386. setTimeout("TreeWidgetElem_EditKeyAccept("+this.widID+")",1)
  1387. }
  1388. }
  1389. // ================================================================================
  1390. function TreeWidgetElem_EditKeyCancel(id)
  1391. // PRIVATE
  1392. {
  1393. var o=_TreeWidgetElemInstances[id]
  1394. o.showEditInput(false)
  1395. }
  1396. // ================================================================================
  1397. function TreeWidgetElem_EditKeyAccept(id)
  1398. // PRIVATE
  1399. {
  1400. var o=_TreeWidgetElemInstances[id]
  1401. if (o.validChangeNameCB)
  1402. {
  1403. if (o.validChangeNameCB(_globTreeTxtvalue)==false)
  1404. return
  1405. }
  1406. o.change(null,_globTreeTxtvalue)
  1407. o.showEditInput(false)
  1408. if (o.changeNameCB)
  1409. o.changeNameCB()
  1410. }
  1411. // ================================================================================
  1412. _globTreeTxt=null
  1413. function TreeWidgetElem_showEditInput(show)
  1414. {
  1415. var o=this
  1416. o.init()
  1417. var lyr=o.domElem,css=lyr.style
  1418. if (show&&(css.display!="none"))
  1419. {
  1420. var par=lyr.parentNode,w=lyr.offsetWidth,h=lyr.offsetHeight
  1421. css.display="none"
  1422. var tl=_globTreeTxt=_curDoc.createElement("INPUT");
  1423. tl.type="text"
  1424. tl.className="textinputs"
  1425. tl.value=o.name
  1426. tl.ondragstart=TreeWidgetElem_EditNormalBehaviour
  1427. tl.onselectstart=TreeWidgetElem_EditNormalBehaviour
  1428. tl.onblur=TreeWidgetElem_EditBlurCB
  1429. tl.onkeydown=TreeWidgetElem_EditKeyDown
  1430. tl.widID=o.id
  1431. var tc=tl.style
  1432. tc.width=""+(w+20)+"px"
  1433. par.appendChild(tl);
  1434. tl.focus()
  1435. tl.select()
  1436. }
  1437. if ((show!=true)&&(css.display=="none"))
  1438. {
  1439. var tl=_globTreeTxt
  1440. if (tl)
  1441. {
  1442. tl.parentNode.removeChild(tl)
  1443. css.display=""
  1444. _globTreeTxt=null
  1445. }
  1446. }
  1447. }
  1448. // ================================================================================
  1449. function TreeWidgetElem_setEditable(isEditable, changeNameCB,validChangeNameCB)
  1450. // Set the elem editable (i.e. the name can be changed)
  1451. // changeNameCB [function optional]: callback when the name is changed
  1452. // validChangeNameCB [function optional] : callback called before text is chaged. Returns a boolean
  1453. // if true, the changes are accepted
  1454. {
  1455. var o=this
  1456. if (isEditable)
  1457. {
  1458. o.changeNameCB=changeNameCB
  1459. o.validChangeNameCB=validChangeNameCB
  1460. }
  1461. o.isEditable=isEditable
  1462. }
  1463. // ================================================================================
  1464. function TreeWidgetElem_triggerDD()
  1465. {
  1466. var o=_treeWClickedW,e=_curWin.event
  1467. if (o&&(o.clicked)&&(e.button==_leftBtn))
  1468. {
  1469. if (o.initialX!=null)
  1470. {
  1471. var x=eventGetX(e),y=eventGetY(e),threshold=3
  1472. if ((x<(o.initialX-threshold))||(x>(o.initialX+threshold))||(y<(o.initialY-threshold))||(y>(o.initialY+threshold)))
  1473. {
  1474. this.dragDrop()
  1475. o.clicked=false
  1476. }
  1477. }
  1478. }
  1479. }
  1480. // ================================================================================
  1481. function TreeWidgetElem_mouseUp()
  1482. {
  1483. var o=_treeWClickedW,ev=_curWin.event
  1484. o.select(null,ev)
  1485. o.domElem.onmouseup=null
  1486. }
  1487. // ================================================================================
  1488. function TreeWidgetElem_init()
  1489. {
  1490. var o=this
  1491. if (o.layer==null)
  1492. {
  1493. var sub=o.sub,len=sub.length,exp=(len>0)||o.isIncomplete
  1494. // Init Widgets
  1495. o.layer=getLayer(_codeWinName+"TWe_"+o.id);
  1496. if (o.layer==null)
  1497. return;
  1498. var cNodes=o.layer.childNodes,cLen=cNodes.length
  1499. o.plusLyr=exp?cNodes[0].childNodes[1]:null
  1500. o.icnLyr=(o.iconId>-1)?cNodes[exp?1:0]:null
  1501. o.checkElem=o.isCheck?cNodes[cLen-2]:null
  1502. o.domElem=cNodes[cLen-1]
  1503. o.toggleLyr=getLayer(_codeWinName+"trTog"+o.id)
  1504. // Init Callbacks
  1505. if(o.treeView.mouseOverTooltip||o.treeView.mouseOverCB)
  1506. o.domElem.onmouseout=TreeFuncMouseout
  1507. if (exp)
  1508. {
  1509. addDblClickCB(o.plusLyr,_tpdb)
  1510. }
  1511. if (exp&&o.generated)
  1512. {
  1513. for (var i in sub)
  1514. sub[i].init()
  1515. }
  1516. addDblClickCB(o.domElem,_tpdb)
  1517. }
  1518. }
  1519. // ================================================================================
  1520. function TreeIdToIdx(l)
  1521. {
  1522. if (l)
  1523. {
  1524. var id=l.id
  1525. if (id)
  1526. {
  1527. var idx=id.lastIndexOf("TWe_")
  1528. if (idx>=0)
  1529. return parseInt(id.slice(idx+4))
  1530. else
  1531. return -1
  1532. }
  1533. else
  1534. return TreeIdToIdx(l.parentNode)
  1535. }
  1536. return -1
  1537. }
  1538. function TreeFuncMouseout(e)
  1539. {
  1540. _tmoc(this,TreeIdToIdx(this),false,e)
  1541. }
  1542. function _tmvc(l,ev)
  1543. {
  1544. _tmoc(l,TreeIdToIdx(l),true,ev)
  1545. }
  1546. function _tpl(l,event)
  1547. // PRIVATE
  1548. // Single click on the +/- icon
  1549. {
  1550. TreeWidget_clickCB(TreeIdToIdx(l),true,event,true);
  1551. return false
  1552. }
  1553. function _tkl(l,event)
  1554. //PRIVATE
  1555. // Enter key on the +/- icon
  1556. {
  1557. var k = eventGetKey(event);
  1558. if(k == 13) {
  1559. return _tpl(l,event);
  1560. }
  1561. }
  1562. function _tkt(l,event)
  1563. // PRIVATE
  1564. // Enter key on text
  1565. {
  1566. var k = eventGetKey(event);
  1567. if(k == 13) {
  1568. return _tpt(l,event);
  1569. }
  1570. }
  1571. function _tpt(l,event)
  1572. // PRIVATE
  1573. // Single click on text
  1574. {
  1575. TreeWidget_clickCB(TreeIdToIdx(l),false,event,true);
  1576. return false
  1577. }
  1578. function _tpdb(e)
  1579. // PRIVATE
  1580. // Double click on the +/- icon
  1581. {
  1582. treeDblClickCB(TreeIdToIdx(this),_ie?event:e)
  1583. return false
  1584. }
  1585. function _tfcc(l,e)
  1586. {
  1587. treeFCCB(l,TreeIdToIdx(l),true,e)
  1588. l.onblur=_tblc
  1589. }
  1590. function _tblc(e)
  1591. {
  1592. treeFCCB(this,TreeIdToIdx(this),false,e)
  1593. }
  1594. // ================================================================================
  1595. function TreeWidgetElem_getHTML(indent,isFirst)
  1596. // Get the tree element HTML
  1597. // indent [int] : element indentation in pixels
  1598. // returns [String] the HTML
  1599. {
  1600. var s='';
  1601. with (this)
  1602. {
  1603. htmlWritten=true,isRoot=(par==null)
  1604. var len=sub.length,exp=(len>0)||isIncomplete,a=new Array,i=0
  1605. if (this.extraIndent)
  1606. indent+=_trIndent*extraIndent
  1607. var keyCB = 'onkeydown=" return ' + _codeWinName+'._tkt(this,event)" ';
  1608. var mouseCB='onfocus="'+_codeWinName+'._tfcc(this,event)" onclick="return '+_codeWinName+'._tpt(this,event)" '
  1609. if(treeView.mouseOverTooltip || treeView.mouseOverCB)
  1610. mouseCB+='onmouseover="'+_codeWinName+'._tmvc(this,event)" '
  1611. var contextMenu=''
  1612. if (treeView.rightClickMenuCB != null)
  1613. {
  1614. contextMenu= ' oncontextmenu="' + _codeWinName + '.treeContextMenuCB(\''+ id + '\', event);return false" '
  1615. }
  1616. var acceptDD=''
  1617. if ((treeView.acceptDropCB != null) && (_ie))
  1618. {
  1619. acceptDD= ' ondragenter="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
  1620. acceptDD += ' ondragover="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
  1621. }
  1622. // begin container
  1623. a[i++]='<div id="'+_codeWinName+'TWe_'+id+'"'+contextMenu+' class=trElt>'
  1624. var onkeydown='onkeydown="return '+_codeWinName+'._tkl(this,event)" ';
  1625. var onclick='onclick="return '+_codeWinName+'._tpl(this,event)" ';
  1626. if (exp)
  1627. {
  1628. var expIcon;
  1629. var iconTooltip;
  1630. if(expanded)
  1631. {
  1632. if(treeView.minIcon != null)
  1633. expIcon = treeView.minIcon;
  1634. else
  1635. expIcon = _skin+'../min.gif';
  1636. iconTooltip = _collapseNode.replace('%1', name);
  1637. }
  1638. else
  1639. {
  1640. if(treeView.plusIcon != null)
  1641. expIcon = treeView.plusIcon;
  1642. else
  1643. expIcon = _skin+'../plus.gif';
  1644. iconTooltip = _expandNode.replace('%1', name);
  1645. }
  1646. a[i++]='<a tabindex=1 '+ onclick + ' ' + onkeydown +' href="javascript:doNothing();"><span style="display:none">' + iconTooltip + '</span><img class=trPlus src="'+expIcon+'"/></a>'
  1647. }
  1648. if (iconId>-1)
  1649. a[i++]='<img tabindex=1 '+mouseCB + ' ' + keyCB +'class=trIcn'+(exp||isRoot?'Plus':'')+' '+attr('src', _skin+'../transp.gif')+attr('alt',iconAlt)+' align=top style="'+backImgOffset(treeView.icns,(treeView.iconOrientVertical?0:treeView.iconW*(expanded?iconSelId:iconId)),(treeView.iconOrientVertical?treeView.iconH*(expanded?iconSelId:iconId):0))+'" >'
  1650. else if (!exp&&!isRoot)
  1651. a[i++]='<img tabindex=1 class=trSep '+attr('src', _skin+'../transp.gif')+'>'
  1652. if (isCheck)
  1653. a[i++]='<input type=checkbox style="margin:0px;" onclick="'+_codeWinName+'.TreeWidgetElem_checkCB(this,\''+id+'\')"'+(this.checked?' checked':'')+'>'
  1654. a[i++]='<a href="javascript:doNothing();" '+mouseCB+ ' ' + keyCB + ' tabindex=1 '+acceptDD+' class='+nonselectedClass+'>'
  1655. a[i++]=(isHTML?name:convStr(name))
  1656. a[i++]='</a>'
  1657. a[i++]='</div>'
  1658. // end container
  1659. /*
  1660. a[i++]='<nobr>'
  1661. // Icon
  1662. a[i++]='<span id="'+_codeWinName+'icn'+id+'" '+(_moz?'onclick':'onmousedown')+'="'+_codeWinName+'.TreeWidget_clickCB('+id+',true,event,true); if (_ie) return false" ondblclick="'+_codeWinName+'.treeDblClickCB('+id+',event);return false" ' + contextMenu + '>'
  1663. a[i++]=(exp?imgOffset(_skin+'../tree.gif',13,12,expanded?0:13,0,null,null,expanded?_expandedLab:_collapsedLab,mrg,'top'):'')
  1664. a[i++]=(iconId>-1?imgOffset(treeView.icns,treeView.iconW,treeView.iconH,(treeView.iconOrientVertical?0:treeView.iconW*(expanded?iconSelId:iconId)),(treeView.iconOrientVertical?treeView.iconH*(expanded?iconSelId:iconId):0),null,null,,exp?'':mrg,'top'):'')
  1665. a[i++]='</span>'
  1666. // Text
  1667. a[i++]=((!exp && iconId==-1)?img(_skin+'../transp.gif',indent+13,1) :'')
  1668. // Check box related
  1669. if (isCheck)
  1670. {
  1671. a[i++]='<input onclick="'+_codeWinName+'.TreeWidgetElem_checkCB(this,\''+id+'\')" style="margin:0px;'+(_ie?'':'margin-left:2px')+'" type="checkbox" id="chk'+id+ '"' +(this.checked?' checked':'')+'>'
  1672. }
  1673. a[i++]='<a style="height:'+(iconId>-1?16:14)+'px;padding-top:0px;padding-bottom:0px;"
  1674. id="'+_codeWinName+'trLstElt'+id+'" class="'+nonselectedClass+ '" ' + acceptDD + ' href="javascript:void(0)"
  1675. onclick="eventCancelBubble(event);return false" onmousedown="'+_codeWinName+'.TreeWidget_clickCB('+id+',false,event,true);return false"
  1676. ondblclick="'+_codeWinName+'.treeDblClickCB('+id+',event);return false"
  1677. onfocus="'+_codeWinName+'.treeFCCB(this,'+id+',true)"
  1678. onblur="'+_codeWinName+'.treeFCCB(this,'+id+',false)" '+ mouseCB + contextMenu + '>'
  1679. a[i++]=(isHTML?name:convStr(name))
  1680. a[i++]='</a>'
  1681. // End container
  1682. a[i++]='</nobr><br>'
  1683. */
  1684. // Sub tree container
  1685. //if (exp) a[i++]='<span id="'+_codeWinName+'trTog'+id+'" style="display:'+(expanded?'':'none')+'">'
  1686. if (exp) a[i++]='<div id="'+_codeWinName+'trTog'+id+'" style="margin-left:18px;display:'+(expanded?'':'none')+'">'
  1687. // Generate child HTML if needed
  1688. if (expanded)
  1689. {
  1690. generated=true
  1691. //var idt=indent+_trIndent
  1692. //for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(idt,j==0);
  1693. for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(0,j==0);
  1694. }
  1695. if (exp)
  1696. {
  1697. nodeIndent=indent
  1698. a[i++]="</div>"
  1699. }
  1700. }
  1701. return a.join("");
  1702. }
  1703. // ================================================================================
  1704. function TreeWidgetElem_setGrayStyle(isGray)
  1705. {
  1706. var o=this,cls=isGray?o.grayTxt:o.blackTxt
  1707. if (cls!=o.nonselectedClass)
  1708. {
  1709. o.nonselectedClass=cls
  1710. o.init()
  1711. if (o.domElem&&(o.domElem.className!=o.selectedClass))
  1712. o.domElem.className=cls
  1713. }
  1714. }
  1715. // ================================================================================
  1716. function TreeWidgetElem_isGrayStyle()
  1717. {
  1718. return this.nonselectedClass==this.grayTxt
  1719. }
  1720. // ================================================================================
  1721. function TreeWidgetElem_setIncomplete(querycompleteCB)
  1722. {
  1723. this.isIncomplete=true
  1724. this.querycompleteCB=querycompleteCB
  1725. }
  1726. // ================================================================================
  1727. function TreeWidgetElem_finishComplete()
  1728. {
  1729. this.isIncomplete=false
  1730. TreeWidget_toggleCB(this.id)
  1731. this.treeView.buildElems()
  1732. }
  1733. // ================================================================================
  1734. function TreeWidgetElem_findByData(data)
  1735. {
  1736. var o=this
  1737. if (o.userData==data)
  1738. return o
  1739. var sub=o.sub
  1740. for (var i in sub)
  1741. {
  1742. var item=sub[i].findByData(data)
  1743. if (item!=null)
  1744. return item
  1745. }
  1746. return null
  1747. }
  1748. // ================================================================================
  1749. function TreeWidgetElem_findInName(text,matchCase,matchWholeW,next,starWith)
  1750. {
  1751. var o=this, name=o.name
  1752. if(text=="" || text==null) return; //safe test
  1753. if(!matchCase || (matchCase == null))//ignore case
  1754. {
  1755. name=name.toLowerCase();
  1756. text=text.toLowerCase();
  1757. }
  1758. if(matchWholeW)//match word
  1759. {
  1760. var arrWords = name.split(" ");//to improve later
  1761. for(var i = 0; i<arrWords.length; i++)
  1762. {
  1763. if(arrWords[i] == text)
  1764. return o;
  1765. }
  1766. }
  1767. else
  1768. {
  1769. var idx = name.indexOf(text); // search occurence
  1770. if (starWith == true )
  1771. {
  1772. if(idx == 0) return o;
  1773. }
  1774. else
  1775. {
  1776. if(idx>-1) return o;
  1777. }
  1778. }
  1779. return null
  1780. }
  1781. // ================================================================================
  1782. function TreeWidgetElem_findById(id)
  1783. {
  1784. var o=this
  1785. if (o.id==id)
  1786. return o
  1787. var sub=o.sub
  1788. for (var i in sub)
  1789. {
  1790. var item=sub[i].findById(id)
  1791. if (item!=null)
  1792. return item
  1793. }
  1794. return null
  1795. }
  1796. // ================================================================================
  1797. function TreeWidgetElem_change(iconId, name, userData, help,iconSelId,tooltip)
  1798. {
  1799. var o=this,treeView=o.treeView
  1800. if (iconId!=null) o.iconId=iconId
  1801. if (name!=null) o.name=name
  1802. o.userData=userData
  1803. if (help!=null) o.help=help
  1804. o.iconSelId=(iconSelId!=null)?iconSelId:o.iconId
  1805. if (tooltip!=null) o.tooltip=tooltip
  1806. o.init()
  1807. if (o.domElem)
  1808. o.domElem.innerHTML=convStr(o.name)
  1809. if (o.icnLyr)
  1810. {
  1811. if(o.icnLyr.childNodes.length>0)
  1812. {
  1813. var iconL=o.icnLyr.childNodes[o.sub.length>0?1:0]
  1814. changeOffset(iconL,
  1815. treeView.iconOrientVertical?0:o.treeView.iconW*(o.expanded?o.iconSelId:o.iconId),
  1816. treeView.iconOrientVertical?o.treeView.iconH*(o.expanded?o.iconSelId:o.iconId):0)
  1817. }
  1818. }
  1819. }
  1820. // ================================================================================
  1821. // added for inside tree D&D
  1822. function treeInitDropFunc(lyr,elemId)
  1823. {
  1824. var e=_TreeWidgetElemInstances[elemId]
  1825. if (lyr.ondrop==null) // lyr
  1826. {
  1827. e.treeView.dragDrop.attachCallbacks(lyr,true)
  1828. lyr.domEltID=elemId
  1829. }
  1830. }
  1831. // ================================================================================
  1832. function TreeWidget_toggleCB(elemId,noTimeOut)
  1833. // Expand or collapse a tree element children
  1834. // Returns [void]
  1835. {
  1836. var elem=_TreeWidgetElemInstances[elemId]
  1837. // if no children the + disappear
  1838. if (elem.sub.length==0) {
  1839. elem.plusLyr.style.visibility='hidden'
  1840. return
  1841. }
  1842. elem.expanded=!elem.expanded
  1843. elem.init()
  1844. if (noTimeOut) {
  1845. dispIcn(elemId);
  1846. } else {
  1847. setTimeout(elem.treeView.dispIcnFuncName+'('+elemId+')',1)
  1848. }
  1849. var tree=elem.treeView
  1850. if (elem.expanded&&tree.expandCB)
  1851. tree.expandCB(elem.userData)
  1852. if (!elem.expanded&&tree.collapseCB)
  1853. tree.collapseCB(elem.userData)
  1854. }
  1855. // ================================================================================
  1856. function dispIcn(eId)
  1857. {
  1858. var e=_TreeWidgetElemInstances[eId]
  1859. with (e)
  1860. {
  1861. if (expanded&&!generated)
  1862. {
  1863. generated=true;
  1864. var a=new Array,i=0,len=sub.length,newInd=nodeIndent+_trIndent
  1865. for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(newInd,j==0);
  1866. toggleLyr.innerHTML=a.join('');
  1867. }
  1868. toggleLyr.style.display=expanded?'block':'none'
  1869. if(expanded)
  1870. {
  1871. if(treeView.minIcon != null)
  1872. plusLyr.src = treeView.minIcon;
  1873. else
  1874. plusLyr.src = _skin+'../min.gif';
  1875. }
  1876. else
  1877. {
  1878. if(treeView.plusIcon != null)
  1879. plusLyr.src = treeView.plusIcon;
  1880. else
  1881. plusLyr.src = _skin+'../plus.gif';
  1882. }
  1883. plusLyr.title=expanded?_expandedLab:_collapsedLab
  1884. if(icnLyr&&icnLyr.childNodes&&icnLyr.childNodes.length>1)
  1885. {
  1886. var iconL=icnLyr.childNodes[1]
  1887. changeOffset(iconL,
  1888. treeView.iconOrientVertical?0:treeView.iconW*(expanded?iconSelId:iconId),
  1889. treeView.iconOrientVertical?treeView.iconH*(expanded?iconSelId:iconId):0)
  1890. }
  1891. }
  1892. }
  1893. // ================================================================================
  1894. function TreeWidgetElem_add(elem)
  1895. {
  1896. with (this)
  1897. {
  1898. elem.treeView=treeView;
  1899. elem.par=this;
  1900. sub[sub.length]=elem;
  1901. }
  1902. return elem
  1903. }
  1904. // ================================================================================
  1905. function TreeWidgetElem_getHiddenParent()
  1906. {
  1907. var par=this.par
  1908. if (par==null) return null
  1909. if (!par.expanded)
  1910. return par
  1911. return
  1912. par.getHiddenParent()
  1913. }
  1914. // ================================================================================
  1915. function TreeWidgetElem_getNextPrev(delta)
  1916. {
  1917. with (this)
  1918. {
  1919. if (elemPos==-1) treeView.buildElems()
  1920. var newPos=elemPos+delta
  1921. if ((newPos>=0)&&(newPos<treeView.elems.length))
  1922. {
  1923. var ret=treeView.elems[newPos]
  1924. var hidden=ret.getHiddenParent()
  1925. if (hidden!=null) return ret.getNextPrev(delta)
  1926. else return ret
  1927. }
  1928. else return null;
  1929. }
  1930. }
  1931. // ================================================================================
  1932. function TreeWidgetElem_scroll(elemLyr,treeLyr)
  1933. {
  1934. var scrollH = Math.max(0,treeLyr.offsetHeight-20), scrollY = treeLyr.scrollTop
  1935. var elPos = getPos(elemLyr,treeLyr)
  1936. var y = elPos.offsetTop, h = elemLyr.offsetHeight
  1937. if ((y-scrollY+h) > scrollH ) {
  1938. treeLyr.scrollTop=y+h-scrollH
  1939. }
  1940. if ((y-scrollY) < 0) {
  1941. treeLyr.scrollTop= y
  1942. }
  1943. }
  1944. // ================================================================================
  1945. function TreeWidgetElem_unselect()
  1946. {
  1947. var o=this
  1948. with(o)
  1949. {
  1950. init()
  1951. if (domElem) {
  1952. domElem.className=o.nonselectedClass
  1953. }
  1954. treeView.selId=-1
  1955. if(treeView.multiSelection)
  1956. {
  1957. var idx = arrayFind(treeView,'selIds',id)
  1958. if(idx>-1)
  1959. {
  1960. //update array selIds
  1961. arrayRemove(treeView,'selIds',idx);
  1962. //update _BOselIds
  1963. treeView.layer._BOselIds=""
  1964. var len = treeView.selIds.length;
  1965. for(var i=0;i<len;i++)
  1966. {
  1967. if(treeView.layer._BOselIds == "")
  1968. treeView.layer._BOselIds=""+treeView.selIds[i];
  1969. else
  1970. treeView.layer._BOselIds+=";"+treeView.selIds[i];
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. // ================================================================================
  1977. function TreeWidgetElem_select(setFocus,ev,noSendClickCB,isFromKeybArrow)
  1978. {
  1979. // If some parents are collapsed, expand them before
  1980. var coll=new Array
  1981. var par=this.par
  1982. while (par)
  1983. {
  1984. if (!par.expanded)
  1985. coll[coll.length]=par
  1986. par=par.par
  1987. }
  1988. var cLen=coll.length
  1989. for (var i=cLen-1;i>=0;i--)
  1990. {
  1991. TreeWidget_toggleCB(coll[i].id,true)//direct construction of the HTML of children
  1992. }
  1993. if (cLen>0)
  1994. {
  1995. /*
  1996. _tvw_param0=this
  1997. _tvw_param1=setFocus
  1998. _tvw_param2=ev
  1999. _tvw_param3=noSendClickCB
  2000. _tvw_param4=isFromKeybArrow
  2001. setTimeout("_tvw_param0.select(_tvw_param1,_tvw_param2,_tvw_param3,_tvw_param4)",1)
  2002. return;
  2003. */
  2004. this.select(setFocus,ev,noSendClickCB,isFromKeybArrow);
  2005. }
  2006. //multi selection treeview
  2007. if(this.treeView.multiSelection)
  2008. {
  2009. TreeWidgetElem_multiSelect(this,setFocus,ev,noSendClickCB,isFromKeybArrow);
  2010. return;
  2011. }
  2012. //mono selection treeview
  2013. if (noSendClickCB==null)
  2014. noSendClickCB=false
  2015. with (this)
  2016. {
  2017. if (treeView.selId!=id)
  2018. {
  2019. if (treeView.selId>=0)
  2020. {
  2021. var prev=_TreeWidgetElemInstances[treeView.selId]
  2022. prev.init()
  2023. if (prev.domElem) {
  2024. prev.domElem.className=prev.nonselectedClass
  2025. }
  2026. //window.status=prev.nonselectedClass
  2027. }
  2028. treeView.selId=id;
  2029. init()
  2030. treeView.layer._BOselId=id
  2031. var de=domElem
  2032. if (de == null) return
  2033. //highlight path
  2034. if(treeView.hlPath)
  2035. treeView.highlightPath(id);
  2036. else
  2037. de.className=selectedClass
  2038. //window.status=prev.selectedClass
  2039. if (setFocus) {
  2040. safeSetFocus(de)
  2041. }
  2042. TreeWidgetElem_scroll(de,treeView.layer)
  2043. //if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData)
  2044. //window.status= "Normal Elem_select=" + id
  2045. }
  2046. if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData,isFromKeybArrow!=null?isFromKeybArrow:false)
  2047. }
  2048. // stop propagating event to the other link
  2049. /*if (ev)
  2050. eventCancelBubble(ev)*/ //DOESN'T WORK WITH NETSCAPE
  2051. }
  2052. // ================================================================================
  2053. _startShift=null;
  2054. function TreeWidgetElem_multiSelect(o,setFocus,ev,noSendClickCB,isFromKeybArrow)
  2055. {
  2056. if (noSendClickCB==null)
  2057. noSendClickCB=false
  2058. with (o) // o instanceof TreeWidgetElem
  2059. {
  2060. init();
  2061. var de=domElem
  2062. if (de == null) return
  2063. //reset highlight items
  2064. if(treeView.hlPath) treeView.unhlPath();
  2065. if(ev == null)
  2066. {
  2067. var idx = arrayFind(treeView,'selIds',id);
  2068. if(idx == -1)//not yet selected
  2069. {
  2070. //add item to selected item list
  2071. treeView.selIds[treeView.selIds.length]=id;
  2072. if(treeView.layer._BOselIds == "")
  2073. treeView.layer._BOselIds=""+id;
  2074. else
  2075. treeView.layer._BOselIds+=";"+id;
  2076. de.className=selectedClass
  2077. }
  2078. //need to reset here ?
  2079. _startShift=null;
  2080. }
  2081. else //from event, use ctl and shift to define the action to do
  2082. {
  2083. var idx = arrayFind(treeView,'selIds',id);
  2084. var ctrl=_ie?_curWin.event.ctrlKey:ev.ctrlKey
  2085. var shift=_ie?_curWin.event.shiftKey:ev.shiftKey
  2086. var typeEvt=_ie?_curWin.event.type:ev.type
  2087. if(ctrl && !shift) //select or deselect
  2088. {
  2089. if(idx == -1)//select item
  2090. {
  2091. // don't select if there's a grayed item
  2092. //if (o.isGrayStyle()) return
  2093. treeView.selIds[treeView.selIds.length]=id;
  2094. if(treeView.layer._BOselIds == "")
  2095. treeView.layer._BOselIds=""+id;
  2096. else
  2097. treeView.layer._BOselIds+=";"+id;
  2098. de.className=selectedClass
  2099. }
  2100. else //deselect item
  2101. {
  2102. unselect();
  2103. }
  2104. _startShift= o;
  2105. }
  2106. if(shift) //select block items
  2107. {
  2108. var lastSelId=-1,lastSel=null;
  2109. if(treeView.selIds.length>0)
  2110. {
  2111. lastSelId = treeView.selIds[treeView.selIds.length-1];
  2112. lastSel = _TreeWidgetElemInstances[lastSelId];
  2113. if(_startShift == null)
  2114. _startShift = lastSel;
  2115. if(!ctrl) //do not clear selection if we want to continue shift selection after a ctrl action
  2116. treeView.unselect();
  2117. TreeWidgetElem_multiSelectShift(_startShift.id,id);
  2118. }
  2119. else //select only this item
  2120. {
  2121. treeView.unselect();
  2122. treeView.selIds[0]=id;
  2123. treeView.layer._BOselIds=""+id;
  2124. if(treeView.hlPath)
  2125. treeView.highlightPath(id);
  2126. else
  2127. de.className=selectedClass;
  2128. _startShift=null;
  2129. }
  2130. }
  2131. if(!ctrl && !shift) //simple click
  2132. {
  2133. //be carefull, sometimes we want to drag and drop so don't deselect treeview
  2134. var idx = arrayFind(treeView,'selIds',id);
  2135. if( _ie &&typeEvt=="mousedown" && idx>-1)
  2136. {
  2137. window._treeWClickedW=o
  2138. de.onmouseup=TreeWidgetElem_mouseUp
  2139. }
  2140. else
  2141. {
  2142. treeView.unselect();
  2143. treeView.selIds[0]=id;
  2144. treeView.layer._BOselIds=""+id;
  2145. if(treeView.hlPath)
  2146. treeView.highlightPath(id);
  2147. else
  2148. de.className=selectedClass
  2149. _startShift=null;
  2150. }
  2151. }
  2152. }
  2153. if (setFocus) {
  2154. safeSetFocus(de)
  2155. }
  2156. TreeWidgetElem_scroll(de,treeView.layer)
  2157. if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData,isFromKeybArrow!=null?isFromKeybArrow:false)
  2158. }
  2159. }
  2160. // ================================================================================
  2161. function TreeWidgetElem_multiSelectCtrl()
  2162. {
  2163. }
  2164. // ================================================================================
  2165. //select items between id1 and id2
  2166. function TreeWidgetElem_multiSelectShift(id1,id2)
  2167. {
  2168. var elem1=_TreeWidgetElemInstances[id1];
  2169. var elem2=_TreeWidgetElemInstances[id2];
  2170. var treeView = elem1?elem1.treeView:null;
  2171. if(treeView == null) return;//safe test
  2172. if (elem1.elemPos==-1 || elem2.elemPos==-1 ) treeView.buildElems()
  2173. var startPos= (elem1.elemPos<elem2.elemPos)?elem1.elemPos:elem2.elemPos
  2174. var endPos= (elem1.elemPos>elem2.elemPos)?elem1.elemPos:elem2.elemPos
  2175. if ((startPos>=0)&&(endPos<treeView.elems.length))
  2176. {
  2177. for(var j=startPos;j<=endPos;j++)
  2178. {
  2179. var elem = treeView.elems[j];
  2180. // don't select if there's a grayed item
  2181. //if (elem.isGrayStyle()) return
  2182. var hidden=elem.getHiddenParent();//not visible item
  2183. if((hidden == null)&&(arrayFind(treeView,'selIds',elem.id) == -1))//safe test
  2184. {
  2185. //add to selected items array
  2186. treeView.selIds[treeView.selIds.length]=elem.id;
  2187. if(treeView.layer._BOselIds == "")
  2188. treeView.layer._BOselIds=""+elem.id;
  2189. else
  2190. treeView.layer._BOselIds+=";"+elem.id;
  2191. elem.init();
  2192. if(elem.domElem)
  2193. elem.domElem.className=elem.selectedClass;
  2194. }
  2195. }
  2196. }
  2197. }
  2198. // ================================================================================
  2199. function TreeWidget_clickCB(elemId,isIcon,ev,isDown)
  2200. {
  2201. eventCancelBubble(ev)
  2202. var e=_TreeWidgetElemInstances[elemId]
  2203. if (e==null)
  2204. return
  2205. e.init()
  2206. if (isIcon&&(e.sub.length>0)) TreeWidget_toggleCB(elemId)
  2207. else if (isIcon&&e.isIncomplete&&e.querycompleteCB)
  2208. e.querycompleteCB()
  2209. else e.select(null,ev)
  2210. if (_curDoc.onmousedown)
  2211. _curDoc.onmousedown(ev)
  2212. if (isDown&&_ie)
  2213. {
  2214. window._treeWClickedW=e
  2215. e.init()
  2216. e.clicked=true
  2217. e.initialX=eventGetX(ev)
  2218. e.initialY=eventGetY(ev)
  2219. if (_ie&&e.domElem)
  2220. e.domElem.onmousemove=TreeWidgetElem_triggerDD
  2221. }
  2222. if (_moz&&e.domElem)
  2223. setTimeout("_TreeWidgetElemInstances["+elemId+"].domElem.focus()",1)
  2224. return false
  2225. }
  2226. // ================================================================================
  2227. function treeDblClickCB(elemId,ev)
  2228. {
  2229. eventCancelBubble(ev)
  2230. var e=_TreeWidgetElemInstances[elemId],treeView=e.treeView;
  2231. if (e.sub.length>0) TreeWidget_toggleCB(elemId)
  2232. else if (e.isIncomplete&&e.querycompleteCB)
  2233. {
  2234. e.querycompleteCB()
  2235. return
  2236. }
  2237. if (e.isEditable)
  2238. e.showEditInput(true)
  2239. else
  2240. {
  2241. if (treeView.doubleClickCB) treeView.doubleClickCB(e.userData);
  2242. }
  2243. }
  2244. // ================================================================================
  2245. function TreeWidgetElem_UpdateTooltip(newId,forceSelect)
  2246. {
  2247. var elem=_TreeWidgetElemInstances[newId];
  2248. if(elem)
  2249. {
  2250. elem.init();
  2251. if(elem.domElem != null)
  2252. elem.domElem.title = elem.getTooltip(forceSelect);
  2253. }
  2254. }
  2255. // ================================================================================
  2256. function TreeWidgetElem_getDragTooltip()
  2257. {
  2258. var o=this
  2259. if (o.obj && o.obj.getDragTooltip) return o.obj.getDragTooltip()
  2260. return o.name
  2261. }
  2262. // ================================================================================
  2263. function TreeWidgetElem_getTooltip(forceSelect)
  2264. {
  2265. var tooltip='',o=this
  2266. var itemSelected=false;
  2267. //multi selection
  2268. if(o.treeView.multiSelection)
  2269. {
  2270. itemSelected = (arrayFind(o.treeView,'selIds',o.id) > -1);
  2271. }
  2272. else//mono selection
  2273. {
  2274. itemSelected = (o.treeView.selId == o.id);
  2275. }
  2276. //selection
  2277. if (forceSelect || itemSelected)
  2278. tooltip = _selectedLab + ' ';
  2279. /*
  2280. if(o.tooltip)
  2281. tooltip+=o.tooltip+' ';
  2282. */
  2283. //name
  2284. tooltip+=o.name;
  2285. //expanded or collapsed
  2286. if((o.sub.length > 0) || (o.isIncomplete))
  2287. {
  2288. if(o.expanded)
  2289. tooltip += ' '+ _expandedLab + ' ';
  2290. else
  2291. tooltip += ' '+ _collapsedLab + ' ';
  2292. }
  2293. //case prompt and context selection
  2294. if(o.advTooltip)
  2295. {
  2296. tooltip+=' ('+o.advTooltip+')'
  2297. }
  2298. /*
  2299. if(o.help)
  2300. tooltip +=' - ' + o.help;
  2301. */
  2302. return tooltip;
  2303. }
  2304. //508 tooltip - focus callback
  2305. function treeFCCB(e,elemId,focus,ev)
  2306. {
  2307. var elem =_TreeWidgetElemInstances[elemId];
  2308. if ((elem==null) || elem.treeView.mouseOverTooltip)
  2309. return
  2310. if(focus)
  2311. {
  2312. if (elem.customTooltip && elem.showCustomTooltipCB)
  2313. {
  2314. elem.showCustomTooltipCB(elem.userData,ev)
  2315. elem.init()
  2316. }
  2317. else
  2318. e.title = elem.getTooltip();
  2319. }
  2320. else
  2321. {
  2322. if (elem.customTooltip && elem.hideCustomTooltipCB)
  2323. elem.hideCustomTooltipCB()
  2324. else
  2325. e.title = "";
  2326. }
  2327. }
  2328. //2 possible workflows:
  2329. //1- display tooltip
  2330. //2- item has callback associated to mouse over
  2331. function _tmoc(e,elemId,over,ev)
  2332. {
  2333. e.style.cursor=_hand
  2334. var elem =_TreeWidgetElemInstances[elemId];
  2335. if(elem==null)
  2336. return
  2337. //1: normal tooltip - mouse over callback
  2338. if(elem.treeView.mouseOverTooltip)
  2339. {
  2340. if(over)
  2341. {
  2342. if (elem.customTooltip && elem.showCustomTooltipCB)
  2343. {
  2344. elem.showCustomTooltipCB(elem.userData,ev)
  2345. elem.init()
  2346. }
  2347. else
  2348. e.title = elem.tooltip?elem.tooltip:''
  2349. }
  2350. else
  2351. {
  2352. if (elem.customTooltip && elem.hideCustomTooltipCB)
  2353. elem.hideCustomTooltipCB()
  2354. else
  2355. e.title =''
  2356. }
  2357. }
  2358. //we can also do the mouseover action, it does not interfere with the tooltip action
  2359. //asked by Bruno Rassamy for Mediance
  2360. if(elem.treeView.mouseOverCB)
  2361. elem.treeView.mouseOverCB(elem)
  2362. }
  2363. //
  2364. function treeContextMenuCB(elemId,ev)
  2365. {
  2366. var elem =_TreeWidgetElemInstances[elemId];
  2367. if(elem)
  2368. {
  2369. elem.treeView.rightClickMenuCB(elemId, _ie?_curWin.event:ev)
  2370. }
  2371. }
  2372. //return true if is leaf
  2373. function TreeWidgetElem_isLeaf()
  2374. {
  2375. return (this.sub.length==0 && !this.isIncomplete);
  2376. }
  2377. //return true if is node
  2378. function TreeWidgetElem_isNode()
  2379. {
  2380. return (!this.isLeaf());
  2381. }
  2382. //return true if selected item
  2383. function TreeWidgetElem_isSelected()
  2384. {
  2385. var o=this;
  2386. if(o.treeView.multi)//multi selection
  2387. {
  2388. var idx = arrayFind(o.treeView,'selIds',o.id);
  2389. return (idx>=0);
  2390. }
  2391. else
  2392. {
  2393. return (o.id == o.treeView.selId);
  2394. }
  2395. }
  2396. // =====================
  2397. // TreeWidgetElem class
  2398. // =====================
  2399. /*
  2400. function newTreeWidgetHTMLElem(iconID, name, obj, userData, help)
  2401. {
  2402. var o=newTreeWidgetElem(iconID, name, userData, help);
  2403. o.obj=obj
  2404. o.getHTML=TreeWidgetHTMLElem_getHTML;
  2405. o.selectedClass='filterBoxSelected';
  2406. o.nonselectedClass='filterBox';
  2407. o.feedbackDDClass='filterBoxFeedbackDD'
  2408. o.init=TreeWidgetHTMLElem_init
  2409. return o;
  2410. }
  2411. function TreeWidgetHTMLElem_init()
  2412. {
  2413. this.domElem=getLayer(_codeWinName+'trLstElt' + this.id)
  2414. }
  2415. function TreeWidgetHTMLElem_getHTML(indent,isFirst)
  2416. {
  2417. with (this)
  2418. {
  2419. len=sub.length,exp=(len>0),a=new Array,i=0
  2420. var contextMenu=''
  2421. if (treeView.rightClickMenuCB != null)
  2422. {
  2423. contextMenu= ' oncontextmenu="' + _codeWinName + '.treeContextMenuCB(\''+ id + '\', event);return false" '
  2424. }
  2425. var acceptDD=''
  2426. if ((treeView.acceptDropCB != null) && (_ie))
  2427. {
  2428. acceptDD= ' ondragenter="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
  2429. acceptDD += ' ondragover="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
  2430. }
  2431. a[i++] = '<table border="0" cellspacing="0" cellpadding="0"><tbody><tr>'
  2432. a[i++] = '<td>' + getSpace(indent + 16, 16) + '</td>'
  2433. a[i++] = '<td>'
  2434. a[i++] = '<table id="'+_codeWinName+'trLstElt' + id + '" class="filterBox" onclick="'+_codeWinName+'.TreeWidget_clickCB(\''+ id +'\',false,event,true);if(_saf||_ie) return false" ondblclick="'+_codeWinName+'.treeDblClickCB('+id+',event);if(_saf||_ie) return false" ' + contextMenu + acceptDD + ' border="0" cellspacing="0" cellpadding="0">'
  2435. a[i++] = '<tbody><tr>'
  2436. a[i++] = '<td width="20">'
  2437. a[i++] = '<span style="padding:2px">'
  2438. a[i++] = (iconId>-1?imgOffset(treeView.icns,treeView.iconW,treeView.iconH, treeView.iconW * iconId, treeView.iconH * iconId,null,null,null,'','top'):'')
  2439. a[i++] = '</span>'
  2440. a[i++] = '</td>'
  2441. // see BOFilterNode_getHTML in CommonWom.js
  2442. // BOFilterNode_getHTML(treeView, filterID)
  2443. a[i++] = '<td>' + obj.getHTML(treeView, userData) + '</td>'
  2444. a[i++] = '</tr></tbody></table>'
  2445. a[i++] = '</td></tr></tbody></table>'
  2446. }
  2447. return a.join("");
  2448. }
  2449. //
  2450. function newTreeWidgetVoidElem(iconID, name, obj, userData, help)
  2451. {
  2452. var o=newTreeWidgetElem(iconID, name, userData, help);
  2453. o.obj=obj
  2454. o.getHTML=TreeWidgetVoidElem_getHTML;
  2455. o.selectedClass='filterTextSelected';
  2456. o.nonselectedClass='filterText';
  2457. o.feedbackDDClass='filterTextFeedbackDD '
  2458. o.init=TreeWidgetVoidElem_init
  2459. return o;
  2460. }
  2461. function TreeWidgetVoidElem_init()
  2462. {
  2463. this.domElem=getLayer(_codeWinName+'trLstElt' + this.id)
  2464. }
  2465. function TreeWidgetVoidElem_getHTML(indent,isFirst)
  2466. {
  2467. return ""
  2468. }
  2469. // =================
  2470. // TreeWidget class
  2471. // =================
  2472. function newStaticTreeWidget(id, originalTree)
  2473. {
  2474. var o = newWidget(id);
  2475. o.sub = originalTree.sub;
  2476. return o;
  2477. }
  2478. // =================
  2479. // FolderWidget class
  2480. // =================
  2481. function newFolderWidget(id, exp)
  2482. // Return [FolderWidget] the instance
  2483. {
  2484. var o=newWidget(id)
  2485. o.expanded= (exp)? exp : false
  2486. o.getCross=FolderWidget_getCross
  2487. return o;
  2488. }
  2489. //
  2490. // function getCross(id)
  2491. //
  2492. //
  2493. function FolderWidget_getCross()
  2494. {
  2495. if (_printDoc) return getSep(12,12)
  2496. with(this)
  2497. {
  2498. return '<span style="cursor:'+_hand+'" id="icn'+id+'" '+(_moz?'onclick':'onmousedown')+'="'+_codeWinName+'.clickCrossCB('+id+'); if (_ie) return false" ondblclick="'+_codeWinName+'.clickCrossCB('+id+'); if (_ie) return false">' +
  2499. imgOffset(_skin +'../tree.gif', 13, 9, expanded?0:13, 3, 'img'+ id, null, expanded?_expandedLab:_collapsedLab,null,null,'top') +
  2500. '</span>'
  2501. }
  2502. }
  2503. */