| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986 |
- // <script>
- /*
- =============================================================
- WebIntelligence(r) Report Panel
- Copyright(c) 2001-2003 Business Objects S.A.
- All rights reserved
- Use and support of this software is governed by the terms
- and conditions of the software license agreement and support
- policy of Business Objects S.A. and/or its subsidiaries.
- The Business Objects products and technology are protected
- by the US patent number 5,555,403 and 6,247,008
- File: treeview.js
- Custom treeview control
- =============================================================
- */
- _trIndent=18
- // ================================================================================
- // ================================================================================
- //
- // OBJECT newIconListWidget (Constructor)
- //
- // List box with icons, based on tree widget
- //
- // ================================================================================
- // ================================================================================
- /*
- function newIconListWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass)
- // CONSTRUCTOR
- // id [String] the id for DHTML processing
- // w [int] the tree wiew frame width in pixels
- // h [int] the tree wiew frame height in pixels
- // icn [String] the combined icon URL
- // clickCB [Function] callback called when clicking on an item
- // doubleClickCB [Function] callback called when double clicking on an item
- {
- var o=newTreeWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass)
- o.select=IconListWidget_select
- o.getSelection=IconListWidget_getSelection
- o.initialIndent=-_trIndent+3
- return o
- }
- // ================================================================================
- function IconListWidget_select(pos,setFocus,ev,noSendClickCB,isFromKeyArrow)
- // Select by position
- // pos [int] : the position
- // returns [void]
- {
- if ((pos>=0) && (pos<this.sub.length)) {
- this.sub[pos].select(setFocus,ev,noSendClickCB,isFromKeyArrow)
- }
- }
- // ================================================================================
- function IconListWidget_getSelection()
- // Get selction
- // returns [object] index, value
- {
- var sel=this.getSelectedItem()
- if (sel)
- {
- if (sel.elemPos==-1) this.buildElems()
- var selection=new Object
- selection.index=sel.elemPos
- selection.value=sel.userData
- return selection
- }
- return null
- }
- // ================================================================================
- // ================================================================================
- //
- // OBJECT newIconListPopupWidget (Constructor)
- //
- // List box with icons, based on tree widget show in popup like a menu
- //
- // ================================================================================
- // ================================================================================
- function newIconListPopupWidget(id,w,h,icns,clickCB,doubleClickCB)
- // CONSTRUCTOR
- // id [String] the id for DHTML processing
- // w [int] the tree wiew frame width in pixels
- // h [int] the tree wiew frame height in pixels
- // icn [String] the combined icon URL
- // clickCB [Function] callback called when clicking on an item
- // doubleClickCB [Function] callback called when double clicking on an item
- {
- var o=newWidget(id)
- o.iconList=newIconListWidget("list_"+id,w,h,icns,clickCB,doubleClickCB,"treeNoBorder")
- o.getList=IconListPopupWidget_getList
- //o.init=IconListPopupWidget_init
- o.getHTML=IconListPopupWidget_getHTML
- o.justInTimeInit=IconListPopupWidget_justInTimeInit
- o.getShadowHTML=IconListPopupWidget_getShadowHTML
- o.show=IconListPopupWidget_show
- o.captureClicks=IconListPopupWidget_captureClicks
- o.releaseClicks=IconListPopupWidget_releaseClicks
- o.getSelection=IconListPopupWidget_getSelection
-
- // Click capture
- o.clickCB=new Array
- o.clickCBDocs=new Array
-
- //cancelCB
- o.cancelCB=null;
- return o
- }
- // ================================================================================
- function IconListPopupWidget_init()
- {
- var o=this
- o.iconList.init();
- o.init();
- }
- // ================================================================================
- function IconListPopupWidget_getList()
- {
- return this.iconList;
- }
- // ================================================================================
- function IconListPopupWidget_getSelection()
- {
- }
- // ================================================================================
- function IconListPopupWidget_getShadowHTML()
- // Displays the shadow of the IconListPopup
- // Return [void]
- {
- return getBGIframe('menuIframe_'+this.id)
- }
- // ================================================================================
- function IconListPopupWidget_getHTML()
- // Return [string] the HTML sorce of this widget
- {
- var o=this
- var keyCB=' onkeydown="'+_codeWinName+'.IconListPopupWidget_keyDown(\''+o.id+'\',event)" onkeypress=" return '+_codeWinName+'.IconListPopupWidget_keyPress(\''+o.id+'\',event)" onkeyup="'+_codeWinName+'.IconListPopupWidget_keyUp(\''+o.id+'\',event)"';
- var s=''
- s+=o.getShadowHTML()
- s+='<table id="'+o.id+'" style="display:none;" class="menuFrame" cellspacing="0" cellpadding="0" border="0" '+keyCB+'><tbody>'
- s+='<tr><td align="center">'+o.iconList.getHTML()+'</td></tr>'
- s+='</tbody></table>'
-
- return s
- }
- // ================================================================================
- function IconListPopupWidget_justInTimeInit()
- // Initialization called just before showing scrollMenu for the first time
- // Return [void]
- {
- var o=this
- o.layer=getLayer(o.id)
-
- if (o.layer==null)
- {
- targetApp(o.getHTML())
- o.layer=getLayer(o.id)
- }
- o.layer._widget=o.widx
- o.css=o.layer.style
- o.css.visibility="hidden"
-
- o.iframeLyr=getLayer("menuIframe_"+o.id)
- o.iframeCss=o.iframeLyr.style
- o.iconList.init()
- o.iconList.layer.onmousedown=IconListPopupWidget_clickNoBubble
- }
- // ================================================================================
- function IconListPopupWidget_show(show,x,y)
- // show [boolean] if true shows the menu, otherwise hide it
- // x [int] menu abscissa (may be changed if the menu is outside the window)
- // y [int] menu ordinate (may be changed if the menu is outside the window)
- // Return [void]
- {
- var o=this
-
- if (o.layer==null)
- o.justInTimeInit()
- var css=o.css,iCss=o.iframeCss
-
- if (show)
- {
- o.captureClicks()
-
- // Show and place menu
- css.display='block'
- //css.zIndex=(o.zIndex+1)
- css.zIndex=4000
- css.visibility="hidden"
- css.left="-1000px"
- css.top="-1000px"
-
- var w=o.getWidth()
- var h=o.getHeight()
-
- if (o.alignLeft)
- x-=w
-
- // Change coordinates if the menu is out of the window
- var x2=x+w+4,y2=y+h+4
- if (x2>winWidth())
- x=Math.max(0,x-4-w)
- if (y2>winHeight())
- y=Math.max(0,y-4-h)
-
- css.left=""+x+"px"
- css.top=""+y+"px"
-
- //hideAllInputs(x,y,w+4,h+4)
-
- css.visibility="visible"
- // Show and place menu shadow
- iCss.left=""+x+"px"
- iCss.top=""+y+"px"
- iCss.width=""+w+"px"
- iCss.height=""+h+"px"
- iCss.zIndex=3998
- iCss.display='block'
-
- if (_ie)
- {
- y-=2
- x-=2
- }
-
- }
- else
- {
- css.display='none'
- iCss.display='none'
-
- o.releaseClicks()
- }
- }
- // ================================================================================
- function IconListPopupWidget_captureClicks(w)
- // capture click in current frame and sub-frame, so when the users clicks outside
- // the menu, the menu is closed. Eventual click handlers are stored.
- // Use releaseClicks() to restore previous click handlers
- // Returns [void]
- {
- var o=this
- if (o.par==null)
- {
- if (w==null)
- {
- _globMenuCaptured=o
- o.clickCB.length=0
- o.clickCBDocs.length=0
- w=_curWin
- }
- //_excludeFromFrameScan variable is set by a frame that does not want to
- // be scaned, when the frame is used to download document for instance.
- if (canScanFrames(w))
- {
- if (_moz)
- {
- _oldErrHandler=window.onerror
- window.onerror=localErrHandler
- }
-
- try
- {
- d=w.document
- o.clickCB[o.clickCB.length]=d.onmousedown
- o.clickCBDocs[o.clickCBDocs.length]=d
- d.onmousedown=IconListPopupWidget_globalClick
-
- var fr=w.frames,len=fr.length
- for (var i=0;i<len;i++)
- o.captureClicks(fr[i])
- }
- catch(expt)
- {
- }
- if (_moz)
- window.onerror=_oldErrHandler
- }
- }
- }
- // ================================================================================
- function IconListPopupWidget_globalClick()
- // PRIVATE
- // Click handler that close the menu if the user clicks outside the menu
- // Also call releaseClicks() to restore previous click handlers
- {
- var o=_globMenuCaptured
- if (o!=null)
- {
- _globMenuCaptured=null
- o.releaseClicks()
- o.show(false)
- }
- }
- // ================================================================================
- function IconListPopupWidget_releaseClicks()
- // Restore click handlers overrided by captureClicks()
- // Returns [void]
- {
- var o=this
- if (o.par==null)
- {
- var len=o.clickCB.length
- for (var i=0;i<len;i++)
- {
- o.clickCBDocs[i].onmousedown=o.clickCB[i]
- o.clickCB[i]=null
- o.clickCBDocs[i]=null
- }
- o.clickCB.length=0
- o.clickCBDocs.length=0
- }
- }
- // ================================================================================
- function IconListPopupWidget_clickNoBubble(e)
- {
- eventCancelBubble(e)
- }
- // ================================================================================
- //NOTE: these 3 functions are usefull to do not propagate the return carriage for textarea (variableeditordialog.html)
- function IconListPopupWidget_keyDown(id,e)
- {
- var o=getWidget(getLayer(id))
- var key=eventGetKey(e)
- if(key == 27)
- {
- if(o && o.cancelCB)
- o.cancelCB(e)
- }
- if(key == 13)
- {
- eventCancelBubble(e)
- return false
- }
- }
-
- function IconListPopupWidget_keyPress(id,e)
- {
- var o=getWidget(getLayer(id))
- var key=eventGetKey(e)
- if(key == 13 || key == 27)
- {
- eventCancelBubble(e)
- return false
- }
- }
- function IconListPopupWidget_keyUp(id,e)
- {
- var key=eventGetKey(e)
- if(key == 13 || key == 27)
- {
- eventCancelBubble(e)
- return false
- }
- }
- */
- // ================================================================================
- // ================================================================================
- //
- // OBJECT newTreeWidget (Constructor)
- //
- // Tree view class
- //
- // ================================================================================
- // ================================================================================
- function newTreeWidget(id,w,h,icns,clickCB,doubleClickCB,bgClass,expandCB,collapseCB,deleteCB,minIcon,plusIcon)
- // CONSTRUCTOR
- // id [String] the id for DHTML processing
- // w [int] the tree wiew frame width in pixels
- // h [int] the tree wiew frame height in pixels
- // icn [String] the combined icon URL, null if tree without icons
- // clickCB [Function] callback called when clicking on an item
- // doubleClickCB [Function] callback called when double clicking on an item
- // bgClass [String - optional] CSS class for tree background and frame
- // minIcon [String - optional] URL to min.gif
- // plusIcon [String - optional] URL to plus.gif
- {
- var o=newScrolledZoneWidget(id,2,4,w,h,bgClass)
- o.icns=icns
- o.sub = new Array
- o.clickCB=clickCB
- o.doubleClickCB=doubleClickCB
- o.expandCB=expandCB
- o.collapseCB=collapseCB
- o.deleteCB=deleteCB
- o.minIcon = minIcon
- o.plusIcon = plusIcon
- o.mouseOverCB=null
-
- o.rightClickMenuCB=null // need to call setRightClickMenu method
-
- o.mouseOverTooltip=false
- o.dragDrop=null
- o.oldInit=o.init
- o.init=TreeWidget_init
- o.getHTML=TreeWidget_getHTML
-
- o.getSelections=TreeWidget_getSelections
- // deprecated use getSelections()
- o.getSelectedItem=TreeWidget_getSelectedItem
- o.getSelectedItems=TreeWidget_getSelectedItems
- o.getCheckedItems=TreeWidget_getCheckedItems
-
- o.setDragDrop=TreeWidget_setDragDrop
- o.setFocus=TreeWidget_setFocus
- o.add=TreeWidget_add
- o.setRightClickMenuCB=TreeWidget_setRightClickMenuCB
- o.findByData=TreeWidget_findByData
- o.findById=TreeWidget_findById
- o.findInName=TreeWidget_findInName
- o.selectByData=TreeWidget_selectByData
- o.selectById=TreeWidget_selectById
- o.unselect=TreeWidget_unselect
- o.search=TreeWidget_search
- o.treeLyr=null
- o.elems=new Array
- o.elemCount=0
- o.selId=-1;
- o.selIds=new Array;
- o.multiSelection=false;
- o.hlPath=false; //highlight path
- o.hlElems=new Array;
- o.iconOrientVertical=true
- o.deleteAll=TreeWidget_deleteAll
- o.rebuildHTML=TreeWidget_rebuildHTML
- o.iconW=16
- o.iconH=16
- o.initialIndent=0
- o.buildElems=TreeWidget_buildElems
- o.getCount=TreeWidget_getCount
- if (window._TreeWidgetElemInstances==null)
- window._TreeWidgetElemInstances=new Array
- o.dispIcnFuncName="dispIcn"
-
- o.setTooltipOnMouseOver=TreeWidget_setTooltipOnMouseOver
- o.setMouseOverCB=TreeWidget_setMouseOverCB
-
- o.setMultiSelection=TreeWidget_setMultiSelection
- o.setHighlightPath=TreeWidget_setHighlightPath
- o.highlightPath=TreeWidget_highlightPath
- o.unhlPath=TreeWidget_unhlPath
-
- return o
- }
- // ================================================================================
- function TreeWidget_unselect()
- // Unselect in the tree view
- {
- var o=this
- if (o.selId>=0)
- {
- var prev=_TreeWidgetElemInstances[o.selId]
- prev.unselect()
- o.selId=-1
- }
- if(o.multiSelection)
- {
- var len=o.selIds.length, id;
- for(var i=len-1;i>=0;i--)
- {
- var prev=_TreeWidgetElemInstances[o.selIds[i]]
- if(prev) prev.unselect()
- }
- o.selIds.length=0;
- o.layer._BOselIds="";
- }
- //unhighligh if necessary
- o.unhlPath()
- }
- // ================================================================================
- function TreeWidget_selectByData(data,setFocus)
- // Select an item that matches the data parameter
- // data [Variant] the item data to find
- // id [setFocus - Optional] Scroll to the item & set the focus on it
- // return void
- {
- var o=this,item=o.findByData(data)
- if (item)
- {
- item.select(setFocus)
- }
- }
- // ================================================================================
- function TreeWidget_selectById(id,setFocus)
- // Select an item that matches the id parameter
- // id [String] the item id to find
- // id [setFocus - Optional] Scroll to the item & set the focus on it
- // return void
- {
- var o=this,item=o.findById(id)
- if (item)
- {
- item.select(setFocus)
- }
- }
- // ================================================================================
- function TreeWidget_findByData(data)
- {
- var o=this,sub=o.sub,item=null
- for (var i in sub)
- {
- item=sub[i].findByData(data)
- if (item)
- return item
- }
- return null
- }
- // ================================================================================
- function TreeWidget_findById(id)
- {
- var o=this,sub=o.sub,item=null
- for (var i in sub)
- {
- item=sub[i].findById(id)
- if (item)
- return item
- }
- return null
- }
- // ================================================================================
- function TreeWidget_findInName(text,matchCase,matchWholeW,startFrom,next,starWith,visible)
- //text [String] text to search in treeview
- //matchCase [Boolean - Optional] if null or false then case is no sensitive
- //matchWholeW [Boolean - Optional] if null or false then no match whole word
- //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
- //next [Boolean - Optional] search next or previous, by default it is next
- //starWith [Boolean - Optional] search object begenning with this text, by default it is false
- //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
- {
- //safe test
- if(text=="" || text==null) return null;
-
- var o=this,item=null,elem=null,hidden=false;
-
- var startPos=0,newPos=0;
- var bMatchCase=matchCase?matchCase:false;
- var bMatchWW=matchWholeW?matchWholeW:false;
- var bNext=(!next)?next:true;
- var bVisible=visible?visible:false;
-
- var len=o.elems.length;
- if(len == 0)
- {
- o.buildElems();
- len=o.elems.length;
- if( len == 0) return;
- }
- //get the position of the selection
- var arr = o.getSelections();
- if(arr.length>0)
- {
- startPos=arr[0].elemPos+(bNext?1:-1);
-
- //verify that the start position is good
- if((startPos<0) &&! bNext )
- startPos=len-1;
-
- if((startPos==len) && bNext )
- startPos=0;
- }
- else if(startFrom=="begin")
- {
- startPos=0;
- }
- else if(startFrom=="end")
- {
- startPos=len-1;
- }
-
- newPos=startPos;
-
- while ((newPos>=0)&&(newPos<len))
- {
- elem=o.elems[newPos];
- hidden=elem.getHiddenParent();//not visible item
- if((bVisible && !hidden) || (!bVisible))
- item=elem.findInName(text,bMatchCase,bMatchWW,bNext,starWith);
-
- if(item!=null) break;
-
- newPos=newPos+(bNext?1:-1);
-
- if((newPos<0) && !bNext )
- newPos=len-1;
-
- if((newPos==len) && bNext )
- newPos=0;
-
- if(newPos==startPos) break;
- }
-
- return item;
- }
- // ================================================================================
- function TreeWidget_search(text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
- //text [String] text to search in treeview
- //matchCase [Boolean - Optional] if null or false then case is no sensitive
- //matchWholeW [Boolean - Optional] if null or false then no match whole word
- //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
- //next [Boolean - Optional] search next or previous, by default it is next
- //notFoundCB [Callback - Optional] call when no occurence is found
- //starWith [Boolean - Optional] search object begenning with this text, by default it is false
- //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
- //setFocus [Boolean - Optional] set the focus to the found item, by default it is false
- {
- var o=this,item=null;
-
- if(text=="" || text==null) return ;
-
- item = o.findInName(text,matchCase,matchWholeW,startFrom,next,starWith,visible);
-
- if(item)
- {
- o.unselect();
- item.select(setFocus);
- }
- else if(notFoundCB)
- {
- notFoundCB();
- }
- }
- // ================================================================================
- function TreeWidget_add(elem,extraIndent)
- // Add an item in the tree
- // elem [TreeWidgetElem] the tree view elemnt to add
- // extraIndent [int - optional] the element additional indent
- // returns [TreeWidgetElem] elem
- {
- var o=this,sub=o.sub,len=sub.length
- elem.treeView=o
- sub[len]=elem
- elem.expanded=(len==0)
- if (extraIndent)
- elem.extraIndent=extraIndent
- return elem
- }
- // ================================================================================
- function TreeWidget_getHTML()
- // get the widget HTML
- // returns [String] the HTML
- {
- var o=this,sub=o.sub,len=sub.length,a=new Array(len+3),j=0
- //l.onkeydown=TreeWidget_keyDownCB;
- //l.onkeypress=TreeWidget_keyPressCB;
- a[j++]= o.beginHTML()+'<span id="treeCont_'+o.id+'" onkeydown="return '+_codeWinName+'.TreeWidget_keyDownCB(this,event)" >'
- for (var i in sub)
- a[j++]=sub[i].getHTML(o.initialIndent,i==0)
- a[j++]='</span>'+o.endHTML()
- return a.join("")
- }
- // ================================================================================
- function TreeWidget_deleteAll()
- // returns [void]
- {
- var sub=this.sub
- for (var i in sub)
- {
- sub[i].deleteAll()
- sub[i]=null
- }
- sub.length=0
- if (this.elems)
- this.elems.length=0
- }
- // ================================================================================
- function TreeWidget_rebuildHTML()
- // Rebuild completly the tree view
- // returns [void]
- {
- var o=this,sub=o.sub,len=sub.length,a=new Array(len),j=0,idt=o.initialIndent
- for (var i in sub)
- a[j++]=sub[i].getHTML(idt,i==0)
- o.treeLyr.innerHTML=a.join("")
- o.selId=-1
- o.layer._BOselId=-1
-
- //multi selection init
- o.selIds.length=0
- o.layer._BOselIds=""
- this.buildElems()
- }
- // ================================================================================
- function TreeWidget_init()
- // Standard init function
- // returns [void]
- {
- this.oldInit();
- var l=this.treeLyr=getLayer('treeCont_'+this.id);
-
- //l.onkeydown=TreeWidget_keyDownCB;
- //l.onkeypress=TreeWidget_keyPressCB;
-
- if (this.dragDrop)
- this.dragDrop.attachCallbacks(this.layer)
- var oldSel = this.layer._BOselId
- if (oldSel!=null)
- this.selId=oldSel
-
- //multi selection init
- var oldArraySel = this.layer._BOselIds; //string
- if (oldArraySel!=null && oldArraySel!="")
- {
- this.selIds.length=0;
- this.selIds=oldArraySel.split(";");
- }
-
- var sub=this.sub
- }
- // ================================================================================
- function TreeWidget_buildElems(elem)
- {
- with (this)
- {
- if (elem==null)
- elem=this;
- else
- {
- var pos=elems.length;
- elems[pos]=elem;
- elem.elemPos=pos;
- }
- var subArr=elem.sub,len=subArr.length;
- for (var i=0;i<len;i++)
- buildElems(subArr[i]);
- }
- }
- // ================================================================================
- function TreeWidget_getSelectedItem()
- // deprecated use getSelections()
- // Get the selected item
- // Returns [TreeWidgetElem] the selected itel (null if no selection)
- {
- var id=this.selId
- return (id>=0)?_TreeWidgetElemInstances[id]:null
- }
- // ================================================================================
- function TreeWidget_getSelections()
- //unify interface for multi or single selection in treeview
- {
- var o=this;
-
- if(o.multiSelection)
- {
- return o.getSelectedItems();
- }
- else
- {
- var sel=o.getSelectedItem(),arrSel=new Array;
- if(sel!=null) arrSel[0]=sel;
-
- return arrSel;
-
-
- }
- }
- // ================================================================================
- function TreeWidget_setFocus(index)
- {
- var elem=_TreeWidgetElemInstances[index]
- if(elem!=null)
- {
- elem.init()
- safeSetFocus(elem.domElem)
- }
- }
- // ================================================================================
- function TreeWidget_keyPressCB(lay,e)
- // Internal key press event callback
- // Internal Note: Do not forget to fix a bug in single and multi selection functions.
- {
- //multi selection treeview
- if(getWidget(lay).multiSelection)
- {
- return TreeWidget_multiSelKeyPress(lay,e);
- }
-
- //mono selection treeview
- var id=getWidget(lay).selId;
- if (id>=0)
- {
- var elem=_TreeWidgetElemInstances[id]
- var treeView=elem.treeView
- var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
-
- //_ie?_curWin.event.srcElement.id:e.target.id
- var k=eventGetKey(e) , ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey
- //window.status='press touche '+k + '('+ (t) +')'; t=t+1;
- if( k==13 )
- {
- //if(source!=_codeWinName+"trLstElt"+id) //select the item if not selected
- if(source!=id) //select the item if not selected
- {
- TreeWidget_clickCB(source,false,null);
- TreeWidgetElem_UpdateTooltip(source,true);
- }
- //else if ((source==_codeWinName+"trLstElt"+id)&&(treeView.doubleClickCB))
- else if ((source==id)&&(treeView.doubleClickCB))
- treeView.doubleClickCB(elem.userData);
- }
- if((k==10) && ctrl &&(source==_codeWinName+"trLstElt"+id))
- {
- if(elem.sub.length>0)
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
-
- if (elem.isIncomplete&&elem.querycompleteCB)
- {
- elem.querycompleteCB()
- TreeWidgetElem_UpdateTooltip(source);
- }
-
- return false
- }
- }
- else //no selection in tree view
- {
- //var source =_ie?_curWin.event.srcElement.id:e.target.id
- var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
- var k=eventGetKey(e);
- if( k==13 )
- {
- TreeWidget_clickCB(source,false,null);
- TreeWidgetElem_UpdateTooltip(source,true);
- }
- }
- }
- // ================================================================================
- function TreeWidget_multiSelKeyPress(o,e)
- {
- //multi selection treeview
- var treeView = getWidget(o);
- var len = treeView.selIds.length;
- if (len>0) //already has selection
- {
- //var source =_ie?_curWin.event.srcElement.id:e.target.id
- var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
- var k=eventGetKey(e) , ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey
-
- //find the source in the selected items
- var elem = null;
- for(var i=0; i<len;i++)
- {
- var id = treeView.selIds[i];
- //if (source==_codeWinName+"trLstElt"+id)
- if (source==id)
- {
- elem = _TreeWidgetElemInstances[id];
- break;
- }
- }
- //IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //doubleClickCB will only send userData of the elem where the action is performed
- //code must be added by the user in the doubleClickCB to manage the action for all the selected items
- //please refer to sample treeview.html for more details
- if( k==13 )//enter
- {
- //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,null);
- if(elem == null)
- {
- //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,_ie?_curWin.event:e);
- TreeWidget_clickCB(source,false,_ie?_curWin.event:e);
- TreeWidgetElem_UpdateTooltip(source,true);
- }
- else if (elem &&(treeView.doubleClickCB))
- treeView.doubleClickCB(elem.userData);
- }
- if((k==10) && ctrl && elem) //ctrl+enter
- {
- if(elem.sub.length>0)
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
-
- if (elem.isIncomplete&&elem.querycompleteCB)
- {
- elem.querycompleteCB()
- TreeWidgetElem_UpdateTooltip(source);
- }
-
- return false
- }
- }
- else //no selection in tree view
- {
- //var source =_ie?_curWin.event.srcElement.id:e.target.id
- var source =TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
- var k=eventGetKey(e);
- if( k==13 )
- {
- //TreeWidget_clickCB(source.slice(8+_codeWinName.length),false,null);
- TreeWidget_clickCB(source,false,null);
- TreeWidgetElem_UpdateTooltip(source,true);
- }
- }
- return true;
- }
- // ================================================================================
- t=0
- function TreeWidget_keyDownCB(lay,e)
- // Internal key down event callback
- // Internal Note: Do not forget to fix a bug in single and multi selection functions.
- {
-
- //multi selection treeview
- if(getWidget(lay).multiSelection)
- {
- return TreeWidget_multiSelKeyDown(lay,e);
- }
-
- //mono selection treeview
- var id=getWidget(lay).selId;
- var k=eventGetKey(e);
- if (id>=0)
- {
- var elem=_TreeWidgetElemInstances[id]
- if (elem!=null)
- {
- var treeView=elem.treeView
- //var source=_ie?_curWin.event.srcElement.id:e.target.id;
- var source=TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
- switch(k)
- {
- case 107:
- case 39:
- if ((elem.sub.length>0)&&(!elem.expanded))
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
- if (elem.isIncomplete&&elem.querycompleteCB)
- {
- elem.querycompleteCB()
- TreeWidgetElem_UpdateTooltip(source);
- }
- break;
- case 109:
- case 37:
- if ((elem.sub.length>0)&&(elem.expanded))
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
- break;
- case 40:
- case 38:
- var nElt=elem.getNextPrev(k==40?1:-1);if (nElt!=null){nElt.select(null,null,null,true);safeSetFocus(nElt.domElem)}
- return false
- break;
- case 46: //remove
- if(treeView.deleteCB)
- treeView.deleteCB(elem.userData)
- break;
- default:
- //key is alpha numerique, select the first occurence that starts with this character from the current position
- var c = String.fromCharCode(k);
- if(c)//text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
- {
- treeView.search(c,false,false,null,true,null,true,true,true);
- }
- break
- }
- }
- }
- //To implement default action in dialog box with the key Enter
- //we should cancel the bubble for treeview because Enter should not execute
- //the default action in dialog box when it is done on a treview item.
- if(k == 13)
- {
- eventCancelBubble(e);
- }
- }
- // ================================================================================
- function TreeWidget_multiSelKeyDown(o,e)
- {
- //multi selection treeview
- var treeView = getWidget(o);
- var len = treeView.selIds.length;
- var k=eventGetKey(e);
- if (len>0) //already has selection
- {
- var ctrl=_ie?_curWin.event.ctrlKey:e.ctrlKey;
- var shift=_ie?_curWin.event.shiftKey:e.shiftKey;
- //var source=_ie?_curWin.event.srcElement.id:e.target.id;
- var source=TreeIdToIdx(_ie?_curWin.event.srcElement:e.target)
-
- //find the source in the selected items
- var elem = null, id;
-
- for(var i=0; i<len;i++)
- {
- id = treeView.selIds[i];
- //if (source==_codeWinName+"trLstElt"+id)
- if (source==id)
- {
- elem = _TreeWidgetElemInstances[id];
- break;
- }
- }
- if(elem)
- {
- switch(k)
- {
- case 107: //+ ou ->
- case 39:
- //no change for multi selection
- if ((elem.sub.length>0)&&(!elem.expanded))
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
- if (elem.isIncomplete&&elem.querycompleteCB)
- {
- elem.querycompleteCB()
- TreeWidgetElem_UpdateTooltip(source);
- }
- break;
- case 109: //- ou <-
- case 37:
- //no change for multi selection
- if ((elem.sub.length>0)&&(elem.expanded))
- {
- TreeWidget_toggleCB(id);
- TreeWidgetElem_UpdateTooltip(source);
- }
- break;
- case 40: //up or down arrow
- case 38:
- //var nElt=elem.getNextPrev(k==40?1:-1);if (nElt!=null){nElt.select(null,null,null,true);safeSetFocus(nElt.domElem)} return false;
- var nElt=elem.getNextPrev(k==40?1:-1);
- if (nElt!=null)
- {
- nElt.select(null,_ie?_curWin.event:e,null,true);
- safeSetFocus(nElt.domElem)
- }
- return false
- break;
- case 46: //remove
- //IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //deleteCB will only send userData of the elem where the action is performed
- //code must be added by the user in the deleteCB to manage the action for all the selected items
- //please refer to sample treeview.html for more details
- if(treeView.deleteCB)
- treeView.deleteCB(elem.userData)
- break;
-
- default:
- //key is alpha numerique, select the first occurence that starts with this character from the current position
- var c = String.fromCharCode(k);
- if(c)//text,matchCase,matchWholeW,startFrom,next,notFoundCB,starWith,visible,setFocus)
- {
- treeView.search(c,false,false,null,true,null,true,true,true);
- }
- break
- }
- }
- }
- //To implement default action in dialog box with the key Enter
- //we should cancel the bubble for treeview because Enter should not execute
- //the default action in dialog box when it is done on a treview item.
- if(k == 13)
- {
- eventCancelBubble(e);
- }
- }
- // ================================================================================
- function TreeWidget_setDragDrop(dragCB,acceptDropCB,dropCB,dragEndCB)
- // Add drag & drop behaviour to the tree view
- // dragCB (source) : triggered when beginning D&D
- // acceptDropCB (source, target, ctrl, shift) : return boolean if D&D is accepted
- // dropCB (source, target,ctrl, shift) : triggered when ending D&D
- {
- this.dragCB=dragCB
- this.acceptDropCB=acceptDropCB
- this.dropCB=dropCB
- this.dragEndCB=dragEndCB
- this.dragDrop=newDragDropData(this,TreeWidget_dragStartCB,TreeWidget_dragCB,TreeWidget_dragEndCB,TreeWidget_acceptDropCB,TreeWidget_leaveDropCB,TreeWidget_dropCB)
- }
- // ================================================================================
- function TreeWidget_dragStartCB(src)
- // Internal
- // src : widget that started the drag&drop action
- {
- //var item=src.getSelectedItem(),vert=src.iconOrientVertical
- var items=src.getSelections(),vert=src.iconOrientVertical
- src.dragCB(src)
- if (items && items.length==1 )
- {
- var item=items[0]; //display the tooltip of one selection
- var idx=item.iconId
- newTooltipWidget().show
- (
- true,
- item.getDragTooltip(),//item.name,
- idx>=0?src.icns:null,
- src.iconW,
- src.iconH,
- vert?0:src.iconW*idx,
- vert?src.iconH*idx:0
- )
- }
- }
- // ================================================================================
- //this function must be called before the construction of HTML
- function TreeWidget_setRightClickMenuCB(rightClickMenuCB)
- {
- this.rightClickMenuCB=rightClickMenuCB
- }
- // ================================================================================
- // ================================================================================
- function TreeWidget_getCount()
- {
- var o=this
- if (o.sub != null)
- return o.sub.length
- else
- return 0;
- }
- // ================================================================================
- //this function must be called before the construction of HTML
- function TreeWidget_setTooltipOnMouseOver(catchMouseOver)
- {
- this.mouseOverTooltip=catchMouseOver
- }
- // ================================================================================
- function TreeWidget_setMouseOverCB(mouseOverCB)
- {
- this.mouseOverCB=mouseOverCB
- }
- // ================================================================================
- function TreeWidget_dragCB(src)
- {
- newTooltipWidget().setPos();
- }
- // ================================================================================
- function TreeWidget_dragEndCB(src) {
- newTooltipWidget().show(false);
- if (src.dragEndCB) src.dragEndCB()
- }
- // added for inside tree D&D
- function TreeWidget_dragOverEnterCB(lyr,elemId)
- {
- var e=_TreeWidgetElemInstances[elemId]
- if (lyr.ondrop==null) // layer
- {
- e.treeView.dragDrop.attachCallbacks(lyr,true)
- lyr.domEltID=elemId
- }
- var o=_ddData[lyr._dragDropData],e=_curWin.event
- e.dataTransfer.dropEffect=e.ctrlKey?'copy':'move'
-
- if (o.acceptDropCB(window._globalDDD,o.widget,e.ctrlKey,e.ctrlKey?false:e.shiftKey,lyr,false))
- e.returnValue=false
- e.cancelBubble=true
- }
- // ================================================================================
- function TreeWidget_acceptDropCB(src,target,ctrl,shift,layer)
- {
- return target.acceptDropCB(src,target,ctrl,shift,layer)// the callback defined by the client
- }
- // ================================================================================
- function TreeWidget_leaveDropCB(src,target,ctrl,shift)
- {
-
- if (target.dropWidget && target.dropWidget.layer) {
- //window.status="leave: " + target.dropWidget.layer.id
- if (target.dropWidget.layer.className != target.dropWidget.nonselectedClass) {
- target.dropWidget.layer.className = target.dropWidget.nonselectedClass
- }
- //target.dropWidget = null
- }
-
- }
- // ================================================================================
- function TreeWidget_dropCB(src,target,ctrl,shift,layer,enter)
- {
- newTooltipWidget().show(false);
-
- // added for inside tree D&D
- //target.dropWidget=_TreeWidgetElemInstances[layer.domEltID]
-
- //target.dropWidget.layer.className = target.dropWidget.nonselectedClass
- //
- target.dropCB(src,target,ctrl,shift);
- }
- // ================================================================================
- //set multi selection in treeview
- function TreeWidget_setMultiSelection(multi)
- {
- //clean the selection structure before start new selection mode
- if((!this.multiSelection && multi)||(this.multiSelection && !multi))
- this.unselect();
-
- //set selection mode
- this.multiSelection = multi;
- }
- // ================================================================================
- function TreeWidget_getSelectedItems()
- // deprecated use getSelections()
- // Get the selected items
- // Returns an array of [TreeWidgetElem] selected (empty if no selection)
- {
- var arrSel=new Array;
- var len = this.selIds.length, id, cpt=0;
- for(var i=0; i< len; i++)
- {
- id = this.selIds[i];
- if(id>=0)
- {
- arrSel[cpt]=_TreeWidgetElemInstances[id];
- cpt++;
- }
- //arrSel[i]= (id>=0)?_TreeWidgetElemInstances[id]:null;
- }
- return arrSel;
- }
- // ================================================================================
- function TreeWidget_getCheckedItems()
- // Get the checked items
- // Returns an array of [TreeWidgetElem] selected (empty if no selection)
- {
- var arrChecked=new Array;
- var len = _TreeWidgetElemInstances.length, cpt=0;
- for (var i=0; i < len; i++)
- {
- elem = _TreeWidgetElemInstances[i]
- if (elem.isChecked())
- {
- arrChecked[cpt]=elem;
- cpt++;
- }
- }
- return arrChecked;
- }
- // ================================================================================
- //set highlight path parameter in treeview
- function TreeWidget_setHighlightPath(hl)
- {
- this.hlPath=hl;
- if(!hl)
- this.unhlPath();
- }
- // ================================================================================
- function TreeWidget_unhlPath()
- {
- var o=this, len = o.hlElems.length;
- var elem, de;
- if(len>0)//unhighlight previous elems
- {
- for(var i=0;i<len;i++)
- {
- elem = o.hlElems[i];
- elem.init();
- de =elem.domElem;
-
- if( de == null) return;//safe test
-
- if(elem.isSelected())
- de.className=elem.selectedClass;
- else
- de.className=elem.nonselectedClass;
- }
- o.hlElems.length=0;
- }
- }
- //highlight path of the selected item
- function TreeWidget_highlightPath(elemId)
- {
- var o=this;
-
- if(!o.hlPath) return ; //safe test
-
- o.unhlPath();
-
- var elem = _TreeWidgetElemInstances[elemId];
-
- //highlight and select item
- o.hlElems[o.hlElems.length]=elem;
- elem.domElem.className=elem.selectedClass;
-
- if(elem.elemPos == -1) o.buildElems();
-
- //highlight parents
- var papa = elem.par;
- while(papa)
- {
- papa.init();
- papa.domElem.className=papa.hlClass;
- o.hlElems[o.hlElems.length]=papa;
- papa = papa.par;
- }
-
- //highlight children
- if(elem.isNode())
- hlVisibleChildren(elem,o.hlElems);
- }
- function hlVisibleChildren(node,arr)
- {
- if(node.expanded && !node.isIncomplete)
- {
- var len = node.sub.length;
- for(var i=0;i<len;i++)
- {
- var sub = node.sub[i];
- arr[arr.length]=sub;
- sub.init();
- sub.domElem.className=sub.hlClass;
- if(sub.isNode())
- hlVisibleChildren(sub,arr);
- }
- }
- }
- // ================================================================================
- // ================================================================================
- //
- // OBJECT newTreeWidgetElem (Constructor)
- //
- // Tree view element class
- //
- // ================================================================================
- // ================================================================================
- function newTreeWidgetElem(iconId,name,userData,help,iconSelId,tooltip,iconAlt,textClass,textSelectedClass)
- // CONSTRUCTOR
- // iconId [int] the index of the icon in the combined image, -1 if no icon
- // name [String] name of the elem
- // userData [Optional]user data
- // help [Optional]help of the elem (tooltip ???)
- // iconSelId [int Optional] the index of the icon in the combined image when elem is selected
- // tooltip [Optional]tooltip of the elem
- // iconAlt [Optional]tooltip of icon
- // Return [newTreeWidgetElem] the instance
- // to not encode the elemen content, set isHTML to true
- {
- var o=new Object
- // Data
- o.elemPos=-1
- if (window._TreeWidgetElemInstances==null)
- window._TreeWidgetElemInstances=new Array
- o.expanded=false
- o.generated=false
- o.iconId=iconId
- o.iconSelId=iconSelId?iconSelId:iconId
- o.tooltip=tooltip
- o.customTooltip=false
- o.iconAlt=iconAlt
- o.isHTML=false
- // Check box
- o.isCheck=false
- o.checked=false
- o.check=TreeWidgetElem_check
- o.isChecked=TreeWidgetElem_isChecked
- o.checkCB=null
-
- o.name=name
- o.par=null
- o.userData=userData
- o.sub=new Array
- o.treeView=null
- o.id=_TreeWidgetElemInstances.length
- // Layers
- o.layer=null
- o.plusLyr=null
- o.icnLyr=null
- o.checkElem=null
- o.domElem=null
- o.toggleLyr=null
- o.blackTxt=(textClass)?textClass:'treeNormal'
- o.grayTxt='treeGray'
- o.selectedClass=(textSelectedClass)?textSelectedClass:'treeSelected'
- o.nonselectedClass=o.blackTxt
- o.feedbackDDClass='treeFeedbackDD'
-
- o.hlClass='treeHL' //hl=highlight
-
- o.help=help
- _TreeWidgetElemInstances[o.id]=o
- // Methods
- o.getHTML=TreeWidgetElem_getHTML
- o.init=TreeWidgetElem_init
- o.add=TreeWidgetElem_add;
- o.select=TreeWidgetElem_select
- o.unselect=TreeWidgetElem_unselect
- o.getNextPrev=TreeWidgetElem_getNextPrev
- o.getHiddenParent=TreeWidgetElem_getHiddenParent
- o.nodeIndent=0
- o.getTooltip=TreeWidgetElem_getTooltip
- o.getDragTooltip=TreeWidgetElem_getDragTooltip
- o.change=TreeWidgetElem_change
- o.deleteAll=TreeWidget_deleteAll
-
- o.setGrayStyle=TreeWidgetElem_setGrayStyle
- o.isGrayStyle=TreeWidgetElem_isGrayStyle
- o.findByData=TreeWidgetElem_findByData
- o.findById=TreeWidgetElem_findById
- o.findInName=TreeWidgetElem_findInName
- o.isIncomplete=false
- o.querycompleteCB=null
- o.setIncomplete=TreeWidgetElem_setIncomplete
- o.finishComplete=TreeWidgetElem_finishComplete
-
- o.setEditable=TreeWidgetElem_setEditable
- o.showEditInput=TreeWidgetElem_showEditInput
-
- o.isLeaf=TreeWidgetElem_isLeaf
- o.isNode=TreeWidgetElem_isNode
- o.isSelected=TreeWidgetElem_isSelected
- o.htmlWritten=false
-
- o.showCustomTooltipCB=null
- o.hideCustomTooltipCB=null
-
- return o
- }
- // ================================================================================
- function TreeWidgetElem_checkCB(elem, id)
- // PRIVATE
- {
- var o=_TreeWidgetElemInstances[id]
- o.checked=elem.checked
-
- if (o.checkCB)
- o.checkCB(o, id)
- }
- // ================================================================================
- function TreeWidgetElem_isChecked()
- // Test is the element is checked (works if the TreeWidgetElem is a checkbox)
- // Return boolean
- {
- var o=this
- return (o.isCheck ? o.checked : false)
- }
- // ================================================================================
- function TreeWidgetElem_check(checked)
- // check or uncheck the element (works if the TreeWidgetElem is a checkbox)
- // checked [boolean - Mandatory]
- {
- var o=this
- if (o.isCheck)
- {
- o.checked = checked
-
- if (o.htmlWritten)
- {
- o.init()
- o.checkElem.checked = checked
- }
- }
- }
- // ================================================================================
- function TreeWidgetElem_EditNormalBehaviour(e)
- // PRIVATE
- {
- eventCancelBubble(e)
- return true
- }
- // ================================================================================
- function TreeWidgetElem_EditBlurCB()
- // PRIVATE
- {
- setTimeout("TreeWidgetElem_EditKeyCancel("+this.widID+")",1)
- }
- // ================================================================================
- _globTreeTxtvalue=""
- function TreeWidgetElem_EditKeyDown(e)
- // PRIVATE
- {
- eventCancelBubble(e); //do not fire the event in TreeWidgetElem
-
- var k=eventGetKey(e),o=_TreeWidgetElemInstances[this.widID]
- if (k==27) // Escape
- {
- setTimeout("TreeWidgetElem_EditKeyCancel("+this.widID+")",1)
- }
- else if (k==13) // Enter
- {
- _globTreeTxtvalue=this.value
- setTimeout("TreeWidgetElem_EditKeyAccept("+this.widID+")",1)
- }
- }
- // ================================================================================
- function TreeWidgetElem_EditKeyCancel(id)
- // PRIVATE
- {
- var o=_TreeWidgetElemInstances[id]
- o.showEditInput(false)
- }
- // ================================================================================
- function TreeWidgetElem_EditKeyAccept(id)
- // PRIVATE
- {
- var o=_TreeWidgetElemInstances[id]
- if (o.validChangeNameCB)
- {
- if (o.validChangeNameCB(_globTreeTxtvalue)==false)
- return
- }
-
- o.change(null,_globTreeTxtvalue)
- o.showEditInput(false)
- if (o.changeNameCB)
- o.changeNameCB()
- }
- // ================================================================================
- _globTreeTxt=null
- function TreeWidgetElem_showEditInput(show)
- {
- var o=this
-
- o.init()
-
- var lyr=o.domElem,css=lyr.style
-
- if (show&&(css.display!="none"))
- {
- var par=lyr.parentNode,w=lyr.offsetWidth,h=lyr.offsetHeight
- css.display="none"
-
- var tl=_globTreeTxt=_curDoc.createElement("INPUT");
- tl.type="text"
- tl.className="textinputs"
- tl.value=o.name
- tl.ondragstart=TreeWidgetElem_EditNormalBehaviour
- tl.onselectstart=TreeWidgetElem_EditNormalBehaviour
- tl.onblur=TreeWidgetElem_EditBlurCB
- tl.onkeydown=TreeWidgetElem_EditKeyDown
-
- tl.widID=o.id
-
- var tc=tl.style
- tc.width=""+(w+20)+"px"
-
- par.appendChild(tl);
- tl.focus()
- tl.select()
- }
- if ((show!=true)&&(css.display=="none"))
- {
- var tl=_globTreeTxt
- if (tl)
- {
- tl.parentNode.removeChild(tl)
- css.display=""
- _globTreeTxt=null
- }
- }
- }
- // ================================================================================
- function TreeWidgetElem_setEditable(isEditable, changeNameCB,validChangeNameCB)
- // Set the elem editable (i.e. the name can be changed)
- // changeNameCB [function optional]: callback when the name is changed
- // validChangeNameCB [function optional] : callback called before text is chaged. Returns a boolean
- // if true, the changes are accepted
- {
- var o=this
-
- if (isEditable)
- {
- o.changeNameCB=changeNameCB
- o.validChangeNameCB=validChangeNameCB
- }
- o.isEditable=isEditable
- }
- // ================================================================================
- function TreeWidgetElem_triggerDD()
- {
- var o=_treeWClickedW,e=_curWin.event
- if (o&&(o.clicked)&&(e.button==_leftBtn))
- {
- if (o.initialX!=null)
- {
- var x=eventGetX(e),y=eventGetY(e),threshold=3
-
- if ((x<(o.initialX-threshold))||(x>(o.initialX+threshold))||(y<(o.initialY-threshold))||(y>(o.initialY+threshold)))
- {
- this.dragDrop()
- o.clicked=false
- }
- }
- }
- }
- // ================================================================================
- function TreeWidgetElem_mouseUp()
- {
- var o=_treeWClickedW,ev=_curWin.event
-
- o.select(null,ev)
- o.domElem.onmouseup=null
- }
- // ================================================================================
- function TreeWidgetElem_init()
- {
- var o=this
- if (o.layer==null)
- {
- var sub=o.sub,len=sub.length,exp=(len>0)||o.isIncomplete
- // Init Widgets
- o.layer=getLayer(_codeWinName+"TWe_"+o.id);
- if (o.layer==null)
- return;
- var cNodes=o.layer.childNodes,cLen=cNodes.length
-
- o.plusLyr=exp?cNodes[0].childNodes[1]:null
- o.icnLyr=(o.iconId>-1)?cNodes[exp?1:0]:null
- o.checkElem=o.isCheck?cNodes[cLen-2]:null
- o.domElem=cNodes[cLen-1]
- o.toggleLyr=getLayer(_codeWinName+"trTog"+o.id)
-
- // Init Callbacks
- if(o.treeView.mouseOverTooltip||o.treeView.mouseOverCB)
- o.domElem.onmouseout=TreeFuncMouseout
- if (exp)
- {
- addDblClickCB(o.plusLyr,_tpdb)
- }
-
- if (exp&&o.generated)
- {
- for (var i in sub)
- sub[i].init()
- }
- addDblClickCB(o.domElem,_tpdb)
- }
- }
- // ================================================================================
- function TreeIdToIdx(l)
- {
- if (l)
- {
- var id=l.id
- if (id)
- {
- var idx=id.lastIndexOf("TWe_")
- if (idx>=0)
- return parseInt(id.slice(idx+4))
- else
- return -1
- }
- else
- return TreeIdToIdx(l.parentNode)
- }
- return -1
- }
- function TreeFuncMouseout(e)
- {
- _tmoc(this,TreeIdToIdx(this),false,e)
- }
- function _tmvc(l,ev)
- {
- _tmoc(l,TreeIdToIdx(l),true,ev)
- }
- function _tpl(l,event)
- // PRIVATE
- // Single click on the +/- icon
- {
- TreeWidget_clickCB(TreeIdToIdx(l),true,event,true);
- return false
- }
- function _tkl(l,event)
- //PRIVATE
- // Enter key on the +/- icon
- {
- var k = eventGetKey(event);
- if(k == 13) {
- return _tpl(l,event);
- }
- }
- function _tkt(l,event)
- // PRIVATE
- // Enter key on text
- {
- var k = eventGetKey(event);
- if(k == 13) {
- return _tpt(l,event);
- }
- }
- function _tpt(l,event)
- // PRIVATE
- // Single click on text
- {
- TreeWidget_clickCB(TreeIdToIdx(l),false,event,true);
- return false
- }
- function _tpdb(e)
- // PRIVATE
- // Double click on the +/- icon
- {
- treeDblClickCB(TreeIdToIdx(this),_ie?event:e)
- return false
- }
- function _tfcc(l,e)
- {
- treeFCCB(l,TreeIdToIdx(l),true,e)
- l.onblur=_tblc
- }
- function _tblc(e)
- {
- treeFCCB(this,TreeIdToIdx(this),false,e)
- }
- // ================================================================================
- function TreeWidgetElem_getHTML(indent,isFirst)
- // Get the tree element HTML
- // indent [int] : element indentation in pixels
- // returns [String] the HTML
- {
- var s='';
- with (this)
- {
- htmlWritten=true,isRoot=(par==null)
- var len=sub.length,exp=(len>0)||isIncomplete,a=new Array,i=0
- if (this.extraIndent)
- indent+=_trIndent*extraIndent
- var keyCB = 'onkeydown=" return ' + _codeWinName+'._tkt(this,event)" ';
- var mouseCB='onfocus="'+_codeWinName+'._tfcc(this,event)" onclick="return '+_codeWinName+'._tpt(this,event)" '
- if(treeView.mouseOverTooltip || treeView.mouseOverCB)
- mouseCB+='onmouseover="'+_codeWinName+'._tmvc(this,event)" '
-
- var contextMenu=''
- if (treeView.rightClickMenuCB != null)
- {
- contextMenu= ' oncontextmenu="' + _codeWinName + '.treeContextMenuCB(\''+ id + '\', event);return false" '
- }
-
-
- var acceptDD=''
- if ((treeView.acceptDropCB != null) && (_ie))
- {
- acceptDD= ' ondragenter="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
- acceptDD += ' ondragover="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
- }
-
- // begin container
- a[i++]='<div id="'+_codeWinName+'TWe_'+id+'"'+contextMenu+' class=trElt>'
- var onkeydown='onkeydown="return '+_codeWinName+'._tkl(this,event)" ';
- var onclick='onclick="return '+_codeWinName+'._tpl(this,event)" ';
-
- if (exp)
- {
- var expIcon;
- var iconTooltip;
- if(expanded)
- {
- if(treeView.minIcon != null)
- expIcon = treeView.minIcon;
- else
- expIcon = _skin+'../min.gif';
- iconTooltip = _collapseNode.replace('%1', name);
- }
- else
- {
- if(treeView.plusIcon != null)
- expIcon = treeView.plusIcon;
- else
- expIcon = _skin+'../plus.gif';
- iconTooltip = _expandNode.replace('%1', name);
- }
- a[i++]='<a tabindex=1 '+ onclick + ' ' + onkeydown +' href="javascript:doNothing();"><span style="display:none">' + iconTooltip + '</span><img class=trPlus src="'+expIcon+'"/></a>'
- }
-
- if (iconId>-1)
- 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))+'" >'
- else if (!exp&&!isRoot)
- a[i++]='<img tabindex=1 class=trSep '+attr('src', _skin+'../transp.gif')+'>'
- if (isCheck)
- a[i++]='<input type=checkbox style="margin:0px;" onclick="'+_codeWinName+'.TreeWidgetElem_checkCB(this,\''+id+'\')"'+(this.checked?' checked':'')+'>'
- a[i++]='<a href="javascript:doNothing();" '+mouseCB+ ' ' + keyCB + ' tabindex=1 '+acceptDD+' class='+nonselectedClass+'>'
- a[i++]=(isHTML?name:convStr(name))
- a[i++]='</a>'
- a[i++]='</div>'
-
-
-
- // end container
-
-
- /*
- a[i++]='<nobr>'
-
- // Icon
- 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 + '>'
- a[i++]=(exp?imgOffset(_skin+'../tree.gif',13,12,expanded?0:13,0,null,null,expanded?_expandedLab:_collapsedLab,mrg,'top'):'')
- 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'):'')
- a[i++]='</span>'
- // Text
- a[i++]=((!exp && iconId==-1)?img(_skin+'../transp.gif',indent+13,1) :'')
-
- // Check box related
- if (isCheck)
- {
- a[i++]='<input onclick="'+_codeWinName+'.TreeWidgetElem_checkCB(this,\''+id+'\')" style="margin:0px;'+(_ie?'':'margin-left:2px')+'" type="checkbox" id="chk'+id+ '"' +(this.checked?' checked':'')+'>'
- }
- a[i++]='<a style="height:'+(iconId>-1?16:14)+'px;padding-top:0px;padding-bottom:0px;"
- id="'+_codeWinName+'trLstElt'+id+'" class="'+nonselectedClass+ '" ' + acceptDD + ' href="javascript:void(0)"
- onclick="eventCancelBubble(event);return false" onmousedown="'+_codeWinName+'.TreeWidget_clickCB('+id+',false,event,true);return false"
- ondblclick="'+_codeWinName+'.treeDblClickCB('+id+',event);return false"
- onfocus="'+_codeWinName+'.treeFCCB(this,'+id+',true)"
- onblur="'+_codeWinName+'.treeFCCB(this,'+id+',false)" '+ mouseCB + contextMenu + '>'
- a[i++]=(isHTML?name:convStr(name))
- a[i++]='</a>'
- // End container
- a[i++]='</nobr><br>'
- */
- // Sub tree container
- //if (exp) a[i++]='<span id="'+_codeWinName+'trTog'+id+'" style="display:'+(expanded?'':'none')+'">'
-
- if (exp) a[i++]='<div id="'+_codeWinName+'trTog'+id+'" style="margin-left:18px;display:'+(expanded?'':'none')+'">'
- // Generate child HTML if needed
- if (expanded)
- {
- generated=true
- //var idt=indent+_trIndent
- //for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(idt,j==0);
- for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(0,j==0);
- }
- if (exp)
- {
- nodeIndent=indent
- a[i++]="</div>"
- }
- }
- return a.join("");
- }
- // ================================================================================
- function TreeWidgetElem_setGrayStyle(isGray)
- {
- var o=this,cls=isGray?o.grayTxt:o.blackTxt
- if (cls!=o.nonselectedClass)
- {
- o.nonselectedClass=cls
-
- o.init()
- if (o.domElem&&(o.domElem.className!=o.selectedClass))
- o.domElem.className=cls
- }
- }
- // ================================================================================
- function TreeWidgetElem_isGrayStyle()
- {
- return this.nonselectedClass==this.grayTxt
- }
- // ================================================================================
- function TreeWidgetElem_setIncomplete(querycompleteCB)
- {
- this.isIncomplete=true
- this.querycompleteCB=querycompleteCB
- }
- // ================================================================================
- function TreeWidgetElem_finishComplete()
- {
- this.isIncomplete=false
- TreeWidget_toggleCB(this.id)
- this.treeView.buildElems()
- }
- // ================================================================================
- function TreeWidgetElem_findByData(data)
- {
- var o=this
- if (o.userData==data)
- return o
- var sub=o.sub
- for (var i in sub)
- {
- var item=sub[i].findByData(data)
- if (item!=null)
- return item
- }
- return null
- }
- // ================================================================================
- function TreeWidgetElem_findInName(text,matchCase,matchWholeW,next,starWith)
- {
- var o=this, name=o.name
-
- if(text=="" || text==null) return; //safe test
-
- if(!matchCase || (matchCase == null))//ignore case
- {
- name=name.toLowerCase();
- text=text.toLowerCase();
- }
- if(matchWholeW)//match word
- {
- var arrWords = name.split(" ");//to improve later
- for(var i = 0; i<arrWords.length; i++)
- {
- if(arrWords[i] == text)
- return o;
- }
- }
- else
- {
- var idx = name.indexOf(text); // search occurence
- if (starWith == true )
- {
- if(idx == 0) return o;
- }
- else
- {
- if(idx>-1) return o;
- }
- }
-
- return null
- }
- // ================================================================================
- function TreeWidgetElem_findById(id)
- {
- var o=this
- if (o.id==id)
- return o
- var sub=o.sub
- for (var i in sub)
- {
- var item=sub[i].findById(id)
- if (item!=null)
- return item
- }
- return null
- }
- // ================================================================================
- function TreeWidgetElem_change(iconId, name, userData, help,iconSelId,tooltip)
- {
- var o=this,treeView=o.treeView
- if (iconId!=null) o.iconId=iconId
- if (name!=null) o.name=name
- o.userData=userData
- if (help!=null) o.help=help
- o.iconSelId=(iconSelId!=null)?iconSelId:o.iconId
- if (tooltip!=null) o.tooltip=tooltip
- o.init()
- if (o.domElem)
- o.domElem.innerHTML=convStr(o.name)
- if (o.icnLyr)
- {
- if(o.icnLyr.childNodes.length>0)
- {
- var iconL=o.icnLyr.childNodes[o.sub.length>0?1:0]
- changeOffset(iconL,
- treeView.iconOrientVertical?0:o.treeView.iconW*(o.expanded?o.iconSelId:o.iconId),
- treeView.iconOrientVertical?o.treeView.iconH*(o.expanded?o.iconSelId:o.iconId):0)
- }
- }
- }
- // ================================================================================
- // added for inside tree D&D
- function treeInitDropFunc(lyr,elemId)
- {
- var e=_TreeWidgetElemInstances[elemId]
-
- if (lyr.ondrop==null) // lyr
- {
- e.treeView.dragDrop.attachCallbacks(lyr,true)
- lyr.domEltID=elemId
- }
- }
- // ================================================================================
- function TreeWidget_toggleCB(elemId,noTimeOut)
- // Expand or collapse a tree element children
- // Returns [void]
- {
- var elem=_TreeWidgetElemInstances[elemId]
-
- // if no children the + disappear
- if (elem.sub.length==0) {
- elem.plusLyr.style.visibility='hidden'
- return
- }
- elem.expanded=!elem.expanded
- elem.init()
- if (noTimeOut) {
- dispIcn(elemId);
- } else {
- setTimeout(elem.treeView.dispIcnFuncName+'('+elemId+')',1)
- }
-
- var tree=elem.treeView
- if (elem.expanded&&tree.expandCB)
- tree.expandCB(elem.userData)
- if (!elem.expanded&&tree.collapseCB)
- tree.collapseCB(elem.userData)
- }
- // ================================================================================
- function dispIcn(eId)
- {
- var e=_TreeWidgetElemInstances[eId]
- with (e)
- {
- if (expanded&&!generated)
- {
- generated=true;
- var a=new Array,i=0,len=sub.length,newInd=nodeIndent+_trIndent
- for (var j=0;j<len;j++) a[i++]=sub[j].getHTML(newInd,j==0);
- toggleLyr.innerHTML=a.join('');
- }
- toggleLyr.style.display=expanded?'block':'none'
- if(expanded)
- {
- if(treeView.minIcon != null)
- plusLyr.src = treeView.minIcon;
- else
- plusLyr.src = _skin+'../min.gif';
- }
- else
- {
- if(treeView.plusIcon != null)
- plusLyr.src = treeView.plusIcon;
- else
- plusLyr.src = _skin+'../plus.gif';
- }
- plusLyr.title=expanded?_expandedLab:_collapsedLab
-
- if(icnLyr&&icnLyr.childNodes&&icnLyr.childNodes.length>1)
- {
- var iconL=icnLyr.childNodes[1]
- changeOffset(iconL,
- treeView.iconOrientVertical?0:treeView.iconW*(expanded?iconSelId:iconId),
- treeView.iconOrientVertical?treeView.iconH*(expanded?iconSelId:iconId):0)
- }
- }
- }
- // ================================================================================
- function TreeWidgetElem_add(elem)
- {
- with (this)
- {
- elem.treeView=treeView;
- elem.par=this;
- sub[sub.length]=elem;
- }
- return elem
- }
- // ================================================================================
- function TreeWidgetElem_getHiddenParent()
- {
- var par=this.par
- if (par==null) return null
- if (!par.expanded)
- return par
- return
- par.getHiddenParent()
- }
- // ================================================================================
- function TreeWidgetElem_getNextPrev(delta)
- {
- with (this)
- {
- if (elemPos==-1) treeView.buildElems()
- var newPos=elemPos+delta
- if ((newPos>=0)&&(newPos<treeView.elems.length))
- {
- var ret=treeView.elems[newPos]
- var hidden=ret.getHiddenParent()
- if (hidden!=null) return ret.getNextPrev(delta)
- else return ret
- }
- else return null;
- }
- }
- // ================================================================================
- function TreeWidgetElem_scroll(elemLyr,treeLyr)
- {
- var scrollH = Math.max(0,treeLyr.offsetHeight-20), scrollY = treeLyr.scrollTop
- var elPos = getPos(elemLyr,treeLyr)
- var y = elPos.offsetTop, h = elemLyr.offsetHeight
-
- if ((y-scrollY+h) > scrollH ) {
- treeLyr.scrollTop=y+h-scrollH
- }
- if ((y-scrollY) < 0) {
- treeLyr.scrollTop= y
- }
- }
- // ================================================================================
- function TreeWidgetElem_unselect()
- {
- var o=this
- with(o)
- {
- init()
- if (domElem) {
- domElem.className=o.nonselectedClass
- }
- treeView.selId=-1
-
- if(treeView.multiSelection)
- {
- var idx = arrayFind(treeView,'selIds',id)
- if(idx>-1)
- {
- //update array selIds
- arrayRemove(treeView,'selIds',idx);
-
- //update _BOselIds
- treeView.layer._BOselIds=""
- var len = treeView.selIds.length;
- for(var i=0;i<len;i++)
- {
- if(treeView.layer._BOselIds == "")
- treeView.layer._BOselIds=""+treeView.selIds[i];
- else
- treeView.layer._BOselIds+=";"+treeView.selIds[i];
- }
- }
- }
- }
- }
- // ================================================================================
- function TreeWidgetElem_select(setFocus,ev,noSendClickCB,isFromKeybArrow)
- {
- // If some parents are collapsed, expand them before
- var coll=new Array
- var par=this.par
- while (par)
- {
- if (!par.expanded)
- coll[coll.length]=par
- par=par.par
- }
-
- var cLen=coll.length
- for (var i=cLen-1;i>=0;i--)
- {
- TreeWidget_toggleCB(coll[i].id,true)//direct construction of the HTML of children
- }
- if (cLen>0)
- {
- /*
- _tvw_param0=this
- _tvw_param1=setFocus
- _tvw_param2=ev
- _tvw_param3=noSendClickCB
- _tvw_param4=isFromKeybArrow
- setTimeout("_tvw_param0.select(_tvw_param1,_tvw_param2,_tvw_param3,_tvw_param4)",1)
- return;
- */
- this.select(setFocus,ev,noSendClickCB,isFromKeybArrow);
- }
-
- //multi selection treeview
- if(this.treeView.multiSelection)
- {
- TreeWidgetElem_multiSelect(this,setFocus,ev,noSendClickCB,isFromKeybArrow);
- return;
- }
-
- //mono selection treeview
- if (noSendClickCB==null)
- noSendClickCB=false
- with (this)
- {
- if (treeView.selId!=id)
- {
- if (treeView.selId>=0)
- {
- var prev=_TreeWidgetElemInstances[treeView.selId]
- prev.init()
- if (prev.domElem) {
- prev.domElem.className=prev.nonselectedClass
- }
- //window.status=prev.nonselectedClass
- }
- treeView.selId=id;
- init()
- treeView.layer._BOselId=id
- var de=domElem
- if (de == null) return
-
- //highlight path
- if(treeView.hlPath)
- treeView.highlightPath(id);
- else
- de.className=selectedClass
-
- //window.status=prev.selectedClass
- if (setFocus) {
- safeSetFocus(de)
- }
-
- TreeWidgetElem_scroll(de,treeView.layer)
-
-
- //if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData)
- //window.status= "Normal Elem_select=" + id
- }
- if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData,isFromKeybArrow!=null?isFromKeybArrow:false)
- }
- // stop propagating event to the other link
- /*if (ev)
- eventCancelBubble(ev)*/ //DOESN'T WORK WITH NETSCAPE
- }
- // ================================================================================
- _startShift=null;
- function TreeWidgetElem_multiSelect(o,setFocus,ev,noSendClickCB,isFromKeybArrow)
- {
- if (noSendClickCB==null)
- noSendClickCB=false
- with (o) // o instanceof TreeWidgetElem
- {
- init();
- var de=domElem
- if (de == null) return
-
- //reset highlight items
- if(treeView.hlPath) treeView.unhlPath();
-
- if(ev == null)
- {
- var idx = arrayFind(treeView,'selIds',id);
- if(idx == -1)//not yet selected
- {
- //add item to selected item list
- treeView.selIds[treeView.selIds.length]=id;
- if(treeView.layer._BOselIds == "")
- treeView.layer._BOselIds=""+id;
- else
- treeView.layer._BOselIds+=";"+id;
- de.className=selectedClass
- }
- //need to reset here ?
- _startShift=null;
- }
- else //from event, use ctl and shift to define the action to do
- {
- var idx = arrayFind(treeView,'selIds',id);
- var ctrl=_ie?_curWin.event.ctrlKey:ev.ctrlKey
- var shift=_ie?_curWin.event.shiftKey:ev.shiftKey
- var typeEvt=_ie?_curWin.event.type:ev.type
-
- if(ctrl && !shift) //select or deselect
- {
- if(idx == -1)//select item
- {
- // don't select if there's a grayed item
- //if (o.isGrayStyle()) return
-
- treeView.selIds[treeView.selIds.length]=id;
- if(treeView.layer._BOselIds == "")
- treeView.layer._BOselIds=""+id;
- else
- treeView.layer._BOselIds+=";"+id;
-
- de.className=selectedClass
- }
- else //deselect item
- {
- unselect();
- }
- _startShift= o;
- }
- if(shift) //select block items
- {
- var lastSelId=-1,lastSel=null;
- if(treeView.selIds.length>0)
- {
- lastSelId = treeView.selIds[treeView.selIds.length-1];
- lastSel = _TreeWidgetElemInstances[lastSelId];
-
- if(_startShift == null)
- _startShift = lastSel;
-
- if(!ctrl) //do not clear selection if we want to continue shift selection after a ctrl action
- treeView.unselect();
-
- TreeWidgetElem_multiSelectShift(_startShift.id,id);
- }
- else //select only this item
- {
- treeView.unselect();
- treeView.selIds[0]=id;
- treeView.layer._BOselIds=""+id;
-
- if(treeView.hlPath)
- treeView.highlightPath(id);
- else
- de.className=selectedClass;
-
- _startShift=null;
- }
- }
- if(!ctrl && !shift) //simple click
- {
- //be carefull, sometimes we want to drag and drop so don't deselect treeview
- var idx = arrayFind(treeView,'selIds',id);
- if( _ie &&typeEvt=="mousedown" && idx>-1)
- {
- window._treeWClickedW=o
- de.onmouseup=TreeWidgetElem_mouseUp
- }
- else
- {
- treeView.unselect();
- treeView.selIds[0]=id;
- treeView.layer._BOselIds=""+id;
-
- if(treeView.hlPath)
- treeView.highlightPath(id);
- else
- de.className=selectedClass
-
- _startShift=null;
- }
- }
- }
- if (setFocus) {
- safeSetFocus(de)
- }
- TreeWidgetElem_scroll(de,treeView.layer)
-
- if ((treeView.clickCB)&&(!noSendClickCB)) treeView.clickCB(userData,isFromKeybArrow!=null?isFromKeybArrow:false)
- }
- }
- // ================================================================================
- function TreeWidgetElem_multiSelectCtrl()
- {
- }
- // ================================================================================
- //select items between id1 and id2
- function TreeWidgetElem_multiSelectShift(id1,id2)
- {
- var elem1=_TreeWidgetElemInstances[id1];
- var elem2=_TreeWidgetElemInstances[id2];
- var treeView = elem1?elem1.treeView:null;
-
- if(treeView == null) return;//safe test
-
- if (elem1.elemPos==-1 || elem2.elemPos==-1 ) treeView.buildElems()
- var startPos= (elem1.elemPos<elem2.elemPos)?elem1.elemPos:elem2.elemPos
- var endPos= (elem1.elemPos>elem2.elemPos)?elem1.elemPos:elem2.elemPos
-
- if ((startPos>=0)&&(endPos<treeView.elems.length))
- {
- for(var j=startPos;j<=endPos;j++)
- {
- var elem = treeView.elems[j];
-
- // don't select if there's a grayed item
- //if (elem.isGrayStyle()) return
-
- var hidden=elem.getHiddenParent();//not visible item
-
- if((hidden == null)&&(arrayFind(treeView,'selIds',elem.id) == -1))//safe test
- {
- //add to selected items array
- treeView.selIds[treeView.selIds.length]=elem.id;
- if(treeView.layer._BOselIds == "")
- treeView.layer._BOselIds=""+elem.id;
- else
- treeView.layer._BOselIds+=";"+elem.id;
-
- elem.init();
- if(elem.domElem)
- elem.domElem.className=elem.selectedClass;
- }
- }
- }
- }
- // ================================================================================
- function TreeWidget_clickCB(elemId,isIcon,ev,isDown)
- {
- eventCancelBubble(ev)
-
- var e=_TreeWidgetElemInstances[elemId]
- if (e==null)
- return
-
- e.init()
- if (isIcon&&(e.sub.length>0)) TreeWidget_toggleCB(elemId)
- else if (isIcon&&e.isIncomplete&&e.querycompleteCB)
- e.querycompleteCB()
- else e.select(null,ev)
- if (_curDoc.onmousedown)
- _curDoc.onmousedown(ev)
- if (isDown&&_ie)
- {
- window._treeWClickedW=e
- e.init()
- e.clicked=true
- e.initialX=eventGetX(ev)
- e.initialY=eventGetY(ev)
- if (_ie&&e.domElem)
- e.domElem.onmousemove=TreeWidgetElem_triggerDD
- }
- if (_moz&&e.domElem)
- setTimeout("_TreeWidgetElemInstances["+elemId+"].domElem.focus()",1)
- return false
- }
- // ================================================================================
- function treeDblClickCB(elemId,ev)
- {
- eventCancelBubble(ev)
- var e=_TreeWidgetElemInstances[elemId],treeView=e.treeView;
- if (e.sub.length>0) TreeWidget_toggleCB(elemId)
- else if (e.isIncomplete&&e.querycompleteCB)
- {
- e.querycompleteCB()
- return
- }
- if (e.isEditable)
- e.showEditInput(true)
- else
- {
- if (treeView.doubleClickCB) treeView.doubleClickCB(e.userData);
- }
- }
- // ================================================================================
- function TreeWidgetElem_UpdateTooltip(newId,forceSelect)
- {
- var elem=_TreeWidgetElemInstances[newId];
- if(elem)
- {
- elem.init();
- if(elem.domElem != null)
- elem.domElem.title = elem.getTooltip(forceSelect);
- }
- }
- // ================================================================================
- function TreeWidgetElem_getDragTooltip()
- {
- var o=this
- if (o.obj && o.obj.getDragTooltip) return o.obj.getDragTooltip()
- return o.name
- }
- // ================================================================================
- function TreeWidgetElem_getTooltip(forceSelect)
- {
- var tooltip='',o=this
-
- var itemSelected=false;
- //multi selection
- if(o.treeView.multiSelection)
- {
- itemSelected = (arrayFind(o.treeView,'selIds',o.id) > -1);
- }
- else//mono selection
- {
- itemSelected = (o.treeView.selId == o.id);
- }
-
- //selection
- if (forceSelect || itemSelected)
- tooltip = _selectedLab + ' ';
- /*
- if(o.tooltip)
- tooltip+=o.tooltip+' ';
- */
- //name
- tooltip+=o.name;
- //expanded or collapsed
- if((o.sub.length > 0) || (o.isIncomplete))
- {
- if(o.expanded)
- tooltip += ' '+ _expandedLab + ' ';
- else
- tooltip += ' '+ _collapsedLab + ' ';
- }
-
- //case prompt and context selection
- if(o.advTooltip)
- {
- tooltip+=' ('+o.advTooltip+')'
- }
- /*
- if(o.help)
- tooltip +=' - ' + o.help;
- */
- return tooltip;
- }
- //508 tooltip - focus callback
- function treeFCCB(e,elemId,focus,ev)
- {
- var elem =_TreeWidgetElemInstances[elemId];
- if ((elem==null) || elem.treeView.mouseOverTooltip)
- return
-
- if(focus)
- {
- if (elem.customTooltip && elem.showCustomTooltipCB)
- {
- elem.showCustomTooltipCB(elem.userData,ev)
- elem.init()
- }
- else
- e.title = elem.getTooltip();
- }
- else
- {
- if (elem.customTooltip && elem.hideCustomTooltipCB)
- elem.hideCustomTooltipCB()
- else
- e.title = "";
- }
- }
- //2 possible workflows:
- //1- display tooltip
- //2- item has callback associated to mouse over
- function _tmoc(e,elemId,over,ev)
- {
- e.style.cursor=_hand
- var elem =_TreeWidgetElemInstances[elemId];
- if(elem==null)
- return
-
- //1: normal tooltip - mouse over callback
- if(elem.treeView.mouseOverTooltip)
- {
- if(over)
- {
- if (elem.customTooltip && elem.showCustomTooltipCB)
- {
- elem.showCustomTooltipCB(elem.userData,ev)
- elem.init()
-
- }
- else
- e.title = elem.tooltip?elem.tooltip:''
- }
- else
- {
- if (elem.customTooltip && elem.hideCustomTooltipCB)
- elem.hideCustomTooltipCB()
- else
- e.title =''
- }
- }
- //we can also do the mouseover action, it does not interfere with the tooltip action
- //asked by Bruno Rassamy for Mediance
- if(elem.treeView.mouseOverCB)
- elem.treeView.mouseOverCB(elem)
- }
- //
- function treeContextMenuCB(elemId,ev)
- {
- var elem =_TreeWidgetElemInstances[elemId];
- if(elem)
- {
- elem.treeView.rightClickMenuCB(elemId, _ie?_curWin.event:ev)
- }
- }
- //return true if is leaf
- function TreeWidgetElem_isLeaf()
- {
- return (this.sub.length==0 && !this.isIncomplete);
- }
- //return true if is node
- function TreeWidgetElem_isNode()
- {
- return (!this.isLeaf());
- }
- //return true if selected item
- function TreeWidgetElem_isSelected()
- {
- var o=this;
- if(o.treeView.multi)//multi selection
- {
- var idx = arrayFind(o.treeView,'selIds',o.id);
- return (idx>=0);
- }
- else
- {
- return (o.id == o.treeView.selId);
- }
- }
- // =====================
- // TreeWidgetElem class
- // =====================
- /*
- function newTreeWidgetHTMLElem(iconID, name, obj, userData, help)
- {
- var o=newTreeWidgetElem(iconID, name, userData, help);
- o.obj=obj
- o.getHTML=TreeWidgetHTMLElem_getHTML;
- o.selectedClass='filterBoxSelected';
- o.nonselectedClass='filterBox';
- o.feedbackDDClass='filterBoxFeedbackDD'
- o.init=TreeWidgetHTMLElem_init
-
- return o;
- }
- function TreeWidgetHTMLElem_init()
- {
- this.domElem=getLayer(_codeWinName+'trLstElt' + this.id)
- }
- function TreeWidgetHTMLElem_getHTML(indent,isFirst)
- {
- with (this)
- {
- len=sub.length,exp=(len>0),a=new Array,i=0
-
- var contextMenu=''
- if (treeView.rightClickMenuCB != null)
- {
- contextMenu= ' oncontextmenu="' + _codeWinName + '.treeContextMenuCB(\''+ id + '\', event);return false" '
- }
-
- var acceptDD=''
- if ((treeView.acceptDropCB != null) && (_ie))
- {
- acceptDD= ' ondragenter="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
- acceptDD += ' ondragover="' + _codeWinName + '.TreeWidget_dragOverEnterCB(this,\''+id+'\');" '
- }
-
- a[i++] = '<table border="0" cellspacing="0" cellpadding="0"><tbody><tr>'
- a[i++] = '<td>' + getSpace(indent + 16, 16) + '</td>'
- a[i++] = '<td>'
- 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">'
- a[i++] = '<tbody><tr>'
- a[i++] = '<td width="20">'
- a[i++] = '<span style="padding:2px">'
- a[i++] = (iconId>-1?imgOffset(treeView.icns,treeView.iconW,treeView.iconH, treeView.iconW * iconId, treeView.iconH * iconId,null,null,null,'','top'):'')
- a[i++] = '</span>'
- a[i++] = '</td>'
- // see BOFilterNode_getHTML in CommonWom.js
- // BOFilterNode_getHTML(treeView, filterID)
- a[i++] = '<td>' + obj.getHTML(treeView, userData) + '</td>'
- a[i++] = '</tr></tbody></table>'
- a[i++] = '</td></tr></tbody></table>'
- }
- return a.join("");
- }
- //
- function newTreeWidgetVoidElem(iconID, name, obj, userData, help)
- {
- var o=newTreeWidgetElem(iconID, name, userData, help);
- o.obj=obj
- o.getHTML=TreeWidgetVoidElem_getHTML;
- o.selectedClass='filterTextSelected';
- o.nonselectedClass='filterText';
- o.feedbackDDClass='filterTextFeedbackDD '
- o.init=TreeWidgetVoidElem_init
- return o;
- }
- function TreeWidgetVoidElem_init()
- {
- this.domElem=getLayer(_codeWinName+'trLstElt' + this.id)
- }
- function TreeWidgetVoidElem_getHTML(indent,isFirst)
- {
- return ""
- }
- // =================
- // TreeWidget class
- // =================
- function newStaticTreeWidget(id, originalTree)
- {
- var o = newWidget(id);
- o.sub = originalTree.sub;
- return o;
- }
- // =================
- // FolderWidget class
- // =================
- function newFolderWidget(id, exp)
- // Return [FolderWidget] the instance
- {
- var o=newWidget(id)
- o.expanded= (exp)? exp : false
- o.getCross=FolderWidget_getCross
- return o;
- }
- //
- // function getCross(id)
- //
- //
- function FolderWidget_getCross()
- {
- if (_printDoc) return getSep(12,12)
-
- with(this)
- {
- 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">' +
- imgOffset(_skin +'../tree.gif', 13, 9, expanded?0:13, 3, 'img'+ id, null, expanded?_expandedLab:_collapsedLab,null,null,'top') +
- '</span>'
- }
-
- }
- */
|