CTreeIE5NS6.js 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2021
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. // Constants
  13. var giDRAW_BLOCKSIZE = 50;
  14. var giDRAW_INTERVAL = 50;
  15. var gsCTREE_checkbox = "checkbox";
  16. var gsCTREE_click = "click";
  17. var gsCTREE_contextmenu = "contextmenu";
  18. var gsCTREE_dblclick = "dblclick";
  19. var gsCTREE_dragRef = "dragRef";
  20. var gsCTREE_dragTree = "dragTree";
  21. var gsCTREE_drag = "drag";
  22. var gsCTREE_dragend = "dragend";
  23. var gsCTREE_dragstart = "dragstart";
  24. var gsCTREE_icon = "icon";
  25. var gsCTREE_img = "img";
  26. var gsCTREE_indicator = "indicator";
  27. var gsCTREE_indicatorSpan = "indicatorSpan";
  28. var gsCTREE_keypress = "keypress";
  29. var gsCTREE_label = "label";
  30. var gsCTREE_labelText = "labelText";
  31. var gsCTREE_middle = "middle";
  32. var gsCTREE_nobr = "nobr";
  33. var gsCTREE_onclick = "onclick";
  34. var gsCTREE_oncontextmenu = "oncontextmenu";
  35. var gsCTREE_ondblclick = "ondblclick";
  36. var gsCTREE_ondrag = "ondrag";
  37. var gsCTREE_ondragend = "ondragend";
  38. var gsCTREE_ondragstart = "ondragstart";
  39. var gsCTREE_onkeypress = "onkeypress";
  40. var gsCTREE_toggle = "toggle_";
  41. var gsCTREE_tree = "tree";
  42. var gsCTREE_treeRef = "treeRef";
  43. // Fix for COGCQ00685248 - Icon text is top-aligned in Firefox in Query Studio
  44. // changed this.m_oTREELINE.align = gsCTREE_middle; to
  45. // this.m_oTREELINE.className = CLS_TREE_TEXTICON_ALIGNFIX;
  46. // This fix aligns the Icon and the text correctly
  47. //TREE CONTROL
  48. // oPane: the HTML element where the tree will be rendered
  49. // oSubmit: the form control to submit selections to the server
  50. // bRequired: is this a required field [true|false]
  51. // bMultiSelect: can the user pick more than one value [true|false]
  52. // sRef: the name of this object
  53. // oImgTest: the image object used for validation handling
  54. // oErrorFeedback: object used to provide validation feedback
  55. // oBidi: object used to provide Bidi methods
  56. function CTree(oPane, oSubmit, bRequired, bMultiSelect, sRef, oImgTest, oErrorFeedback, sCVId, sStyle, oBidi)
  57. {
  58. this.contentLocale = null;
  59. this.setCVId(sCVId);
  60. this.m_style = sStyle;
  61. //html div element where adornments will be rendered
  62. this.m_oOuterPane = oPane;
  63. //html element where the tree will be rendered
  64. this.m_oPane = null;
  65. //create a root node for the tree
  66. //new nodes are added by calling the appendChild method for each node
  67. this.m_oRoot = new CTreeNode(null, tntRoot, true, 'root', 'root', false);
  68. this.m_oRoot.m_oTree = this;
  69. this.m_oRoot.setTreeRef(K_PRMT_sEMPTY);
  70. if (this.m_oOuterPane != null) {
  71. this.m_oOuterPane.setAttribute("role", "tree");
  72. }
  73. this.m_oSubmit = oSubmit;
  74. this.m_bRequired = bRequired;
  75. //determine the selection mode for the tree
  76. if (bMultiSelect == false)
  77. {
  78. this.m_iSelectionMode = SINGLE_TREE_SELECTION;
  79. this.m_sSelectTreeUI = NORMAL_TREE;
  80. }
  81. else
  82. {
  83. this.m_iSelectionMode = DISCONTIGUOUS_TREE_SELECTION;
  84. this.m_sSelectTreeUI = CHECKBOX_TREE;
  85. }
  86. //check the state of the control?
  87. //this needs to happen after the nodes are added
  88. this.m_bValid = false;
  89. this.m_sRef = sRef;
  90. //maintain a list of selections
  91. this.m_sTreeProcessResult = K_PRMT_sEMPTY;
  92. this.m_oErrorFeedback = oErrorFeedback;
  93. //../prompting/images for handling errors
  94. this.m_oImgCheck = oImgTest;
  95. if (this.m_oImgCheck != null)
  96. {
  97. this.m_oImgErrorFalse= new Image();
  98. this.m_oImgErrorFalse.src = ERROR_TIMED_SMALL_OFF;
  99. this.m_oImgErrorTrue = new Image();
  100. this.m_oImgErrorTrue.src = ERROR_TIMED_SMALL;
  101. }
  102. this.m_bShowRootNode = false;
  103. this.m_bLoadOnTheFly = false;
  104. this.m_iIsLoading = 0;
  105. this.m_bForceSelectionAtLowestLevel = false;
  106. this.m_bAllowSelectionToggle = true;
  107. this.m_oAnchorNode = null;
  108. this.m_bAllowDragDrop = false;
  109. this.m_fOnDragStartFunc = null;
  110. this.m_fOnDragFunc = null;
  111. this.m_fOnDragEndFunc = null;
  112. this.m_fOnContextMenu = null;
  113. this.m_bTrackSelectionOrder = false;
  114. this.m_aSelectionOrder = new Array();
  115. this.m_fSingleClickFunc = null;
  116. this.m_fDoubleClickFunc = null;
  117. this.m_bHideAdornments = false;
  118. this.m_bMustChangeDefault = false;
  119. this.m_bHideOuterTable = false;
  120. this.m_bRecursiveSelect = true;
  121. this.m_bPromptTree = false;
  122. this.m_iMaxValueCount = 5000;
  123. this.m_bShowPreviousValues = true;
  124. this.m_aAllSelections = null;
  125. this.m_iContainerWidth = null;
  126. this.m_iContainerHeight = null;
  127. this.m_bNodesCanHaveChildren = true;
  128. this.m_bIsDisabled = false;
  129. this.m_bHasBeenDrawn = false;
  130. this.m_oLastSelectedNode = null;
  131. this.m_itemTabIndex = 1;
  132. // A11Y check for Event Studio keyboard support
  133. if (typeof AccessibilityHandler != "undefined") {
  134. this.m_itemTabIndex = -1;
  135. }
  136. //skin folder
  137. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  138. if (typeof gDispatcher != K_PRMT_sUNDEFINED) // Try to find global dispatcher object first
  139. {
  140. this.m_oDispatcher = gDispatcher;
  141. }
  142. else if (typeof CDispatcher != K_PRMT_sUNDEFINED)
  143. {
  144. this.m_oDispatcher = new CDispatcher();
  145. }
  146. else
  147. {
  148. this.m_oDispatcher = null;
  149. }
  150. this.m_sServerPath = this.getGateway();
  151. // DOM objects used to create child nodes.
  152. this.m_oTREELINE = document.createElement("IMG");
  153. this.m_oTREELINE.src = TREE_I_ONLY;
  154. this.m_oTREELINE.className = CLS_TREE_TEXTICON_ALIGNFIX;
  155. this.m_oTREELINE.alt = "";
  156. this.m_oTREELINE.setAttribute(gsCTREE_treeRef, gsCTREE_img);
  157. this.m_oDIVnewElement = document.createElement("DIV");
  158. this.m_oNOBR = document.createElement("NOBR");
  159. this.m_oNOBR.setAttribute(gsCTREE_treeRef, gsCTREE_nobr);
  160. this.m_oIcon = document.createElement("IMG");
  161. this.m_oIcon.setAttribute(gsCTREE_treeRef, gsCTREE_img);
  162. this.m_oIndicatorSPAN = document.createElement("SPAN");
  163. this.m_oIndicatorSPAN.style.paddingLeft = 3;
  164. this.m_oIndicatorIMG = document.createElement("IMG");
  165. this.m_oIndicatorIMG.className = CLS_TREE_TEXTICON_ALIGNFIX;
  166. this.m_oTextSPAN = document.createElement("SPAN");
  167. this.m_oToggleIMG = document.createElement("IMG");
  168. this.m_oToggleIMG.className = CLS_TREE_TEXTICON_ALIGNFIX;
  169. this.m_oToggleIMG.onclick = null;
  170. this.m_oToggleIMG.src = TREE_L_ONLY;
  171. this.m_oToggleIMG.alt = "";
  172. this.m_oCheckIMG = document.createElement("IMG");
  173. this.m_oCheckIMG.className = CLS_TREE_TEXTICON_ALIGNFIX;
  174. this.m_oLabelSPAN = document.createElement("SPAN");
  175. this.m_oLabelA = document.createElement("A");
  176. this.m_oLabelA.className = CLS_TREE_TEXT_NO_LINK;
  177. if (window.ie11)
  178. {
  179. this.m_oLabelA.href = "#";
  180. this.m_oLabelA.addEventListener("mouseover", function() {window.status=K_PRMT_sEMPTY;return true;});
  181. this.m_oLabelA.addEventListener("mouseout", function() {window.status=K_PRMT_sEMPTY;return true;});
  182. this.m_oLabelA.addEventListener("mouseup", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  183. this.m_oLabelA.addEventListener("mousedown", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  184. this.m_oLabelA.addEventListener("mousemove", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  185. this.m_oLabelA.addEventListener(gsCTREE_click, function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  186. }
  187. else if (window.ie)
  188. {
  189. this.m_oLabelA.href = "#";
  190. this.m_oLabelA.attachEvent("onmouseover", function() {window.status=K_PRMT_sEMPTY;return true;});
  191. this.m_oLabelA.attachEvent("onmouseout", function() {window.status=K_PRMT_sEMPTY;return true;});
  192. this.m_oLabelA.attachEvent("onmouseup", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  193. this.m_oLabelA.attachEvent("onmousedown", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  194. this.m_oLabelA.attachEvent("onmousemove", function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  195. this.m_oLabelA.attachEvent(gsCTREE_onclick, function(e) {window.status=K_PRMT_sEMPTY;e.returnValue = false;});
  196. }
  197. else
  198. {
  199. this.m_oLabelA.addEventListener("mouseover", function() {window.status=K_PRMT_sEMPTY;return false;}, true);
  200. this.m_oLabelA.addEventListener("mouseout", function() {window.status=K_PRMT_sEMPTY;return false;}, true);
  201. this.m_oLabelA.addEventListener("mouseup", function(e) {window.status=K_PRMT_sEMPTY;e.preventDefault();return false;}, true);
  202. this.m_oLabelA.addEventListener("mousedown", function(e) {window.status=K_PRMT_sEMPTY;e.preventDefault();return false;}, true);
  203. this.m_oLabelA.addEventListener("mousemove", function(e) {window.status=K_PRMT_sEMPTY;e.preventDefault();return false;}, true);
  204. this.m_oLabelA.addEventListener(gsCTREE_click, function(e) {window.status=K_PRMT_sEMPTY;e.preventDefault();return false;}, true);
  205. }
  206. this.m_oAncestry = null;
  207. this.m_oBidi = oBidi;
  208. this.cacheKeyPrefix = "";
  209. this.bAllowStateCache = false;
  210. this.m_oTreeControl = null;
  211. }
  212. CTree.prototype = new CPromptControl();
  213. CTree.prototype.setItemTabIndex = function(val)
  214. {
  215. this.m_itemTabIndex = val;
  216. }
  217. CTree.prototype.setAllowStateCache = function(bAllowStateCache, keyPrefix){
  218. this.bAllowStateCache = bAllowStateCache;
  219. this.cacheKeyPrefix = keyPrefix;
  220. };
  221. CTree.prototype.savePromptControlRef = function (oPromptControl)
  222. {
  223. this.m_oTreeControl = oPromptControl;
  224. };
  225. // Set this to the tree's parameter name if this is a prompt control tree
  226. // getPromptValues OM function will be called automatically if this is a prompting tree
  227. CTree.prototype.setPromptingTree = function(val)
  228. {
  229. this.m_bPromptTree = val;
  230. };
  231. CTree.prototype.setLocale = function(val)
  232. {
  233. this.contentLocale = val;
  234. };
  235. CTree.prototype.setLabel = function(treeLabel){
  236. if (treeLabel != null){
  237. this.m_oOuterPane.setAttribute("aria-label", treeLabel);
  238. }
  239. };
  240. CTree.prototype.getGateway = function()
  241. {
  242. var v_sGateway = document.location.pathname;
  243. var v_oCV = (this.getCV ? this.getCV() : null);
  244. if (v_oCV && v_oCV.getGateway) {
  245. v_sGateway = v_oCV.getGateway();
  246. }
  247. return v_sGateway;
  248. };
  249. CTree.prototype.getPromptingTree = function()
  250. {
  251. return this.m_bPromptTree;
  252. };
  253. CTree.prototype.setDisabled = function(val)
  254. {
  255. this.m_bIsDisabled = val;
  256. };
  257. CTree.prototype.getDisabled = function()
  258. {
  259. return this.m_bIsDisabled;
  260. };
  261. CTree.prototype.setMaxValueCount = function(val)
  262. {
  263. this.m_iMaxValueCount = val;
  264. };
  265. CTree.prototype.getMaxValueCount = function()
  266. {
  267. return this.m_iMaxValueCount;
  268. };
  269. CTree.prototype.getHasBeenDrawn = function()
  270. {
  271. return this.m_bHasBeenDrawn;
  272. };
  273. CTree.prototype.setContainerWidth = function(val)
  274. {
  275. this.m_iContainerWidth = val;
  276. };
  277. CTree.prototype.getContainerWidth = function()
  278. {
  279. return this.m_iContainerWidth;
  280. };
  281. CTree.prototype.setContainerHeight = function(val)
  282. {
  283. this.m_iContainerHeight = val;
  284. };
  285. CTree.prototype.getContainerHeight = function()
  286. {
  287. return this.m_iContainerHeight;
  288. };
  289. CTree.prototype.getStyle = function()
  290. {
  291. return this.m_style;
  292. };
  293. //deprecated, use addToPrevSelArray
  294. CTree.prototype.addToPreviousSelections = function(val)
  295. {
  296. val = sDecodeU003( val );
  297. if (this.m_aAllSelections == null) {
  298. this.m_aAllSelections = new Array();
  299. }
  300. this.m_aAllSelections[this.m_aAllSelections.length] = val;
  301. };
  302. //deprecated, use getPrevSelArray
  303. CTree.prototype.getPreviousSelections = function()
  304. {
  305. return this.m_aAllSelections;
  306. };
  307. //deprecated, use clearPrevSelArray
  308. CTree.prototype.clearPreviousSelections = function()
  309. {
  310. this.clearPrevSelArray();
  311. };
  312. CTree.prototype.addToPrevSelArray = function(useVal, displayVal)
  313. {
  314. if (this.m_aAllSelections == null) {
  315. this.m_aAllSelections = new Array();
  316. }
  317. useVal = sDecodeU003( useVal );
  318. displayVal = sDecodeU003( displayVal );
  319. this.m_aAllSelections[this.m_aAllSelections.length] = new Array (displayVal, useVal);
  320. };
  321. CTree.prototype.removeFromPrevSelArray = function( v_sValue, v_sName )
  322. {
  323. if (this.m_aAllSelections == null)
  324. {
  325. return;
  326. }
  327. for (var v_idxPS = 0; v_idxPS < this.m_aAllSelections.length; v_idxPS++)
  328. {
  329. var v_sUse = this.m_aAllSelections[v_idxPS];
  330. var v_sDisplay = v_sUse;
  331. if ( typeof v_sUse == K_PRMT_sOBJECT && v_sUse.length )
  332. {
  333. v_sDisplay = v_sUse[0];
  334. v_sUse = v_sUse[1];
  335. }
  336. if ( typeof v_sName == K_PRMT_sUNDEFINED )
  337. {
  338. v_sName = v_sValue;
  339. }
  340. if ( v_sUse == v_sValue && v_sDisplay == v_sName )
  341. {
  342. this.m_aAllSelections.splice( v_idxPS, 1 );
  343. v_idxPS--;
  344. }
  345. }
  346. if (this.m_aAllSelections.length < 1)
  347. {
  348. this.m_aAllSelections = null;
  349. }
  350. };
  351. CTree.prototype.getPrevSelArray = function()
  352. {
  353. return this.m_aAllSelections;
  354. };
  355. CTree.prototype.clearPrevSelArray = function()
  356. {
  357. this.m_aAllSelections = null;
  358. this.m_oAncestry = null;
  359. };
  360. CTree.prototype.setShowPreviousValues = function(val)
  361. {
  362. this.m_bShowPreviousValues = val;
  363. };
  364. CTree.prototype.getShowPreviousValues = function()
  365. {
  366. return this.m_bShowPreviousValues;
  367. };
  368. CTree.prototype.setSingleClickFunc = function(val)
  369. {
  370. this.m_fSingleClickFunc = val;
  371. };
  372. CTree.prototype.getSingleClickFunc = function()
  373. {
  374. return this.m_fSingleClickFunc;
  375. };
  376. CTree.prototype.setDoubleClickFunc = function(val)
  377. {
  378. this.m_fDoubleClickFunc = val;
  379. };
  380. CTree.prototype.getDoubleClickFunc = function()
  381. {
  382. return this.m_fDoubleClickFunc;
  383. };
  384. CTree.prototype.setLastSelectedNode = function(val)
  385. {
  386. this.m_oLastSelectedNode = val;
  387. };
  388. CTree.prototype.getLastSelectedNode = function()
  389. {
  390. return this.m_oLastSelectedNode;
  391. };
  392. CTree.prototype.addToSelectionOrder = function(node)
  393. {
  394. for (var i = 0; i < this.m_aSelectionOrder.length; i++)
  395. {
  396. if (this.m_aSelectionOrder[i] == node)
  397. {
  398. return;
  399. }
  400. }
  401. this.m_aSelectionOrder[this.m_aSelectionOrder.length] = node;
  402. };
  403. CTree.prototype.removeFromSelectionOrder = function(node)
  404. {
  405. for (var i = 0; i < this.m_aSelectionOrder.length; i++)
  406. {
  407. if (this.m_aSelectionOrder[i] == node)
  408. {
  409. delete this.m_aSelectionOrder[i];
  410. break;
  411. }
  412. }
  413. };
  414. CTree.prototype.getSelectionOrder = function()
  415. {
  416. var tempArr = new Array();
  417. for (var i = 0; i < this.m_aSelectionOrder.length; i++)
  418. {
  419. if (this.m_aSelectionOrder[i] != null) {
  420. tempArr[tempArr.length] = this.m_aSelectionOrder[i];
  421. }
  422. }
  423. return tempArr;
  424. };
  425. CTree.prototype.clearSelectionOrder = function()
  426. {
  427. this.m_aSelectionOrder = new Array();
  428. };
  429. CTree.prototype.setTrackSelectionOrder = function(val)
  430. {
  431. this.m_bTrackSelectionOrder = val;
  432. };
  433. CTree.prototype.getTrackSelectionOrder = function()
  434. {
  435. return this.m_bTrackSelectionOrder;
  436. };
  437. CTree.prototype.setContextMenu = function(val)
  438. {
  439. this.m_fOnContextMenu = val;
  440. };
  441. CTree.prototype.getContextMenu = function()
  442. {
  443. return this.m_fOnContextMenu;
  444. };
  445. CTree.prototype.setAllowDragDrop = function(val)
  446. {
  447. this.m_bAllowDragDrop = val;
  448. };
  449. CTree.prototype.getAllowDragDrop = function()
  450. {
  451. return this.m_bAllowDragDrop;
  452. };
  453. CTree.prototype.setOnDragEnd = function(val)
  454. {
  455. this.m_fOnDragEndFunc = val;
  456. };
  457. CTree.prototype.getOnDragEnd = function()
  458. {
  459. return this.m_fOnDragEndFunc;
  460. };
  461. CTree.prototype.setOnDragStart = function(val)
  462. {
  463. this.m_fOnDragStartFunc = val;
  464. };
  465. CTree.prototype.getOnDragStart = function()
  466. {
  467. return this.m_fOnDragStartFunc;
  468. };
  469. CTree.prototype.setOnDrag = function(val)
  470. {
  471. this.m_fOnDragFunc = val;
  472. };
  473. CTree.prototype.getOnDrag = function()
  474. {
  475. return this.m_fOnDragFunc;
  476. };
  477. CTree.prototype.setAnchorNode = function(val)
  478. {
  479. this.m_oAnchorNode = val;
  480. };
  481. CTree.prototype.getAnchorNode = function()
  482. {
  483. return this.m_oAnchorNode;
  484. };
  485. CTree.prototype.setMustChangeDefaultValue = function(val)
  486. {
  487. this.m_bMustChangeDefault = val;
  488. this.m_aDefaultSelNodes = new Array();
  489. // flag to make sure selected values are only added to default selection array when control is created
  490. this.setDefaultSelectLock(true);
  491. };
  492. CTree.prototype.getMustChangeDefaultValue = function()
  493. {
  494. return this.m_bMustChangeDefault;
  495. };
  496. CTree.prototype.setAllowSelectionToggle = function(val)
  497. {
  498. this.m_bAllowSelectionToggle = val;
  499. };
  500. CTree.prototype.getAllowSelectionToggle = function()
  501. {
  502. return this.m_bAllowSelectionToggle;
  503. };
  504. CTree.prototype.setSelectTreeUI = function(val)
  505. {
  506. this.m_sSelectTreeUI = val;
  507. if (val == NORMAL_TREE) {
  508. this.setAllowSelectionToggle(false);
  509. }
  510. };
  511. CTree.prototype.getSelectTreeUI = function()
  512. {
  513. return this.m_sSelectTreeUI;
  514. };
  515. CTree.prototype.setRootNodeShowing = function(val)
  516. {
  517. this.m_bShowRootNode = val;
  518. };
  519. CTree.prototype.getRootNodeShowing = function()
  520. {
  521. return this.m_bShowRootNode;
  522. };
  523. CTree.prototype.setForceSelectionAtLowestLevel = function(val)
  524. {
  525. this.m_bForceSelectionAtLowestLevel = val;
  526. };
  527. CTree.prototype.getForceSelectionAtLowestLevel = function()
  528. {
  529. return this.m_bForceSelectionAtLowestLevel;
  530. };
  531. CTree.prototype.setLoadOnTheFlyFunction = function(funcVal)
  532. {
  533. this.m_bLoadOnTheFly = funcVal;
  534. };
  535. CTree.prototype.getLoadOnTheFly = function()
  536. {
  537. return this.m_bLoadOnTheFly;
  538. };
  539. CTree.prototype.setLoading = function(val)
  540. {
  541. if (val) {
  542. this.m_iIsLoading += 1;
  543. }
  544. else if (this.m_iIsLoading > 0) {
  545. this.m_iIsLoading -= 1;
  546. }
  547. };
  548. CTree.prototype.getLoading = function()
  549. {
  550. return this.m_iIsLoading;
  551. };
  552. //can any node (other than those at the root) contain other nodes
  553. CTree.prototype.nodesCanHaveChildren = function()
  554. {
  555. return this.m_bNodesCanHaveChildren;
  556. };
  557. CTree.prototype.setNodesCanHaveChildren = function(val)
  558. {
  559. this.m_bNodesCanHaveChildren = val;
  560. };
  561. //string return the javascript object name of the tree
  562. CTree.prototype.getName = function()
  563. {
  564. return this.m_sRef;
  565. };
  566. //search paths are used to identify the correct node
  567. //CTree: return tree root node
  568. CTree.prototype.getRootNode = function()
  569. {
  570. return this.m_oRoot;
  571. };
  572. //UI related
  573. CTree.prototype.drawAll = function()
  574. {
  575. if (this.m_oPane == null) {
  576. this.setupOuterTable();
  577. }
  578. this.draw(this.getRootNode(), this.m_oPane);
  579. if (this.getDefaultSelectLock() == true && this.getMustChangeDefaultValue() == true) {
  580. this.setDefaultSelectLock(false);
  581. }
  582. };
  583. CTree.prototype.setupOuterTable = function()
  584. {
  585. if (this.getHideOuterTable() == false)
  586. {
  587. this.drawOuterTable();
  588. this.m_oPane = document.getElementById("treePane" + this.m_sRef);
  589. }
  590. else {
  591. this.m_oPane = this.m_oOuterPane;
  592. }
  593. if (window.ie)
  594. {
  595. this.m_oPane.onselectstart = function () {document.selection.empty(); return false;};
  596. }
  597. };
  598. CTree.prototype.setHideAdornments = function(val)
  599. {
  600. this.m_bHideAdornments = val;
  601. };
  602. CTree.prototype.getHideAdornments = function()
  603. {
  604. return this.m_bHideAdornments;
  605. };
  606. CTree.prototype.setHideOuterTable = function(val)
  607. {
  608. this.m_bHideOuterTable = val;
  609. };
  610. CTree.prototype.getHideOuterTable = function()
  611. {
  612. return this.m_bHideOuterTable;
  613. };
  614. CTree.prototype.getErrorFeedbackWidget = function()
  615. {
  616. return this.m_oErrorFeedback;
  617. };
  618. CTree.prototype.setErrorFeedbackWidget = function(obj)
  619. {
  620. this.m_oErrorFeedback = obj;
  621. };
  622. CTree.prototype.getImgCheck = function()
  623. {
  624. return this.m_oImgCheck;
  625. };
  626. CTree.prototype.setImgCheck = function(obj)
  627. {
  628. this.m_oImgCheck = obj;
  629. };
  630. CTree.prototype.setImgErrorFalse = function(path)
  631. {
  632. this.m_oImgErrorFalse= new Image();
  633. this.m_oImgErrorFalse.src = path;
  634. };
  635. CTree.prototype.setImgErrorTrue = function(path)
  636. {
  637. this.m_oImgErrorTrue = new Image();
  638. this.m_oImgErrorTrue.src = path;
  639. };
  640. CTree.prototype.setRecursiveSelect = function(val)
  641. {
  642. this.m_bRecursiveSelect = val;
  643. };
  644. CTree.prototype.getRecursiveSelect = function()
  645. {
  646. return this.m_bRecursiveSelect;
  647. };
  648. //select all the items in a tree
  649. CTree.prototype.selectAll = function ()
  650. {
  651. this.getRootNode().setSelected(true, true);
  652. this.redraw();
  653. this.checkData();
  654. };
  655. //remove any selections
  656. CTree.prototype.deSelectAll = function ()
  657. {
  658. this.getRootNode().setSelected(false, true);
  659. this.clearPrevSelArray();
  660. if (this.getTrackSelectionOrder())
  661. {
  662. this.clearSelectionOrder();
  663. }
  664. this.redraw();
  665. this.checkData();
  666. };
  667. //redraw the tree
  668. CTree.prototype.redraw = function ()
  669. {
  670. redrawChildren(this.getRootNode(),this.getName());
  671. };
  672. //integer enumeration: determine the selection mode for the tree (e.g. single select, multiple select)
  673. CTree.prototype.getSelectionMode = function()
  674. {
  675. return this.m_iSelectionMode;
  676. };
  677. CTree.prototype.setSelectionMode = function(iSelectionMode)
  678. {
  679. this.m_iSelectionMode = iSelectionMode;
  680. };
  681. //other get/set functions
  682. CTree.prototype.getRequired = function()
  683. {
  684. return this.m_bRequired;
  685. };
  686. CTree.prototype.getDefaultSelectedNodes = function()
  687. {
  688. return this.m_aDefaultSelNodes;
  689. };
  690. CTree.prototype.addDefaultSelectedNode = function(node)
  691. {
  692. this.m_aDefaultSelNodes[this.m_aDefaultSelNodes.length] = node;
  693. };
  694. CTree.prototype.setDefaultSelectLock = function(val)
  695. {
  696. this.m_bSetDefaultSelection = val;
  697. };
  698. CTree.prototype.getDefaultSelectLock = function()
  699. {
  700. return this.m_bSetDefaultSelection;
  701. };
  702. /*
  703. When processing, start at the top to the tree iterate down a path if the there is at least one
  704. selected child (at any level). Stop when the current node is selected (regardless whether the
  705. children are selected or not).
  706. Note that only selected nodes appear in the selectChoices list (this is a flat list)
  707. <selectChoices>
  708. <selectTreeOption displayValue="[user value]" useValue="[system value]"/>
  709. <selectTreeOption displayValue="[user value]" useValue="[system value]"/>
  710. </selectChoices>
  711. */
  712. CTree.prototype.preProcess = function ()
  713. {
  714. //convert the data to XML and submit
  715. var sURLValues = K_PRMT_sEMPTY;
  716. this.m_sTreeProcessResult = K_PRMT_sEMPTY;
  717. //move recursively and render all children
  718. var children = this.getRootNode().getChildren();
  719. if (children.length > 0)
  720. {
  721. for (var j = 0; j < children.length; j++)
  722. {
  723. this.processTree(children[j]);
  724. }
  725. }
  726. var prevSels = this.getPreviousSelections();
  727. if (prevSels != null)
  728. {
  729. for (var i = 0; i < prevSels.length; i++)
  730. {
  731. if (typeof prevSels[i] == K_PRMT_sSTRING) //deprecated
  732. {
  733. this.m_sTreeProcessResult += '<selectOption displayValue="' + sXmlEncode(prevSels[i]) + '" useValue="' + sXmlEncode(prevSels[i]) + '"/>';
  734. }
  735. else if (typeof prevSels[i] == K_PRMT_sOBJECT)
  736. {
  737. this.m_sTreeProcessResult += '<selectOption displayValue="' + sXmlEncode(prevSels[i][0]) + '" useValue="' + sXmlEncode(prevSels[i][1]) + '"/>';
  738. }
  739. }
  740. }
  741. sURLValues += this.m_sTreeProcessResult;
  742. addSelectChoices(this.m_oSubmit, sURLValues);
  743. };
  744. //loop through the tree recursively to build the tree
  745. CTree.prototype.processTree = function (node)
  746. {
  747. if (node.isSelected())
  748. {
  749. var isSelectedAlready = false;
  750. var prevSels = this.getPreviousSelections();
  751. if (prevSels != null)
  752. {
  753. var value = node.getValue();
  754. for (var i = 0; i < prevSels.length; i++)
  755. {
  756. if ((typeof prevSels[i] == K_PRMT_sSTRING) && (prevSels[i] == value))
  757. {
  758. isSelectedAlready = true;
  759. break;
  760. }
  761. else if ((typeof prevSels[i] == K_PRMT_sOBJECT) && (prevSels[i][1] == value))
  762. {
  763. isSelectedAlready = true;
  764. // make sure the display value is set ( RSVP isn't setting it )
  765. if ( !prevSels[i][0] )
  766. {
  767. prevSels[i][0] = node.getName();
  768. }
  769. break;
  770. }
  771. }
  772. }
  773. if (!isSelectedAlready)
  774. {
  775. this.m_sTreeProcessResult += '<selectOption displayValue="' + sXmlEncode(node.getName()) + '" useValue="' + sXmlEncode(node.getValue()) + '"/>';
  776. }
  777. }
  778. if (this.nodesCanHaveChildren() && node.hasSelectedChildren())
  779. {
  780. //get any children
  781. var children = node.getChildren();
  782. //move recursively and find all children
  783. for (var iChildCounter = 0; iChildCounter < children.length; iChildCounter++)
  784. {
  785. this.processTree(children[iChildCounter]);
  786. }
  787. }
  788. };
  789. CTree.prototype.getSelectedLeafNodes = function (node)
  790. {
  791. if (!node) {
  792. node = this.getRootNode();
  793. }
  794. var selectedNodes = new Array();
  795. if (node.canHaveChildren() && node.hasSelectedChildren())
  796. {
  797. //get any children
  798. var children = node.getChildren();
  799. //move recursively and find all children
  800. for (var iChildCounter = 0; iChildCounter < children.length; iChildCounter++)
  801. {
  802. var theSelectedNodes = this.getSelectedLeafNodes(children[iChildCounter]);
  803. for (var i in theSelectedNodes)
  804. {
  805. selectedNodes[selectedNodes.length] = theSelectedNodes[i];
  806. }
  807. }
  808. if(node.getTree().getSelectTreeUI() == CHECKBOX_TREE && node.getTree().getSelectionMode() == DISCONTIGUOUS_TREE_SELECTION && node.isSelected() && node.getNodeTypeObject().getRecursiveSelect() == false)
  809. {
  810. // can select this node separately from its children
  811. selectedNodes[selectedNodes.length] = node;
  812. }
  813. }
  814. else if (node.getNodeType() == TREE_ITEM && node.isSelected())
  815. {
  816. selectedNodes[selectedNodes.length] = node;
  817. }
  818. return selectedNodes;
  819. };
  820. CTree.prototype.getSelectedFolderNodes = function (node)
  821. {
  822. if (!node) {
  823. node = this.getRootNode();
  824. }
  825. var selectedNodes = new Array();
  826. if (node.canHaveChildren())
  827. {
  828. if (node.getNodeType() == TREE_FOLDER && node.isSelected())
  829. {
  830. selectedNodes[selectedNodes.length] = node;
  831. }
  832. //get any children
  833. var children = node.getChildren();
  834. //move recursively and find all children
  835. for (var iChildCounter = 0; iChildCounter < children.length; iChildCounter++)
  836. {
  837. var theSelectedNodes = this.getSelectedFolderNodes(children[iChildCounter]);
  838. for (var i in theSelectedNodes)
  839. {
  840. selectedNodes[selectedNodes.length] = theSelectedNodes[i];
  841. }
  842. }
  843. }
  844. return selectedNodes;
  845. };
  846. CTree.prototype.getSelectedUnfetchedChildren = function ()
  847. {
  848. var theFolderNodes = this.getSelectedFolderNodes();
  849. var unfetchedChildren = false;
  850. for (var i in theFolderNodes)
  851. {
  852. if (this.m_bRecursiveSelect && theFolderNodes[i].getNodeTypeObject().getRecursiveSelect() &&
  853. theFolderNodes[i].canHaveChildren() && !theFolderNodes[i].hasChildren())
  854. {
  855. theFolderNodes[i].fetchChildren();
  856. unfetchedChildren = true;
  857. }
  858. }
  859. return unfetchedChildren;
  860. };
  861. //check whether the default value must be changed.. if yes, also check whether it has changed
  862. CTree.prototype.checkDefaultValid = function ()
  863. {
  864. var selectionValid = true;
  865. var selectedNodes = new Array();
  866. if (this.m_bMustChangeDefault)
  867. {
  868. selectedNodes = this.getSelectedLeafNodes(this.getRootNode());
  869. selectedNodes = selectedNodes.concat(this.getSelectedFolderNodes(this.getRootNode()));
  870. // can potentially determine right away if selection is valid
  871. if (selectedNodes.length != this.getDefaultSelectedNodes().length) {
  872. return true;
  873. }
  874. var longArray, shortArray;
  875. if (selectedNodes.length > this.getDefaultSelectedNodes().length)
  876. {
  877. longArray = selectedNodes;
  878. shortArray = this.getDefaultSelectedNodes();
  879. }
  880. else
  881. {
  882. longArray = this.getDefaultSelectedNodes();
  883. shortArray = selectedNodes;
  884. }
  885. for (var i = 0; i < longArray.length; i++)
  886. {
  887. for (var j = 0; j < shortArray.length; j++)
  888. {
  889. if (shortArray[j].getId() == longArray[i].getId())
  890. {
  891. selectionValid = false;
  892. break;
  893. }
  894. }
  895. if (selectionValid == true)
  896. {
  897. return true;
  898. }
  899. selectionValid = true;
  900. }
  901. return false;
  902. }
  903. return true;
  904. };
  905. //called by observer notification when a Reprompt button is selected
  906. CTree.prototype.handleNotify = function()
  907. {
  908. this.cleanCacheValues(true);
  909. };
  910. //check whether the user has selected a value
  911. CTree.prototype.checkData = function()
  912. {
  913. if ( this.m_oWrapper )
  914. {
  915. return this.m_oWrapper.checkData();
  916. }
  917. if (this.getDisabled() == true)
  918. {
  919. if (this.isRequired() == false)
  920. {
  921. this.m_bValid = true;
  922. this.checkPass();
  923. }
  924. else
  925. {
  926. this.m_bValid = false;
  927. this.checkFail();
  928. }
  929. }
  930. else if ((((this.isRequired() == false) || (this.getRootNode().hasSelectedChildren() == true)) && this.checkDefaultValid() == true) || this.getPreviousSelections() != null)
  931. {
  932. this.m_bValid = true;
  933. this.checkPass();
  934. }
  935. else
  936. {
  937. this.m_bValid = false;
  938. this.checkFail();
  939. }
  940. };
  941. //render the validated state
  942. CTree.prototype.checkPass = function ()
  943. {
  944. if ((this.m_oImgCheck != null) && (this.m_oImgCheck.src != this.m_oImgErrorFalse.src))
  945. {
  946. this.m_oImgCheck.src = this.m_oImgErrorFalse.src;
  947. }
  948. if (this.m_oErrorFeedback)
  949. {
  950. this.m_oErrorFeedback.className ="clsFeedbackWidget";
  951. }
  952. this.notify();
  953. };
  954. //render the validation error state
  955. CTree.prototype.checkFail = function ()
  956. {
  957. if ((this.m_oImgCheck != null) && (this.m_oImgCheck.src != this.m_oImgErrorTrue.src))
  958. {
  959. this.m_oImgCheck.src = this.m_oImgErrorTrue.src;
  960. }
  961. if (this.m_oErrorFeedback)
  962. {
  963. this.m_oErrorFeedback.className ="clsFeedbackWidgetParseError";
  964. }
  965. this.notify(gFAIL, this);
  966. };
  967. //set the control's validity
  968. CTree.prototype.setValid = function (bValid)
  969. {
  970. this.m_bValid = bValid;
  971. };
  972. CTree.prototype.redrawNodeToggle = function (node, nodeId) {
  973. var newToggleIcon = document.getElementById(nodeId + gsCTREE_toggle + node.getTreeHierarchy());
  974. if (newToggleIcon != null) {
  975. //pick what to draw
  976. if (node.isLast() == true && node.getParent().getMoreData() != true) {
  977. if (node.canHaveChildren() == true) {
  978. if (node.isOpen() == true) {
  979. newToggleIcon.src = TREE_L_MINUS;
  980. newToggleIcon.title = PMT_TRE_COLLAPSE;
  981. newToggleIcon.alt = PMT_TRE_COLLAPSE;
  982. }
  983. else {
  984. newToggleIcon.src = TREE_L_PLUS;
  985. newToggleIcon.title = PMT_TRE_EXPAND;
  986. newToggleIcon.alt = PMT_TRE_EXPAND;
  987. }
  988. newToggleIcon.tabIndex = this.m_itemTabIndex;
  989. newToggleIcon.onclick = toggle;
  990. if (window.ie11) {
  991. newToggleIcon.addEventListener(gsCTREE_keypress, toggle);
  992. } else if (window.ie) {
  993. newToggleIcon.attachEvent(gsCTREE_onkeypress, toggle);
  994. } else {
  995. newToggleIcon.addEventListener(gsCTREE_keypress, toggle, true);
  996. }
  997. }
  998. else {
  999. newToggleIcon.src = TREE_L_ONLY;
  1000. newToggleIcon.alt = "";
  1001. newToggleIcon.onclick = null;
  1002. }
  1003. }
  1004. else {
  1005. if (node.canHaveChildren() == true) {
  1006. if (node.isOpen() == true) {
  1007. newToggleIcon.src = TREE_T_MINUS;
  1008. newToggleIcon.title = PMT_TRE_COLLAPSE;
  1009. newToggleIcon.alt = PMT_TRE_COLLAPSE;
  1010. }
  1011. else {
  1012. newToggleIcon.src = TREE_T_PLUS;
  1013. newToggleIcon.title = PMT_TRE_EXPAND;
  1014. newToggleIcon.alt = PMT_TRE_EXPAND;
  1015. }
  1016. newToggleIcon.tabIndex = this.m_itemTabIndex;
  1017. newToggleIcon.onclick = toggle;
  1018. if (window.ie11) {
  1019. newToggleIcon.addEventListener(gsCTREE_keypress, toggle);
  1020. } else if (window.ie) {
  1021. newToggleIcon.attachEvent(gsCTREE_onkeypress, toggle);
  1022. } else {
  1023. newToggleIcon.addEventListener(gsCTREE_keypress, toggle, true);
  1024. }
  1025. }
  1026. else {
  1027. newToggleIcon.src = TREE_T_ONLY;
  1028. newToggleIcon.alt = "";
  1029. newToggleIcon.onclick = null;
  1030. }
  1031. }
  1032. }
  1033. };
  1034. CTree.prototype.drawLoading = function(node, nodeId)
  1035. {
  1036. var theElement = document.getElementById(nodeId);
  1037. if (!theElement && node.getNodeType() == TREE_ROOT && this.getRootNodeShowing() == false)
  1038. {
  1039. theElement = this.m_oPane;
  1040. }
  1041. if (theElement != null)
  1042. {
  1043. var newDivContainer = document.createElement("DIV");
  1044. newDivContainer.className = CLS_TREE_LEVEL;
  1045. newDivContainer.id = this.getName() + node.getTreeRef() + "loading";
  1046. newDivContainer.style.width = "100%";
  1047. var newNobrLoadingContainer = document.createElement("NOBR");
  1048. this.drawTreeLines(node, newNobrLoadingContainer, node.getLevel() + 1);
  1049. if (!(node.getNodeType() == TREE_ROOT && node.getTree().getRootNodeShowing() == false && node.getMoreData() != true))
  1050. {
  1051. var newLIcon = document.createElement("IMG");
  1052. newLIcon.className = CLS_TREE_TEXTICON_ALIGNFIX;
  1053. newLIcon.src = TREE_L_ONLY;
  1054. newLIcon.alt="";
  1055. newNobrLoadingContainer.appendChild(newLIcon);
  1056. }
  1057. var newLoadingIcon = document.createElement("IMG");
  1058. newLoadingIcon.className = CLS_TREE_TEXTICON_ALIGNFIX;
  1059. newLoadingIcon.src = TREE_LOADING;
  1060. newNobrLoadingContainer.appendChild(newLoadingIcon);
  1061. var newLabelContainer = document.createElement("SPAN");
  1062. newLabelContainer.className = CLS_TREE_NODE_UNSELECTED + K_PRMT_sSP + CLS_TREE_TEXT;
  1063. //We need the localized string for "Loading..." here
  1064. if (typeof PMT_TRE_TREE_LOADING != K_PRMT_sUNDEFINED)
  1065. {
  1066. var newLoadingText = document.createTextNode(PMT_TRE_TREE_LOADING);
  1067. newLabelContainer.appendChild(newLoadingText);
  1068. newLabelContainer.title = PMT_TRE_TREE_LOADING;
  1069. }
  1070. newNobrLoadingContainer.appendChild(newLabelContainer);
  1071. newDivContainer.appendChild(newNobrLoadingContainer);
  1072. theElement.appendChild(newDivContainer);
  1073. }
  1074. };
  1075. CTree.prototype.removeLoading = function(node)
  1076. {
  1077. var loadingDiv = document.getElementById(this.getName() + node.getTreeRef() + "loading");
  1078. if (!loadingDiv && node.getNodeType() == TREE_ROOT && this.getRootNodeShowing() == false)
  1079. {
  1080. loadingDiv = this.m_oPane;
  1081. }
  1082. if (loadingDiv)
  1083. {
  1084. loadingDiv.parentNode.removeChild(loadingDiv);
  1085. }
  1086. };
  1087. CTree.prototype.drawMoreData = function(node, nodeId)
  1088. {
  1089. var theElement = document.getElementById(nodeId);
  1090. if (!theElement && node.getNodeType() == TREE_ROOT && this.getRootNodeShowing() == false)
  1091. {
  1092. theElement = this.m_oPane;
  1093. }
  1094. if (theElement != null)
  1095. {
  1096. var newDivContainer = document.createElement("DIV");
  1097. newDivContainer.className = CLS_TREE_LEVEL;
  1098. newDivContainer.id = this.getName() + node.getTreeRef() + "moredata";
  1099. newDivContainer.style.width = "100%";
  1100. var newNobrMoreDataContainer = document.createElement("NOBR");
  1101. this.drawTreeLines(node, newNobrMoreDataContainer, node.getLevel() + 1);
  1102. var newLIcon = document.createElement("IMG");
  1103. newLIcon.className = CLS_TREE_TEXTICON_ALIGNFIX;
  1104. newLIcon.src = TREE_L_ONLY;
  1105. newIcon.alt="";
  1106. newNobrMoreDataContainer.appendChild(newLIcon);
  1107. var newMoreDataIcon = document.createElement("IMG");
  1108. newMoreDataIcon.className = CLS_TREE_TEXTICON_ALIGNFIX;
  1109. newMoreDataIcon.src = TREE_MORE_DATA;
  1110. newNobrMoreDataContainer.appendChild(newMoreDataIcon);
  1111. var newLabelContainer = document.createElement("SPAN");
  1112. newLabelContainer.className = CLS_TREE_NODE_UNSELECTED + K_PRMT_sSP + CLS_TREE_TEXT_LINK;
  1113. //We need the localized string for "More" here
  1114. if (typeof PMT_TRE_MORE != K_PRMT_sUNDEFINED)
  1115. {
  1116. var newMoreDataText = document.createTextNode(PMT_TRE_MORE);
  1117. newLabelContainer.appendChild(newMoreDataText);
  1118. newLabelContainer.title = PMT_TRE_MORE;
  1119. }
  1120. newLabelContainer.id = this.getName() + node.getTreeRef() + "moredatalabel";
  1121. newLabelContainer.setAttribute(gsCTREE_tree, this.getName());
  1122. newLabelContainer.setAttribute(gsCTREE_treeRef, node.getTreeRef());
  1123. newLabelContainer.tabIndex = this.m_itemTabIndex;
  1124. if (window.ie11) {
  1125. newLabelContainer.addEventListener(gsCTREE_click, getMoreDataForTreeNode);
  1126. newLabelContainer.addEventListener(gsCTREE_keypress, getMoreDataForTreeNode);
  1127. } else if (window.ie) {
  1128. newLabelContainer.attachEvent(gsCTREE_onclick, getMoreDataForTreeNode);
  1129. newLabelContainer.attachEvent(gsCTREE_onkeypress, getMoreDataForTreeNode);
  1130. }
  1131. else
  1132. {
  1133. newLabelContainer.addEventListener(gsCTREE_click, getMoreDataForTreeNode, true);
  1134. newLabelContainer.addEventListener(gsCTREE_keypress, getMoreDataForTreeNode, true);
  1135. }
  1136. newNobrMoreDataContainer.appendChild(newLabelContainer);
  1137. newDivContainer.appendChild(newNobrMoreDataContainer);
  1138. theElement.appendChild(newDivContainer);
  1139. }
  1140. };
  1141. CTree.prototype.removeMoreData = function(node)
  1142. {
  1143. var moreDataDiv = document.getElementById(this.getName() + node.getTreeRef() + "moredata");
  1144. if (!moreDataDiv && node.getNodeType() == TREE_ROOT && this.getRootNodeShowing() == false)
  1145. {
  1146. moreDataDiv = this.m_oPane;
  1147. }
  1148. if (moreDataDiv)
  1149. {
  1150. moreDataDiv.parentNode.removeChild(moreDataDiv);
  1151. }
  1152. };
  1153. CTree.prototype.drawTreeLines = function(node, newElement, drawToLevel)
  1154. {
  1155. // put in appropriate spacers
  1156. if (drawToLevel > 1)
  1157. {
  1158. for (var n = 1; n < drawToLevel; n++)
  1159. {
  1160. var spacerIcon = this.m_oTREELINE.cloneNode(true);
  1161. var oParent = node.getParentAtLevel(n);
  1162. if (oParent.isLast() == true && oParent.getParent().getMoreData() != true)
  1163. {
  1164. //if the parent was last
  1165. spacerIcon.src = TREE_SPACE;
  1166. spacerIcon.alt="";
  1167. }
  1168. newElement.appendChild(spacerIcon);
  1169. }
  1170. }
  1171. };
  1172. CTree.prototype.drawOuterTable = function()
  1173. {
  1174. if (this.m_oOuterPane != null)
  1175. {
  1176. var sId = this.m_sRef;
  1177. var sStyle = this.getStyle();
  1178. var HTMLOut = "<fieldset class='clsFieldSet' style='" + cssParser(sStyle, gsCSS_DEFAULT_STYLE + ',height') +"'><table cellpading='0' cellspacing='0' border='0' onclick='treeContainerClicked(event)' class='clsPromptComponent' style='"+cssParser(sStyle,"visibility,height")+"'>" +
  1179. "<tr>";
  1180. if (this.getHideAdornments() != true)
  1181. {
  1182. HTMLOut += "<td valign='top' width='10px'>" +
  1183. "<table cellpadding='0' cellspacing='0' border='0' width='10' height='20'>";
  1184. if (this.getRequired() == true)
  1185. {
  1186. HTMLOut += "<tr>" +
  1187. "<td valign='top'><img src='" + this.m_sSkin + "/prompting/images/icon_required.gif' class='clsErrorRequired' align='top' height='10' width='10' border='0'/></td>" +
  1188. "</tr>";
  1189. }
  1190. HTMLOut += "<tr>" +
  1191. "<td valign='middle'><img id='imgTest_tree" + sId + "' name='imgTest_tree" + sId + "' class='clsErrorRequired' src='" + this.m_sSkin + "/prompting/images/error_timed_small_off.gif' align='bottom' height='10' width='10' border='0'/></td>" +
  1192. "</tr>" +
  1193. "</table>" +
  1194. "</td>";
  1195. }
  1196. HTMLOut += "<td>" +
  1197. "<table cellpadding='0' cellspacing='0' border='0' width='100%'>" +
  1198. "<tr>" +
  1199. "<td><div id='treePane" + sId + "' class='clsTreePane pa'";
  1200. if (this.getContainerWidth() != null || this.getContainerHeight() != null)
  1201. {
  1202. HTMLOut += " style='";
  1203. if (this.getContainerWidth() != null) {
  1204. HTMLOut += "width:" + this.getContainerWidth() + ";";
  1205. }
  1206. if (this.getContainerHeight() != null) {
  1207. HTMLOut += "height:" + this.getContainerHeight() + ";";
  1208. }
  1209. HTMLOut += "'";
  1210. }
  1211. HTMLOut += "></div></td>" +
  1212. "</tr>";
  1213. if (this.getHideAdornments() != true)
  1214. {
  1215. HTMLOut += "<tr>" +
  1216. "<td><div id='feedback_tree" + sId + "' class='clsFeedbackWidget'><IMG name='sizer_tree" + sId + "' src='" + this.m_sSkin + "/prompting/images/spacer.gif' alt='' width='100%' height='3'/></div></td>" +
  1217. "</tr>";
  1218. }
  1219. if (this.getSelectionMode() != SINGLE_TREE_SELECTION)
  1220. {
  1221. HTMLOut += "<tr>" +
  1222. "<td align='right'>";
  1223. if (this.getSelectTreeUI() != CHECKBOX_TREE || this.getSelectionMode() != DISCONTIGUOUS_TREE_SELECTION) {
  1224. HTMLOut += "<A href='javascript:" + sId + ".selectAll()' class='clsLink pl'>" + PMT_UIM_SELECTALL + "</A>&nbsp;";
  1225. }
  1226. HTMLOut += "<A href='javascript:" + sId + ".deSelectAll()' class='clsLink pl'>" + PMT_UIM_DESELECTALL + "</A>" +
  1227. "</td>" +
  1228. "</tr>";
  1229. }
  1230. HTMLOut += "</table>" +
  1231. "</td>" +
  1232. "</tr>" +
  1233. "</table></fieldset>";
  1234. this.m_oOuterPane.innerHTML = HTMLOut;
  1235. if (this.getErrorFeedbackWidget() == null) {
  1236. this.setErrorFeedbackWidget(document.getElementById("feedback_tree" + sId));
  1237. }
  1238. if (this.getImgCheck() == null)
  1239. {
  1240. this.setImgCheck(document.getElementById("imgTest_tree" + sId));
  1241. if (this.getImgCheck() != null)
  1242. {
  1243. this.setImgErrorFalse(ERROR_TIMED_SMALL_OFF);
  1244. this.setImgErrorTrue(ERROR_TIMED_SMALL);
  1245. }
  1246. }
  1247. }
  1248. };
  1249. CTree.prototype.draw = function(node, oParentElement)
  1250. {
  1251. if (node.getTree().getDisabled() == true)
  1252. {
  1253. return false;
  1254. }
  1255. var treeRef = node.getTreeRef();
  1256. var treeName = this.getName();
  1257. //if the node is the root node, removes the old root node so that the entire tree is redrawn
  1258. //this takes care of the case where a loading tree is replaced with real data
  1259. if (node.getNodeType() == TREE_ROOT)
  1260. {
  1261. var rootNode = document.getElementById(treeName);
  1262. if (rootNode != null) {
  1263. oParentElement.removeChild(rootNode);
  1264. }
  1265. oParentElement.setAttribute(gsCTREE_treeRef, treeRef);
  1266. oParentElement.setAttribute(gsCTREE_tree, treeName);
  1267. }
  1268. var newElement = this.m_oDIVnewElement.cloneNode(true);
  1269. if (this.getAllowDragDrop() == true && (this.getSelectTreeUI() == NORMAL_TREE || this.getSelectionMode() == SINGLE_TREE_SELECTION))
  1270. {
  1271. if (window.ie11)
  1272. {
  1273. newElement.addEventListener(gsCTREE_dragstart, dragStartOnNode);
  1274. newElement.addEventListener(gsCTREE_drag, dragOnNode);
  1275. newElement.addEventListener(gsCTREE_dragend, dragEndOnNode);
  1276. }
  1277. else if (window.ie)
  1278. {
  1279. newElement.attachEvent(gsCTREE_ondragstart, dragStartOnNode);
  1280. newElement.attachEvent(gsCTREE_ondrag, dragOnNode);
  1281. newElement.attachEvent(gsCTREE_ondragend, dragEndOnNode);
  1282. }
  1283. else
  1284. {
  1285. newElement.setAttribute("draggable", "true");
  1286. newElement.addEventListener(gsCTREE_dragstart, dragStartOnNode);
  1287. newElement.addEventListener(gsCTREE_drag, dragOnNode);
  1288. newElement.addEventListener(gsCTREE_dragend, dragEndOnNode);
  1289. }
  1290. // Chrome browser require it for firing dragstart event properly.
  1291. if (window.chrome) {
  1292. newElement.addEventListener("mousemove", function(e) {cancelBub(e);});
  1293. }
  1294. }
  1295. newElement.setAttribute(gsCTREE_treeRef, treeRef);
  1296. newElement.setAttribute(gsCTREE_tree, treeName);
  1297. newElement.id = treeName + treeRef;
  1298. if (!(node.getNodeType() == TREE_ROOT && this.getRootNodeShowing() == false))
  1299. {
  1300. newElement.className = CLS_TREE_LEVEL;
  1301. var newNobr = this.m_oNOBR.cloneNode(true);
  1302. newNobr.setAttribute(gsCTREE_tree, treeName);
  1303. newElement.appendChild(newNobr);
  1304. this.drawTreeLines(node, newNobr, node.getLevel());
  1305. var newElementIcon = this.m_oIcon.cloneNode(true);
  1306. newElementIcon.id = treeName + treeRef + gsCTREE_icon;
  1307. newElementIcon.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1308. newElementIcon.setAttribute(gsCTREE_dragTree, treeName);
  1309. // put in the indicator if there is one
  1310. var newElementIndicator = null;
  1311. if (node.getIndicator() != null)
  1312. {
  1313. // create indicator span
  1314. newElementIndicator = this.m_oIndicatorSPAN.cloneNode(true);
  1315. newElementIndicator.id = treeName + treeRef + gsCTREE_indicatorSpan;
  1316. newElementIndicator.setAttribute(gsCTREE_treeRef, treeRef);
  1317. newElementIndicator.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1318. newElementIndicator.setAttribute(gsCTREE_dragTree, treeName);
  1319. newElementIndicator.setAttribute(gsCTREE_tree, treeName);
  1320. // create the indicator image
  1321. var newElementIndicatorImage = this.m_oIndicatorIMG.cloneNode(true);
  1322. newElementIndicatorImage.id = treeName + treeRef + gsCTREE_indicator;
  1323. newElementIndicatorImage.setAttribute(gsCTREE_treeRef, treeRef);
  1324. newElementIndicatorImage.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1325. newElementIndicatorImage.setAttribute(gsCTREE_dragTree, treeName);
  1326. newElementIndicatorImage.setAttribute(gsCTREE_tree, treeName);
  1327. // set the image
  1328. newElementIndicatorImage.src = node.getIndicator();
  1329. // add this into the span
  1330. newElementIndicator.appendChild(newElementIndicatorImage);
  1331. }
  1332. //get the current state
  1333. var newElementText = this.m_oTextSPAN.cloneNode(true);
  1334. newElementText.id = treeName + treeRef + gsCTREE_label;
  1335. newElementText.setAttribute(gsCTREE_treeRef, treeRef);
  1336. newElementText.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1337. newElementText.setAttribute(gsCTREE_dragTree, treeName);
  1338. newElementText.setAttribute(gsCTREE_tree, treeName);
  1339. if (node.getTooltip() != false) {
  1340. newElementText.title = this.bidiSafeText(node.getTooltip());
  1341. }
  1342. else {
  1343. newElementText.title = this.bidiSafeText(node.getName());
  1344. }
  1345. newElementIcon.src = getIconSrc(node);
  1346. var altText = node.getNodeTypeObject().m_sIconAltText;
  1347. if (altText != null){
  1348. newElementIcon.alt = altText;
  1349. }
  1350. newElementIcon.className = CLS_TREE_TEXTICON_ALIGNFIX;
  1351. newElement.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1352. newElement.setAttribute(gsCTREE_dragTree, treeName);
  1353. if (node.getNodeType() == TREE_ROOT) {
  1354. newElementText.onclick = function() {return false;};
  1355. node.m_sTreeItemId = newElementText.id;
  1356. }
  1357. else
  1358. {
  1359. var newToggleIcon = this.m_oToggleIMG.cloneNode(true);
  1360. //pick what to draw
  1361. if (node.isLast() == true && node.getParent().getMoreData() != true)
  1362. {
  1363. if (node.canHaveChildren() == true)
  1364. {
  1365. if (node.isOpen() == true)
  1366. {
  1367. newToggleIcon.src = TREE_L_MINUS;
  1368. newToggleIcon.title = PMT_TRE_COLLAPSE;
  1369. newToggleIcon.alt = PMT_TRE_COLLAPSE;
  1370. }
  1371. else
  1372. {
  1373. newToggleIcon.src = TREE_L_PLUS;
  1374. newToggleIcon.title = PMT_TRE_EXPAND;
  1375. newToggleIcon.alt = PMT_TRE_EXPAND;
  1376. }
  1377. newToggleIcon.tabIndex = this.m_itemTabIndex;
  1378. newToggleIcon.onclick = toggle;
  1379. newToggleIcon.className = CLS_TRE_EXPAND_COLLAPSE_HOVER;
  1380. if (window.ie11) {
  1381. newToggleIcon.addEventListener(gsCTREE_keypress, toggle);
  1382. } else if (window.ie) {
  1383. newToggleIcon.attachEvent(gsCTREE_onkeypress, toggle);
  1384. }
  1385. else
  1386. {
  1387. newToggleIcon.addEventListener(gsCTREE_keypress, toggle, true);
  1388. }
  1389. }
  1390. else
  1391. {
  1392. newToggleIcon.src = TREE_L_ONLY;
  1393. newToggleIcon.alt="";
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if (node.canHaveChildren() == true)
  1399. {
  1400. if (node.isOpen() == true)
  1401. {
  1402. newToggleIcon.src = TREE_T_MINUS;
  1403. newToggleIcon.title = PMT_TRE_COLLAPSE;
  1404. newToggleIcon.alt = PMT_TRE_COLLAPSE;
  1405. }
  1406. else
  1407. {
  1408. newToggleIcon.src = TREE_T_PLUS;
  1409. newToggleIcon.title = PMT_TRE_EXPAND;
  1410. newToggleIcon.alt = PMT_TRE_EXPAND;
  1411. }
  1412. newToggleIcon.tabIndex = this.m_itemTabIndex;
  1413. newToggleIcon.onclick = toggle;
  1414. newToggleIcon.className = CLS_TRE_EXPAND_COLLAPSE_HOVER;
  1415. if (window.ie11) {
  1416. newToggleIcon.addEventListener(gsCTREE_keypress, toggle);
  1417. } else if (window.ie) {
  1418. newToggleIcon.attachEvent(gsCTREE_onkeypress, toggle);
  1419. }
  1420. else
  1421. {
  1422. newToggleIcon.addEventListener(gsCTREE_keypress, toggle, true);
  1423. }
  1424. }
  1425. else
  1426. {
  1427. newToggleIcon.src = TREE_T_ONLY;
  1428. newToggleIcon.alt = "";
  1429. }
  1430. }
  1431. newToggleIcon.setAttribute(gsCTREE_treeRef, gsCTREE_img);
  1432. newToggleIcon.id = treeName + treeRef + gsCTREE_toggle + node.getTreeHierarchy();
  1433. node.m_sToggleIconId = newToggleIcon.id;
  1434. newNobr.appendChild(newToggleIcon);
  1435. if ((node.getTree().getForceSelectionAtLowestLevel() == true && node.getNodeType() == TREE_ITEM) || (node.getTree().getForceSelectionAtLowestLevel() == false))
  1436. {
  1437. newElementText.tabIndex = this.m_itemTabIndex;
  1438. PRMTTreeUtils.f_addEvent(newElementText, gsCTREE_click, selectNode, true);
  1439. if (node.getTree().getSingleClickFunc() != null)
  1440. {
  1441. if (window.ie11) {
  1442. newElementText.addEventListener(gsCTREE_click, singleClickCaller, true);
  1443. newElementText.addEventListener(gsCTREE_keypress, singleClickCaller, true);
  1444. } else if (window.ie) {
  1445. newElementText.attachEvent(gsCTREE_onclick, singleClickCaller);
  1446. newElementText.attachEvent(gsCTREE_onkeypress, singleClickCaller);
  1447. }
  1448. else
  1449. {
  1450. newElementText.addEventListener(gsCTREE_click, singleClickCaller, true);
  1451. newElementText.addEventListener(gsCTREE_keypress, singleClickCaller, true);
  1452. }
  1453. }
  1454. if (node.getTree().getDoubleClickFunc() != null)
  1455. {
  1456. if (window.ie11) {
  1457. newElementText.addEventListener(gsCTREE_dblclick, doubleClickCaller);
  1458. } else if (window.ie) {
  1459. newElementText.attachEvent(gsCTREE_ondblclick, doubleClickCaller);
  1460. }
  1461. else
  1462. {
  1463. newElementText.addEventListener(gsCTREE_dblclick, doubleClickCaller, true);
  1464. // A11Y check for Event Studio keyboard support
  1465. if (typeof AccessibilityHandler != "undefined") {
  1466. newElementText.addEventListener(gsCTREE_keypress, doubleClickCaller, true);
  1467. }
  1468. }
  1469. }
  1470. newElementText.onmouseover = treeNodeMouseOver;
  1471. newElementText.onmouseout = treeNodeMouseOut;
  1472. if (window.ie11) {
  1473. newElementText.addEventListener(gsCTREE_contextmenu, contextMenuCaller);
  1474. newElementText.addEventListener(gsCTREE_keypress, selectNode);
  1475. } else if (window.ie)
  1476. {
  1477. newElementText.attachEvent(gsCTREE_oncontextmenu, contextMenuCaller);
  1478. newElementText.attachEvent(gsCTREE_onkeypress, selectNode);
  1479. }
  1480. else
  1481. {
  1482. newElementText.addEventListener(gsCTREE_contextmenu, contextMenuCaller, true);
  1483. newElementText.addEventListener(gsCTREE_keypress, selectNode, true);
  1484. }
  1485. }
  1486. //add a checkbox for multiselect trees
  1487. if (this.getSelectionMode() != SINGLE_TREE_SELECTION && this.getSelectTreeUI() == CHECKBOX_TREE)
  1488. {
  1489. var newCheckBoxIcon = this.m_oCheckIMG.cloneNode(true);
  1490. newCheckBoxIcon.src = getCheckBoxSrc(node);
  1491. newCheckBoxIcon.setAttribute(gsCTREE_treeRef, gsCTREE_checkbox);
  1492. newCheckBoxIcon.id = treeName + treeRef + gsCTREE_checkbox;
  1493. //set up events
  1494. if ((node.getTree().getForceSelectionAtLowestLevel() == true && node.getNodeType() == TREE_ITEM) || (node.getTree().getForceSelectionAtLowestLevel() == false))
  1495. {
  1496. if (window.ie11) {
  1497. newCheckBoxIcon.tabIndex = this.m_itemTabIndex;
  1498. newCheckBoxIcon.onclick = selectNode;
  1499. newCheckBoxIcon.addEventListener(gsCTREE_contextmenu, contextMenuCaller);
  1500. newCheckBoxIcon.addEventListener(gsCTREE_keypress, selectNode);
  1501. } else if (window.ie) {
  1502. newCheckBoxIcon.tabIndex = this.m_itemTabIndex;
  1503. newCheckBoxIcon.onclick = selectNode;
  1504. newCheckBoxIcon.attachEvent(gsCTREE_oncontextmenu, contextMenuCaller);
  1505. newCheckBoxIcon.attachEvent(gsCTREE_onkeypress, selectNode);
  1506. }
  1507. else
  1508. {
  1509. newCheckBoxIcon.addEventListener(gsCTREE_click, selectNode, true);
  1510. newCheckBoxIcon.addEventListener(gsCTREE_contextmenu, contextMenuCaller, true);
  1511. newCheckBoxIcon.addEventListener(gsCTREE_keypress, selectNode, true);
  1512. }
  1513. }
  1514. newNobr.appendChild(newCheckBoxIcon);
  1515. }
  1516. }
  1517. newElementText.setAttribute("role","treeitem");
  1518. if (this.contentLocale != null){
  1519. newElementText.setAttribute("lang",this.contentLocale);
  1520. }
  1521. //icon
  1522. newElementText.appendChild(newElementIcon);
  1523. // add the indicator if there is one
  1524. if (newElementIndicator != null)
  1525. {
  1526. newElementText.appendChild(newElementIndicator);
  1527. }
  1528. //text
  1529. var newElementLabelContainer = this.m_oLabelSPAN.cloneNode(true);
  1530. newElementLabelContainer.id = treeName + treeRef + gsCTREE_labelText;
  1531. newElementLabelContainer.className = getClassName(node, this);
  1532. newElementLabelContainer.setAttribute(gsCTREE_treeRef, treeRef);
  1533. newElementLabelContainer.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1534. newElementLabelContainer.setAttribute(gsCTREE_dragTree, treeName);
  1535. newElementLabelContainer.setAttribute(gsCTREE_tree, treeName);
  1536. node.m_oLabelText = newElementLabelContainer;
  1537. node.m_sTreeItemId = newElementLabelContainer.id;
  1538. // A11Y check for Event Studio keyboard support
  1539. if (typeof AccessibilityHandler != "undefined" && AccessibilityHandler.isEnabled()) {
  1540. if(node.getNodeType() == TREE_ROOT || node.getParent().getLableText() == null && node.getIndex() == 0) {
  1541. newElementLabelContainer.setAttribute("tabindex", "0");
  1542. }
  1543. else {
  1544. newElementLabelContainer.setAttribute("tabindex", "-1");
  1545. }
  1546. newElementLabelContainer.setAttribute("role", "treeitem");
  1547. newElementText.removeAttribute("role");
  1548. }
  1549. var newElementLabelLink = this.m_oLabelA.cloneNode(true);
  1550. var newElementLabel = document.createTextNode(this.bidiSafeText(node.getName()));
  1551. newElementLabelLink.appendChild(newElementLabel);
  1552. newElementLabelLink.setAttribute("id", node.getTreeHierarchy());
  1553. var sStyle = this.getStyle();
  1554. newElementLabelLink.style.color= cssParser(sStyle,"color",true);
  1555. newElementLabelLink.style.backgroundColor= cssParser(sStyle,"background-color",true);
  1556. newElementLabelLink.style.fontFamily= cssParser(sStyle,"font-family",true);
  1557. newElementLabelLink.style.fontSize= cssParser(sStyle,"font-size",true);
  1558. newElementLabelLink.style.fontWeight= cssParser(sStyle,"font-weight",true);
  1559. newElementLabelLink.style.fontStyle= cssParser(sStyle,"font-style",true);
  1560. newElementLabelLink.style.fontVariant= cssParser(sStyle,"font-variant",true);
  1561. newElementLabelLink.style.textAlign= cssParser(sStyle,"text-align",true);
  1562. newElementLabelLink.style.textVariant= cssParser(sStyle,"text-variant",true);
  1563. newElementLabelLink.style.textIndent= cssParser(sStyle,"text-indent",true);
  1564. newElementLabelLink.style.textTransform= cssParser(sStyle,"text-transform",true);
  1565. newElementLabelLink.setAttribute(gsCTREE_treeRef, treeRef);
  1566. newElementLabelLink.setAttribute(gsCTREE_dragRef, treeRef.toString());
  1567. newElementLabelLink.setAttribute(gsCTREE_dragTree, treeName);
  1568. newElementLabelLink.setAttribute(gsCTREE_tree, treeName);
  1569. newElementLabelContainer.appendChild(newElementLabelLink);
  1570. newElementText.appendChild(newElementLabelContainer);
  1571. newNobr.appendChild(newElementText);
  1572. if (node.isOpen())
  1573. {
  1574. node.setRendered(true);
  1575. }
  1576. }
  1577. oParentElement.appendChild(newElement);
  1578. // A11Y check for Event Studio keyboard support
  1579. if (typeof AccessibilityHandler != "undefined" && AccessibilityHandler.isEnabled()) {
  1580. node.attachEvents();
  1581. }
  1582. if (node.hasChildren() == true)
  1583. {
  1584. if (node.isOpen() == true)
  1585. {
  1586. //get any children
  1587. var children = node.getChildren();
  1588. var parent = node.getParent();
  1589. // make sure setSelected is run only once, since it traverses through all the child nodes.
  1590. if (node.isSelected() == true && parent != null && parent.isSelected() == false)
  1591. {
  1592. node.setSelected(true);
  1593. }
  1594. //move recursively and render all children
  1595. for (var iChildCounter = 0; iChildCounter < children.length; iChildCounter++)
  1596. {
  1597. this.draw(children[iChildCounter], newElement);
  1598. }
  1599. }
  1600. else
  1601. {
  1602. var unopenedSelectedChildren = this.hasUnopenedSelectedChild(node);
  1603. if ((node.isSelected() == false) && unopenedSelectedChildren == true)
  1604. {
  1605. node.setHasSelectedChildren(true);
  1606. node.updateNodeSelection();
  1607. }
  1608. if (node.hasSelectedChildren() == true || unopenedSelectedChildren == true)
  1609. {
  1610. if (this.getSelectionMode() == CONTIGUOUS_TREE_SELECTION) {
  1611. node.updateParent();
  1612. }
  1613. else {
  1614. node.partialSelectParent();
  1615. }
  1616. }
  1617. }
  1618. }
  1619. else
  1620. {
  1621. if ((node.getNodeType() == TREE_ROOT) && ((node.getTree().getPromptingTree() != false) || (node.getTree().getLoadOnTheFly() != false)))
  1622. {
  1623. node.setRendered(false);
  1624. node.fetchChildren();
  1625. }
  1626. else if ((node.isSelected() == true))
  1627. {
  1628. if (this.getSelectionMode() == CONTIGUOUS_TREE_SELECTION) {
  1629. node.updateParent();
  1630. }
  1631. else {
  1632. node.partialSelectParent();
  1633. }
  1634. }
  1635. }
  1636. this.m_bHasBeenDrawn = true;
  1637. };
  1638. //update selections
  1639. //loop through the tree recursively to paint selections
  1640. CTree.prototype.updateSelections = function (node, otherSelections)
  1641. {
  1642. if (typeof otherSelections == K_PRMT_sUNDEFINED) {
  1643. otherSelections = false;
  1644. }
  1645. if (node.isSelected())
  1646. {
  1647. if ((this.getForceSelectionAtLowestLevel() == true && otherSelections == false) || this.getSelectionMode() != SINGLE_TREE_SELECTION || (this.getSelectionMode() == SINGLE_TREE_SELECTION && otherSelections == false))
  1648. {
  1649. //select all the children
  1650. node.setSelected(true);
  1651. //update the parent
  1652. node.updateParent();
  1653. return true;
  1654. }
  1655. else
  1656. {
  1657. //unselect all the children
  1658. node.setSelected(false);
  1659. //update the parent
  1660. node.updateParent();
  1661. return false;
  1662. }
  1663. }
  1664. else
  1665. {
  1666. //get any children
  1667. var children = node.getChildren();
  1668. //move recursively and check all children
  1669. for (var iChildCounter = children.length - 1; iChildCounter >= 0; iChildCounter--)
  1670. {
  1671. if (this.updateSelections(children[iChildCounter], otherSelections)) {
  1672. otherSelections = true;
  1673. }
  1674. }
  1675. return otherSelections;
  1676. }
  1677. };
  1678. CTree.prototype.hasUnopenedSelectedChild = function (node)
  1679. {
  1680. //get any children
  1681. var children = node.getChildren();
  1682. //move recursively and check if any children are selected
  1683. for (var iChildCounter = children.length - 1; iChildCounter >= 0; iChildCounter--)
  1684. {
  1685. if (children[iChildCounter].isSelected() || this.hasUnopenedSelectedChild(children[iChildCounter])) {
  1686. return true;
  1687. }
  1688. }
  1689. return false;
  1690. };
  1691. CTree.prototype.childrenReadyForNode = function (node)
  1692. {
  1693. var theNode = this.findTreeNode(this.getRootNode(), node);
  1694. theNode.setLoading(false);
  1695. this.setLoading(false);
  1696. if (theNode.getShowUI()) {
  1697. this.removeLoading(theNode);
  1698. }
  1699. var theNodeRef = this.getName() + theNode.getTreeRef();
  1700. if (theNode.getChildren().length > 0)
  1701. {
  1702. theNode.setCanHaveChildren(true);
  1703. if (theNode.isOpen() && theNode.getRendered() == false && theNode.getShowUI())
  1704. {
  1705. // get the parent element
  1706. var oParentElement = document.getElementById(theNodeRef);
  1707. gDrawChildren(theNode, oParentElement,
  1708. function() {
  1709. theNode.setRendered(true);
  1710. if (theNode.getShowUI())
  1711. {
  1712. var oTree = theNode.getTree();
  1713. oTree.redrawNodeToggle(theNode, theNodeRef);
  1714. oTree.updateSelections(theNode, false);
  1715. oTree.redraw();
  1716. oTree.checkData();
  1717. if (theNode.getMoreData() == true)
  1718. {
  1719. oTree.drawMoreData(theNode, theNodeRef);
  1720. }
  1721. }
  1722. theNode.setShowUI(true);
  1723. }
  1724. );
  1725. return;
  1726. }
  1727. }
  1728. else
  1729. {
  1730. theNode.setCanHaveChildren(false);
  1731. }
  1732. if (theNode.getShowUI())
  1733. {
  1734. this.redrawNodeToggle(theNode, theNodeRef);
  1735. theNode.getTree().updateSelections(theNode, false);
  1736. theNode.getTree().redraw();
  1737. theNode.getTree().checkData();
  1738. if (theNode.getMoreData() == true)
  1739. {
  1740. this.drawMoreData(theNode, theNodeRef);
  1741. }
  1742. }
  1743. theNode.setShowUI(true);
  1744. };
  1745. CTree.prototype.findTreeNode = function (rootNode, node)
  1746. {
  1747. if (rootNode.m_sId != node.m_sId)
  1748. {
  1749. if (rootNode.hasChildren())
  1750. {
  1751. var theChildren = rootNode.getChildren();
  1752. for (var i = 0; i < theChildren.length; i++)
  1753. {
  1754. var thisChild = this.findTreeNode(theChildren[i], node);
  1755. if (thisChild != null)
  1756. {
  1757. return thisChild;
  1758. }
  1759. }
  1760. }
  1761. return null;
  1762. }
  1763. return rootNode;
  1764. };
  1765. CTree.prototype.setRootNodeType = function(oTreeNodeType)
  1766. {
  1767. // we should make sure that the type is a rootNodeType
  1768. if (oTreeNodeType != null && oTreeNodeType instanceof CTreeNodeType && oTreeNodeType.m_iType == TREE_ROOT) {
  1769. this.m_oRoot.setNodeTypeObject(oTreeNodeType);
  1770. }
  1771. };
  1772. CTree.prototype.setWrapper = function( v_oWrapper )
  1773. {
  1774. this.m_oWrapper = v_oWrapper;
  1775. };
  1776. CTree.prototype.bidiSafeText = function( v_text )
  1777. {
  1778. return (typeof this.m_oBidi != "undefined" && typeof this.m_oBidi["btdInjectUCCIntoStr"] != "undefined" ? this.m_oBidi.btdInjectUCCIntoStr( v_text ) : v_text);
  1779. };
  1780. CTree.prototype.getTracking = function()
  1781. {
  1782. return this.m_oTreeControl.getTracking();
  1783. };
  1784. CTree.prototype.getConversation = function(){
  1785. var sConversation = K_PRMT_sEMPTY;
  1786. var oCV = this.getCV();
  1787. if (oCV && typeof oCV.getConversation == K_PRMT_sFUNCTION)
  1788. {
  1789. sConversation = oCV.getConversation();
  1790. }
  1791. else
  1792. {
  1793. // can't find ui.conversation in CCognosViewer, trying with a form
  1794. var oForm = document.getElementById("formWarpRequest" + this.getCVId());
  1795. if (!oForm) {
  1796. document.getElementById("formWarpRequest");
  1797. }
  1798. if (oForm) {
  1799. if (typeof oForm.elements["ui.conversation"] != K_PRMT_sUNDEFINED) {
  1800. sConversation = oForm.elements["ui.conversation"].value;
  1801. }
  1802. }
  1803. }
  1804. return sConversation;
  1805. };
  1806. CTree.prototype.getUniqueKey = function (key)
  1807. {
  1808. var promptKey = "";
  1809. var rootChildren = "root_children";
  1810. var sTrackingInfo = this.getTracking();
  1811. if (key.toUpperCase() == rootChildren.toUpperCase())
  1812. {
  1813. if (this.bAllowStateCache)
  1814. {
  1815. // try to get cached prompt names
  1816. var sPromptNames = this.m_oTreeControl.getCachedPromptNames(sTrackingInfo);
  1817. var v_aPromptIds = [];
  1818. var v_oPromptControlLookup = {};
  1819. var sMyself = this.m_oTreeControl.getName();
  1820. if ((sPromptNames != null) && (sPromptNames.length != 0))
  1821. {
  1822. var aPromptNames = sPromptNames.split(":");
  1823. // get display values of prompts
  1824. for (var i = 0; i < aPromptNames.length; i++)
  1825. {
  1826. // ignore myself
  1827. if (aPromptNames[i] != sMyself)
  1828. {
  1829. v_aPromptIds.push(aPromptNames[i]);
  1830. var sPromptDisplayValues = this.m_oTreeControl.getCachedDisplayValues(sTrackingInfo,aPromptNames[i]);
  1831. v_oPromptControlLookup[aPromptNames[i]] = sPromptDisplayValues;
  1832. }
  1833. }
  1834. // sort the ids
  1835. v_aPromptIds.sort();
  1836. for (var i = 0; i < v_aPromptIds.length; i++)
  1837. {
  1838. promptKey += v_aPromptIds[i];
  1839. promptKey += "_";
  1840. promptKey += v_oPromptControlLookup[v_aPromptIds[i]];
  1841. }
  1842. }
  1843. }
  1844. }
  1845. return "PRMT_TREE_" + sTrackingInfo + promptKey + this.cacheKeyPrefix + key;
  1846. }
  1847. CTree.prototype.setCacheValue = function( key, value, bNoRetryWhenFull){
  1848. var uniqueKey = this.getUniqueKey(key);
  1849. var valueToSet = value;
  1850. var cachedValue = window.sessionStorage.getItem(uniqueKey);
  1851. if (this.bAllowStateCache && window.sessionStorage){
  1852. try {
  1853. if(cachedValue != null && cachedValue != valueToSet) // merge any new child values to the existing set of child values
  1854. {
  1855. valueToSet = PRMTTreeUtils.mergeChildrenInfo(cachedValue, valueToSet);
  1856. }
  1857. window.sessionStorage.setItem(uniqueKey, valueToSet);
  1858. } catch(e) {
  1859. // This could happen if we exceed the maximum of allowed storage size.
  1860. if (!bNoRetryWhenFull){
  1861. // Try to recover by clear the cache and try to set the value again
  1862. this.cleanCacheValues();
  1863. this.setCacheValue(key, valueToSet, true);
  1864. }
  1865. }
  1866. }
  1867. };
  1868. CTree.prototype.cleanCacheValues = function(removeAll){
  1869. if (this.bAllowStateCache && window.sessionStorage){
  1870. var currentKeyPrefix = "PRMT_TREE_" + this.getTracking();
  1871. for (var key in window.sessionStorage){
  1872. if (removeAll){
  1873. // In this case we want to dump the cache state because the Reprompt button has been selected
  1874. if (key.indexOf("PRMT_TREE_") == 0){
  1875. window.sessionStorage.removeItem(key);
  1876. }
  1877. } else {
  1878. // We only remove the entries with a different tracking number so that we don't affect the current tree state
  1879. if (key.indexOf("PRMT_TREE_") == 0 && key.indexOf(currentKeyPrefix) == -1 ){
  1880. window.sessionStorage.removeItem(key);
  1881. }
  1882. }
  1883. }
  1884. }
  1885. };
  1886. CTree.prototype.getCacheValue = function( key ){
  1887. var value = null;
  1888. if (this.bAllowStateCache && window.sessionStorage){
  1889. var uniqueKey = this.getUniqueKey(key);
  1890. value = window.sessionStorage.getItem(uniqueKey);
  1891. }
  1892. return value;
  1893. };
  1894. CTree.prototype.removeCacheValue = function( key ){
  1895. var value = null;
  1896. if (this.bAllowStateCache && window.sessionStorage){
  1897. var uniqueKey = this.getUniqueKey(key);
  1898. value = window.sessionStorage.removeItem(uniqueKey);
  1899. }
  1900. return value;
  1901. };
  1902. /////////////
  1903. //tree event handlers
  1904. function toggle(evt, uiNode)
  1905. {
  1906. //get the event in a cross-browser fashion
  1907. evt = (evt) ? evt : ((event) ? event : null);
  1908. //cancel any text selection
  1909. clearSelection();
  1910. //prevent the event from bubbling to other elements
  1911. cancelBub(evt);
  1912. //get UI Node
  1913. if (!uiNode)
  1914. {
  1915. uiNode = getUINode(evt);
  1916. }
  1917. else
  1918. {
  1919. uiNode = getUINode(null, uiNode);
  1920. }
  1921. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  1922. //get the tree object
  1923. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  1924. //get tree Node
  1925. var node = getTreeNode(tree, uiNodeTreeRef);
  1926. //toggle folders
  1927. var k = 0, j = 0, children = null;
  1928. if ((node.getTree().getPromptingTree() != false) || (typeof node.getTree().getLoadOnTheFly() == K_PRMT_sFUNCTION))
  1929. {
  1930. if (((node.getTree().getPromptingTree() != false) && (typeof activeFetchingTreeNode == K_PRMT_sUNDEFINED || activeFetchingTreeNode == null)) || (typeof node.getTree().getLoadOnTheFly() == K_PRMT_sFUNCTION))
  1931. {
  1932. if (node.isOpen() == false)
  1933. {
  1934. //shows either the children or the loading message
  1935. for (k = 0; k < uiNode.childNodes.length; k ++)
  1936. {
  1937. if ((uiNode.childNodes[k].nodeType == 1) && (uiNode.childNodes[k].tagName != 'IMG') && (uiNode.childNodes[k].tagName != 'SPAN') && (uiNode.childNodes[k].tagName != 'NOBR'))
  1938. {
  1939. uiNode.childNodes[k].style.display = "block";
  1940. }
  1941. }
  1942. if (node.hasChildren())
  1943. {
  1944. //draw the nodes if they haven't been rendered
  1945. if (node.getRendered() == false)
  1946. {
  1947. gDrawChildren(node, uiNode,
  1948. function() {
  1949. node.setRendered(true);
  1950. node.setOpen(true);
  1951. updateToggleIcon(node, tree);
  1952. }
  1953. );
  1954. return;
  1955. }
  1956. }
  1957. else
  1958. {
  1959. if (node.fetchChildren() == false) {
  1960. return false;
  1961. }
  1962. }
  1963. node.setOpen(true);
  1964. }
  1965. else
  1966. {
  1967. //hides either the children or the loading message
  1968. for (k = 0; k < uiNode.childNodes.length; k ++)
  1969. {
  1970. if ((uiNode.childNodes[k].nodeType == 1) && (uiNode.childNodes[k].tagName != 'IMG') && (uiNode.childNodes[k].tagName != 'SPAN') && (uiNode.childNodes[k].tagName != 'NOBR'))
  1971. {
  1972. uiNode.childNodes[k].style.display = "none";
  1973. }
  1974. }
  1975. node.setOpen(false);
  1976. }
  1977. }
  1978. else {
  1979. return false;
  1980. }
  1981. }
  1982. else
  1983. {
  1984. if (node.isOpen() == false)
  1985. {
  1986. for (k = 0; k < uiNode.childNodes.length; k ++)
  1987. {
  1988. if ((uiNode.childNodes[k].nodeType == 1) && (uiNode.childNodes[k].tagName != 'IMG') && (uiNode.childNodes[k].tagName != 'SPAN') && (uiNode.childNodes[k].tagName != 'NOBR'))
  1989. {
  1990. uiNode.childNodes[k].style.display = "block";
  1991. }
  1992. }
  1993. node.setOpen(true);
  1994. //draw the nodes if they haven't been rendered
  1995. if (node.getRendered() == false)
  1996. {
  1997. children = node.getChildren();
  1998. for (j = 0; j < children.length; j ++)
  1999. {
  2000. node.getTree().draw (children[j], uiNode);
  2001. }
  2002. node.setRendered(true);
  2003. }
  2004. }
  2005. else
  2006. {
  2007. for (k = 0; k < uiNode.childNodes.length; k ++)
  2008. {
  2009. if ((uiNode.childNodes[k].nodeType == 1) && (uiNode.childNodes[k].tagName != 'IMG') && (uiNode.childNodes[k].tagName != 'SPAN') && (uiNode.childNodes[k].tagName != 'NOBR'))
  2010. {
  2011. uiNode.childNodes[k].style.display = "none";
  2012. }
  2013. }
  2014. node.setOpen(false);
  2015. }
  2016. }
  2017. updateToggleIcon(node, tree);
  2018. }
  2019. function gDrawChildren(oNode, oParentUI, oFctWhenComplete, iStart)
  2020. {
  2021. var aChildren = oNode.getChildren();
  2022. var oTree = oNode.getTree();
  2023. if (!iStart) {
  2024. iStart = 0;
  2025. }
  2026. var iMax = Math.min((iStart + giDRAW_BLOCKSIZE), aChildren.length);
  2027. var idxChild = iStart;
  2028. for (idxChild = iStart; idxChild < iMax; idxChild++)
  2029. {
  2030. oTree.draw(aChildren[idxChild], oParentUI);
  2031. }
  2032. if (idxChild < aChildren.length)
  2033. {
  2034. setTimeout(
  2035. function () {
  2036. gDrawChildren(oNode, oParentUI, oFctWhenComplete, idxChild);
  2037. }
  2038. ,
  2039. giDRAW_INTERVAL );
  2040. }
  2041. else if (typeof oFctWhenComplete == K_PRMT_sFUNCTION)
  2042. {
  2043. oFctWhenComplete();
  2044. }
  2045. }
  2046. function updateToggleIcon(oNode, sTreeName)
  2047. {
  2048. //update the icons
  2049. var icon = document.getElementById(sTreeName + oNode.getTreeRef() + gsCTREE_icon);
  2050. if (icon)
  2051. {
  2052. icon.src = getIconSrc(oNode);
  2053. var toggleIcon = document.getElementById(sTreeName + oNode.getTreeRef() + gsCTREE_toggle + oNode.getTreeHierarchy());
  2054. toggleIcon.src = getToggleSrc(oNode);
  2055. toggleIcon.title = getToggleTitle(oNode);
  2056. }
  2057. }
  2058. function treeContainerClicked(evt)
  2059. {
  2060. //get the event in a cross-browser fashion
  2061. evt = (evt) ? evt : ((event) ? event : null);
  2062. //cancel any text selection
  2063. clearSelection();
  2064. //prevent the event from bubbling to other elements
  2065. cancelBub(evt);
  2066. try
  2067. {
  2068. //get UI Node
  2069. var uiNode = getUINode(evt);
  2070. //get the tree object
  2071. var tree = eval(uiNode.getAttribute(gsCTREE_tree).toString());
  2072. if (tree.getSelectTreeUI() != CHECKBOX_TREE) {
  2073. tree.getRootNode().setSelected(false);
  2074. }
  2075. tree.setLastSelectedNode(null);
  2076. tree.redraw();
  2077. tree.checkData();
  2078. }
  2079. catch (e)
  2080. {
  2081. }
  2082. }
  2083. function contextMenuCaller(evt)
  2084. {
  2085. //get the event in a cross-browser fashion
  2086. evt = (evt) ? evt : ((event) ? event : null);
  2087. //cancel any text selection
  2088. clearSelection();
  2089. //prevent the event from bubbling to other elements
  2090. cancelBub(evt);
  2091. //get UI Node
  2092. var uiNode = getUINode(evt);
  2093. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2094. //get the tree object
  2095. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2096. //get tree Node
  2097. var node = getTreeNode(tree, uiNodeTreeRef);
  2098. if (node.getTree().getContextMenu() != null)
  2099. {
  2100. var contextMenuFunc = node.getTree().getContextMenu();
  2101. contextMenuFunc(evt);
  2102. cancelBub(evt);
  2103. if((evt != null) && (typeof evt.preventDefault === "function"))
  2104. {
  2105. evt.preventDefault();
  2106. }
  2107. return false;
  2108. }
  2109. }
  2110. function singleClickCaller(evt)
  2111. {
  2112. //get the event in a cross-browser fashion
  2113. evt = (evt) ? evt : ((event) ? event : null);
  2114. if ((evt !== null) && (evt.keyCode != null) && (evt.keyCode != 13) && (evt.keyCode !== 0))
  2115. {
  2116. return false;
  2117. }
  2118. //cancel any text selection
  2119. clearSelection();
  2120. //prevent the event from bubbling to other elements
  2121. cancelBub(evt);
  2122. //get UI Node
  2123. var uiNode = getUINode(evt);
  2124. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2125. //get the tree object
  2126. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2127. //get tree Node
  2128. var node = getTreeNode(tree, uiNodeTreeRef);
  2129. var singleClickFunc = node.getTree().getSingleClickFunc();
  2130. if (singleClickFunc != null)
  2131. {
  2132. singleClickFunc(evt);
  2133. cancelBub(evt);
  2134. if (!window.ie)
  2135. {
  2136. evt.preventDefault();
  2137. }
  2138. return false;
  2139. }
  2140. }
  2141. function doubleClickCaller(evt)
  2142. {
  2143. //get the event in a cross-browser fashion
  2144. evt = (evt) ? evt : ((event) ? event : null);
  2145. // A11Y check for Event Studio keyboard support
  2146. if (typeof AccessibilityHandler != "undefined" && AccessibilityHandler.isEnabled() && evt.keyCode != 13 && evt.keyCode != null) {
  2147. return false;
  2148. }
  2149. // For Event Studio Metadata tree items Enter key press
  2150. if (typeof AccessibilityHandler != "undefined") {
  2151. selectNode(evt);
  2152. }
  2153. //cancel any text selection
  2154. clearSelection();
  2155. //prevent the event from bubbling to other elements
  2156. cancelBub(evt);
  2157. //get UI Node
  2158. var uiNode = getUINode(evt);
  2159. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2160. //get the tree object
  2161. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2162. //get tree Node
  2163. var node = getTreeNode(tree, uiNodeTreeRef);
  2164. if (node.getTree().getDoubleClickFunc() != null)
  2165. {
  2166. var doubleClickFunc = node.getTree().getDoubleClickFunc();
  2167. doubleClickFunc(evt);
  2168. cancelBub(evt);
  2169. if (!window.ie)
  2170. {
  2171. evt.preventDefault();
  2172. }
  2173. return false;
  2174. }
  2175. }
  2176. function selectNode(evt)
  2177. {
  2178. //get the event in a cross-browser fashion
  2179. evt = (evt) ? evt : ((event) ? event : null);
  2180. if ((evt !== null) && (evt.keyCode != null) && (evt.keyCode != 13) && (evt.keyCode !== 0))
  2181. {
  2182. return false;
  2183. }
  2184. //cancel any text selection
  2185. clearSelection();
  2186. //prevent the event from bubbling to other elements
  2187. cancelBub(evt);
  2188. //get UI Node
  2189. var uiNode = getUINode(evt);
  2190. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2191. //get the tree object
  2192. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2193. //get tree Node
  2194. var node = getTreeNode(tree, uiNodeTreeRef);
  2195. var oTree = node.getTree();
  2196. //handle multiple select
  2197. if (oTree.getSelectionMode() != SINGLE_TREE_SELECTION)
  2198. {
  2199. if ((evt.ctrlKey == false) && (evt.shiftKey == false) && (oTree.getSelectTreeUI() != CHECKBOX_TREE))
  2200. {
  2201. oTree.clearPreviousSelections();
  2202. }
  2203. var normalTreeNeedsRedraw = ((oTree.getSelectTreeUI() == NORMAL_TREE) && (evt.ctrlKey == false) && (evt.shiftKey == false));
  2204. var unselectNode = ((oTree.getSelectTreeUI() == CHECKBOX_TREE) || ((oTree.getSelectTreeUI() == NORMAL_TREE) && ((oTree.getAllowSelectionToggle() == true) || ((oTree.getAllowSelectionToggle() == false) && (evt.ctrlKey == true)))));
  2205. if (normalTreeNeedsRedraw)
  2206. {
  2207. oTree.getRootNode().setSelected(false);
  2208. if (oTree.getTrackSelectionOrder())
  2209. {
  2210. oTree.clearSelectionOrder();
  2211. }
  2212. }
  2213. //setSelected
  2214. var nodeWasSelected = node.isSelected();
  2215. if ((oTree.getSelectTreeUI() == NORMAL_TREE) && (evt.shiftKey == true))
  2216. {
  2217. var anchorNode = oTree.getAnchorNode();
  2218. if (anchorNode != null && node.getRootNode().hasSelectedChildren())
  2219. {
  2220. if (node.getParent() == anchorNode.getParent())
  2221. {
  2222. var anchorNodeIndex = anchorNode.getIndex();
  2223. var nodeIndex = node.getIndex();
  2224. var iCurrentNode = anchorNodeIndex;
  2225. var iIncrement;
  2226. if (anchorNodeIndex > nodeIndex)
  2227. {
  2228. iIncrement = -1;
  2229. }
  2230. else
  2231. {
  2232. iIncrement = 1;
  2233. }
  2234. //select all of the children between the anchor node and the selected node
  2235. while (iCurrentNode != nodeIndex + iIncrement)
  2236. {
  2237. var siblingNode = node.getParent().m_oChildren[iCurrentNode];
  2238. siblingNode.setSelected(true);
  2239. var oLabel = siblingNode.getLabel(tree);
  2240. oLabel.className = getClassName(siblingNode, oTree);
  2241. redrawChildren(siblingNode, tree);
  2242. iCurrentNode += iIncrement;
  2243. }
  2244. }
  2245. }
  2246. }
  2247. if (nodeWasSelected == true)
  2248. {
  2249. if (unselectNode)
  2250. {
  2251. node.setSelected(false);
  2252. oTree.setLastSelectedNode(null);
  2253. oTree.removeFromPrevSelArray( node.getValue(), node.getName() );
  2254. }
  2255. }
  2256. else
  2257. {
  2258. node.setSelected(true);
  2259. oTree.setLastSelectedNode(node);
  2260. }
  2261. node.updateNodeSelection();
  2262. node.updateParent();
  2263. var label = node.getLabel(tree);
  2264. label.className = getClassName(node, oTree);
  2265. oTree.checkData();
  2266. if (normalTreeNeedsRedraw)
  2267. {
  2268. oTree.redraw();
  2269. oTree.checkData();
  2270. }
  2271. else
  2272. {
  2273. redrawChildren(node, tree);
  2274. redrawParents(node, tree);
  2275. }
  2276. if (unselectNode && nodeWasSelected)
  2277. {
  2278. oTree.setAnchorNode(null);
  2279. }
  2280. else
  2281. {
  2282. oTree.setAnchorNode(node);
  2283. }
  2284. }
  2285. else
  2286. {
  2287. //single select remove all other selections
  2288. oTree.clearPreviousSelections();
  2289. if (node.isSelected() == true && oTree.getAllowSelectionToggle() == true)
  2290. {
  2291. oTree.getRootNode().setSelected(false);
  2292. oTree.setLastSelectedNode(null);
  2293. }
  2294. else
  2295. {
  2296. oTree.getRootNode().setSelected(false);
  2297. node.setSelected(true);
  2298. oTree.setLastSelectedNode(node);
  2299. }
  2300. node.updateParent();
  2301. oTree.redraw();
  2302. oTree.checkData();
  2303. }
  2304. if (!window.ie)
  2305. {
  2306. evt.stopPropagation();
  2307. evt.preventDefault();
  2308. }
  2309. return false;
  2310. }
  2311. function redrawChildren(node,tree)
  2312. {
  2313. //has the child node been rendered?
  2314. //draw the nodes if they haven't been rendered
  2315. if (node.getRendered() == true)
  2316. {
  2317. var children = node.getChildren();
  2318. var oTree = node.getTree();
  2319. var oParentUI = document.getElementById(tree + node.getTreeRef());
  2320. for (var j = 0; j < children.length; j++)
  2321. {
  2322. var oChild = children[j];
  2323. var label = oChild.getLabel(tree);
  2324. if (label == null)
  2325. {
  2326. if (j > 0)
  2327. {
  2328. oTree.redrawNodeToggle(children[j - 1], tree + children[j - 1].getTreeRef());
  2329. }
  2330. oTree.draw(oChild, oParentUI);
  2331. if (node.isOpen() == false)
  2332. {
  2333. document.getElementById(tree + oChild.getTreeRef()).style.display = "none";
  2334. }
  2335. }
  2336. else
  2337. {
  2338. label.className = getClassName(oChild, oTree);
  2339. if (oTree.getSelectionMode() != SINGLE_TREE_SELECTION)
  2340. {
  2341. if (oTree.getSelectTreeUI() == CHECKBOX_TREE)
  2342. {
  2343. var checkbox = oChild.getCheckbox(tree);
  2344. if (checkbox) checkbox.src = getCheckBoxSrc(oChild);
  2345. }
  2346. }
  2347. }
  2348. redrawChildren(oChild,tree);
  2349. }
  2350. }
  2351. }
  2352. function redrawParents(node, tree)
  2353. {
  2354. var parentNode = node.getParent();
  2355. if (parentNode != null)
  2356. {
  2357. var label = parentNode.getLabel(tree);
  2358. if (label != null)
  2359. {
  2360. label.className = getClassName(parentNode, parentNode.getTree());
  2361. if (node.getTree().getSelectionMode() != SINGLE_TREE_SELECTION)
  2362. {
  2363. if (parentNode.getTreeRef() != null && parentNode.getTreeRef().length !== 0)
  2364. {
  2365. if (node.getTree().getSelectTreeUI() == CHECKBOX_TREE)
  2366. {
  2367. var checkbox = parentNode.getCheckbox(tree);
  2368. checkbox.src = getCheckBoxSrc(parentNode);
  2369. }
  2370. redrawParents(parentNode, tree);
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. function dragStartOnNode(evt)
  2377. {
  2378. //get the event in a cross-browser fashion
  2379. evt = (evt) ? evt : ((event) ? event : null);
  2380. //cancel any text selection
  2381. clearSelection();
  2382. //prevent the event from bubbling to other elements
  2383. cancelBub(evt);
  2384. var dragRef = (evt.srcElement) ? evt.srcElement.getAttribute(gsCTREE_dragRef) : ((evt.originalTarget) ? evt.originalTarget.getAttribute(gsCTREE_dragRef) : null);
  2385. if (dragRef != null && typeof dragRef == K_PRMT_sSTRING && dragRef.length !== 0)
  2386. {
  2387. var uiNode = getUINode(evt);
  2388. if (uiNode)
  2389. {
  2390. //get the tree object
  2391. var tree = uiNode.getAttribute(gsCTREE_dragTree).toString();
  2392. //get tree Node
  2393. var node = getTreeNode(tree, dragRef);
  2394. var treeObj = node.getTree();
  2395. if (!node.isSelected())
  2396. {
  2397. if ((evt.ctrlKey == false) && (evt.shiftKey == false))
  2398. {
  2399. treeObj.getRootNode().setSelected(false);
  2400. treeObj.clearPreviousSelections();
  2401. if (treeObj.getTrackSelectionOrder())
  2402. {
  2403. treeObj.clearSelectionOrder();
  2404. }
  2405. }
  2406. //select all the children
  2407. node.setSelected(true);
  2408. //update the parent
  2409. node.updateParent();
  2410. var label = node.getLabel();
  2411. label.className = getClassName(node, treeObj);
  2412. if ((evt.ctrlKey == false) && (evt.shiftKey == false))
  2413. {
  2414. treeObj.redraw();
  2415. treeObj.checkData();
  2416. }
  2417. }
  2418. var selectedNodes = treeObj.getSelectedFolderNodes();
  2419. selectedNodes = selectedNodes.concat(treeObj.getSelectedLeafNodes());
  2420. var selNodesStr = tree + "~~~~~";
  2421. for (var i = 0; i < selectedNodes.length; i++)
  2422. {
  2423. if (i > 0)
  2424. {
  2425. selNodesStr += "~~~";
  2426. }
  2427. selNodesStr += selectedNodes[i].getTreeRef();
  2428. }
  2429. evt.dataTransfer.setData("Text", selNodesStr);
  2430. if (treeObj.getOnDragStart() != null)
  2431. {
  2432. var dragStartFunction = treeObj.getOnDragStart();
  2433. dragStartFunction(evt);
  2434. }
  2435. }
  2436. }
  2437. }
  2438. function dragOnNode(evt)
  2439. {
  2440. //get the event in a cross-browser fashion
  2441. evt = (evt) ? evt : ((event) ? event : null);
  2442. //cancel any text selection
  2443. clearSelection();
  2444. //prevent the event from bubbling to other elements
  2445. cancelBub(evt);
  2446. var dragRef = (evt.srcElement) ? evt.srcElement.getAttribute(gsCTREE_dragRef) : ((evt.originalTarget) ? evt.originalTarget.getAttribute(gsCTREE_dragRef) : null);
  2447. if (dragRef != null && typeof dragRef == K_PRMT_sSTRING && dragRef.length !== 0)
  2448. {
  2449. var uiNode = getUINode(evt);
  2450. if (uiNode)
  2451. {
  2452. //get the tree object
  2453. var tree = uiNode.getAttribute(gsCTREE_dragTree).toString();
  2454. //get tree Node
  2455. var node = getTreeNode(tree, dragRef);
  2456. var treeObj = node.getTree();
  2457. if (treeObj.getOnDrag() != null)
  2458. {
  2459. var dragFunction = treeObj.getOnDrag();
  2460. dragFunction(evt);
  2461. }
  2462. }
  2463. }
  2464. if (!window.ie)
  2465. {
  2466. evt.preventDefault();
  2467. }
  2468. }
  2469. function dragEndOnNode(evt)
  2470. {
  2471. //get the event in a cross-browser fashion
  2472. evt = (evt) ? evt : ((event) ? event : null);
  2473. //cancel any text selection
  2474. clearSelection();
  2475. //prevent the event from bubbling to other elements
  2476. cancelBub(evt);
  2477. var dragRef = (evt.srcElement) ? evt.srcElement.getAttribute(gsCTREE_dragRef) : ((evt.originalTarget) ? evt.originalTarget.getAttribute(gsCTREE_dragRef) : null);
  2478. if (dragRef != null && typeof dragRef == K_PRMT_sSTRING && dragRef.length !== 0)
  2479. {
  2480. var uiNode = getUINode(evt);
  2481. if (uiNode)
  2482. {
  2483. //get the tree object
  2484. var tree = uiNode.getAttribute(gsCTREE_dragTree).toString();
  2485. //get tree Node
  2486. var node = getTreeNode(tree, dragRef);
  2487. var treeObj = node.getTree();
  2488. if (treeObj.getOnDragEnd() != null)
  2489. {
  2490. var dragEndFunction = treeObj.getOnDragEnd();
  2491. dragEndFunction(evt);
  2492. }
  2493. }
  2494. }
  2495. if (!window.ie)
  2496. {
  2497. evt.preventDefault();
  2498. }
  2499. }
  2500. /////////////////////
  2501. //utility functions
  2502. //cancel any text selection
  2503. function clearSelection()
  2504. {
  2505. if (typeof document.selection != K_PRMT_sUNDEFINED && typeof document.selection.createRange == K_PRMT_sFUNCTION && document.selection.createRange().text != K_PRMT_sEMPTY)
  2506. {
  2507. //IE specific
  2508. document.selection.empty();
  2509. }
  2510. else if (typeof window.getSelection == K_PRMT_sFUNCTION && typeof window.getSelection() == K_PRMT_sOBJECT)
  2511. {
  2512. //NS6 specific
  2513. window.getSelection().removeAllRanges();
  2514. }
  2515. }
  2516. //find the element that the event occurred
  2517. function getUINode (evt, uiNode)
  2518. {
  2519. if (!uiNode)
  2520. {
  2521. //get the element that trapped the event in a cross-browser fashion
  2522. uiNode = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  2523. }
  2524. //check to see if this is a text node.
  2525. while (uiNode.nodeType == 3)
  2526. {
  2527. //this is a text node, get the parent node
  2528. uiNode = uiNode.parentNode;
  2529. }
  2530. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2531. //bubble event to the correct node
  2532. if ((uiNodeTreeRef == gsCTREE_img) || (uiNodeTreeRef == gsCTREE_label) || (uiNodeTreeRef == gsCTREE_checkbox))
  2533. {
  2534. //pass the event from icon to the parent node
  2535. uiNode = uiNode.parentNode;
  2536. }
  2537. uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2538. if (uiNodeTreeRef == gsCTREE_nobr)
  2539. {
  2540. //pass the event from icon to the parent node
  2541. uiNode = uiNode.parentNode;
  2542. }
  2543. return uiNode;
  2544. }
  2545. //get the javascript treenode for a given tree
  2546. //and tree reference
  2547. function getTreeNode(tree, uiNodeTreeRef)
  2548. {
  2549. var node = null;
  2550. if (uiNodeTreeRef != K_PRMT_sEMPTY)
  2551. {
  2552. //find the target tree node
  2553. var arTreeNodeArray = uiNodeTreeRef.split(K_PRMT_sDOT);
  2554. var treeNode = K_PRMT_sEMPTY;
  2555. for (var k = 0; k < arTreeNodeArray.length; k++)
  2556. {
  2557. if (arTreeNodeArray[k] != K_PRMT_sEMPTY)
  2558. {
  2559. treeNode += ".m_oChildren[" + arTreeNodeArray[k] + "]";
  2560. }
  2561. }
  2562. node = eval(tree + ".getRootNode()" + treeNode);
  2563. }
  2564. else
  2565. {
  2566. node = eval(tree + ".getRootNode()");
  2567. }
  2568. return node;
  2569. }
  2570. //return the appropriate classname for the given node
  2571. function getClassName(node,tree)
  2572. {
  2573. var newClassName = CLS_TREE_NODE_UNSELECTED;
  2574. //get the current state
  2575. //the selection classnames only apply to single select trees
  2576. if ((tree.getSelectionMode() == SINGLE_TREE_SELECTION || tree.getSelectTreeUI() == NORMAL_TREE) && tree.getRootNode() != node)
  2577. {
  2578. switch (node.getState())
  2579. {
  2580. case NODE_PARTIAL:
  2581. newClassName = CLS_TREE_NODE_PARTIAL;
  2582. break;
  2583. case NODE_SELECTED:
  2584. newClassName = CLS_TREE_NODE_SELECTED;
  2585. break;
  2586. }
  2587. }
  2588. return newClassName;
  2589. }
  2590. //return appropriate checkbox image src for the given node
  2591. function getCheckBoxSrc(node)
  2592. {
  2593. var newImageSrc = K_PRMT_sEMPTY;
  2594. //get the current state
  2595. switch (node.getState())
  2596. {
  2597. case NODE_UNSELECTED:
  2598. newImageSrc = CHECKBOX_UNSELECTED;
  2599. break;
  2600. case NODE_PARTIAL:
  2601. newImageSrc = CHECKBOX_PARTIAL;
  2602. break;
  2603. case NODE_SELECTED:
  2604. newImageSrc = CHECKBOX_SELECTED;
  2605. break;
  2606. }
  2607. return newImageSrc;
  2608. }
  2609. function getIconSrc(node)
  2610. {
  2611. var newImageSrc = K_PRMT_sEMPTY;
  2612. if (node.isOpen() == true)
  2613. {
  2614. newImageSrc = node.getNodeTypeObject().m_sIconOpenSrc;
  2615. }
  2616. else
  2617. {
  2618. newImageSrc = node.getNodeTypeObject().m_sIconSrc;
  2619. }
  2620. return newImageSrc;
  2621. }
  2622. function getIconAlign(node)
  2623. {
  2624. //node.getNodeTypeObject().m_sIconAlign;
  2625. // Removed the attribute m_sIconAlign, for backward compatibility
  2626. return gsCTREE_middle;
  2627. }
  2628. //return plus or minus icons for the given node
  2629. function getToggleSrc(node)
  2630. {
  2631. if (node.isOpen() == true)
  2632. {
  2633. if (node.isLast() == true && node.getParent().getMoreData() != true)
  2634. {
  2635. return TREE_L_MINUS;
  2636. }
  2637. else
  2638. {
  2639. return TREE_T_MINUS;
  2640. }
  2641. }
  2642. else
  2643. {
  2644. if (node.isLast() == true && node.getParent().getMoreData() != true)
  2645. {
  2646. return TREE_L_PLUS;
  2647. }
  2648. else
  2649. {
  2650. return TREE_T_PLUS;
  2651. }
  2652. }
  2653. }
  2654. //return plus or minus title for the given node
  2655. function getToggleTitle(node)
  2656. {
  2657. if (node.isOpen() == true)
  2658. {
  2659. return PMT_TRE_COLLAPSE;
  2660. }
  2661. else
  2662. {
  2663. return PMT_TRE_EXPAND;
  2664. }
  2665. }
  2666. function treeNodeMouseOver(evt)
  2667. {
  2668. //get the event in a cross-browser fashion
  2669. evt = (evt) ? evt : ((event) ? event : null);
  2670. //cancel any text selection
  2671. clearSelection();
  2672. //prevent the event from bubbling to other elements
  2673. cancelBub(evt);
  2674. //get UI Node
  2675. var uiNode = getUINode(evt);
  2676. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2677. //get the tree object
  2678. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2679. //get tree Node
  2680. var node = getTreeNode(tree, uiNodeTreeRef);
  2681. window.status = K_PRMT_sEMPTY;
  2682. if (node.getNodeTypeObject().getSelectable() && node.isSelected() == false && node.hasSelectedChildren() == false)
  2683. {
  2684. var label = node.getLabel(tree);
  2685. label.className = CLS_TREE_NODE_HOVER;
  2686. }
  2687. }
  2688. function treeNodeMouseOut(evt)
  2689. {
  2690. //get the event in a cross-browser fashion
  2691. evt = (evt) ? evt : ((event) ? event : null);
  2692. //cancel any text selection
  2693. clearSelection();
  2694. //prevent the event from bubbling to other elements
  2695. cancelBub(evt);
  2696. //get UI Node
  2697. var uiNode = getUINode(evt);
  2698. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  2699. //get the tree object
  2700. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  2701. //get tree Node
  2702. var node = getTreeNode(tree, uiNodeTreeRef);
  2703. window.status = K_PRMT_sEMPTY;
  2704. if (node.isSelected() == false && node.hasSelectedChildren() == false)
  2705. {
  2706. var label = node.getLabel(tree);
  2707. label.className = CLS_TREE_NODE_UNSELECTED;
  2708. }
  2709. }
  2710. /////////////////////////////////
  2711. // Tree node object
  2712. // oParentTreeNode: the parent node - null for the root node
  2713. // oTreeNodeType: the type of node, a TreeNodeType object (e.g. folder/leaf)
  2714. // bOpenState: if this is a container, whether the the default state is open or closed [true|false]
  2715. // name: the display value for the tree node
  2716. // value: the use value for the tree node
  2717. // bSelected: whether this node has been selected or not
  2718. //Tree nodes
  2719. function CTreeNode(oParentTreeNode, oTreeNodeType, bOpenState, sName, value, bSelected)
  2720. {
  2721. if (oTreeNodeType)
  2722. {
  2723. this.init(oParentTreeNode, oTreeNodeType, bOpenState, sName, value, bSelected);
  2724. }
  2725. }
  2726. CTreeNode.prototype.init = function(oParentTreeNode, oTreeNodeType, bOpenState, sName, value, bSelected)
  2727. {
  2728. //id is the searchpath
  2729. this.m_sId = this.generateId();
  2730. this.m_sName = sDecodeU003( sName );
  2731. this.m_sValue = sDecodeU003( value );
  2732. this.m_oChildren = [];
  2733. this.m_iSelectedChildrenCount = 0;
  2734. this.m_bOpen = bOpenState;
  2735. //has this node been rendered?
  2736. this.m_bRendered = bOpenState;
  2737. //tree reference
  2738. this.m_sTreeRef = null;
  2739. if (oParentTreeNode != null)
  2740. {
  2741. this.m_oParentTreeNode = oParentTreeNode;
  2742. this.setLevel(this.m_oParentTreeNode.getLevel() + 1);
  2743. if (((this.getTree().getForceSelectionAtLowestLevel() == true && oTreeNodeType.m_iType == TREE_ITEM) || (this.getTree().getForceSelectionAtLowestLevel() == false)) && (this.getTree().getShowPreviousValues() == true))
  2744. {
  2745. this.m_bSelected = bSelected;
  2746. }
  2747. else
  2748. {
  2749. this.m_bSelected = false;
  2750. }
  2751. this.m_oParentTreeNode.appendChild(this);
  2752. var prevSels = this.getTree().getPreviousSelections();
  2753. if (prevSels != null)
  2754. {
  2755. for (var i = 0; i < prevSels.length; i++)
  2756. {
  2757. if ((typeof prevSels[i] == K_PRMT_sSTRING) && (prevSels[i] == this.m_sValue))
  2758. {
  2759. this.m_bSelected = true;
  2760. break;
  2761. }
  2762. else if ((typeof prevSels[i] == K_PRMT_sOBJECT) && (prevSels[i][1] == this.m_sValue))
  2763. {
  2764. this.m_bSelected = true;
  2765. break;
  2766. }
  2767. }
  2768. }
  2769. }
  2770. else
  2771. {
  2772. this.m_oParentTreeNode = null;
  2773. this.setLevel(0);
  2774. this.m_bSelected = false;
  2775. }
  2776. //node type
  2777. this.m_oTreeNodeType = oTreeNodeType;
  2778. if (oTreeNodeType.m_isContainer == true && (oParentTreeNode != null && this.getTree().nodesCanHaveChildren() == true))
  2779. {
  2780. this.setCanHaveChildren(true);
  2781. }
  2782. else
  2783. {
  2784. this.setCanHaveChildren(false);
  2785. }
  2786. this.m_bHasSelectedChildren = false;
  2787. this.m_oRoot = null;
  2788. this.m_bIsLoading = false;
  2789. this.m_sToolTip = false;
  2790. this.m_bIsMoreData = false;
  2791. this.m_iSkipValueCount = 0;
  2792. // default indicator - used for QoS
  2793. this.m_sIndicator = null;
  2794. this.allowUIForChildren = true;
  2795. var v_oTree = this.getTree();
  2796. if ( v_oTree && v_oTree.m_oAncestry && v_oTree.m_oAncestry[this.m_sValue] )
  2797. {
  2798. this.setHasSelectedChildren(true);
  2799. }
  2800. }
  2801. CTreeNode.prototype.attachEvents = function() {
  2802. var treeItem = this.getHTMLTreeItem();
  2803. if(treeItem == null)
  2804. return; // just to be safe
  2805. treeItem.onkeypress = this.onkeypress;
  2806. treeItem.treeNode = eval(this);
  2807. }
  2808. CTreeNode.prototype.onkeypress = function(evt) {
  2809. evt = (evt) ? evt : ((event) ? event : null);
  2810. var keyCode = evt.keyCode || evt.which;
  2811. var treeNode = this.treeNode;
  2812. var parentNode = treeNode.getParent();
  2813. var toggleIcon = treeNode.getHTMLToggleIcon();
  2814. // check for root node
  2815. if (parentNode == null) {
  2816. // only for Down key
  2817. if (keyCode == 40) {
  2818. treeNode.getChild(0).getHTMLTreeItem().focus();
  2819. }
  2820. // other key press do nothing
  2821. }
  2822. // check for Left key press
  2823. else if (keyCode == 37) {
  2824. if (treeNode.isOpen()) {
  2825. toggleIcon.click();
  2826. }
  2827. else if (parentNode.getHTMLTreeItem() != null) {
  2828. parentNode.getHTMLTreeItem().focus();
  2829. if (parentNode != treeNode.getRootNode()) {
  2830. parentNode.getHTMLToggleIcon().click();
  2831. }
  2832. }
  2833. }
  2834. // check for Right key press
  2835. else if (keyCode == 39) {
  2836. if (!treeNode.isOpen()) {
  2837. toggleIcon.click();
  2838. }
  2839. }
  2840. // check for Up and Down key press
  2841. else if (keyCode == 38 || keyCode == 40) {
  2842. var nextTreeNode = treeNode.getNextTreeNode(keyCode);
  2843. if (nextTreeNode != null && nextTreeNode.getHTMLTreeItem() != null) {
  2844. nextTreeNode.getHTMLTreeItem().focus();
  2845. }
  2846. }
  2847. }
  2848. CTreeNode.prototype.getNextTreeNode = function(keyCode) {
  2849. var current, next, first = 0;
  2850. var parentNode = this.getParent();
  2851. var nextTreeNode = null;
  2852. for (var i=0; i<parentNode.getChildrenLength(); i++) {
  2853. if(this == parentNode.getChild(i)) {
  2854. current = i;
  2855. break;
  2856. }
  2857. }
  2858. if (keyCode == 38) {
  2859. next = current -1;
  2860. if (current == first) {
  2861. next = first;
  2862. if (parentNode.isOpen()) {
  2863. return parentNode;
  2864. }
  2865. }
  2866. nextTreeNode = parentNode.getChild(next);
  2867. while (nextTreeNode.isOpen()) {
  2868. var last = nextTreeNode.getChildrenLength() - 1;
  2869. nextTreeNode = nextTreeNode.getChild(last);
  2870. }
  2871. }
  2872. else if (keyCode == 40) {
  2873. if (this.isOpen()) {
  2874. return this.getChild(0);
  2875. }
  2876. next = current + 1;
  2877. nextTreeNode = parentNode.getChild(next);
  2878. if (this.isLast()) {
  2879. while (parentNode != this.getRootNode()) {
  2880. if (parentNode.isLast()) {
  2881. parentNode = parentNode.getParent();
  2882. }
  2883. else {
  2884. return parentNode.getParent().getChild(parentNode.getIndex() + 1);
  2885. }
  2886. }
  2887. nextTreeNode = null;
  2888. }
  2889. }
  2890. return nextTreeNode;
  2891. }
  2892. CTreeNode.prototype.getHTMLTreeItem = function() {
  2893. return document.getElementById(this.m_sTreeItemId);
  2894. }
  2895. CTreeNode.prototype.getHTMLToggleIcon = function() {
  2896. return document.getElementById(this.m_sToggleIconId);
  2897. }
  2898. CTreeNode.prototype.getLableText = function() {
  2899. return this.m_oLabelText;
  2900. }
  2901. CTreeNode.prototype.getTreeHierarchy = function()
  2902. {
  2903. var iLevel = this.getLevel();
  2904. var sHierarchyName = this.getName();
  2905. var iParentLevel;
  2906. var oCurrentNode = this;
  2907. for (iParentLevel = iLevel-1; iParentLevel >= 0; iParentLevel--)
  2908. {
  2909. oCurrentNode = oCurrentNode.getParent();
  2910. sHierarchyName = oCurrentNode.getName() + "_" + sHierarchyName;
  2911. }
  2912. return sHierarchyName;
  2913. };
  2914. CTreeNode.prototype.setSkipValueCount = function(val)
  2915. {
  2916. this.m_iSkipValueCount = val;
  2917. };
  2918. CTreeNode.prototype.getSkipValueCount = function()
  2919. {
  2920. return this.m_iSkipValueCount;
  2921. };
  2922. CTreeNode.prototype.getTooltip = function ()
  2923. {
  2924. return this.m_sToolTip;
  2925. };
  2926. CTreeNode.prototype.setTooltip = function (val)
  2927. {
  2928. this.m_sToolTip = val;
  2929. };
  2930. CTreeNode.prototype.getNodeTypeObject = function ()
  2931. {
  2932. return this.m_oTreeNodeType;
  2933. };
  2934. CTreeNode.prototype.setNodeTypeObject = function(oTreeNodeType)
  2935. {
  2936. this.m_oTreeNodeType = oTreeNodeType;
  2937. };
  2938. CTreeNode.prototype.getNodeType = function ()
  2939. {
  2940. return this.getNodeTypeObject().m_iType;
  2941. };
  2942. CTreeNode.prototype.generateId = function ()
  2943. {
  2944. return (Date.parse((new Date()).toString()) / 1000000) + Math.random();
  2945. };
  2946. CTreeNode.prototype.getRootNode = function ()
  2947. {
  2948. if (this.m_oRoot == null)
  2949. {
  2950. var theRoot = this;
  2951. while (theRoot.getLevel() != 0)
  2952. {
  2953. theRoot = theRoot.getParent();
  2954. }
  2955. this.m_oRoot = theRoot;
  2956. }
  2957. return this.m_oRoot;
  2958. };
  2959. CTreeNode.prototype.getTree = function ()
  2960. {
  2961. return this.getRootNode().m_oTree;
  2962. };
  2963. CTreeNode.prototype.getParentAtLevel = function (iLevel)
  2964. {
  2965. var parentAtLevel = this;
  2966. var iCurrentLevel = this.getLevel();
  2967. if (this.getLevel() > iLevel)
  2968. {
  2969. for ( var j=iLevel; j < iCurrentLevel; j++)
  2970. {
  2971. parentAtLevel = parentAtLevel.getParent();
  2972. }
  2973. }
  2974. return parentAtLevel;
  2975. };
  2976. CTreeNode.prototype.isLast = function ()
  2977. {
  2978. if ((this.getParent() != null) && (this.getTreeRef() == this.getParent().m_oChildren[this.getParent().getChildrenLength() - 1].getTreeRef()))
  2979. {
  2980. return true;
  2981. }
  2982. else
  2983. {
  2984. return false;
  2985. }
  2986. };
  2987. CTreeNode.prototype.getCheckbox = function (sTreeRef)
  2988. {
  2989. if (!this.m_oCheckbox) {
  2990. this.m_oCheckbox = document.getElementById(sTreeRef + this.getTreeRef() + gsCTREE_checkbox);
  2991. }
  2992. return this.m_oCheckbox;
  2993. };
  2994. CTreeNode.prototype.getLabel = function (sTreeRef)
  2995. {
  2996. if (!this.m_oLabelText) {
  2997. this.m_oLabelText = document.getElementById(sTreeRef + this.getTreeRef() + gsCTREE_labelText);
  2998. }
  2999. return this.m_oLabelText;
  3000. };
  3001. //integer: has this tree node been rendered yet?
  3002. CTreeNode.prototype.setLevel = function (iLevel)
  3003. {
  3004. this.m_oLevel = iLevel;
  3005. };
  3006. CTreeNode.prototype.getLevel = function ()
  3007. {
  3008. return this.m_oLevel;
  3009. };
  3010. //boolean: has this tree node been rendered yet?
  3011. CTreeNode.prototype.setRendered = function (bRendered)
  3012. {
  3013. this.m_bRendered = bRendered;
  3014. };
  3015. CTreeNode.prototype.getRendered = function ()
  3016. {
  3017. return this.m_bRendered;
  3018. };
  3019. //treeRef: a comma separated list that uniquely identifies tree nodes
  3020. CTreeNode.prototype.setTreeRef = function (sTreeRef)
  3021. {
  3022. this.m_sTreeRef = sTreeRef;
  3023. };
  3024. CTreeNode.prototype.getTreeRef = function ()
  3025. {
  3026. return this.m_sTreeRef;
  3027. };
  3028. //boolean: returns whether the node has children or not
  3029. CTreeNode.prototype.hasChildren = function ()
  3030. {
  3031. if (this.getChildrenLength() > 0)
  3032. {
  3033. return true;
  3034. }
  3035. else
  3036. {
  3037. return false;
  3038. }
  3039. };
  3040. //container: can this node contain other nodes
  3041. CTreeNode.prototype.canHaveChildren = function ()
  3042. {
  3043. return this.m_bCanHaveChildren;
  3044. };
  3045. CTreeNode.prototype.setCanHaveChildren = function (val)
  3046. {
  3047. this.m_bCanHaveChildren = val;
  3048. };
  3049. //selected: user choice state for the node
  3050. CTreeNode.prototype.isSelected = function ()
  3051. {
  3052. return this.m_bSelected;
  3053. };
  3054. //boolean: does this node have any selected children at any level?
  3055. CTreeNode.prototype.setHasSelectedChildren = function (bSelectedChildren)
  3056. {
  3057. this.m_bHasSelectedChildren = bSelectedChildren;
  3058. };
  3059. CTreeNode.prototype.hasSelectedChildren = function ()
  3060. {
  3061. return this.m_bHasSelectedChildren;
  3062. };
  3063. //recurse through the tree and select all children
  3064. CTreeNode.prototype.setSelected = function (bSelected, bForceRecurs)
  3065. {
  3066. if (this.getNodeTypeObject().getSelectable())
  3067. {
  3068. this.m_bSelected = bSelected;
  3069. //add to default selected list only when tree is first rendered
  3070. if (this.isSelected() && this.getTree().getDefaultSelectLock())
  3071. {
  3072. this.getTree().addDefaultSelectedNode(this);
  3073. }
  3074. if (this.getTree().getTrackSelectionOrder())
  3075. {
  3076. if (bSelected) {
  3077. this.getTree().addToSelectionOrder(this);
  3078. }
  3079. else {
  3080. this.getTree().removeFromSelectionOrder(this);
  3081. }
  3082. }
  3083. }
  3084. //select children too
  3085. if (bForceRecurs == true || ((this.getTree().getSelectTreeUI() != CHECKBOX_TREE || this.getTree().getSelectionMode() != DISCONTIGUOUS_TREE_SELECTION) && (!bSelected || (this.getTree().getRecursiveSelect() && this.getNodeTypeObject().getRecursiveSelect()))))
  3086. {
  3087. this.setHasSelectedChildren(bSelected);
  3088. for (var j=0; j < this.getChildrenLength(); j++)
  3089. {
  3090. this.m_oChildren[j].setSelected(bSelected, bForceRecurs);
  3091. }
  3092. }
  3093. };
  3094. //Update this nodes childrens references to their position in the tree
  3095. //this is called when removing nodes
  3096. CTreeNode.prototype.updateTreeRefs = function ()
  3097. {
  3098. var children = this.getChildren();
  3099. for (var j = 0; j < this.getChildrenLength(); j++)
  3100. {
  3101. var treeRef = K_PRMT_sEMPTY + children[j].getTreeRef();
  3102. var ref_replace_regex = /(\.{0,1})[0-9]+$/;
  3103. treeRef = treeRef.replace(ref_replace_regex, "$1" + j);
  3104. //re create the refs
  3105. children[j].setTreeRef(treeRef);
  3106. }
  3107. };
  3108. //Update this node
  3109. CTreeNode.prototype.update = function ()
  3110. {
  3111. if (this.getTree().getSelectTreeUI() != CHECKBOX_TREE || this.getTree().getSelectionMode() != DISCONTIGUOUS_TREE_SELECTION) {
  3112. this.m_bSelected = false;
  3113. }
  3114. var hasSelectedChildren = false;
  3115. var iSelectedChildren = 0;
  3116. var children = this.getChildren();
  3117. for (var j = 0; j < this.getChildrenLength(); j++)
  3118. {
  3119. if(children[j].isSelected() == true)
  3120. {
  3121. iSelectedChildren += 1;
  3122. hasSelectedChildren = true;
  3123. }
  3124. else if(children[j].hasSelectedChildren())
  3125. {
  3126. //parent.setHasSelectedChildren
  3127. hasSelectedChildren = true;
  3128. }
  3129. }
  3130. this.setSelectedChildrenCount(iSelectedChildren);
  3131. this.setHasSelectedChildren(hasSelectedChildren);
  3132. if (this.getNodeTypeObject().getRecursiveSelect() == true)
  3133. {
  3134. if (
  3135. this.getTree().getSelectionMode() == CONTIGUOUS_TREE_SELECTION &&
  3136. iSelectedChildren == this.getChildrenLength() &&
  3137. this.getNodeTypeObject().getFullChildSelectable()
  3138. ) {
  3139. this.m_bSelected = true;
  3140. }
  3141. this.updateNodeSelection();
  3142. }
  3143. this.updateParent();
  3144. };
  3145. //Update the parent
  3146. CTreeNode.prototype.updateParent = function ()
  3147. {
  3148. var parent = this.getParent();
  3149. if (parent)
  3150. {
  3151. parent.update();
  3152. }
  3153. };
  3154. //if it is known that a child is selected, just iterate through and partial select all parents
  3155. CTreeNode.prototype.partialSelectParent = function ()
  3156. {
  3157. var parent = this.getParent();
  3158. if (parent != null)
  3159. {
  3160. parent.setHasSelectedChildren(true);
  3161. if (parent != this.getRootNode())
  3162. {
  3163. parent.updateNodeSelection();
  3164. parent.partialSelectParent();
  3165. }
  3166. }
  3167. };
  3168. CTreeNode.prototype.updateNodeSelection = function ()
  3169. {
  3170. if (this.getTree().getSelectTreeUI() == NORMAL_TREE)
  3171. {
  3172. if (this.getTree().getSelectionMode() == CONTIGUOUS_TREE_SELECTION && this.isSelected() == false && this.getNodeType() == TREE_FOLDER && this.getChildrenLength() == this.getSelectedChildrenCount()) {
  3173. this.m_bSelected = true;
  3174. }
  3175. var label = this.getLabel(this.getTree().getName());
  3176. if (label != null) {
  3177. label.className = getClassName(this, this.getTree());
  3178. }
  3179. }
  3180. else
  3181. {
  3182. var checkbox = this.getCheckbox(this.getTree().getName());
  3183. if (checkbox != null) {
  3184. checkbox.src = getCheckBoxSrc(this);
  3185. }
  3186. }
  3187. };
  3188. //open: specifies whether the children of a container node should be displayed
  3189. CTreeNode.prototype.isOpen = function ()
  3190. {
  3191. return this.m_bOpen;
  3192. };
  3193. CTreeNode.prototype.setOpen = function (bOpen)
  3194. {
  3195. this.m_bOpen = bOpen;
  3196. };
  3197. //string: return the id of the node
  3198. CTreeNode.prototype.getId = function ()
  3199. {
  3200. return this.m_sId;
  3201. };
  3202. //string: return the name of the node
  3203. CTreeNode.prototype.getName = function ()
  3204. {
  3205. return this.m_sName;
  3206. };
  3207. //void: set the name of the node
  3208. CTreeNode.prototype.setName = function (name)
  3209. {
  3210. this.m_sName = name;
  3211. };
  3212. //string: return the value of the node
  3213. CTreeNode.prototype.getValue = function ()
  3214. {
  3215. return this.m_sValue;
  3216. };
  3217. //void: set the value of the node
  3218. CTreeNode.prototype.setValue = function (value)
  3219. {
  3220. this.m_sValue = sDecodeU003( value );
  3221. };
  3222. //tree node array: return the children
  3223. CTreeNode.prototype.getChildren = function ()
  3224. {
  3225. return this.m_oChildren;
  3226. };
  3227. //tree node array: return the children array length
  3228. CTreeNode.prototype.getChildrenLength = function ()
  3229. {
  3230. return this.m_oChildren.length;
  3231. };
  3232. //tree node array: return the parent node
  3233. CTreeNode.prototype.getParent = function ()
  3234. {
  3235. return this.m_oParentTreeNode;
  3236. };
  3237. //node manipulation functions
  3238. CTreeNode.prototype.appendChild = function (obj)
  3239. {
  3240. var iAppendPos = this.getChildrenLength();
  3241. this.m_oChildren[iAppendPos] = obj;
  3242. if (obj.isSelected() == true) {
  3243. this.m_iSelectedChildrenCount += 1;
  3244. }
  3245. var newTreeRef;
  3246. if (this.getTreeRef() != null && this.getTreeRef().length !== 0)
  3247. {
  3248. newTreeRef = this.getTreeRef() + K_PRMT_sDOT + iAppendPos;
  3249. }
  3250. else
  3251. {
  3252. newTreeRef = iAppendPos;
  3253. }
  3254. this.m_oChildren[iAppendPos].setTreeRef(newTreeRef);
  3255. };
  3256. //take the passed node out of this node
  3257. CTreeNode.prototype.removeChild = function (obj)
  3258. {
  3259. //is it a node we know
  3260. if (!obj.m_sId)
  3261. {
  3262. return;
  3263. }
  3264. var iSize = this.getChildrenLength();
  3265. var oNewChildren = new Array();
  3266. for (var i = 0; i < iSize; i++)
  3267. {
  3268. if (obj.m_sId != this.m_oChildren[i].m_sId)
  3269. {
  3270. oNewChildren.push(this.m_oChildren[i]);
  3271. }
  3272. }
  3273. //replace the children with the filtered results
  3274. this.m_oChildren = oNewChildren;
  3275. //rejig the tree refs
  3276. this.updateTreeRefs();
  3277. };
  3278. //return the child at the appropriate position
  3279. CTreeNode.prototype.getChild = function (index)
  3280. {
  3281. if (index >= 0 && index < this.getChildrenLength())
  3282. {
  3283. return this.m_oChildren[index];
  3284. }
  3285. return null;
  3286. };
  3287. //take the passed node out of this node
  3288. CTreeNode.prototype.removeChildren = function (childNodes)
  3289. {
  3290. //is it a node array?
  3291. if (!childNodes || !childNodes.length || childNodes.length === 0)
  3292. {
  3293. return;
  3294. }
  3295. var oRef_map = new Object();
  3296. var i = 0;
  3297. for (i = 0; i < childNodes.length; i++)
  3298. {
  3299. if (childNodes[i].m_sId)
  3300. {
  3301. oRef_map[childNodes[i].m_sId] = childNodes[i];
  3302. }
  3303. }
  3304. var oNewChildren = new Array();
  3305. for (i = 0; i < this.getChildrenLength(); i++)
  3306. {
  3307. if (!oRef_map[this.m_oChildren[i].m_sId])
  3308. {
  3309. //this is saved from the bin
  3310. oNewChildren.push(this.m_oChildren[i]);
  3311. }
  3312. }
  3313. //replace the children with the filtered results
  3314. this.m_oChildren = oNewChildren;
  3315. //rejig the tree refs
  3316. this.updateTreeRefs();
  3317. };
  3318. //remove this node from its parent
  3319. CTreeNode.prototype.detach = function ()
  3320. {
  3321. this.getParent().removeChild(this);
  3322. };
  3323. CTreeNode.prototype.getSelectedChildrenCount = function ()
  3324. {
  3325. return this.m_iSelectedChildrenCount;
  3326. };
  3327. CTreeNode.prototype.setSelectedChildrenCount = function (count)
  3328. {
  3329. this.m_iSelectedChildrenCount = count;
  3330. };
  3331. CTreeNode.prototype.addSelectedChildrenCount = function ()
  3332. {
  3333. this.m_iSelectedChildrenCount = this.m_iSelectedChildrenCount + 1;
  3334. };
  3335. CTreeNode.prototype.removeSelectedChildrenCount = function ()
  3336. {
  3337. this.m_iSelectedChildrenCount = this.m_iSelectedChildrenCount - 1;
  3338. };
  3339. //return the current state of the node
  3340. CTreeNode.prototype.getState = function ()
  3341. {
  3342. if (this.isSelected())
  3343. {
  3344. return NODE_SELECTED;
  3345. }
  3346. else if (this.hasSelectedChildren() == true)
  3347. {
  3348. if ((this.getTree().getSelectionMode() == CONTIGUOUS_TREE_SELECTION) &&
  3349. (this.getSelectedChildrenCount() > 0) &&
  3350. (this.getSelectedChildrenCount() == this.getChildrenLength()) &&
  3351. this.getNodeTypeObject().getFullChildSelectable())
  3352. {
  3353. return NODE_SELECTED;
  3354. }
  3355. else
  3356. {
  3357. return NODE_PARTIAL;
  3358. }
  3359. }
  3360. return NODE_UNSELECTED;
  3361. };
  3362. CTreeNode.prototype.setShowUI = function (showUI)
  3363. {
  3364. this.allowUIForChildren = showUI;
  3365. };
  3366. CTreeNode.prototype.getShowUI = function()
  3367. {
  3368. return this.allowUIForChildren;
  3369. };
  3370. CTreeNode.prototype.getResponseCacheKey = function(response){
  3371. return this.getValue() + "_children";
  3372. };
  3373. //fetch the children of the node
  3374. CTreeNode.prototype.fetchChildren = function (bForceFetch)
  3375. {
  3376. var v_oTree = this.getTree();
  3377. if ( !v_oTree.nodesCanHaveChildren() && bForceFetch !== true)
  3378. {
  3379. return;
  3380. }
  3381. if (v_oTree.getPromptingTree() != false)
  3382. {
  3383. if ((typeof activeFetchingTreeNode == K_PRMT_sUNDEFINED || activeFetchingTreeNode == null) && (v_oTree.m_oDispatcher != null) && (this.getLoading() == false))
  3384. {
  3385. this.setLoading(true);
  3386. v_oTree.setLoading(true);
  3387. if (this.getShowUI())
  3388. {
  3389. this.setOpen(true);
  3390. v_oTree.redrawNodeToggle(this, v_oTree.getName() + this.getTreeRef());
  3391. v_oTree.drawLoading(this, v_oTree.getName() + this.getTreeRef());
  3392. }
  3393. activeFetchingTreeNode = this;
  3394. var cachedResponse = SYSTEMPROPERTY_TREE_CACHE_IGNORE_PRIOR_RSVP_RESPONSES ? false : this.getTree().getCacheValue(this.getResponseCacheKey());
  3395. if (cachedResponse && !this.bShouldFetchChildren){
  3396. promptTreeCallback(cachedResponse);
  3397. }else{
  3398. this.sendFetchChildrenRequest();
  3399. }
  3400. }
  3401. return true;
  3402. }
  3403. else if (typeof v_oTree.getLoadOnTheFly() == K_PRMT_sFUNCTION)
  3404. {
  3405. if (this.getLoading() == false)
  3406. {
  3407. this.setLoading(true);
  3408. v_oTree.setLoading(true);
  3409. if (this.getShowUI())
  3410. {
  3411. this.setOpen(true);
  3412. v_oTree.redrawNodeToggle(this, v_oTree.getName() + this.getTreeRef());
  3413. v_oTree.drawLoading(this, v_oTree.getName() + this.getTreeRef());
  3414. }
  3415. var theFunction = v_oTree.getLoadOnTheFly();
  3416. theFunction(this);
  3417. }
  3418. return true;
  3419. }
  3420. else
  3421. {
  3422. this.setCanHaveChildren(false);
  3423. if (this.getShowUI())
  3424. {
  3425. v_oTree.redrawNodeToggle(this, v_oTree.getName() + this.getTreeRef());
  3426. }
  3427. return false;
  3428. }
  3429. };
  3430. // If the tracking information is not available call sendFetchChildrenRequest
  3431. // after a delay of WAIT_FOR_TRACKING_TIMEOUT_MS. There is also a retry count
  3432. // just in case the tracking information is always empty.
  3433. var WAIT_FOR_TRACKING_TIMEOUT_MS = 100; // 100 milliseconds
  3434. var TRACKING_RETRY_CNT_MAX = 500; // 500 * 100 ms = 50 seconds worth of trying
  3435. CTreeNode.prototype.sendFetchChildrenRequest = function( v_oParams, v_iRetryCount )
  3436. {
  3437. // Call the XTS to load the prompting tree
  3438. var cafContextId = K_PRMT_sEMPTY; // TODO
  3439. var url = "b_action=xts.run&m=/prompting/promptTree.xts";
  3440. // Pass the m_tracking node
  3441. var tracking_info = this.getTree().getTracking();
  3442. var sConversation = this.getTree().getConversation();
  3443. var retries = TRACKING_RETRY_CNT_MAX;
  3444. if ( typeof v_iRetryCount != "undefined" )
  3445. {
  3446. retries = v_iRetryCount;
  3447. }
  3448. if (tracking_info=="") {
  3449. if ( retries > 0 )
  3450. {
  3451. var _self = this;
  3452. setTimeout(
  3453. function() {
  3454. _self.sendFetchChildrenRequest(v_oParams, retries-1);
  3455. }, WAIT_FOR_TRACKING_TIMEOUT_MS );
  3456. return;
  3457. }
  3458. }
  3459. if (cafContextId != K_PRMT_sEMPTY) {
  3460. url += "&ui.cafcontextid=" + cafContextId;
  3461. }
  3462. if (this.getMoreData() == true)
  3463. {
  3464. url += "&skipValueCount=" + (this.getSkipValueCount() + this.getTree().getMaxValueCount());
  3465. }
  3466. else
  3467. {
  3468. url += "&skipValueCount=" + this.getSkipValueCount();
  3469. }
  3470. url += "&maximumValueCount=" + this.getTree().getMaxValueCount();
  3471. url += "&paramName=" + encodeURIComponent(this.getTree().getPromptingTree());
  3472. url += "&treeNodeName=" + this.getTree().getName() + this.getTreeRef();
  3473. if (this.getNodeType() != TREE_ROOT)
  3474. {
  3475. url += "&useValue=" + encodeURIComponent(this.getValue());
  3476. url += "&displayValue=" + encodeURIComponent(this.getName());
  3477. }
  3478. if ( v_oParams )
  3479. {
  3480. for( var v_sParamName in v_oParams )
  3481. {
  3482. if ( v_sParamName == "m_tracking" )
  3483. {
  3484. tracking_info = v_oParams[v_sParamName];
  3485. }
  3486. else if ( v_sParamName == "ui.conversation" )
  3487. {
  3488. sConversation = v_oParams[v_sParamName];
  3489. }
  3490. else
  3491. {
  3492. url += "&" + v_sParamName + "=" + encodeURIComponent( v_oParams[v_sParamName] );
  3493. }
  3494. }
  3495. }
  3496. url += "&m_tracking=" + tracking_info;
  3497. url += "&ui.conversation=" + sConversation;
  3498. var v_oRequest = this.getTree().m_oDispatcher.createRequest(this.getTree().getGateway(), url, promptTreeCallback);
  3499. this.getTree().m_oDispatcher.setErrorHandlerFunction(treeErrorHandler);
  3500. this.getTree().m_oDispatcher.dispatchRequest(v_oRequest);
  3501. }
  3502. CTreeNode.prototype.setLoading = function (val)
  3503. {
  3504. this.m_bIsLoading = val;
  3505. };
  3506. CTreeNode.prototype.getLoading = function ()
  3507. {
  3508. return this.m_bIsLoading;
  3509. };
  3510. CTreeNode.prototype.setMoreData = function (val)
  3511. {
  3512. this.m_bIsMoreData = val;
  3513. };
  3514. CTreeNode.prototype.getMoreData = function ()
  3515. {
  3516. return this.m_bIsMoreData;
  3517. };
  3518. CTreeNode.prototype.getIndex = function ()
  3519. {
  3520. if (this.getParent() != null)
  3521. {
  3522. var children = this.getParent().getChildren();
  3523. for (var i = 0; i < children.length; i++)
  3524. {
  3525. if (children[i] == this) {
  3526. return i;
  3527. }
  3528. }
  3529. }
  3530. else
  3531. {
  3532. return null;
  3533. }
  3534. };
  3535. /*
  3536. CTreeNode.prototype.findCommonParent = function (otherNode)
  3537. {
  3538. var i = this.getParent();
  3539. var rootNode = this.getRootNode();
  3540. while(i != rootNode)
  3541. {
  3542. var otheri = otherNode.getParent();
  3543. while (otheri != rootNode)
  3544. {
  3545. if(otheri == i)
  3546. return i;
  3547. otheri = otheri.getParent();
  3548. }
  3549. if(otheri == i)
  3550. return i;
  3551. i = i.getParent();
  3552. }
  3553. return rootNode;
  3554. }
  3555. */
  3556. CTreeNode.prototype.setIndicator = function(sIndicatorSrc)
  3557. {
  3558. // set the indicator value
  3559. this.m_sIndicator = sIndicatorSrc;
  3560. };
  3561. CTreeNode.prototype.getIndicator = function()
  3562. {
  3563. // return the indicator value
  3564. return this.m_sIndicator;
  3565. };
  3566. //definitions for the types of nodes
  3567. function CTreeNodeType(iType, isContainer, sIconSrc, sIconOpenSrc)
  3568. {
  3569. this.m_iType = iType;
  3570. this.m_isContainer = isContainer;
  3571. this.m_sIconSrc = sIconSrc;
  3572. this.m_sIconOpenSrc = sIconOpenSrc;
  3573. this.m_sIconAltText = null;
  3574. this.m_bSelectable = true;
  3575. this.m_bRecursiveSelect = true;
  3576. this.m_bFullChildSelect = true;
  3577. }
  3578. CTreeNodeType.prototype.setSelectable = function(val)
  3579. {
  3580. this.m_bSelectable = val;
  3581. };
  3582. CTreeNodeType.prototype.setAltText = function(altText)
  3583. {
  3584. this.m_sIconAltText = altText;
  3585. };
  3586. CTreeNodeType.prototype.getSelectable = function()
  3587. {
  3588. return this.m_bSelectable;
  3589. };
  3590. CTreeNodeType.prototype.setFullChildSelectable = function(val)
  3591. {
  3592. this.m_bFullChildSelect = val;
  3593. };
  3594. CTreeNodeType.prototype.getFullChildSelectable = function()
  3595. {
  3596. return this.m_bFullChildSelect;
  3597. };
  3598. CTreeNodeType.prototype.setRecursiveSelect = function(val)
  3599. {
  3600. this.m_bRecursiveSelect = val;
  3601. };
  3602. CTreeNodeType.prototype.getRecursiveSelect = function()
  3603. {
  3604. return this.m_bRecursiveSelect;
  3605. };
  3606. function handleWorking(response)
  3607. {
  3608. var responseArray = response.split('","');
  3609. var url = "b_action=xts.run&m=/prompting/promptTree.xts";
  3610. var cafContextId = K_PRMT_sEMPTY; // TODO
  3611. if (cafContextId != K_PRMT_sEMPTY) {
  3612. url += "&ui.cafcontextid=" + cafContextId;
  3613. }
  3614. var treeName = responseArray[1];
  3615. url += "&treeNodeName=" + treeName;
  3616. url += "&doWait=1&m_tracking=" + responseArray[2];
  3617. //DO WE NEED TO GET PARAMETERS FROM SOMEWHERE??? Probably not
  3618. // url += "&doWait=1&m_tracking=" + responseArray[2] + "&parameterValues=" + encodeURIComponent(cfgGet("parameterValues"));
  3619. var treeNode = activeFetchingTreeNode;
  3620. var request = treeNode.getTree().m_oDispatcher.createRequest(treeNode.getTree().getGateway(), url, promptTreeCallback);
  3621. // alert("about to dispatch: [" + url + "]")
  3622. treeNode.getTree().m_oDispatcher.dispatchRequest(request);
  3623. }
  3624. function cleanupActiveFetchingTreeNodeOnError()
  3625. {
  3626. var theNode = activeFetchingTreeNode;
  3627. if (theNode) {
  3628. var theTree = theNode.getTree();
  3629. if (theNode.getShowUI())
  3630. {
  3631. theTree.removeLoading(theNode);
  3632. }
  3633. if (theNode.getChildren().length == 0)
  3634. {
  3635. theNode.setCanHaveChildren(false);
  3636. }
  3637. if (theNode.getShowUI())
  3638. {
  3639. var theNodeRef = theTree.getName() + theNode.getTreeRef();
  3640. theTree.redrawNodeToggle(theNode, theNodeRef);
  3641. theTree.updateSelections(theNode, false);
  3642. theTree.redraw();
  3643. theTree.checkData();
  3644. }
  3645. }
  3646. activeFetchingTreeNode = null;
  3647. }
  3648. CTreeNode.prototype.createNewNode = function(treeNode, tntGeneric, name, value, isSelected)
  3649. {
  3650. new TreeNode(treeNode, tntGeneric, false, jsDecodeStr(name), jsDecodeStr(value), isSelected);
  3651. };
  3652. CTreeNode.prototype.setFetchChildrenFlag = function(bShouldFetch)
  3653. {
  3654. this.bShouldFetchChildren = bShouldFetch;
  3655. };
  3656. function promptTreeCallback(response, reRenderPage)
  3657. {
  3658. // web page(error, timeout, etc) or working response
  3659. if (response != K_PRMT_sEMPTY && !PRMTTreeUtils.isChildrenInfo(response))
  3660. {
  3661. var responseArray = response.split('","');
  3662. if (responseArray[0].substr(1) == "working") {
  3663. setTimeout("handleWorking('" + response + "');", 100);
  3664. } else {
  3665. var v_oTree = activeFetchingTreeNode;
  3666. if ( v_oTree ) { v_oTree = v_oTree.getTree(); }
  3667. var v_oCV = ( v_oTree ? v_oTree.getCV() : null );
  3668. if ( v_oCV && v_oCV.sSkin && typeof response == K_PRMT_sSTRING )
  3669. {
  3670. // add default CSS for this skin before the first <link> tag.
  3671. response = response.replace("<link ", '<link type="text/css" rel="stylesheet" href="' + v_oCV.sSkin + '/portal/default.css">\n<link ');
  3672. }
  3673. response += '<script type="text/javascript">\nif (parent.CTree_setPromptAction){parent.CTree_setPromptAction(this);}\n</script>';
  3674. var v_oIFrame = null;
  3675. if (reRenderPage) {
  3676. v_oIFrame = document.getElementById( 'CTree_IFramePOPUP' );
  3677. v_oIFrame.setAttribute('reRender', true);
  3678. } else {
  3679. CTree_clearIFramePopup();
  3680. v_oIFrame = document.createElement( 'iframe' );
  3681. v_oIFrame.id = 'CTree_IFramePOPUP';
  3682. v_oIFrame.src = "../common/blank.html";
  3683. v_oIFrame.className = "clsPromptDialog";
  3684. var d = ( document.body ? document.body : document.documentElement );
  3685. d.appendChild( v_oIFrame );
  3686. }
  3687. var v_doc = (v_oIFrame && v_oIFrame.contentWindow ? v_oIFrame.contentWindow.document : null);
  3688. if ( v_doc )
  3689. {
  3690. // Enable designMode to prevent issues with long lines and loading scripts in Internet Explorer
  3691. if (window.ie) v_doc.designMode = "On";
  3692. v_doc.open();
  3693. v_doc.writeln( response );
  3694. v_doc.close();
  3695. // Disable designMode to re-enable javascript.
  3696. if (window.ie) v_doc.designMode = "Off";
  3697. }
  3698. PRMTTreeUtils.setPopupFormTarget(v_oIFrame);
  3699. }
  3700. }
  3701. else if (response != K_PRMT_sEMPTY) // children
  3702. {
  3703. var responseArray = response.split('","');
  3704. var moreData = jsDecodeStr(responseArray[1]);
  3705. var skipValueCount = parseInt(jsDecodeStr(responseArray[2]), 10);
  3706. var maxValueCount = parseInt(jsDecodeStr(responseArray[3]), 10);
  3707. var treeNode = activeFetchingTreeNode;
  3708. // Cache the response if caching is enabled.
  3709. treeNode.getTree().setCacheValue(treeNode.getResponseCacheKey() , response);
  3710. if (treeNode && treeNode.createNewNode) {
  3711. var preDataLength = 6; // because we have x values at the beginning that aren't part of any node
  3712. if ( !(responseArray.length == preDataLength && (jsDecodeStr(responseArray[preDataLength - 1]).indexOf('"') > -1)) )
  3713. {
  3714. if ((responseArray.length - preDataLength) % 4 != 0) {
  3715. return false;
  3716. }
  3717. for (var i = preDataLength; i < responseArray.length; i += 4)
  3718. {
  3719. var isSelected = false;
  3720. if (jsDecodeStr(responseArray[i + 3]).charAt(0) == "t")
  3721. {
  3722. isSelected = true;
  3723. }
  3724. treeNode.createNewNode(treeNode, tntGeneric, responseArray[i + 1], responseArray[i + 2], isSelected);
  3725. }
  3726. }
  3727. treeNode.setMoreData(moreData == "true");
  3728. if(moreData == "true")
  3729. {
  3730. treeNode.setFetchChildrenFlag(true);
  3731. }
  3732. treeNode.setSkipValueCount(skipValueCount);
  3733. treeNode.getTree().setMaxValueCount(maxValueCount);
  3734. treeNode.getTree().childrenReadyForNode(treeNode);
  3735. }
  3736. activeFetchingTreeNode = null;
  3737. }
  3738. else
  3739. {
  3740. cleanupActiveFetchingTreeNodeOnError();
  3741. }
  3742. }
  3743. function getMoreDataForTreeNode(evt)
  3744. {
  3745. //get the event in a cross-browser fashion
  3746. evt = (evt) ? evt : ((event) ? event : null);
  3747. // don't return when Enter, ArrowRight, ArrowUp or undefined keys are pressed
  3748. if ((evt !== null) && (evt.keyCode != null) && (evt.keyCode != K_KEY_UP) && (evt.keyCode != K_KEY_RIGHT) && (evt.keyCode != K_KEY_ENTER) && (evt.keyCode !== 0) && (evt.keyCode != K_KEY_TAB || !evt.shiftKey))
  3749. {
  3750. return false;
  3751. }
  3752. //cancel any text selection
  3753. clearSelection();
  3754. //prevent the event from bubbling to other elements
  3755. cancelBub(evt);
  3756. //get UI Node
  3757. var uiNode = null;
  3758. if ( evt.target )
  3759. {
  3760. uiNode = evt.target;
  3761. }
  3762. else if ( evt.srcElement )
  3763. {
  3764. uiNode = evt.srcElement;
  3765. }
  3766. else
  3767. {
  3768. return false;
  3769. }
  3770. var uiNodeTreeRef = uiNode.getAttribute(gsCTREE_treeRef).toString();
  3771. //get the tree object
  3772. var tree = uiNode.getAttribute(gsCTREE_tree).toString();
  3773. //get tree Node
  3774. var node = getTreeNode(tree, uiNodeTreeRef);
  3775. if (typeof activeFetchingTreeNode == K_PRMT_sUNDEFINED || activeFetchingTreeNode == null)
  3776. {
  3777. // expand the node when Enter or ArrowRight keys are pressed
  3778. if (evt.keyCode == K_KEY_ENTER || evt.keyCode == K_KEY_RIGHT || evt.keyCode == 0 || evt.keyCode == null)
  3779. {
  3780. node.getTree().removeMoreData(node, node.getTree().getName() + node.getTreeRef());
  3781. node.fetchChildren(true);
  3782. }
  3783. var v_oTree = node.getTree();
  3784. if (v_oTree)
  3785. {
  3786. // if the pressed key is ArowUp then move the focus to the previous node which is the last sibling before More node
  3787. // there will always be a previous node for a More node
  3788. // do the same if the Shift+Tab keys are both pressed
  3789. // otherwise, i.e. for ArrowRight, ArrowLeft, Enter, and undefined keys, move the focus to the parent node
  3790. // there will always be a parent node for a More node
  3791. // note that the user should be forced to collapse the parent node to navigate to its next sibling
  3792. // the More link loses the focus but it should still be tab-able
  3793. var moreDataNode = v_oTree.m_lastFocus;
  3794. if (evt.keyCode == K_KEY_UP || (evt.keyCode == K_KEY_TAB && evt.shiftKey) || evt.keyCode == K_KEY_RIGHT || evt.keyCode == K_KEY_ENTER || evt.type == gsCTREE_click)
  3795. {
  3796. // the last child of 'node' is the node before More node
  3797. v_oTree.f_moveFocus(null, node.getLastChild());
  3798. }
  3799. else
  3800. {
  3801. v_oTree.f_moveFocus(null, node);
  3802. }
  3803. // make the more data node tab-able
  3804. moreDataNode.tabIndex = 0;
  3805. }
  3806. }
  3807. }
  3808. function treeErrorHandler(errorStoppedAt, e)
  3809. {
  3810. // alert("errorHandler broke at: [" + errorStoppedAt + "]\nwith message: [" + e.message + "]\nin file: [" + e.fileName + "]\nat line: [" + e.lineNumber + "]");
  3811. }
  3812. function CTree_clearIFramePopup()
  3813. {
  3814. var v_oIFrame = null;
  3815. while( v_oIFrame = document.getElementById( 'CTree_IFramePOPUP' ) )
  3816. {
  3817. v_oIFrame.parentNode.removeChild( v_oIFrame );
  3818. delete v_oIFrame;
  3819. }
  3820. G_CTREE_IFramePopupWindow = null;
  3821. }
  3822. function CTree_promptAction(sAction, sArg)
  3823. {
  3824. var v_oCV = PRMTTreeUtils.getCVObjectFromActiveTree();
  3825. if ( v_oTree ) { v_oTree = v_oTree.getTree(); }
  3826. var v_oCV = ( v_oTree ? v_oTree.getCV() : null );
  3827. if ( sAction == K_ACTION_CANCEL )
  3828. {
  3829. // we use setTimeout to start a different thread for the request.
  3830. // Otherwise, the request aborts in Firefox when this function ends.
  3831. setTimeout( v_oCV.promptAction.bind( v_oCV, sAction, sArg ), 10 );
  3832. }
  3833. else
  3834. {
  3835. var aPreProcess = G_CTREE_IFramePopupWindow.getPreProcessControlArray();
  3836. if (aPreProcess)
  3837. {
  3838. G_CTREE_IFramePopupWindow.preProcessForm(aPreProcess);
  3839. var ar = aPreProcess;
  3840. var kCount = ar.length;
  3841. var k = 0;
  3842. var sXML = K_PRMT_sEMPTY;
  3843. var v_oParams = {};
  3844. for (k=0; k<kCount; k++)
  3845. {
  3846. var v_oPC = G_CTREE_IFramePopupWindow.eval(ar[k]);
  3847. v_oParams[ v_oPC.m_oSubmit.name ] = v_oPC.sGetValue();
  3848. }
  3849. if ( G_CTREE_IFramePopupWindow.PT_CONVERSATION_INFO ) {
  3850. v_oParams[ "PT_CONVERSATION_INFO" ] = G_CTREE_IFramePopupWindow.PT_CONVERSATION_INFO;
  3851. }
  3852. if ( G_CTREE_IFramePopupWindow.PT_TRACKING ) {
  3853. v_oParams[ "m_tracking" ] = G_CTREE_IFramePopupWindow.PT_TRACKING;
  3854. }
  3855. // we use setTimeout to start a different thread for the request.
  3856. // Otherwise, the request aborts in Firefox when this function ends.
  3857. setTimeout( activeFetchingTreeNode.sendFetchChildrenRequest.bind( activeFetchingTreeNode, v_oParams ), 10 );
  3858. }
  3859. }
  3860. CTree_clearIFramePopup();
  3861. }
  3862. var PRMTTreeUtils =
  3863. {
  3864. f_addEvent: function( v_oElement, v_sType, v_oFct, v_bUseCapture ) {
  3865. v_bUseCapture = !v_bUseCapture ? false : v_bUseCapture;
  3866. if ( v_oElement )
  3867. {
  3868. if ( v_oElement.addEventListener )
  3869. {
  3870. v_oElement.addEventListener( v_sType, v_oFct, v_bUseCapture );
  3871. }
  3872. else
  3873. {
  3874. v_oElement.attachEvent('on' + v_sType, v_oFct );
  3875. }
  3876. }
  3877. },
  3878. isHTMLPage: function (sArg) {
  3879. // html starts with '<!DOCTYPE html' or <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">'
  3880. var reHTML = new RegExp("^<(!DOCTYPE )?html", "i");
  3881. var result = (sArg.match( reHTML )? true : false);
  3882. return result;
  3883. },
  3884. isChildrenInfo: function (sArg) {
  3885. // children info is in JSON format inside a minimal html wrapper, the json content starts 'var j="CTree'
  3886. var reHTML = new RegExp("j=\\[\"CTree", "i");
  3887. var result = (sArg.match( reHTML )? true : false);
  3888. return result;
  3889. },
  3890. mergeChildrenInfo: function(sArg1, sArg2) {
  3891. //helper function to merge two different sets of children info for the same tree node into one html wrapper
  3892. //1. extract child information from html wrapper in sArg2
  3893. //2. merge extracted child information with cached child info in sArg1
  3894. var retVal = "";
  3895. var parts = sArg1.split('","');
  3896. var cachedSkipValueCount = parseInt(jsDecodeStr(parts[2]), 10);
  3897. var extractedVal = '","';
  3898. var childInfo = sArg2.split('","');
  3899. var responseSkipValueCount = parseInt(jsDecodeStr(childInfo[2]), 10);
  3900. var newSkipValueCount = cachedSkipValueCount + responseSkipValueCount;
  3901. parts[2] = jsEncodeStr(newSkipValueCount.toString());
  3902. retVal = parts.join('","');
  3903. var indexOfClosingTag = childInfo[childInfo.length - 1].lastIndexOf("</script>");
  3904. childInfo[childInfo.length - 1] = childInfo[childInfo.length - 1].substring(0, indexOfClosingTag);
  3905. childInfo = childInfo.splice(6, childInfo.length);
  3906. for (var i = 0; i < childInfo.length; i++)
  3907. {
  3908. extractedVal += childInfo[i];
  3909. if(i != (childInfo.length - 1))
  3910. {
  3911. extractedVal += '","';
  3912. }
  3913. }
  3914. retVal = retVal.replace("\"]</script>", extractedVal + "</script>");
  3915. return retVal;
  3916. },
  3917. getCVObjectFromActiveTree: function () {
  3918. var v_oTree = activeFetchingTreeNode;
  3919. if ( v_oTree ) { v_oTree = v_oTree.getTree(); }
  3920. var v_oCV = ( v_oTree ? v_oTree.getCV() : null );
  3921. return v_oCV;
  3922. },
  3923. getIframeDoc: function (v_iFrame) {
  3924. var v_oDoc = null;
  3925. if (v_iFrame) {
  3926. if (v_iFrame.contentDocument) {
  3927. v_oDoc = v_iFrame.contentDocument;
  3928. } else if (v_iFrame.contentWindow && v_iFrame.contentWindow.document) {
  3929. v_oDoc = v_iFrame.contentWindow.document;
  3930. } else if (v_iFrame.document) {
  3931. v_oDoc = v_iFrame.document;
  3932. }
  3933. }
  3934. return v_oDoc;
  3935. },
  3936. f_iFramePopupExists: function() {
  3937. var v_oIFrame = null;
  3938. var result = false;
  3939. v_oIFrame = document.getElementById( 'CTree_IFramePOPUP' );
  3940. if (v_oIFrame && v_oIFrame.reRender) {
  3941. result = true;
  3942. }
  3943. return result;
  3944. },
  3945. f_createTargetIFrame: function () { // create/recycle target iframe
  3946. var v_sIFrameId = 'CTree_IFramePOPUPTarget';
  3947. //remove if exists
  3948. var v_targetIframe = $(v_sIFrameId);
  3949. if (v_targetIframe) { // and PRMTUtils.f_isDOMElem(v_alertDiv))
  3950. PRMTUtils.f_removeElement(v_targetIframe.parent);
  3951. }
  3952. // create a new one
  3953. var v_oEle = document.createElement('DIV');
  3954. v_oEle.innerHTML = '<iframe style="display:none" src="about:blank" content="text/xml" id="'+v_sIFrameId+'" name="'+ v_sIFrameId + '"></iframe>';
  3955. document.body.appendChild(v_oEle);
  3956. var iFrame = document.getElementById(v_sIFrameId);
  3957. PRMTUtils.f_addEvent(iFrame, "load", PRMTTreeUtils.f_popupSubmitCallback);
  3958. return v_sIFrameId;
  3959. },
  3960. f_popupSubmitCallback: function () {
  3961. var v_oIFrame = (window.ie?document.getElementById('CTree_IFramePOPUPTarget'):this);
  3962. var v_oDoc = (v_oIFrame.contentDocument? v_oIFrame.contentDocument : (v_oIFrame.contentWindow? v_oIFrame.contentWindow.document : v_oIFrame.document) );
  3963. if (v_oDoc && v_oDoc.location && v_oDoc.location.href != "about:blank") {
  3964. // extract response string
  3965. var responseString = null;
  3966. if (v_oDoc.implementation && v_oDoc.implementation.createDocument) {
  3967. var v_oSerializer = new XMLSerializer();
  3968. responseString = v_oSerializer.serializeToString(v_oDoc);
  3969. } else { // IE
  3970. if (null != v_oDoc.body.parentNode.innerHTML) {
  3971. responseString = v_oDoc.body.parentNode.innerHTML;
  3972. } else {
  3973. return;
  3974. }
  3975. }
  3976. if (PRMTTreeUtils.isChildrenInfo(responseString)) {
  3977. parent.CTree_clearIFramePopup();
  3978. parent.promptTreeCallback(responseString);
  3979. } else {
  3980. // check to skip double submit
  3981. if (!parent.PRMTTreeUtils.f_iFramePopupExists()) {
  3982. parent.promptTreeCallback(responseString, true);
  3983. }
  3984. }
  3985. }
  3986. }
  3987. };
  3988. /**
  3989. * Target the form in the popup iframe to a hidden iframe where we can parse the response
  3990. */
  3991. var K_PRMT_WAIT_FOR_POPUP_TIMEOUT_MS = 100; // 100 milliseconds
  3992. var K_PRMT_POPUP_RETRY_CNT_MAX = 500; // 500 * 100 ms = 50 seconds worth of trying
  3993. PRMTTreeUtils.setPopupFormTarget = function(iframe, v_iRetryCount) {
  3994. var v_iframeDoc = null;
  3995. var v_aForms = null;
  3996. var v_targetIframeId = null;
  3997. try {
  3998. v_iframeDoc = PRMTTreeUtils.getIframeDoc(iframe);
  3999. if (v_iframeDoc && v_iframeDoc.getElementsByTagName) {
  4000. v_aForms = v_iframeDoc.getElementsByTagName('form');
  4001. }
  4002. var retries = K_PRMT_POPUP_RETRY_CNT_MAX;
  4003. if ( typeof v_iRetryCount != "undefined" ) {
  4004. retries = v_iRetryCount;
  4005. }
  4006. } catch(e) {
  4007. // trace(e.message);
  4008. }
  4009. if ( v_aForms && v_aForms.length > 0 ) {
  4010. v_targetIframeId = PRMTTreeUtils.f_createTargetIFrame();
  4011. var v_oForm = v_aForms[0];
  4012. v_oForm.setAttribute('target', v_targetIframeId);
  4013. if (iframe.reRender) {
  4014. iframe.removeAttribute('reRender');
  4015. }
  4016. } else {
  4017. if ( retries > 0 ) {
  4018. setTimeout( function() { PRMTTreeUtils.setPopupFormTarget(iframe, retries-1); }, K_PRMT_WAIT_FOR_POPUP_TIMEOUT_MS );
  4019. return;
  4020. }
  4021. }
  4022. };
  4023. function CTree_setPromptAction( v_oWin )
  4024. {
  4025. var v_oCV = v_oWin.oCV;
  4026. if ( v_oCV )
  4027. {
  4028. G_CTREE_IFramePopupWindow = v_oWin;
  4029. v_oCV.promptAction = CTree_promptAction;
  4030. }
  4031. if ( v_oWin.doCancel )
  4032. {
  4033. v_oWin.doCancel = CTree_promptAction.bind( this, K_ACTION_CANCEL );
  4034. }
  4035. }
  4036. //skin folder
  4037. var PROMPT_SKIN = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  4038. var PROMT_IMAGES = PROMPT_SKIN + "/prompting/images/";
  4039. //Constants
  4040. var TREE_ROOT = 0;
  4041. var TREE_FOLDER = 1;
  4042. var TREE_ITEM = 2;
  4043. //Selection Constants
  4044. // Allow only a single node to be selected (default)
  4045. var SINGLE_TREE_SELECTION = 0;
  4046. // Allow multiple selections of visible nodes
  4047. var DISCONTIGUOUS_TREE_SELECTION = 1;
  4048. // Allow selection to span one vertical contiguous set of nodes
  4049. var CONTIGUOUS_TREE_SELECTION = 2;
  4050. //Tree Type Constant
  4051. var NORMAL_TREE = "normalTree";
  4052. var CHECKBOX_TREE = "checkboxTree";
  4053. //Tree Classes
  4054. var CLS_TREE_TEXT = "clsTreeText";
  4055. var CLS_TREE_TEXT_LINK = "clsTreeText aLink";
  4056. var CLS_TREE_TEXT_NO_LINK = "clsTreeText noLink";
  4057. var CLS_TREE_LEVEL = "clsTreeLevel";
  4058. var CLS_TREE_NODE_SELECTED = "clsTreeNode_selected";
  4059. var CLS_TREE_NODE_PARTIAL = "clsTreeNode_partial";
  4060. var CLS_TREE_NODE_UNSELECTED = "clsTreeNode_unselected";
  4061. var CLS_TREE_NODE_HOVER = "clsTreeNode_hover";
  4062. var CLS_TRE_EXPAND_COLLAPSE_HOVER = "clsExpandCollapseHover clsTextIconAlignFix";
  4063. var CLS_TREE_TEXTICON_ALIGNFIX = "clsTextIconAlignFix";
  4064. //tree node types
  4065. var tntRoot = new CTreeNodeType(TREE_ROOT, true, PROMT_IMAGES + "icon_tree_folder_closed.gif", PROMT_IMAGES + "icon_tree_folder_open.gif");
  4066. var tntFolder = new CTreeNodeType(TREE_FOLDER, true, PROMT_IMAGES + "icon_tree_folder_closed.gif", PROMT_IMAGES + "icon_tree_folder_open.gif");
  4067. var tntLeaf = new CTreeNodeType(TREE_ITEM, false, PROMT_IMAGES + "icon_tree_leaf.gif", PROMT_IMAGES + "icon_tree_leaf.gif");
  4068. //tri-state checkboxes have the following states:
  4069. // node is selected
  4070. // node is not selected
  4071. // node has some or all children that are selected
  4072. var CHECKBOX_UNSELECTED = PROMT_IMAGES + "checkbox_unchecked.gif";
  4073. var CHECKBOX_PARTIAL = PROMT_IMAGES + "checkbox_mixed.gif";
  4074. var CHECKBOX_SELECTED = PROMT_IMAGES + "checkbox_checked.gif";
  4075. //Error state graphics
  4076. var ERROR_TIMED_SMALL_OFF = PROMT_IMAGES + "error_timed_small_off.gif";
  4077. var ERROR_TIMED_SMALL = PROMT_IMAGES + "error_timed_small.gif";
  4078. var NODE_UNSELECTED = 0;
  4079. var NODE_PARTIAL = 1;
  4080. var NODE_SELECTED = 2;
  4081. //line connector definitions
  4082. var TREE_T_PLUS = PROMT_IMAGES + "icon_tree_Tplus.gif";
  4083. var TREE_T_MINUS = PROMT_IMAGES + "icon_tree_Tminus.gif";
  4084. var TREE_T_ONLY = PROMT_IMAGES + "icon_tree_T.gif";
  4085. var TREE_L_PLUS = PROMT_IMAGES + "icon_tree_Lplus.gif";
  4086. var TREE_L_MINUS = PROMT_IMAGES + "icon_tree_Lminus.gif";
  4087. var TREE_L_ONLY = PROMT_IMAGES + "icon_tree_L.gif";
  4088. var TREE_L_ONLY_RTL = PROMT_IMAGES + "icon_tree_L_rtl.gif";
  4089. var TREE_I_ONLY = PROMT_IMAGES + "icon_tree_I.gif";
  4090. var TREE_SPACE = PROMT_IMAGES + "icon_tree_white.gif";
  4091. //loading icon
  4092. var TREE_LOADING = PROMT_IMAGES + "loading_timed.gif";
  4093. //more data icon
  4094. var TREE_MORE_DATA = PROMT_IMAGES + "icon_more.gif";
  4095. var G_CTREE_IFramePopupWindow = null;
  4096. // Event Studio is not loading externsions.js so repeating browser id
  4097. if (typeof window.ie === 'undefined') {
  4098. if (!!window.MSInputMethodContext && !!document.documentMode && (document.documentMode == 11)) { window.ie = window.ie11 = true; }
  4099. else if (document.childNodes && !document.all && !navigator.taintEnabled && !!window.StyleMedia) { window.ie = window.ie11 = window.edge = true; }
  4100. else if (document.all && !!window.atob) { window.ie = window['ie10'] = true; }
  4101. else if (document.all && !!document.addEventListener) { window.ie = window['ie9'] = true; }
  4102. else if (document.all && !!document.querySelector) { window.ie = window['ie8'] = true; }
  4103. else if (document.all && !!window.XMLHttpRequest) { window.ie = window['ie7'] = true; }
  4104. else if (document.all && !!document.compatMode) { window.ie = window['ie6'] = true; }
  4105. else if (document.all) { window.ie = window['ie5'] = true; }
  4106. };