ViewerIWidget.js 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2018
  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. dojo.provide("bux.reportViewer");
  13. dojo.require("dojo.buxViewer"); // This is an optimized layer, it should have the required dojo/dijit dependencies in it.
  14. dojo.require("bux.AnnotationHelper");
  15. dojo.require("bux.AnnotationIndicator");
  16. dojo.require("viewer.AnnotationHelper");
  17. dojo.require("bux.data.AnnotationStore");
  18. dojo.require("bux.iwidget.common.MultilingualWidgetBase");
  19. dojo.require("InfoBarBase");
  20. dojo.require("WidgetContextManager");
  21. var globalViewerIdentifier = 1;
  22. dojo.declare("bux.reportViewer", bux.iwidget.common.MultilingualWidgetBase, {
  23. annotationStore: null,
  24. annotationHelper: null,
  25. savedOutput: null,
  26. undoRedoQueue: null,
  27. dojoConnections : null, //An array to manage all connections to be disconnected.
  28. properties: null,
  29. promptParametersRetrieved: false,
  30. viewerId: null,
  31. xNodeId: null,
  32. //This value is included in the cv.id parameter in order to ensure that
  33. //the value begins with a letter. This is to guard against javascript
  34. //variable naming errors (a js var starting with a number is illegal).
  35. namespacePrefix: "x",
  36. //Timer for global callback necessary to make sure all scripts are loaded
  37. //and executed before continuing
  38. timer: null,
  39. //Interval (in milliseconds) for global script loader callback
  40. timerInterval: 20,
  41. //This constant must match the version value in ViewerIWidget.xml
  42. GODASHBOARD_REPORT_VERSION: "1.0.0.0",
  43. BUX_REPORT_VERSION: "4.0.0.0.0", //Colorado RP1 version was "1.0.0.0.0", Caspian GA version was "2.0.0.0"
  44. BUX_REPORT_CASPIAN_RP1_VERSION: "3.0.0.0.0",
  45. RAP_REPORT_INFO_VERSION: "1.0.0.0", //Caspian was "1.0.0.0.0"
  46. //This object is to hold last action and parameters at of IWidget level.
  47. //If response is unexpected and Viewer object does not exist, this Widget level last action may be used for resubmit.
  48. viewerWidgetLastAction: null,
  49. //An object that holds the state of all sliders on the canvas affecting this widget.
  50. sliderState: null,// moved this.sliderState = {}; to constructor to make it instance variable
  51. sViewerIWidgetId: null,
  52. bToolbarInitialized: false,
  53. m_oWidgetContextManager: null,
  54. //An object that holds states of whether infoBar is collasped or expanded. A widget can have many infoBars.
  55. m_oInfoBarRenderedState: {},
  56. m_bRunReportOption : null,
  57. m_oLoadManager: null,
  58. m_visible: null,
  59. //BEGIN DEBUG CODE
  60. // When delayed viewer loading implementation is complete, this variable and parts of the code which
  61. // reference it can be removed. It has three values:
  62. // 0 - use all new code (development mode)
  63. // 1 - run reports and load viewers on workspace load, but do not run reports when they are not visible
  64. // 2 - always run reports (existing behaviour)
  65. m_debugDelayedViewerLoadingMode: 0,
  66. //END DEBUG CODE
  67. m_delayedLoadingContext : null,
  68. m_doGetParametersOnLoad : null,
  69. widgetSize : null,
  70. //widget resource from widget copy/paste action
  71. copyPasteResource : null,
  72. _pastedWidget : false,
  73. //in CI published dashboard , report widget doesn't have originalReport instead we have to use savedReportPath
  74. // when we do copy/paste to set this variable for setting ui.object ,
  75. //ui.object will be used to query environment variables such as object permissions
  76. ciPublishedReportPath : null,
  77. touchStartX : -1, //For touch handling, need to track the startX
  78. touchPaging : false, //True when this widget is paging as a result of a touch.
  79. _BUXDBInfoArray: null, //bux run time state information saved inside widget rsstate itemsets
  80. m_bSelectionFilterSwitch: false,
  81. savedToolbarButtons: null,
  82. constructor: function() {
  83. this.onUnloadInProgress = false;
  84. this.annotationHelper = new viewer.AnnotationHelper(this);
  85. this.savedOutput = new CIWidgetSavedOutput(this);
  86. this.undoRedoQueue = new UndoRedoQueue(this);
  87. this.viewerIdentifier = (globalViewerIdentifier++).toString();
  88. this.m_oCV = null;
  89. this.m_oLoadManager = new ViewerLoadManager(this);
  90. this.m_doGetParametersOnLoad = false;
  91. this._isMobile = false;
  92. this.m_bSelectionFilterSwitch = false;
  93. this.m_oWidgetContextManager = new WidgetContextManager(this);
  94. this.addWindowEventListeners();
  95. this.m_bReportDropped = false;
  96. this.sliderState = {};
  97. this.savedToolbarButtons = {};
  98. },
  99. getWidgetId: function() {
  100. return this.sViewerIWidgetId;
  101. },
  102. getAnnotationHelper: function() {
  103. return this.annotationHelper;
  104. },
  105. getUndoRedoQueue: function() {
  106. return this.undoRedoQueue;
  107. },
  108. getDisplayName: function() {
  109. var buxrtstate = this.iContext.getItemSet("buxrtstate", false);
  110. if( buxrtstate ){
  111. var result = buxrtstate.getItemValue("displayTitle");
  112. return result? result : "";
  113. }
  114. return "";
  115. },
  116. getSavedOutput: function() {
  117. return this.savedOutput;
  118. },
  119. getAttributeValue: function(name) {
  120. return this.iContext.getiWidgetAttributes().getItemValue(name);
  121. },
  122. setAttributeValue: function(name, value) {
  123. this.iContext.getiWidgetAttributes().setItemValue(name, value);
  124. },
  125. removeAttributeValue: function(name) {
  126. this.iContext.getiWidgetAttributes().removeItem(name);
  127. },
  128. getViewerObject: function() {
  129. if(!this.m_oCV) {
  130. try {
  131. this.m_oCV = window["oCV" + this.getViewerId()];
  132. }
  133. catch (ex) {
  134. //In Internet Explorer, if the variable has been previously deleted, an exception is
  135. //thrown when trying to reference it.
  136. //Since you can't even check for the existence of the variable without referencing it,
  137. //ignore the exception and return null.
  138. return null;
  139. }
  140. if(!this.m_oCV) {
  141. var widgetId = this.getWidgetId();
  142. for (var iIndex=0; iIndex < window.gaRV_INSTANCES.length; iIndex++) {
  143. // a final try to find the correct CCognosViewer object. Loop through all the Viewer's to
  144. // if any have the correct widgetId
  145. if (window.gaRV_INSTANCES[iIndex].widgetId == widgetId) {
  146. this.m_oCV = window.gaRV_INSTANCES[iIndex];
  147. var oldId = this.getViewerId();
  148. var newId = this.m_oCV.getId();
  149. this.setViewerId(newId);
  150. // We're switching the Viewer ID, we should update the namespaceId attribute of the elements in the head
  151. // so that they get correctly cleaned up when the widget is deleted
  152. var headChildNodes = document.getElementsByTagName("head").item(0).childNodes;
  153. // Loops through all the nodes in the head
  154. for (var i=0; i < headChildNodes.length; i++) {
  155. var node = headChildNodes[i];
  156. if (node.getAttribute && node.getAttribute("namespaceId") == oldId) {
  157. node.setAttribute("namespaceId", newId);
  158. }
  159. }
  160. break;
  161. }
  162. }
  163. }
  164. }
  165. return this.m_oCV;
  166. },
  167. setViewerId: function(id) {
  168. this.viewerId = id;
  169. },
  170. getViewerId: function() {
  171. if (!this.viewerId) {
  172. this.viewerId = this.namespacePrefix + this.viewerIdentifier;
  173. }
  174. return this.viewerId;
  175. },
  176. getLoadManager: function() {
  177. return this.m_oLoadManager;
  178. },
  179. /**
  180. * Report blocker is a div that blocks any event when a request is being processed.
  181. */
  182. getReportBlocker: function()
  183. {
  184. if( !this.m_reportBlocker )
  185. {
  186. this.m_reportBlocker = new Blocker( this.m_oCV.getId());
  187. }
  188. return this.m_reportBlocker;
  189. },
  190. placeTabControlInView: function() {
  191. var oCV = this.getViewerObject();
  192. if (oCV && oCV.getTabController()) {
  193. if (oCV.getTabController().getSelectedTab() && oCV.getTabController().getSelectedTab().getFocusableDiv()) {
  194. oCV.setKeepFocus(oCV.getTabController().getSelectedTab().getFocusableDiv());
  195. }
  196. dojo.window.scrollIntoView(oCV.getTabController().getWrapperDiv());
  197. }
  198. },
  199. setReportBlocker: function( reportBlocker ){
  200. this.m_reportBlocker = reportBlocker;
  201. },
  202. isSavedOutput: function() {
  203. var viewerObject = this.getViewerObject();
  204. if(typeof viewerObject !== "undefined" && viewerObject !== null) {
  205. var action = (viewerObject.envParams["ui.action"]);
  206. return ( action === 'view' || action === 'buxView');
  207. }
  208. return false;
  209. },
  210. isMobile: function() {
  211. return this._isMobile;
  212. },
  213. getEmbeddedMobileItem: function() {
  214. var isMobile = false;
  215. var buxrtstate = this.iContext.getItemSet("buxrtstate", false);
  216. if( buxrtstate ){
  217. isMobile = buxrtstate.getItemValue("embeddedMobile") == "true" ? true : false;
  218. }
  219. return isMobile;
  220. },
  221. /**
  222. *Concat the cached info with dynamic info
  223. **/
  224. getBUXRTStateInfoMap: function(extraInfo/*a String of XML content*/){
  225. if(!window.icdConfig || !window.icdConfig.ZIPIMode || window.icdConfig.ZIPIMode === "0"){ //0:off 1:concise 2:verbose
  226. return "";
  227. }
  228. var aResult=["<RTStateInfo>"];
  229. if(extraInfo && extraInfo.length>0){
  230. aResult.push(extraInfo);//Add passed in extra info
  231. }
  232. var sWidgetTitle = this.getDisplayName();
  233. if(sWidgetTitle && sWidgetTitle.length>0){
  234. aResult.push("<widgetTitle>",xml_encode(sWidgetTitle),"</widgetTitle>");//Add widget Title
  235. }
  236. if(this._BUXDBInfoArray && this._BUXDBInfoArray.length >0){
  237. aResult = aResult.concat(this._BUXDBInfoArray);//Add cached dashboard info
  238. }
  239. aResult.push("</RTStateInfo>")
  240. return aResult.length>2 ? aResult.join("") : "";
  241. },
  242. /**
  243. * Cache the dashboard object information within the lifecycle of one viewer widget
  244. **/
  245. getBUXDBInfoArray: function(updateInfo){
  246. var sDBTitle = null;
  247. var sDBSearchPath = null;
  248. if(updateInfo){
  249. sDBTitle = updateInfo.dbTitle;
  250. sDBSearchPath = updateInfo.dbSearchPath;
  251. }else{
  252. var buxrtstate = this.iContext.getItemSet("buxrtstate", false);
  253. if( buxrtstate ){
  254. sDBTitle = buxrtstate.getItemValue("dbTitle");
  255. sDBSearchPath = buxrtstate.getItemValue("dbSearchPath");
  256. }
  257. }
  258. var aResult = [];
  259. if(sDBTitle && sDBSearchPath && sDBSearchPath.length >0){
  260. aResult.push("<dbTitle>", xml_encode(sDBTitle),"</dbTitle><dbSearchPath>",xml_encode(sDBSearchPath),"</dbSearchPath>");
  261. }
  262. return aResult;
  263. },
  264. loadExtraJavascriptFiles: function(webContent) {
  265. if (typeof CSelectionContext == "undefined") {
  266. this._loadFile("/drill/CSelectionContextBuilder.js", webContent);
  267. }
  268. this._loadFile("/mdsrv/lineage.js", webContent);
  269. if (window.cognosViewerDebug) {
  270. this._loadFile("/rv/viewer.extra.debug.js", webContent);
  271. }
  272. else {
  273. this._loadFile("/rv/viewer.extra.js", webContent);
  274. }
  275. },
  276. _loadFile: function(sPath, webContent) {
  277. /**
  278. * There's an issue with how dojo loads scripts and how IE handles eval.
  279. * Here's a reference to the issue http://trac.dojotoolkit.org/ticket/744
  280. * To fix this, we'd have to change all our global to have window., so instead of foo = "a" it would need to be window.foo = "a"
  281. * If webContentRoot starts with .. dojo with use the dojo path to try and load the file
  282. */
  283. if (dojo.isIE || dojo.isTrident || webContent.indexOf("..") == 0) {
  284. var responseText = window.gScriptLoader.loadFile(webContent + sPath, "", "GET");
  285. var scriptElement = document.createElement('script');
  286. scriptElement.type = "text/javascript";
  287. scriptElement.text = responseText;
  288. document.getElementsByTagName('head')[0].appendChild(scriptElement);
  289. }
  290. else {
  291. dojo._loadPath(webContent + sPath, null);
  292. }
  293. },
  294. _getCWALaunchInformation: function() {
  295. var args = {
  296. url: this.buildPostUrl(),
  297. sync: false,
  298. handleAs: "json",
  299. preventCache: true,
  300. content: {
  301. "b_action" : "cognosViewer",
  302. "ui.action" : "noOp",
  303. "cv.responseFormat" : "getCWALaunchParameters"
  304. },
  305. error: dojo.hitch(this, function(response) {
  306. this.fireEvent("com.ibm.bux.widget.render.done", null, {noAutoResize:true});
  307. this.fireEvent("com.ibm.bux.widget.notification", null, {type: "error", message: response.message, description: response.description});
  308. }),
  309. load: dojo.hitch(this, function(response, ioArgs) {
  310. var responseContentType = ioArgs.xhr.getResponseHeader("Content-Type");
  311. if (responseContentType && responseContentType.indexOf("text/html") != -1 && response && response.match(/<ERROR_CODE>CAM_PASSPORT_ERROR<\/ERROR_CODE>/)) {
  312. this.handlePassportErrorFromDispatcher();
  313. } else {
  314. this._launchCWA(response);
  315. }
  316. })
  317. };
  318. dojo.xhrPost(args);
  319. },
  320. _launchCWA: function(response) {
  321. if (response) {
  322. if (typeof NewReportAction == "undefined") {
  323. this.loadExtraJavascriptFiles(response.webContentRoot);
  324. if (response.productLocale != "en") {
  325. this._loadFile("rv/res/viewer_" + response.productLocale + ".js", response.webContentRoot);
  326. }
  327. }
  328. var action = new NewReportAction();
  329. action.setRequestParms({
  330. "packageSearchPath" : this.getAttributeValue("packageSearchPath"),
  331. "viewerIWidget" : this,
  332. "webContentRoot" : response.webContentRoot,
  333. "gateway" : response.gateway,
  334. "capabilitiesXml" : response.capabilitiesXML,
  335. "cafContextId" : response.cafContextId
  336. });
  337. this.removeAttributeValue("packageSearchPath");
  338. action.execute();
  339. }
  340. },
  341. /**
  342. * When we get the response from CWA for a new report, we need to set the information here
  343. * so that our buildPostContent method can pick it up.
  344. */
  345. setNewReportInfo: function(info) {
  346. this._newReportInfo = info;
  347. },
  348. /**
  349. * User hit cancel on the select a package dialog, remove the widget
  350. */
  351. _handleFileDialogCancel : function() {
  352. this.fireEvent("com.ibm.bux.widget.action", null, { action: 'deleteWidget' });
  353. },
  354. /**
  355. * User selected a package and hit Ok. Set the searchPath to the package
  356. * as the 'packageSearchPath' itemSet and recall the onLoad function so that we
  357. * can piggy pack of the functionality of creating a new report from the content tree
  358. */
  359. _handleFileDialogOk : function(storeId) {
  360. this.removeAttributeValue("newReport");
  361. this.setAttributeValue("packageSearchPath", "storeID(\"" + storeId + "\")");
  362. this.onLoad();
  363. },
  364. onLoad: function() {
  365. this.sViewerIWidgetId = this.iContext.getRootElement().id;
  366. // If we're creating a new report we don't need to run anything else in ViewerIWidget until we get
  367. // the report spec back from CWA
  368. if (this.getAttributeValue("packageSearchPath")) {
  369. this._getCWALaunchInformation();
  370. return;
  371. }
  372. else if (this.getAttributeValue("newReport") === "true") {
  373. dojo["require"]("bux.dialogs.FileDialog"); //@lazyload
  374. var oDlg = new bux.dialogs.PackageDialog({
  375. onCancelHandler: dojo.hitch(this, this._handleFileDialogCancel),
  376. selectPackageHandler: dojo.hitch(this, this._handleFileDialogOk)
  377. });
  378. oDlg.startup();
  379. oDlg.show();
  380. return;
  381. }
  382. var viewerConcurrentRequestLimit = this.getAttributeValue("ViewerConcurrentRequestLimit");
  383. if (viewerConcurrentRequestLimit) {
  384. this.removeAttributeValue("ViewerConcurrentRequestLimit");
  385. if(!window['gReportWidgetLoadQueue']) {
  386. window['gReportWidgetLoadQueue'] = new ReportWidgetLoadQueue(viewerConcurrentRequestLimit);
  387. }
  388. }
  389. this._isMobile = this.getEmbeddedMobileItem();
  390. this._BUXDBInfoArray = this.getBUXDBInfoArray();//HashMap
  391. var properties = this.getAttributeValue( "viewerProperties");
  392. var promptParametersRetrieved = this.getAttributeValue( "promptParametersRetrieved");
  393. if ( promptParametersRetrieved !== null && promptParametersRetrieved == "true") {
  394. this.promptParametersRetrieved = true;
  395. }
  396. this.properties = this.createProperties(properties);
  397. this.savedOutput.setPagedOutput( !this.properties.getRetrieveAll());
  398. this.setWidgetCopyPasteParameters();
  399. this.m_bSelectionFilterSwitch = this.getAttributeValue("selectionFilterEnabled") == "true" ? true : false;
  400. if (this.isOpeningSavedDashboard() && this.copyPasteResource == null) {
  401. //Opening a dashboard
  402. this.disableListenToIfFullReportUpgraded();
  403. this.enableFlashChartsToIfReportPartUpgraded();
  404. this.disableListenToIfReportPartUpgraded();
  405. if(this.isVisible()) {
  406. if(window['gReportWidgetLoadQueue']) {
  407. window['gReportWidgetLoadQueue'].add(this);
  408. } else {
  409. this.postReport(null);
  410. }
  411. }
  412. } else {
  413. //Dropping a report on the canvas or copy/paste as we need to collect filters before posting report
  414. var payload = { action: 'canvas.filters' };
  415. this.fireEvent("com.ibm.bux.widget.action", null, payload );
  416. this.getLoadManager().viewerLoadInitiated();
  417. this.m_visible = true;
  418. }
  419. this.addWidgetEventListeners();
  420. // need to register a new wire directly to the Canvas for the context event. Canvas doesn't support dynamic set up of events yet.
  421. this.iContext.iEvents.svc.addWire(this.iContext.widgetId, "com.ibm.widget.contextChanged", "widgetBuxCanvasTabs", "com.ibm.widget.contextChanged");
  422. this.iContext.iEvents.svc.addWire(this.iContext.widgetId, "com.ibm.bux.data.filterCache.init", "widgetBuxCanvasTabs", "com.ibm.bux.data.filterCache.init");
  423. /*
  424. * This event is necessary because storeId in viewerProperty itemSet might be incorrect if workspace is imported through deployment.
  425. * Canvas will return back right storeId in dashboard spec which is taken care by deployment.
  426. */
  427. this.fireEvent("com.ibm.bux.widget.updateStoreID", null, {});
  428. },
  429. addWindowEventListeners : function()
  430. {
  431. if (!this.dojoConnections) {
  432. this.dojoConnections=[];
  433. }
  434. this.dojoConnections.push(dojo.connect(window, "onresize", this, this.onBrowserResize));
  435. this.dojoConnections.push(dojo.connect(window, "onbeforeunload", this, this.possibleUnloadEvent));
  436. },
  437. addWidgetEventListeners : function()
  438. {
  439. //Touch paging events must be attached to the widget not the window.
  440. if (this.isMobile()) {
  441. this.dojoConnections.push(dojo.connect(this.iContext.getRootElement(), "touchstart", this, this.onTouchStart));
  442. this.dojoConnections.push(dojo.connect(this.iContext.getRootElement(), "touchmove", this, this.onTouchMove));
  443. }
  444. },
  445. addChromeWhitespaceHandler: function(sCVid) {
  446. if (isIE()) { //IE only
  447. var nViewer = document.getElementById('mainViewerTR' + sCVid);
  448. if (nViewer) {
  449. //The event on Chrome whitespace clears current selections.
  450. this.dojoConnections.push(dojo.connect(nViewer, "onmousedown", this, this.onMouseDownOnChromeDiv));
  451. }
  452. }
  453. },
  454. /*
  455. * Calls clear selection if evt is from on beyond report area
  456. */
  457. onMouseDownOnChromeDiv: function (evt) {
  458. //Ignor the rest if "onmousedown" event happened from on beyond prompt control area
  459. if (evt.srcElement.id.indexOf('PRMT', 0) === 0) {
  460. return;
  461. }
  462. var oCV = this.getViewerObject();
  463. if (oCV) {
  464. var nReportDiv = oCV.getReportDiv();
  465. if (nReportDiv) {
  466. var oBoundingClientRect = nReportDiv.getBoundingClientRect();
  467. var iClientYOfBottomOfReport = oBoundingClientRect.top + nReportDiv.offsetHeight;
  468. if (evt.clientY > iClientYOfBottomOfReport && evt.button !== 2) { //ignore right click
  469. //the evt is from Chrome whitespace
  470. if (oCV.getSelectionController()) {
  471. oCV.getSelectionController().clearSelectedObjects();
  472. this.onSelectionChange();
  473. stopEventBubble(evt);
  474. }
  475. }
  476. }
  477. }
  478. },
  479. removeWindowEventListeners : function()
  480. {
  481. if (this.dojoConnections) {
  482. for (var i=0; i<this.dojoConnections.length; ++i) {
  483. dojo.disconnect(this.dojoConnections[i]);
  484. }
  485. delete this.dojoConnections;
  486. }
  487. },
  488. onBrowserResize: function()
  489. {
  490. var oCV=this.getViewerObject();
  491. if (oCV && oCV.getPinFreezeManager()) {
  492. oCV.getPinFreezeManager().onResizeCanvas(this.isVisible());
  493. }
  494. },
  495. onTouchStart: function(e)
  496. {
  497. //To support page swipe next page/previous page, capture the startX
  498. this.touchPaging=false; //Set to true only when a nextPage or previousPage has been called after the touch started
  499. if (this.m_oCV && e && e.changedTouches && e.touches && e.touches.length == 1) {
  500. var touchobj = e.changedTouches[0]; // reference first touch point for this event
  501. if (touchobj && touchobj.clientX) {
  502. this.touchStartX=parseInt(touchobj.clientX);
  503. }
  504. }
  505. },
  506. onTouchMove: function(e)
  507. {
  508. //Assume page swipe if the distance between the firstX of the swipe and the currentX is large enough AND there are more pages in the given direction.
  509. if (!this.touchPaging && this.touchStartX!=-1 && this.m_oCV && e && e.changedTouches && e.touches && e.touches.length == 1) {
  510. var touchobj = e.changedTouches[0]; // reference first touch point for this event
  511. if (touchobj && touchobj.clientX) {
  512. var touchCurrentX=parseInt(touchobj.clientX);
  513. if (this.m_oCV.hasNextPage() && this.touchStartX - touchCurrentX > 10) {
  514. this.touchPaging=true;
  515. this.m_oCV.pageAction("nextPage");
  516. this.m_oCV.setKeepFocus(false);
  517. } else if (this.m_oCV.hasPrevPage() && touchCurrentX - this.touchStartX > 10) {
  518. this.touchPaging=true;
  519. this.m_oCV.pageAction("previousPage");
  520. this.m_oCV.setKeepFocus(false);
  521. } else {
  522. this.touchPaging=false;
  523. this.touchStartX=-1; //Its not fast enough....
  524. }
  525. }
  526. }
  527. if (this.touchStartX > 0) {
  528. stopEventBubble(e);
  529. }
  530. },
  531. isLiveReport: function()
  532. {
  533. return this.isSavedOutput() === false && !this.isLimitedInteractiveMode();
  534. },
  535. createProperties: function(properties) {
  536. return new bux.reportViewer.Properties( this, properties );
  537. },
  538. disableListenToIfFullReportUpgraded: function() {
  539. if (this.isGoDashboardReportUpgrade()) {
  540. if (this.getAttributeValue( "flexParam_properties" )==null) {
  541. var payload = {};
  542. payload[ '*' ] = { blockedEvents:
  543. ['com.ibm.bux.data.filter', 'com.ibm.bux.filter.values.get', 'com.ibm.bux.filter.items.get']
  544. };
  545. this.fireEvent("com.ibm.bux.widget.updateEventFilter", null, payload);
  546. }
  547. }
  548. },
  549. enableFlashChartsToIfReportPartUpgraded: function() {
  550. if (this.isGoDashboardReportUpgrade()) {
  551. var sOriginalReportPart = this.getAttributeValue("originalReportPart");
  552. if (typeof sOriginalReportPart !== "undefined" && sOriginalReportPart!==null) {
  553. this.properties.setProperty('flashCharts',"true");
  554. }
  555. }
  556. },
  557. disableListenToIfReportPartUpgraded: function() {
  558. if (this.isGoDashboardReportUpgrade()) {
  559. var sOriginalReportPart = this.getAttributeValue("originalReportPart");
  560. if (typeof sOriginalReportPart !== "undefined" && sOriginalReportPart!==null) {
  561. var payload = {};
  562. payload[ '*' ] = { blockedEvents:
  563. ['com.ibm.bux.viewer.drill', 'com.ibm.bux.viewer.prompt']
  564. };
  565. this.fireEvent("com.ibm.bux.widget.updateEventFilter", null, payload);
  566. }
  567. }
  568. },
  569. /**
  570. * We registered a onBeforeCallback but it will get called before the warning to the user
  571. * issued from CW to allow them to stay on the current page. So this is simply a hint that a possible
  572. * unload could be happening which is enough to allow us to swallow any http faults that could happen on
  573. * any active http requests
  574. */
  575. possibleUnloadEvent: function() {
  576. var oCV = this.getViewerObject();
  577. if (oCV) {
  578. oCV.getViewerDispatcher().possibleUnloadEvent();
  579. }
  580. },
  581. onUnload: function() {
  582. this.onUnloadInProgress = true;
  583. this.destroy();
  584. this.iContext = null;
  585. },
  586. onGetFiltersDone: function(evt) {
  587. // filterRequiredAction : Undo | Redo | ResetToOriginal
  588. if (typeof this.filterRequiredAction != "undefined" && this.filterRequiredAction != null) {
  589. var dataFiltersParam = this.buildDataFiltersParam(evt.payload.filters);
  590. var actionFactory = new ActionFactory(this.getViewerObject());
  591. var action = actionFactory.load(this.filterRequiredAction);
  592. action.dispatchRequest(dataFiltersParam, this.filterRequiredAction);
  593. this.filterRequiredAction = null;
  594. } else {
  595. this.postReport(evt.payload.filters);
  596. this.postSetWidgetCopyPasteParameters();
  597. }
  598. },
  599. getOriginalFormFields: function() {
  600. return this.m_originalFormFields;
  601. },
  602. setOriginalFormFields: function(formFields) {
  603. this.m_originalFormFields = formFields;
  604. },
  605. getXNodeId: function() {
  606. return this.xNodeId;
  607. },
  608. setXNodeId: function(nodeId) {
  609. this.xNodeId = nodeId;
  610. },
  611. postReport: function(filters) {
  612. this.getLoadManager().viewerLoadInitiated();
  613. this.viewerWidgetLastAction = {"functionName": "postReport", "param": [filters]};
  614. if(this.getRunReportOption() !== false) {
  615. //Record that the report is being run
  616. this.m_oLoadManager.runningReport();
  617. }
  618. var content = this.buildPostContent(filters);
  619. if( content["ui.reportDrop"] == "true" ) {
  620. //save this state flag
  621. this.m_bReportDropped = true;
  622. }
  623. // need to save the initial form fields in case the request fails so we can do a 'retry'
  624. this.m_originalFormFields = new CDictionary();
  625. for (var formField in content) {
  626. if (formField != "cv.outputKey") {
  627. this.m_originalFormFields.add(formField, content[formField]);
  628. }
  629. }
  630. var header = {};
  631. if (this.getAttributeValue("X-Node-ID")) {
  632. this.setXNodeId(this.getAttributeValue("X-Node-ID"));
  633. header["X-Node-ID"] = this.getAttributeValue("X-Node-ID");
  634. this.removeAttributeValue("X-Node-ID");
  635. }
  636. var args = {
  637. url: this.buildPostUrl(),
  638. sync: false,
  639. preventCache: true,
  640. content: content,
  641. headers: header,
  642. error: dojo.hitch(this, function(response){
  643. this.fireEvent("com.ibm.bux.widget.render.done", null, {noAutoResize:true});
  644. this.fireEvent("com.ibm.bux.widget.notification", null, {type: "error", message: response.message, description: response.description});
  645. })
  646. };
  647. if (typeof xhrMultiPart !== "undefined" && xhrMultiPart.active) {
  648. args.load = dojo.hitch(this, function(response){
  649. this.loadContent(response.responseText);
  650. });
  651. xhrMultiPart.Post(args);
  652. } else {
  653. args.load = dojo.hitch(this, function(response, ioArgs){
  654. var responseContentType = ioArgs.xhr.getResponseHeader("Content-Type");
  655. if (responseContentType && responseContentType.indexOf("text/html") != -1 && response && response.match(/<ERROR_CODE>CAM_PASSPORT_ERROR<\/ERROR_CODE>/)) {
  656. this.handlePassportErrorFromDispatcher();
  657. } else {
  658. this.loadContent(response);
  659. }
  660. });
  661. dojo.xhrPost(args);
  662. }
  663. },
  664. isDropped : function(){
  665. return this.m_bReportDropped;
  666. },
  667. /**
  668. * Remove any styles that we added to the head if we're currently hidden
  669. */
  670. cleanupStyles : function() {
  671. this._cssLimitReached = true;
  672. // If we're hidden
  673. if(!this.isVisible()) {
  674. if (!this._styles) {
  675. this._styles = [];
  676. }
  677. var id = this.getViewerId();
  678. var styleNodes = document.getElementsByTagName("head").item(0).getElementsByTagName("style");
  679. // Loops through all the style elements to find those with the correct namespaceId
  680. for (var i=0; i < styleNodes.length; i++) {
  681. var style = styleNodes[i];
  682. if (style.getAttribute && style.getAttribute("namespaceId") == id) {
  683. style.parentNode.removeChild(style);
  684. this._styles.push(style);
  685. i--;
  686. }
  687. }
  688. }
  689. },
  690. /**
  691. * Add back any styles that we had previously removed from the head
  692. */
  693. reloadStyles : function() {
  694. if (this._styles) {
  695. while (this._styles.length > 0) {
  696. var style = this._styles.pop();
  697. document.getElementsByTagName("head").item(0).appendChild(style);
  698. }
  699. }
  700. },
  701. loadStylesAndScripts: function(sHTML, oReportDiv, bProcessDocumentWrite) {
  702. window.gScriptLoader.m_bIgnoreAjaxWarnings = true;
  703. window.gScriptLoader.setHandlerStylesheetLimit(true);
  704. var domElement = this.iContext.getRootElement();
  705. if (!domElement)
  706. {
  707. return;
  708. }
  709. sHTML = window.gScriptLoader.loadCSS(sHTML, oReportDiv, true, this.getViewerId());
  710. if (dojo.isIE || dojo.isTrident)
  711. {
  712. // IE specific 'fix' where if sHTML has script tags at the beginning they won't be loaded into the DOM.
  713. // Adding a valid tag first causes all subsequent scripts to be loaded into the DOM.
  714. sHTML = "<span style='display:none'>&nbsp;</span>" + sHTML;
  715. }
  716. oReportDiv.innerHTML = sHTML;
  717. if (this.isSelectionFilterEnabled()) {
  718. this.updateDrillThroughLinks();
  719. }
  720. var callback = GUtil.generateCallback(this.fireResizeEvent, [], this);
  721. this.m_sScriptLoaderNamespace = this.getViewerId(); // Keep a reference to this ID, ViewerId may be different when it gets into destroy.
  722. window.gScriptLoader.loadAll(oReportDiv, callback, this.m_sScriptLoaderNamespace, bProcessDocumentWrite);
  723. },
  724. /**
  725. * A function to be used as a call back to fire a resize event
  726. */
  727. fireResizeEvent: function ()
  728. {
  729. var viewerObject = this.getViewerObject();
  730. if (viewerObject == null) {
  731. this.fireEvent("com.ibm.bux.widget.render.done", null, {});
  732. }
  733. else {
  734. var iWidget = viewerObject.getViewerWidget();
  735. if (iWidget) {
  736. viewerObject.m_resizeReady = true;
  737. viewerObject.doneLoading();
  738. }
  739. else {
  740. var objRef = this;
  741. setTimeout(function() { objRef.fireResizeEvent(); }, 100);
  742. }
  743. }
  744. },
  745. /*
  746. * We need to reconstruct the saved report search path. If we don't we could be referencing the wrong
  747. * report as in the case when the dashboard is copied in CC.
  748. */
  749. getSavedReportSearchPath: function(sSavedReportName) {
  750. var sSavedReportPath = this.getAttributeValue( 'savedReportPath' );
  751. if( sSavedReportPath )
  752. {
  753. return sSavedReportPath;
  754. }
  755. var sDashboardId = this.getAttributeValue("dashboardID");
  756. sDashboardId = sDashboardId.substr("$$dbid$$".length );
  757. var savedReportSearchPath = "storeID(\"" + sDashboardId + "\")/*[@name=" + xpath_attr_encode(sSavedReportName) +"]";
  758. return savedReportSearchPath;
  759. },
  760. isSavedReport: function( sOriginalItem, sSavedItem ) {
  761. return ( typeof sSavedItem !== "undefined" &&
  762. sSavedItem !== null &&
  763. sSavedItem.length > 0 &&
  764. sOriginalItem !== sSavedItem );
  765. },
  766. getGlobalPromptsInfo : function() {
  767. var result = null;
  768. var oCV = null;
  769. var promptsInfo = [];
  770. var cvPromptInfo = null;
  771. if (window.gaRV_INSTANCES) {
  772. for (var iIndex=0; iIndex < window.gaRV_INSTANCES.length; iIndex++) {
  773. oCV = window.gaRV_INSTANCES[iIndex];
  774. cvPromptInfo = oCV.getPromptParametersInfo();
  775. if (cvPromptInfo != null) {
  776. promptsInfo.push(cvPromptInfo);
  777. }
  778. }
  779. }
  780. if (promptsInfo.length > 0) {
  781. result = "<globalPromptInfo>" + promptsInfo.join("")+ "</globalPromptInfo>";
  782. }
  783. return result;
  784. },
  785. buildPostUrl: function () {
  786. return this.getAttributeValue("gateway");
  787. },
  788. getSavedItem: function() {
  789. var sSavedItem = this.getAttributeValue("savedReportPath");
  790. if( !sSavedItem )
  791. {
  792. //for backwards compatibility
  793. sSavedItem = this.getAttributeValue("savedReportName");
  794. }
  795. return sSavedItem;
  796. },
  797. setRunReportOption: function( option ) {
  798. this.m_bRunReportOption = option;
  799. },
  800. getRunReportOption: function() {
  801. return this.m_bRunReportOption;
  802. },
  803. resetRunReportOption: function() {
  804. this.m_bRunReportOption = null;
  805. },
  806. buildPostContent: function (filters) {
  807. var sOriginalItem = this.getAttributeValue("originalReport");
  808. var sSavedItem = this.getSavedItem();
  809. var sOriginalReportPart = this.getAttributeValue("originalReportPart");
  810. var sFlexParamProperties = this.getAttributeValue("flexParam_properties");
  811. var sFlexPromptData = this.getAttributeValue("flexParam_promptData");
  812. var bIsSavedReport = this.isSavedReport( sOriginalItem, sSavedItem);
  813. var bPromptUser = this.getPromptRunOption(sFlexPromptData, bIsSavedReport);
  814. var bAction = this.getAttributeValue("cv.outputKey") ? "cvx.high" : "cognosViewer";
  815. var content = {
  816. "b_action" : bAction,
  817. "run.outputFormat" : "HTML",
  818. "bux" : "true",
  819. "cv.responseFormat" : "iWidget",
  820. "cv.id" : this.getViewerId()
  821. };
  822. if (this.isMobile()) {
  823. content["container"] = "mobile";
  824. }
  825. if (this.getAttributeValue("cv.outputKey")) {
  826. content["cv.outputKey"] = this.getAttributeValue("cv.outputKey");
  827. this.removeAttributeValue("cv.outputKey");
  828. // if we're calling cvx handler, send along the widgetId
  829. content["widget.id"] = this.getWidgetId();
  830. }
  831. if (this.getAttributeValue("gateway")) {
  832. content["cv.gateway"] = this.getAttributeValue("gateway");
  833. }
  834. if (this.getAttributeValue("webcontent")) {
  835. content["cv.webcontent"] = this.getAttributeValue("webcontent");
  836. }
  837. this.sInitialSpec = this.getAttributeValue("specification");
  838. if( bIsSavedReport ){
  839. this.addUserParamsToContent( content );
  840. }
  841. /*
  842. * If there is no saved report, the saved report name is the same as the original report
  843. */
  844. if (!this.sInitialSpec || this.copyPasteResource) {
  845. if ( bIsSavedReport ) {
  846. content["ui.object"] = this.getSavedReportSearchPath( sSavedItem );
  847. //for backwards compatibility
  848. if( !this.getAttributeValue('savedReportPath' ) && this.getAttributeValue('savedReportName' ) )
  849. {
  850. content["savedReportName"] = sSavedItem;
  851. }
  852. content["widget.isSavedReport"] = 'true';
  853. content["ui.reRunObj"] = this.getSavedReportSearchPath( sSavedItem );
  854. } else {
  855. content["ui.object"] = sOriginalItem;
  856. //check for G!D properties to upgrade
  857. if( sFlexParamProperties && sFlexParamProperties.length > 0)
  858. {
  859. content["flexParamProperties"] = sFlexParamProperties;
  860. }
  861. if( sFlexPromptData && sFlexPromptData.length > 0)
  862. {
  863. content["gdPromptAnswers"] = sFlexPromptData;
  864. }//end of G!D properties check
  865. }
  866. content["originalReport"] = sOriginalItem;
  867. }
  868. // widget saved to specific output
  869. if (this.getAttributeValue("savedOutputSearchPath") != null) {
  870. this.setSavedOutputSearchPath(this.getAttributeValue("savedOutputSearchPath"));
  871. content["ui.savedOutputSearchPath"] = this.getAttributeValue("savedOutputSearchPath");
  872. content["ui.action"] = "buxView";
  873. }
  874. // widget saved to view most recent output
  875. else if (this.getAttributeValue("mostRecentSavedOutput") == "true") {
  876. content["ui.action"] = "buxView";
  877. }
  878. // we have a copied report under the dashboard
  879. else if (bIsSavedReport) {
  880. if( this.getAttributeValue( "limitedInteractiveMode" ) === "true" ) {
  881. content["limitedInteractiveMode"] = "true";
  882. content["ui.action"] = "run";
  883. content["run.xslURL"] = "bux.xsl";
  884. }
  885. else
  886. {
  887. content["ui.action"] = "bux";
  888. }
  889. if( this.getRunReportOption() !== null )
  890. {
  891. content['widget.runReport'] = ( this.getRunReportOption() ) ? 'true' : 'false' ;
  892. /**
  893. * This triggers getParameters in the case of delayed viewer loading and widget needs to handle
  894. * share prompt event and there is not parameters saved.
  895. */
  896. if( this.getDoGetParametersOnLoad() ){
  897. content['widget.globalPromptInfo'] = '<globalPromptInfo></globalPromptInfo>';
  898. }
  899. this.resetRunReportOption();
  900. }
  901. }
  902. // user dragged a report part to the canvas
  903. else if (sOriginalReportPart && sOriginalReportPart.length > 0 && this.copyPasteResource == null) {
  904. content["ui.reportDrop"] = "true";
  905. content["ui.action"] = "bux";
  906. content["reportpart_id"] = sOriginalReportPart;
  907. }
  908. // specification passed in from bux copy/paste
  909. else if (this.copyPasteResource) {
  910. if (this.ciPublishedReportPath != null) {
  911. //used to query envionment variables such as object permissions
  912. content["ui.object"] = this.ciPublishedReportPath;
  913. }
  914. var resource = dojo.fromJson(this.copyPasteResource);
  915. if (resource[0] && resource[0].body) {
  916. var conversation = this.getAttributeValue("copy.conversation");
  917. if (conversation) {
  918. content["ui.conversation"] = conversation;
  919. }
  920. if (resource[0].body.specification ) {
  921. content["ui.spec"] = resource[0].body.specification;
  922. content["ui.action"] = "buxCopyPaste";
  923. if (this.getAttributeValue("reportCreatedInCW") === "true") {
  924. content["cv.objectPermissions"] = "read write execute setPolicy traverse";
  925. }
  926. } else {
  927. //in case as with "LimitedInteractiveMode" when there is no report spec in resource
  928. content["ui.reportDrop"] = "true";
  929. content["ui.action"] = "buxDropReportOnCanvas";
  930. }
  931. }
  932. }
  933. // specification passed in from container
  934. else if (this.sInitialSpec) {
  935. content["ui.spec"] = this.sInitialSpec;
  936. content["ui.action"] = "buxRunSpecification";
  937. content["cv.objectPermissions"] = "read write execute setPolicy traverse";
  938. }
  939. else if (this._newReportInfo) {
  940. for (prop in this._newReportInfo) {
  941. content[prop] = this._newReportInfo[prop];
  942. }
  943. content["ui.reportDrop"] = "true";
  944. content["ui.action"] = "bux";
  945. content["cv.objectPermissions"] = "read write execute setPolicy traverse";
  946. content["ui.objectClass"] = "report";
  947. content["openReportFromClipboard"] = "true";
  948. }
  949. // user dragged a report to the canvas
  950. else {
  951. content["ui.reportDrop"] = "true";
  952. content["ui.action"] = "buxDropReportOnCanvas";
  953. }
  954. if( bPromptUser !== null )
  955. {
  956. content["run.prompt"] = (bPromptUser ? "true" : "false");
  957. }
  958. if (this.getAttributeValue("lastLocaleSaved") != null) {
  959. content["lastLocaleSaved"] = this.getAttributeValue("lastLocaleSaved");
  960. }
  961. var dataFiltersParam = "";
  962. if (this.copyPasteResource){
  963. dataFiltersParam = this.updateCopyPasteFilters(filters);
  964. }else {
  965. dataFiltersParam = this.buildDataFiltersParam(filters);
  966. if (typeof filters=="undefined" || filters==null) {
  967. dataFiltersParam = this.buildFiltersParamFromLoadedSliderState();
  968. }
  969. }
  970. if(dataFiltersParam != "")
  971. {
  972. content["cv.updateDataFilters"] = dataFiltersParam;
  973. }
  974. if (this.properties && this.properties.getFlashCharts() !== null) {
  975. content["savedFlashChartOption"] = (this.properties.getFlashCharts() ? "true" : "false");
  976. var isAVS = this.getAttributeValue("hasAVSChart");
  977. if (isAVS == "true") {
  978. content["hasAVSChart"] = "true";
  979. }
  980. else {
  981. content["hasAVSChart"] = "false";
  982. }
  983. }
  984. if (this.properties.getRowsPerPage() != null)
  985. {
  986. content["run.verticalElements"] = this.properties.getRowsPerPage();
  987. }
  988. var enablePromptAndDrillEventsByDefault = this.getAttributeValue("syncNewWidgets");
  989. if(enablePromptAndDrillEventsByDefault === null || enablePromptAndDrillEventsByDefault === "true") {
  990. enablePromptAndDrillEventsByDefault = true;
  991. } else {
  992. enablePromptAndDrillEventsByDefault = false;
  993. }
  994. if ( !bIsSavedReport && enablePromptAndDrillEventsByDefault) {
  995. var globalPrompts = this.getGlobalPromptsInfo();
  996. if (globalPrompts !== null ) {
  997. content["widget.globalPromptInfo"] = globalPrompts;
  998. }
  999. }
  1000. if (this.isOpeningSavedDashboard()) {
  1001. content["ui.preserveRapTags"] = "true";
  1002. }
  1003. if( bIsSavedReport === true && this.getAttributeValue( "limitedInteractiveMode" ) !== "true" )
  1004. {
  1005. this.getUserId();
  1006. }
  1007. if( window.cognosViewerDebug )
  1008. {
  1009. content.debug = true;
  1010. }
  1011. content["cv.buxCurrentUserRole"] = this.getUserRole();
  1012. if (this.shouldUseSavedReportInfo()) {
  1013. content["rap.getReportInfo"] = "false";
  1014. }
  1015. //Add dashboard information, such as title, searchPath and widget information, such as title to content
  1016. if(window.icdConfig && window.icdConfig.ZIPIMode != "0"){
  1017. this.addBUXRTStateInfoToContent(content);
  1018. }
  1019. this.addBUXWidgetTitleToContent(content);
  1020. return content;
  1021. },
  1022. addBUXRTStateInfoToContent: function(content/*HashMap of form fields*/){
  1023. if(content != null){
  1024. var sStateInfo = this.getBUXRTStateInfoMap();/*XML String*/
  1025. if(sStateInfo && sStateInfo.length >0){
  1026. content["cv.buxRTStateInfo"] = sStateInfo;
  1027. }
  1028. }
  1029. },
  1030. addBUXWidgetTitleToContent: function(content/*HashMap of form fields*/){
  1031. if(content != null){
  1032. var sWidgetTitle = this.getAttributeValue("widgetTitle");
  1033. if(sWidgetTitle && sWidgetTitle.length >0){
  1034. content["widgetTitle"] = sWidgetTitle;//Default Widget Title, Same String as original report name
  1035. }
  1036. var sDisplayTitle = this.getDisplayName();
  1037. if(sDisplayTitle && sDisplayTitle.length >0){
  1038. content["displayTitle"] = sDisplayTitle;//Custom Widget title for the given content locale
  1039. }
  1040. }
  1041. },
  1042. addUserParamsToContent: function( content) {
  1043. var userParams = this.getAttributeValue("userParams");
  1044. if( !userParams) { return; }
  1045. var doc = XMLBuilderLoadXMLFromString( userParams );
  1046. if( !doc ){ return; }
  1047. var eItems = XMLHelper_FindChildrenByTagName( doc.documentElement, 'item', false );
  1048. var count = eItems.length;
  1049. for( var i = 0; i < count; i++ ){
  1050. if( !eItems[i] ){ continue; }
  1051. var paramNameElem = XMLHelper_FindChildByTagName( eItems[i], 'name', false );
  1052. if( !paramNameElem ){ continue; }
  1053. var paramValueElem = XMLHelper_FindChildByTagName( eItems[i], 'value', false );
  1054. content[ XMLHelper_GetText( paramNameElem ) ] = ( !paramValueElem ? '' : XMLHelper_GetText( paramValueElem ) );
  1055. }
  1056. if (count > 0) {
  1057. content["widget.userParameters"] = "true";
  1058. if (this.getAttributeValue( "viewerReportPrompts")) {
  1059. content["viewerReportPrompts"] = this.getAttributeValue( "viewerReportPrompts");
  1060. }
  1061. }
  1062. this.removeAttributeValue("userParams");
  1063. },
  1064. shouldUseSavedReportInfo: function() {
  1065. return this.getAttributeValue("rapReportInfoVersion") === this.RAP_REPORT_INFO_VERSION && this.getAttributeValue("rapReportInfo") != null;
  1066. },
  1067. isConsumeUser: function() {
  1068. return this.getUserRole() === 'consume';
  1069. },
  1070. getUserRole: function() {
  1071. var userRole = null;
  1072. var userProfileItemSet = this.iContext.getItemSet("buxuserprofile", false);
  1073. if( userProfileItemSet ){
  1074. userRole = userProfileItemSet.getItemValue("currentUserRole");
  1075. }
  1076. return userRole == null ? "assemble" : userRole;
  1077. },
  1078. getUserId : function()
  1079. {
  1080. dojo["require"]("bux.UserAccount"); //@lazyload
  1081. // get user account info
  1082. return bux.UserAccount.getUserAccount().then(
  1083. /*callback*/ dojo.hitch( this, function(userAccount){
  1084. this.m_sUserId = userAccount.cm$searchPath;
  1085. return this.m_sUserId; }
  1086. ));
  1087. },
  1088. _genMobileFormFieldPayload : function(form) {
  1089. var formFieldsPayload = {};
  1090. var inputNodes = form.getElementsByTagName("input");
  1091. if (inputNodes) {
  1092. for (var i=0; i < inputNodes.length; i++) {
  1093. var name = inputNodes[i].getAttribute("name");
  1094. var value = inputNodes[i].getAttribute("value");
  1095. if (name && value) {
  1096. formFieldsPayload[name] = value;
  1097. }
  1098. }
  1099. }
  1100. return formFieldsPayload;
  1101. },
  1102. launchGotoPageForIWidgetMobile : function(form) {
  1103. var payload = {
  1104. "action" : "goto",
  1105. "payload" : this._genMobileFormFieldPayload(form)
  1106. };
  1107. if (typeof console != "undefined" && console && console.log) {
  1108. console.log(payload);
  1109. }
  1110. this.fireEvent("com.ibm.bux.widget.openView", null, payload);
  1111. },
  1112. executeDrillThroughForIWidgetMobile : function(form) {
  1113. var aCells = getChildElementsByAttribute(form, "input", "name", "ui.action");
  1114. if (aCells && aCells.length > 0) {
  1115. aCells[0].setAttribute("value", "authoredDrillThroughMobile");
  1116. }
  1117. var payload = {
  1118. "action" : "drillThrough",
  1119. "payload" : this._genMobileFormFieldPayload(form)
  1120. };
  1121. if (typeof console != "undefined" && console && console.log) {
  1122. console.log(payload);
  1123. }
  1124. this.fireEvent("com.ibm.bux.widget.openView", null, payload);
  1125. },
  1126. isBuxAvailable: function()
  1127. {
  1128. return (this.bux && this.bux._base ? true : false);
  1129. },
  1130. /**
  1131. * return one or more drill optionsas a JSON object
  1132. */
  1133. getDrillOptions: function(){
  1134. return this.properties.getDrillOptions();
  1135. },
  1136. getPromptRunOption: function( sFlexPromptData, bIsSavedReport )
  1137. {
  1138. if( !bIsSavedReport && sFlexPromptData && sFlexPromptData.length > 0)
  1139. {
  1140. //don't prompt if upgrading G!D with saved prompt answers
  1141. return false;
  1142. }
  1143. else if( bIsSavedReport )
  1144. {
  1145. //this is a saved report, use the saved property values
  1146. return this.properties.getPromptUserOnLoad();
  1147. }
  1148. else
  1149. {
  1150. return null;
  1151. }
  1152. },
  1153. buildDataFiltersParam: function(filters) {
  1154. var updateDataFilters = "";
  1155. if(filters && filters.length > 0)
  1156. {
  1157. this.sliderState={};
  1158. updateDataFilters = "<UpdateDataFilters>";
  1159. for(var filter = 0; filter < filters.length; ++filter) {
  1160. var filterDetails =filters[filter];
  1161. var filterObj = dojo.fromJson(filterDetails);
  1162. // If the fileter came from this widget (selection filter) then ignore it
  1163. if (filterObj.clientId == this.getWidgetId()) {
  1164. continue;
  1165. }
  1166. if (!(filterObj["com.ibm.widget.context.bux.selectValueControl"])) {
  1167. this.m_oWidgetContextManager.convertSelectionToSelectValueControlPayload(filterObj);
  1168. this.m_oWidgetContextManager.convertGenericToSelectValueControlPayload(filterObj);
  1169. filterDetails = dojo.toJson(filterObj);
  1170. }
  1171. updateDataFilters += "<filter>" + xml_encode(filterDetails) + "</filter>";
  1172. this.sliderState[filterObj.clientId] =filterDetails;
  1173. }
  1174. updateDataFilters += "</UpdateDataFilters>";
  1175. }
  1176. return updateDataFilters;
  1177. },
  1178. updateCopyPasteFilters: function (filters) {
  1179. this.loadSliderState();
  1180. if(this.sliderState) {
  1181. //update sliderState to set block that will remove filter form report
  1182. for(var sliderID in this.sliderState) {
  1183. this.sliderState[sliderID] = "{'clientId':'" +sliderID + "', 'com.ibm.widget.context':{},'com.ibm.widget.context.bux.selectValueControl':" +
  1184. "{'selectValueControl':{'id':'" + sliderID + "','controlType':'slider','type':'discrete','valueType':'string'}}}";
  1185. }
  1186. }
  1187. if (filters && filters.length > 0) {
  1188. //apply filter values to the matching slider id
  1189. for (var filter = 0; filter < filters.length; ++filter) {
  1190. var filterDetails = filters[filter];
  1191. var filterObj = dojo.fromJson(filterDetails);
  1192. if (filterObj["com.ibm.widget.context.bux.selection"]) {
  1193. this.m_oWidgetContextManager.convertSelectionToSelectValueControlPayload(filterObj);
  1194. this.m_oWidgetContextManager.convertGenericToSelectValueControlPayload(filterObj);
  1195. filterDetails = dojo.toJson(filterObj);
  1196. }
  1197. this.sliderState[filterObj.clientId] = filterDetails;
  1198. }
  1199. }
  1200. return this.buildDataFiltersParam_fromState();
  1201. },
  1202. buildFiltersParamFromLoadedSliderState: function() {
  1203. var dataFiltersParam = "";
  1204. this.loadSliderState();
  1205. dataFiltersParam = this.buildDataFiltersParam_fromState();
  1206. return dataFiltersParam;
  1207. },
  1208. loadSliderState: function() {
  1209. this.sliderState={}; //Clear any previous slider state.
  1210. var sliderIDs = dojo.fromJson(this.getAttributeValue("sliderIDs"));
  1211. if (sliderIDs) {
  1212. for (var i=0; i<sliderIDs.length; ++i) {
  1213. var sliderID = sliderIDs[i];
  1214. var savedState = this.getItemValue("sliderState_" + sliderID);
  1215. if (savedState!=null && savedState!="") {
  1216. this.sliderState[sliderID] = savedState;
  1217. }
  1218. }
  1219. }
  1220. },
  1221. buildDataFiltersParam_fromState: function() {
  1222. var updateDataFilters = "";
  1223. if(this.sliderState) {
  1224. for(var sliderID in this.sliderState) {
  1225. updateDataFilters += "<filter>" + xml_encode(this.sliderState[sliderID]) + "</filter>";
  1226. }
  1227. if (updateDataFilters!=="") {
  1228. return ("<UpdateDataFilters>" + updateDataFilters + "</UpdateDataFilters>");
  1229. }
  1230. }
  1231. return updateDataFilters;
  1232. },
  1233. loadContent: function(response) {
  1234. var oReportDiv = dojo.byId("_" + this.iContext.widgetId + "_cv");
  1235. this.loadStylesAndScripts(response, oReportDiv, true);
  1236. if (!window.gScriptLoader.hasCompletedExecution()) {
  1237. var obj = this;
  1238. this.timer = setInterval(function(){
  1239. window.gInitializeViewer(obj);
  1240. }, this.timerInterval);
  1241. }
  1242. else {
  1243. window.gInitializeViewer(this);
  1244. }
  1245. this.viewerWidgetLastAction = null;
  1246. },
  1247. executeAction: function(evt, action) {
  1248. var viewerObject = this.getViewerObject();
  1249. if( evt && viewerObject ) {
  1250. var sAction = action ? action : evt.payload.name;
  1251. var payload = evt.payload;
  1252. // payload = '' seems valid ???
  1253. if(sAction && typeof payload != "undefined" && payload != null) {
  1254. if(evt.payload.payload) {
  1255. payload = evt.payload.payload;
  1256. }
  1257. viewerObject.executeAction(sAction, payload);
  1258. }
  1259. }
  1260. },
  1261. onContextMenuAction: function(evt) {
  1262. this.executeAction(evt);
  1263. },
  1264. onToolbarAction: function(evt) {
  1265. this.executeAction(evt);
  1266. },
  1267. updateToolbar: function() {
  1268. var viewerObject = this.getViewerObject();
  1269. if (!viewerObject || (!this.bToolbarInitialized && typeof CognosViewerAction != "function")) {
  1270. return;
  1271. }
  1272. if(viewerObject.getStatus() === 'prompting')
  1273. {
  1274. return;
  1275. }
  1276. var toolbarPayload = viewerObject.getToolbar();
  1277. CCognosViewerToolbarHelper.updateToolbarForCurrentSelection(viewerObject, toolbarPayload);
  1278. this.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, viewerObject.getToolbar());
  1279. },
  1280. /**
  1281. * Called when the widget gets focus
  1282. */
  1283. onSelect: function() {
  1284. // The first time we get focus we need to update the toolbar
  1285. if (!this.bToolbarInitialized) {
  1286. this.bToolbarInitialized = true;
  1287. var viewerObject = this.getViewerObject();
  1288. if (viewerObject) {
  1289. var status = viewerObject.getStatus();
  1290. if (status !== "prompting" && status !== "working" && status != "stillWorking") {
  1291. this.updateToolbar();
  1292. }
  1293. }
  1294. }
  1295. this.fireEvent("com.ibm.bux.widget.select.done", null, {});
  1296. },
  1297. hideToolbarAndContextMenu: function()
  1298. {
  1299. this.fireEvent("com.ibm.bux.widget.contextMenu.update");
  1300. this.fireEvent("com.ibm.bux.widgetchrome.toolbar.init");
  1301. },
  1302. updateSavedAttributes: function( attribType )
  1303. {
  1304. this.setAttributeValue( "version", this.BUX_REPORT_VERSION );
  1305. this.setAttributeValue( "viewerProperties", this.properties.toString() );
  1306. //selection objects
  1307. if (this.m_oWidgetContextManager.getSelectionFilterObjects()) {
  1308. this.setAttributeValue( "selectionObjects", this.m_oWidgetContextManager.toStringSelectionFilterObjects() );
  1309. }
  1310. //saving attributes specific to live report
  1311. if( attribType === 'live' )
  1312. {
  1313. var oCV = this.getViewerObject();
  1314. var reportPrompts = this.getEnvParam("reportPrompts");
  1315. if ( this.promptParametersRetrieved == true && reportPrompts && reportPrompts.length > 0 ) {
  1316. this.setAttributeValue( "viewerReportPrompts", this.getEnvParam("reportPrompts"));
  1317. }
  1318. this.setAttributeValue( "promptParametersRetrieved", (this.promptParametersRetrieved ? "true" : "false") );
  1319. this.setAttributeValue("selectionFilterEnabled", this.m_bSelectionFilterSwitch ? "true" : "false");
  1320. // flag needed to disable the snapshots menu on a dashboard open
  1321. if (this.getEnvParam("reportpart_id") && this.getEnvParam("reportpart_id").length > 0)
  1322. {
  1323. this.setAttributeValue("fromReportPart", "true");
  1324. }
  1325. if( this.isLimitedInteractiveMode() )
  1326. {
  1327. this.setAttributeValue( "limitedInteractiveMode", "true" );
  1328. }
  1329. else
  1330. {
  1331. //need to set this only if report is not report view
  1332. this.setAttributeValue( "baseReportModificationTime", oCV.envParams["baseReportModificationTime"]);
  1333. }
  1334. var contentLocale = oCV.envParams["contentLocale"];
  1335. if (contentLocale != null) {
  1336. this.saveSliderState();
  1337. this.setAttributeValue( "lastLocaleSaved", contentLocale );
  1338. }
  1339. this.setAttributeValue( "originalReportLocation", oCV.envParams["originalReportLocation"]);
  1340. this.setAttributeValue("hasAVSChart", oCV.hasAVSChart() ? "true" : "false");
  1341. // the displayTypes property is used for thumbnails
  1342. this.setAttributeValue("displayTypes", this.getDisplayTypes());
  1343. // clear the cached available outputs
  1344. this.setSavedOutputsCMResponse(null);
  1345. if (oCV.getPinFreezeManager()) {
  1346. var sPinFreezeInfo = oCV.getPinFreezeManager().toJSONString();
  1347. this.setAttributeValue("PinFreezeInfo", sPinFreezeInfo);
  1348. }
  1349. if (oCV.envParams["rapReportInfo"]) {
  1350. this.setAttributeValue("rapReportInfoVersion", this.RAP_REPORT_INFO_VERSION);
  1351. this.setAttributeValue("rapReportInfo", oCV.envParams["rapReportInfo"]);
  1352. }
  1353. }
  1354. //saving attributes sepecific to saved output
  1355. if( attribType === 'savedOutput')
  1356. {
  1357. if (this.getSavedOutputSearchPath() == null) {
  1358. this.setAttributeValue("mostRecentSavedOutput", "true");
  1359. }
  1360. else {
  1361. this.setAttributeValue( "savedOutputSearchPath", this.getSavedOutputSearchPath());
  1362. }
  1363. this.setAttributeValue("selectionFilterEnabled", this.m_bSelectionFilterSwitch ? "true" : "false");
  1364. }
  1365. },
  1366. onItemSetChanged: function(event)
  1367. {
  1368. //Only update item set if we have a viewer.
  1369. if(this.getViewerObject()) {
  1370. var aChangedItemSets = event.payload.changes;
  1371. for( var i in aChangedItemSets)
  1372. {
  1373. if( aChangedItemSets[i].id === 'savedReportPath' && aChangedItemSets[i].newVal ){
  1374. this.updateCVEnvParam();
  1375. }
  1376. }
  1377. }
  1378. },
  1379. /**
  1380. * This function is called only after a successful save.
  1381. */
  1382. updateCVEnvParam: function() {
  1383. var oCV = this.getViewerObject();
  1384. oCV.envParams["ui.objectClass"] = this.isSavedOutput() ? 'reportView' : 'report' ;
  1385. oCV.envParams["widget.isSavedReport"] = 'true';
  1386. // for backwards compatibility
  1387. var savedReportName = this.getAttributeValue('savedReportName' );
  1388. if( savedReportName )
  1389. {
  1390. oCV.envParams["ui.object"] = savedReportName;
  1391. oCV.envParams["savedReportName"] = savedReportName;
  1392. }
  1393. else
  1394. {
  1395. oCV.envParams["ui.object"] = this.getAttributeValue( 'savedReportPath');
  1396. }
  1397. },
  1398. onWidgetSave: function(evt) {
  1399. var viewerObject = this.getViewerObject();
  1400. var saveDonePayload = {'status':false};
  1401. //adding copy.conversation parameter for the bux copy/paste action
  1402. if (evt && evt.payload && evt.payload.isCopy === true ) {
  1403. this.setAttributeValue("copy.conversation", viewerObject.getConversation());
  1404. } else {
  1405. //we remove parameters after saving widget
  1406. this.removeItem("copy.conversation");
  1407. this.removeItem("copy.ciPublishedReportPath");
  1408. }
  1409. var isSaveAs = evt && evt.payload && evt.payload.operation == "saveAs" ? true : false;
  1410. // If we're doing a save and the Viewer isn't loaded there's no need to do anything
  1411. if( !viewerObject && !isSaveAs) {
  1412. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1413. return;
  1414. }
  1415. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  1416. var viewerObject = this.getViewerObject();
  1417. viewerObject.loadExtra();
  1418. if( this.isSavedOutput() )
  1419. {
  1420. this.cleanSavedAttributes();
  1421. this.updateSavedAttributes( "savedOutput" );
  1422. saveDonePayload.status = true;
  1423. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1424. }
  1425. else if(this.sInitialSpec)
  1426. {
  1427. // just update the attribute with the latest spec
  1428. saveDonePayload.status = true;
  1429. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1430. }
  1431. else
  1432. {
  1433. var permissions = this.getEnvParam("cv.objectPermissions");
  1434. var widgetSave = new ViewerIWidgetSave( this, evt.payload );
  1435. if( !widgetSave.canSave( permissions ) )
  1436. {
  1437. this.showErrorMessage( RV_RES.IDS_CANNOT_SAVE_CONTENT_ERROR );
  1438. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1439. return;
  1440. }
  1441. /**
  1442. * Make sure we have a report spec or that we're in limited mode before trying to create a report/reportView under
  1443. * the dashboard in CM. We won't have a report spec if a report is still running when the user tries to save the dashboard
  1444. * bug COGCQ00277254
  1445. */
  1446. if (this.isLimitedInteractiveMode() || (viewerObject.envParams["ui.spec"] && viewerObject.envParams["ui.spec"].length > 0)) {
  1447. this.cleanSavedAttributes();
  1448. this.updateSavedAttributes( "live" );
  1449. if(widgetSave.doGetSavePropertiesFromServer()) {
  1450. widgetSave.getSavePropertiesFromServer();
  1451. }
  1452. else {
  1453. this.doWidgetSaveDone(widgetSave);
  1454. }
  1455. }
  1456. else if (!viewerObject.envParams["ui.spec"]) {
  1457. // We don't have a ui.spec and we're not in limited interactive mode, ask CW to do a copy for us
  1458. widgetSave.setDoCWCopy(true);
  1459. this.doWidgetSaveDone(widgetSave);
  1460. }
  1461. else {
  1462. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1463. }
  1464. }
  1465. }), evt);
  1466. },
  1467. doWidgetSaveDone : function( widgetSave )
  1468. {
  1469. var saveDonePayload = widgetSave.getPayload();
  1470. saveDonePayload.status = true;
  1471. if(window.icdConfig && window.icdConfig.ZIPIMode != "0"){
  1472. var oDashboard = widgetSave.m_payload.dashboard;
  1473. if(oDashboard){
  1474. this._BUXDBInfoArray = this.getBUXDBInfoArray({dbTitle: oDashboard.title._text, dbSearchPath: oDashboard.cm$searchPath});
  1475. }
  1476. }
  1477. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload);
  1478. },
  1479. handleGetSavePropertiesFromServerResponse : function( serverResponse, savePayload )
  1480. {
  1481. var widgetSave = new ViewerIWidgetSave( this, savePayload );
  1482. if( serverResponse && serverResponse.getJSONResponseObject() ){
  1483. applyJSONProperties( this.getViewerObject(), serverResponse.getJSONResponseObject() );
  1484. }
  1485. this.doWidgetSaveDone( widgetSave );
  1486. },
  1487. /**
  1488. * check if the saved BUX report was built from pre Caspian RP1 release.
  1489. */
  1490. isPreCaspianRP1BUXReport: function(){
  1491. var sContentVersion = this.getAttributeValue( "version" );
  1492. if(!sContentVersion || sContentVersion < this.BUX_REPORT_CASPIAN_RP1_VERSION ){
  1493. return true;
  1494. }
  1495. return false;
  1496. },
  1497. /*
  1498. * Return true if we are opening/upgrading a go dashboard version report.
  1499. */
  1500. isGoDashboardReportUpgrade: function() {
  1501. var contentVersion = this.getAttributeValue( "version" );
  1502. if (contentVersion==this.GODASHBOARD_REPORT_VERSION) {
  1503. //This is a G!D report being upgraded
  1504. return true;
  1505. }
  1506. return false;
  1507. },
  1508. /*
  1509. * Return true if we are opening/upgrading a saved dashboard.
  1510. */
  1511. isOpeningSavedDashboard: function() {
  1512. var viewerProperties = this.getAttributeValue( "viewerProperties");
  1513. //Once saved, viewer properties will be set as a JSON object.
  1514. //Prior to that, they will be <empty> or not defined.
  1515. if ((viewerProperties && viewerProperties.indexOf("{")===0) || this.isGoDashboardReportUpgrade()) {
  1516. return true;
  1517. }
  1518. return false;
  1519. },
  1520. /*
  1521. * Reset all the attributes we save so there's no issue when switching from
  1522. * a live report and a saved output
  1523. */
  1524. cleanSavedAttributes: function() {
  1525. this.removeAttributeValue("savedOutputSearchPath");
  1526. this.removeAttributeValue("mostRecentSavedOutput");
  1527. this.removeAttributeValue("savedReportName");
  1528. this.removeAttributeValue("dashboardID");
  1529. this.removeAttributeValue("savedReportId");
  1530. this.removeAttributeValue("baseReportModificationTime");
  1531. this.removeAttributeValue("viewerReportPrompts");
  1532. this.removeAttributeValue("promptParametersRetrieved");
  1533. this.removeAttributeValue("selectionFilterEnabled");
  1534. this.removeAttributeValue("PinFreezeInfo");
  1535. this.removeAttributeValue("rapReportInfoVersion");
  1536. this.removeAttributeValue("rapReportInfo");
  1537. this.removeAttributeValue("selectionObjects");
  1538. if( this.isSavedOutput())
  1539. {
  1540. //this is set by chrome and shouldn't be remove unless switching from live to saved output.
  1541. this.removeAttributeValue("savedReportPath");
  1542. }
  1543. },
  1544. handleWidgetSaveDone: function( asynchJSONResponse ) {
  1545. var oCV = this.getViewerObject();
  1546. var jsonResult = asynchJSONResponse.getResult();
  1547. if (jsonResult===null) {
  1548. jsonResult = {};
  1549. }
  1550. this.cleanSavedAttributes();
  1551. this.updateSavedAttributes( "live" );
  1552. var reportName = jsonResult.reportName;
  1553. var dashboardID = jsonResult.dashboard_id;
  1554. this.setAttributeValue( "savedReportName", reportName );
  1555. this.setAttributeValue("dashboardID", '$$dbid$$' + dashboardID );
  1556. if (jsonResult.permissions) {
  1557. oCV.envParams["cv.objectPermissions"] = jsonResult.permissions;
  1558. }
  1559. if (jsonResult.objectClass) {
  1560. oCV.envParams["ui.objectClass"] = jsonResult.objectClass;
  1561. }
  1562. // flag needed to disable the snapshots menu on a dashboard open
  1563. if (this.getEnvParam("reportpart_id") && this.getEnvParam("reportpart_id").length > 0)
  1564. {
  1565. this.setAttributeValue("fromReportPart", "true");
  1566. }
  1567. if( this.isLimitedInteractiveMode() )
  1568. {
  1569. this.setAttributeValue( "limitedInteractiveMode", "true" );
  1570. }
  1571. else
  1572. {
  1573. this.setAttributeValue( "baseReportModificationTime", oCV.envParams["baseReportModificationTime"]);
  1574. }
  1575. var contentLocale = oCV.envParams["contentLocale"];
  1576. if (contentLocale != null) {
  1577. this.saveSliderState();
  1578. this.setAttributeValue( "lastLocaleSaved", contentLocale );
  1579. }
  1580. this.setAttributeValue( "originalReportLocation", oCV.envParams["originalReportLocation"]);
  1581. oCV.envParams["ui.object"] = this.getSavedReportSearchPath( reportName );
  1582. oCV.envParams["savedReportName"] = reportName;
  1583. this.setAttributeValue("hasAVSChart", oCV.hasAVSChart() ? "true" : "false");
  1584. // the displayTypes property is used for thumbnails
  1585. this.setAttributeValue("displayTypes", this.getDisplayTypes());
  1586. // clear the cached available outputs
  1587. this.setSavedOutputsCMResponse(null);
  1588. var saveDonePayload = {'status':true};
  1589. this.fireEvent( "com.ibm.bux.widget.save.done", null, saveDonePayload );
  1590. },
  1591. getDisplayTypes: function() {
  1592. var oCV = this.getViewerObject();
  1593. if (oCV.getRAPReportInfo()) {
  1594. return oCV.getRAPReportInfo().getDisplayTypes();
  1595. }
  1596. },
  1597. saveSliderState: function () {
  1598. //Save slider events that correspond to reportInfo....remove the rest.
  1599. var viewerObject = this.getViewerObject();
  1600. var oRAPReportInfo = viewerObject.getRAPReportInfo();
  1601. var reportInfoSliders = {};
  1602. if (oRAPReportInfo) {
  1603. reportInfoSliders = oRAPReportInfo.collectSliderSetFromReportInfo();
  1604. }
  1605. var i=0;
  1606. var sliderIDsToSave = [];
  1607. for(var sliderIDFromState in this.sliderState) {
  1608. if (typeof reportInfoSliders[sliderIDFromState] != "undefined") {
  1609. this.setItemValue("sliderState_" + sliderIDFromState, this.sliderState[sliderIDFromState]);
  1610. sliderIDsToSave[i++]=sliderIDFromState;
  1611. } else {
  1612. this.removeItem("sliderState_" + sliderIDFromState);
  1613. }
  1614. }
  1615. this.setAttributeValue("sliderIDs", dojo.toJson(sliderIDsToSave));
  1616. },
  1617. onWidgetRefresh: function ( evt ){
  1618. //TODO: Payload.status and Payload.message for widget.refresh.done
  1619. // It is not necessary for now
  1620. var refreshDonePayload = {};
  1621. var viewerObject = this.getViewerObject();
  1622. if( evt && viewerObject){
  1623. if (viewerObject.envParams["ui.action"] == "view" || viewerObject.envParams["ui.action"] == "buxView") {
  1624. viewerObject.executeAction( "RefreshViewEvent" );
  1625. } else {
  1626. /* TODO: Cleaning up, the following first IF condition branch is not being exercised in any case
  1627. * Currently, BUX Chrome will reload the whole dashboard after preferences settings change is detected.
  1628. */
  1629. if (evt.payload && evt.payload.refreshType == "preferencesChanged") {
  1630. this.clearRAPCache();
  1631. viewerObject.executeAction( "EditContent", {"preferencesChanged" : true} );
  1632. viewerObject.executeAction( "Reprompt", {"preferencesChanged" : true} );
  1633. } else {
  1634. //Delay Refresh ('Run') this viewer object on hidden tabs
  1635. if(!this.isVisible()) {
  1636. this.getDelayedLoadingContext().setForceRunReport(true);
  1637. }else{
  1638. viewerObject.executeAction( "Refresh" );
  1639. }
  1640. }
  1641. }
  1642. this.fireEvent( "com.ibm.bux.widget.refresh.done", null, refreshDonePayload);
  1643. }
  1644. },
  1645. invokeDisplayTypeDialog: function( targetTypes, suggestedDisplayTypes )
  1646. {
  1647. if( !this.m_chart )
  1648. {
  1649. this.m_chart = new bux.reportViewer.chart( );
  1650. }
  1651. var dialogDefinition = this.m_chart.getDisplayTypeDialogDefinition( targetTypes );
  1652. var payload= { 'supportedChartTypes' : dialogDefinition, 'suggestedDisplayTypes' : suggestedDisplayTypes };
  1653. this.fireEvent("com.ibm.bux.widget.invokeDisplayTypeDialog", null, payload );
  1654. },
  1655. onChangeDisplayType: function(evt) {
  1656. var viewerObject = this.getViewerObject();
  1657. if(evt && viewerObject) {
  1658. viewerObject.executeAction( "ChangeDisplayType", evt.payload );
  1659. }
  1660. },
  1661. onDisplayTypeDialogVariations: function(evt) {
  1662. var viewerObject = this.getViewerObject();
  1663. if(evt && viewerObject) {
  1664. viewerObject.executeAction( "ChangeDisplayVariations", evt.payload );
  1665. }
  1666. },
  1667. updateDisplayTypeDialogVariations: function(targetTypes, variationGroups )
  1668. {
  1669. if( !this.m_chart )
  1670. {
  1671. this.m_chart = new bux.reportViewer.chart( );
  1672. }
  1673. var dialogDefinition = this.m_chart.getDisplayTypeDialogDefinition( targetTypes );
  1674. var payload= { 'supportedChartTypes' : dialogDefinition, 'variationGroups' : variationGroups };
  1675. this.fireEvent("com.ibm.bux.widget.updateDisplayTypeDialogVariations", null, payload );
  1676. },
  1677. onGetDisplayTitleDone: function(evt) {
  1678. if(evt && evt.payload && evt.payload.callback) {
  1679. evt.payload.callback(evt.payload.title);
  1680. }
  1681. },
  1682. /**
  1683. * @return a value which can be parsed by dojo.when(), which resolves to
  1684. * the storeid
  1685. */
  1686. getWidgetStoreID: function()
  1687. {
  1688. if(typeof this.widgetStoreId === "undefined") {
  1689. if(!this.widgetStoreIdDfd) {
  1690. this.widgetStoreIdDfd = new dojo.Deferred();
  1691. }
  1692. return this.widgetStoreIdDfd;
  1693. }
  1694. return this.widgetStoreId;
  1695. },
  1696. setWidgetStoreID: function(storeId) {
  1697. this.widgetStoreId = storeId;
  1698. if(this.widgetStoreIdDfd) {
  1699. this.widgetStoreIdDfd.callback(this.widgetStoreId);
  1700. this.widgetStoreIdDfd = null;
  1701. }
  1702. },
  1703. onUpdateWidgetStoreIDDone: function(evt) {
  1704. var widgetStoreID = evt.payload.storeID;
  1705. var storeIDStr = 'storeID("';
  1706. if( widgetStoreID && (widgetStoreID.indexOf( storeIDStr ) > -1) )
  1707. {
  1708. //If there's a storeID(...), strip it out.
  1709. widgetStoreID = widgetStoreID.substr(storeIDStr.length, widgetStoreID.length - storeIDStr.length - 1);
  1710. }
  1711. dojo.when(this.getWidgetStoreID(),
  1712. /*callback*/dojo.hitch(this, function(widgetOldStoreID) {
  1713. if(widgetOldStoreID && widgetOldStoreID != widgetStoreID) {
  1714. this._copyComments(widgetOldStoreID, widgetStoreID);
  1715. }
  1716. })
  1717. );
  1718. this.setWidgetStoreID(widgetStoreID);
  1719. },
  1720. //TODO: Move this to AnnotationHelper
  1721. _copyComments: function(widgetOldStoreID, widgetStoreID) {
  1722. var postUrl = this.buildPostUrl();
  1723. if(postUrl) {
  1724. //clone the annotations
  1725. var httpRequest = new XmlHttpObject();
  1726. httpRequest.addFormField("b_action", "cognosViewer");
  1727. httpRequest.addFormField("widgetOldStoreID", widgetOldStoreID);
  1728. httpRequest.addFormField("widgetStoreID", widgetStoreID);
  1729. httpRequest.addFormField("ui.action", "cloneAnnotations");
  1730. httpRequest.addFormField("cv.responseFormat", "json");
  1731. //send asynchronous request
  1732. httpRequest.sendHtmlRequest("POST", postUrl, "", true);
  1733. }
  1734. },
  1735. onRemoveDone: function(evt) {
  1736. this.destroy();
  1737. },
  1738. onGetProperties : function (evt)
  1739. {
  1740. this.initializeProperties();
  1741. this.fireEvent("com.ibm.bux.widget.properties.get.done", null, this.properties.onGet() );
  1742. },
  1743. onSetProperties : function (evt)
  1744. {
  1745. if( evt && evt.payload && evt.payload.properties )
  1746. {
  1747. this.properties.onSet( evt.payload );
  1748. }
  1749. this.fireEvent("com.ibm.bux.widget.properties.set.done");
  1750. var modifiedEventPayload = {'modified':true};
  1751. this.fireEvent("com.ibm.bux.widget.modified", null, modifiedEventPayload);
  1752. },
  1753. getProperties : function ()
  1754. {
  1755. return this.properties;
  1756. },
  1757. clearPropertiesDialog : function() {
  1758. if (this.properties) {
  1759. this.properties.clearDialogSpec();
  1760. }
  1761. },
  1762. onGenericSelectValueControl: function(evt, bResetFirst) {
  1763. // clone the event so we can filter out values which have
  1764. if(evt) {
  1765. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  1766. //we process event only when viewer is loaded
  1767. var bRequestSentToServer = false;
  1768. var filterPayload = this._getFilterPayload( evt );
  1769. var selectValueControlType = (this.m_oWidgetContextManager) ? this.m_oWidgetContextManager.getSelectValueControlTypeFromPayload(filterPayload) : null;
  1770. if(selectValueControlType && selectValueControlType!=="facet") {
  1771. var clonedEvent = dojo.clone(evt);
  1772. this.preProcessFilterValues(clonedEvent);
  1773. this.m_oWidgetContextManager.updateFilterContext(clonedEvent.payload);
  1774. bRequestSentToServer = this.onFilter(clonedEvent, bResetFirst);
  1775. } else {
  1776. this.m_oWidgetContextManager.updateFilterContext(filterPayload);
  1777. bRequestSentToServer = this.onFilter(evt, bResetFirst);
  1778. }
  1779. //return value used by ViewerLoadManager.prototype.processQueue function
  1780. return bRequestSentToServer;
  1781. }), evt.source);
  1782. }
  1783. },
  1784. onFilter: function(evt, bResetFirst) {
  1785. if(evt) {
  1786. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  1787. var bRequestSentToServer = false;
  1788. if( this.isLiveReport() === false ){
  1789. return bRequestSentToServer;
  1790. }
  1791. var filterPayload = this._getFilterPayload( evt );
  1792. var selectValueControlType = (this.m_oWidgetContextManager) ? this.m_oWidgetContextManager.getSelectValueControlTypeFromPayload(filterPayload) : null;
  1793. var filterPayloadItemName = null;
  1794. var names = this.m_oWidgetContextManager.getItemNames(filterPayload);
  1795. var bCanFilter = false;
  1796. for(var i=0; !bCanFilter && i<names.length; i++) {
  1797. filterPayloadItemName = names[i];
  1798. bCanFilter = this.canFilter(filterPayload, filterPayloadItemName, selectValueControlType, evt )
  1799. }
  1800. if (filterPayloadItemName==null && !bCanFilter) {
  1801. //reset request
  1802. bCanFilter = this.canFilter(filterPayload, filterPayloadItemName, selectValueControlType, evt )
  1803. }
  1804. if(bCanFilter) {
  1805. var actionRequestParms = {};
  1806. var aDrillResetHUN = this._getDrillResetHUNForFacet( filterPayloadItemName, selectValueControlType);
  1807. if( aDrillResetHUN && aDrillResetHUN.length > 0 ){
  1808. actionRequestParms.drillResetHUN = aDrillResetHUN;
  1809. }
  1810. var filterPayloadStr = (evt.type=="string") ? evt.payload : dojo.toJson( evt.payload );
  1811. this.sliderState[evt.source] = filterPayloadStr;
  1812. actionRequestParms.filterPayload = filterPayloadStr;
  1813. actionRequestParms.isFacet = ("facet"===selectValueControlType); //only set for generic context (ie: not <filter> form)
  1814. if (bResetFirst) {
  1815. actionRequestParms.forceCleanup = this.m_oWidgetContextManager.genRemoveDiscreteFilterPayload(this.getWidgetId());
  1816. }
  1817. this.getViewerObject().executeAction("UpdateDataFilter", actionRequestParms);
  1818. if(!this.shouldReportBeRunOnAction()) {
  1819. this.getLoadManager().getDelayedLoadingContext().setForceRunReport(true);
  1820. }
  1821. bRequestSentToServer = true;
  1822. }
  1823. return bRequestSentToServer;
  1824. }), evt.source);
  1825. }
  1826. },
  1827. clearSelectionFilter: function() {
  1828. if (this.m_oWidgetContextManager) {
  1829. var selectionJson = this.m_oWidgetContextManager.genEmptySelectionPayload(this.getViewerObject(), this.getWidgetId());
  1830. this._fireContextChangedEvent(selectionJson, false);
  1831. }
  1832. },
  1833. broadcastSelectionFilter: function() {
  1834. this.onSelectionChange();
  1835. },
  1836. /*
  1837. * Selection as Filter:
  1838. * Called by CV when report selection is changed
  1839. */
  1840. onSelectionChange: function()
  1841. {
  1842. if (this.isSelectionFilterEnabled()) {
  1843. var bExcludeContext = ( this.getContainerTypeForSelection() === 'list' );
  1844. var selectionJson = this.m_oWidgetContextManager.genSelectionPayload(this.getViewerObject(), this.getWidgetId(), bExcludeContext);
  1845. //update the flag to true if payload is not for reset
  1846. this._fireContextChangedEvent(selectionJson, !this.m_oWidgetContextManager.isSelectionPayloadForReset(selectionJson));
  1847. }
  1848. },
  1849. /**
  1850. * @param selectionJson: selection json payload
  1851. * @param isFilter: true when payload is not for reset
  1852. */
  1853. _fireContextChangedEvent: function(selectionJson, isFilter)
  1854. {
  1855. this.setSelectionFilterSent(isFilter);
  1856. this.fireEvent("com.ibm.widget.contextChanged", null, selectionJson);
  1857. },
  1858. /*
  1859. * Ideally this function should be in CognosViewer object
  1860. * But for ActiveReprot widget to override, it is at Widget level
  1861. */
  1862. somethingSelected: function()
  1863. {
  1864. var oCV = this.getViewerObject();
  1865. return (oCV && oCV.getSelectionController() && oCV.getSelectionController().getAllSelectedObjects().length>0);
  1866. },
  1867. selectionFilterSent: function()
  1868. {
  1869. return this.m_bSelectionFilterSent;
  1870. },
  1871. setSelectionFilterSent: function(flag)
  1872. {
  1873. this.m_bSelectionFilterSent = flag;
  1874. },
  1875. reselectSelectionFilterObjects: function() {
  1876. if (this.isSelectionFilterEnabled()) {
  1877. var oCV = this.getViewerObject();
  1878. var selectionController = oCV.getSelectionController();
  1879. var aSelectionFilterObjects = this.m_oWidgetContextManager.getSelectionFilterObjects();
  1880. if (!aSelectionFilterObjects) {
  1881. //Opening dashboard case:
  1882. //Check if widget item set has it. if exists, use it then remove from attribute
  1883. var str = this.getAttributeValue( "selectionObjects" );
  1884. if (str && str.length>0) {
  1885. aSelectionFilterObjects = eval(str);
  1886. this.m_oWidgetContextManager.setSelectionFilterObjects(aSelectionFilterObjects);
  1887. this.removeAttributeValue("selectionObjects");
  1888. }
  1889. }
  1890. if (aSelectionFilterObjects && aSelectionFilterObjects.length>0) {
  1891. var reselectAction = new ReselectAction(oCV, aSelectionFilterObjects);
  1892. reselectAction.executeAction();
  1893. }
  1894. }
  1895. },
  1896. _getFilterPayload : function( evt ){
  1897. return (evt.type=="string" ? dojo.fromJson(evt.payload) : evt.payload);
  1898. },
  1899. _getFilterPayloadItemName : function( filterPayload ){
  1900. var filterPayloadItemName = filterPayload.name;
  1901. if (!filterPayload.name) {
  1902. filterPayloadItemName = this.m_oWidgetContextManager.getFilterFirstItemName();
  1903. }
  1904. return filterPayloadItemName;
  1905. },
  1906. canFilter: function(filterPayload, filterPayloadItemName, selectValueControlType, evt) {
  1907. var index;
  1908. var filterableItems = this.getRAPCachedItem("filterableItems");
  1909. if(selectValueControlType!=="facet" && typeof filterPayloadItemName != "undefined" && filterPayloadItemName != null && filterableItems != null) {
  1910. for(var type in filterableItems) { // visible/invisible
  1911. for(index = 0; index < filterableItems[type].length; ++index) {
  1912. if(filterableItems[type][index].name == filterPayloadItemName ||
  1913. filterableItems[type][index].label == filterPayloadItemName) {
  1914. return true;
  1915. }
  1916. }
  1917. }
  1918. }
  1919. else
  1920. {
  1921. var viewerObject = this.getViewerObject();
  1922. var oRAPReportInfo = viewerObject.getRAPReportInfo();
  1923. if (oRAPReportInfo) {
  1924. var selectValueDimensionName = (this.m_oWidgetContextManager) ? this.m_oWidgetContextManager.getSelectValuePropertyFromPayload(filterPayload, "dimension") : null;
  1925. var containers = oRAPReportInfo.getContainers();
  1926. for(var lid in containers) {
  1927. var container = containers[lid];
  1928. var sliders = container.sliders;
  1929. if(sliders && sliders.length) {
  1930. for(var sliderIndex = 0; sliderIndex < sliders.length; ++sliderIndex) {
  1931. var oSlider = sliders[sliderIndex];
  1932. if(oSlider.clientId == filterPayload.clientId ||
  1933. (oSlider.clientId == evt.source) ||
  1934. (oSlider.clientId==oSlider.name && oSlider.name==filterPayloadItemName)) {
  1935. return true;
  1936. }
  1937. }
  1938. }
  1939. var itemInfo = container.itemInfo;
  1940. if (itemInfo && itemInfo.length) {
  1941. for(var itemInfoIndex = 0; itemInfoIndex < itemInfo.length; ++itemInfoIndex) {
  1942. if(itemInfo[itemInfoIndex].item == filterPayloadItemName) {
  1943. return true;
  1944. }
  1945. //Measure facets will be in the item list and will match the dimension.
  1946. if(selectValueControlType==="facet" && itemInfo[itemInfoIndex].dimensionName == filterPayloadItemName) {
  1947. return true;
  1948. }
  1949. //Attribute facets (new payload) will have dimension name specified.
  1950. if(selectValueControlType==="facet" && itemInfo[itemInfoIndex].dimensionName === selectValueDimensionName) {
  1951. return true;
  1952. }
  1953. }
  1954. }
  1955. if (selectValueControlType==="facet") {
  1956. //Defer to server to check validity of attribute facets (could be improved with some type of caching).
  1957. var filterType = (this.m_oWidgetContextManager) ? this.m_oWidgetContextManager.getSelectValuePropertyFromPayload(filterPayload, "filterType") : null;
  1958. if (selectValueControlType==="facet" && filterType==="attribute") {
  1959. return true;
  1960. }
  1961. //For facets, match the hierarchy name.
  1962. var filterInfo = container.filter;
  1963. if (filterInfo && filterInfo.length) {
  1964. for (var filterInfoIndex = 0; filterInfoIndex < filterInfo.length; ++filterInfoIndex) {
  1965. if (filterInfo[filterInfoIndex].hierarchyName === filterPayloadItemName) {
  1966. return true;
  1967. }
  1968. }
  1969. }
  1970. } else {
  1971. if (oRAPReportInfo.getFilterObjectFromContainer(lid, filterPayloadItemName, false)) {
  1972. return true;
  1973. }
  1974. }
  1975. }
  1976. if(oRAPReportInfo.isReportLevel_nonVisibleFilterItem(filterPayloadItemName) ) {
  1977. return true;
  1978. }
  1979. }
  1980. }
  1981. return false;
  1982. },
  1983. _getDrillResetHUNForFacet: function( filterItemName, selectValueControlType ) {
  1984. if( selectValueControlType !== 'facet'){
  1985. return null;
  1986. }
  1987. var drilledOnHUNs = null;
  1988. var viewerObject = this.getViewerObject();
  1989. if (viewerObject.getRAPReportInfo()) {
  1990. drilledOnHUNs = viewerObject.getRAPReportInfo().getDrilledOnHUNs();
  1991. }
  1992. if( !drilledOnHUNs ){ return null; }
  1993. /**
  1994. * DrillReset action takes an array as parameter
  1995. */
  1996. var aDrillResetHUNs = [];
  1997. for( var i = 0; i < drilledOnHUNs.length; i++ ){
  1998. if( drilledOnHUNs[i].indexOf( filterItemName ) !== -1 ) {
  1999. aDrillResetHUNs.push( drilledOnHUNs[i] );
  2000. break;
  2001. }
  2002. }
  2003. return aDrillResetHUNs;
  2004. },
  2005. preProcessFilterValues: function(evt) {
  2006. var contextObject = evt.payload["com.ibm.widget.context"]["values"];
  2007. contextObject = (contextObject) ? contextObject : evt.payload["com.ibm.widget.context"]["ranges"];
  2008. var itemsInItemSpecObject = this.m_oWidgetContextManager.getItemsInItemSpecification(evt.payload);
  2009. var isDeleteSliderEvent=(contextObject) ? false : true;
  2010. if (isDeleteSliderEvent) {
  2011. //Sliders should always be deleted by ID not by name.
  2012. contextObject = evt.payload["com.ibm.widget.context"];
  2013. }
  2014. var viewerObject = this.getViewerObject();
  2015. if (viewerObject) {
  2016. var oRAPReportInfo = viewerObject.getRAPReportInfo();
  2017. for(var dataItem in contextObject) {
  2018. if (!oRAPReportInfo.isReferenced(dataItem) || isDeleteSliderEvent) {
  2019. delete contextObject[dataItem];
  2020. if (itemsInItemSpecObject && itemsInItemSpecObject[dataItem]) {
  2021. delete itemsInItemSpecObject[dataItem];
  2022. }
  2023. }
  2024. }
  2025. }
  2026. // If we're left we no dataItems that we care about, blank out the context information so any previous filter
  2027. // applied by the same 'sender' will get removed.
  2028. if (isObjectEmpty(contextObject)) {
  2029. evt.payload["com.ibm.widget.context"] = {};
  2030. }
  2031. },
  2032. isLimitedInteractiveMode: function() {
  2033. var viewerObject = this.getViewerObject();
  2034. if(viewerObject) {
  2035. return viewerObject.isLimitedInteractiveMode();
  2036. }
  2037. return false;
  2038. },
  2039. onMouseOver: function(evt) {
  2040. if(DragDropAction_isDragging(evt) == false && this.getViewerObject().getStatus() == "complete")
  2041. {
  2042. var action = ActionFactory_loadActionHandler(evt, this.getViewerObject());
  2043. if(action) {
  2044. return action.onMouseOver(evt);
  2045. }
  2046. }
  2047. return true;
  2048. },
  2049. onMouseOut: function(evt) {
  2050. var action = ActionFactory_loadActionHandler(evt, this.getViewerObject());
  2051. if(action && this.getViewerObject().getStatus() == "complete") {
  2052. return action.onMouseOut(evt);
  2053. }
  2054. return true;
  2055. },
  2056. onMouseOverRenamedItem: function(evt) {
  2057. var node = getNodeFromEvent(evt);
  2058. if (node.getAttribute)
  2059. {
  2060. var originalLabel = node.getAttribute("rp_name");
  2061. if(originalLabel != null) {
  2062. var label = this.getViewerObject().getSelectionController().getTextValue(node.childNodes);
  2063. if(originalLabel != label) {
  2064. var id = node.getAttribute("id");
  2065. node.m_tooltip = new bux.reportViewer.ReportInfo(
  2066. {
  2067. connectId: [id],
  2068. position: ["above","below"],
  2069. title: RV_RES.IDS_JS_RENAMED_ITEM,
  2070. text: RV_RES.IDS_JS_RENAMED_ITEM_ORIGINAL_LABEL + " " + node.getAttribute("rp_name")
  2071. });
  2072. node.m_tooltip.open();
  2073. }
  2074. }
  2075. }
  2076. },
  2077. onMouseOutRenamedItem: function(evt) {
  2078. var node = getNodeFromEvent(evt);
  2079. node.m_tooltip = null;
  2080. },
  2081. onDoubleClick: function(evt) {
  2082. // Double click event is used mostly to perform the default drill.
  2083. var action = ActionFactory_loadActionHandler(evt, this.getViewerObject());
  2084. if(action && this.getViewerObject().getStatus() == "complete") {
  2085. return action.onDoubleClick(evt);
  2086. }
  2087. return true;
  2088. },
  2089. onMouseDown: function(evt) {
  2090. var oCV = this.getViewerObject();
  2091. var factory = oCV.getActionFactory();
  2092. // Need to keep the selection action around so it can be used for mouse up as well.
  2093. this._selectionAction = factory.load("Selection");
  2094. if (this.isMobile()) {
  2095. var selectionController = oCV.getSelectionController();
  2096. var nodeSelected = selectionController.pageClickedForMobile(evt);
  2097. // Only get Mobile to show the pop-over if we've selected something in the report and
  2098. // the widget isn't sending contextChanged events
  2099. if (this.isSelectionFilterEnabled()) {
  2100. this.onSelectionChange();
  2101. }
  2102. else if (nodeSelected) {
  2103. this.onContextMenu(evt);
  2104. }
  2105. }
  2106. else if (oCV.envParams["ui.action"] == 'view') {
  2107. this._selectionAction.onMouseDown(evt);
  2108. }
  2109. else if(oCV.getStatus() == "complete") {
  2110. if((evt.button == 1 || evt.button == 0)) {
  2111. // if the onMouseDown returns true, then we executed a drillThrough and shouldn't be doing a drag/drop action
  2112. // if the onMouseDown for rename returns true then the user clicked in the rename edit box so don't start a drag/drop
  2113. if (!this._selectionAction.onMouseDown(evt) && !factory.load("RenameDataItem").onMouseDown(evt)) {
  2114. this.initDragAndDrop();
  2115. factory.load("DragDrop").onMouseDown(evt);
  2116. }
  2117. } else {
  2118. this._selectionAction.onMouseDown(evt);
  2119. }
  2120. }
  2121. },
  2122. onMouseUp: function(evt) {
  2123. if (this.isMobile()) {
  2124. return;
  2125. }
  2126. var srcNode = getCrossBrowserNode(evt);
  2127. // if the event did come from an INPUT or TEXTAREA element cancel the bubble,
  2128. // to prevent lost of focus in IE
  2129. try {
  2130. var nodeName = srcNode.nodeName.toLowerCase();
  2131. if (nodeName == "input" || nodeName == "textarea") {
  2132. evt.cancelBubble = true;
  2133. return false;
  2134. }
  2135. }
  2136. catch(ex) {
  2137. // sometimes node may not be an HTML element (like a XUL element) and accessing nodeType/nodeName/className will generate an error.
  2138. }
  2139. var eventConsumed = false;
  2140. if (this.getViewerObject().envParams["ui.action"] == 'view') {
  2141. setNodeFocus(evt);
  2142. }
  2143. else if (this.getViewerObject().getStatus() == "complete") {
  2144. eventConsumed |= DragDropAction_isDragging(evt);
  2145. DragDropAction_onmouseup(evt);
  2146. this.removeDragAndDrop();
  2147. setNodeFocus(evt);
  2148. }
  2149. if (!this._selectionAction) {
  2150. var oCV = this.getViewerObject();
  2151. var factory = oCV.getActionFactory();
  2152. this._selectionAction = factory.load("Selection");
  2153. }
  2154. this._selectionAction.onMouseUp(evt, eventConsumed);
  2155. clearTextSelection();
  2156. },
  2157. getContainerTypeForSelection : function()
  2158. {
  2159. var viewerObject = this.getViewerObject();
  2160. if( viewerObject )
  2161. {
  2162. var selectionController = viewerObject.getSelectionController();
  2163. return selectionController.getDataContainerType();
  2164. }
  2165. return null;
  2166. },
  2167. onContextMenu: function(evt) {
  2168. var viewerObject = this.getViewerObject();
  2169. if( viewerObject.getStatus() == "complete" || this.isSavedOutput() ) {
  2170. var contextMenu = viewerObject.getContextMenu();
  2171. var tempContextMenu = CCognosViewerToolbarHelper.updateContextMenuForCurrentSelection(viewerObject, contextMenu);
  2172. if (this.isMobile()) {
  2173. var selectionController = viewerObject.getSelectionController();
  2174. var containerType = selectionController.getContainerType();
  2175. // if we're dealing with a chart then get the tooltip
  2176. var chartTooltip = containerType === "chart" ? selectionController.getChartTooltip() : null;
  2177. //if annotation exists
  2178. if (this.getAnnotationStore() && this.getAnnotationStore().hasAnnotation()) {
  2179. var cellComments = this._genMobileCommentMenuItem(selectionController);
  2180. if (cellComments) {
  2181. tempContextMenu.push(cellComments);
  2182. }
  2183. var widgetComments = this._genMobileCommentMenuItem();
  2184. if (widgetComments) {
  2185. var widgetActionsItems = viewerObject.findBlueDotMenu(tempContextMenu);
  2186. if (widgetActionsItems) {
  2187. widgetActionsItems.push(widgetComments);
  2188. }
  2189. }
  2190. }
  2191. var mobileContextMenu = {
  2192. "context" : {
  2193. "event" : evt,
  2194. "viewerContext" : {
  2195. "displayValues" : selectionController.getDisplayValues(),
  2196. "chartTooltip" : chartTooltip,
  2197. "containerType" : containerType
  2198. }
  2199. },
  2200. "menuItems" : tempContextMenu
  2201. };
  2202. if (typeof console != "undefined" && console && console.log) {
  2203. console.log(mobileContextMenu);
  2204. }
  2205. this.fireEvent("com.ibm.bux.widget.contextMenu.update", null, mobileContextMenu);
  2206. }
  2207. else {
  2208. this.fireEvent("com.ibm.bux.widget.contextMenu.update", null, tempContextMenu);
  2209. }
  2210. }
  2211. },
  2212. _genMobileCommentMenuItem: function(selectionController) {
  2213. var ctx = null;
  2214. if (selectionController) {
  2215. if (selectionController.getSelections().length==1) {
  2216. ctx = selectionController.getSelections()[0].getCtxAttributeString();
  2217. }
  2218. if (!ctx) {
  2219. return null;
  2220. }
  2221. }
  2222. var comments = this.getAnnotationStore().getAsJSON(ctx);
  2223. if (comments.length>0) {
  2224. return {
  2225. "name": RV_RES.IDS_JS_ANNOTATIONS,
  2226. "label": RV_RES.IDS_JS_ANNOTATIONS,
  2227. "flatten": false,
  2228. "comments": comments};
  2229. }
  2230. return null;
  2231. },
  2232. initDragAndDrop: function() {
  2233. if (window.attachEvent)
  2234. {
  2235. document.attachEvent("onmouseup", DragDropAction_onmouseup);
  2236. document.attachEvent("onmousemove", DragDropAction_onmousemove);
  2237. }
  2238. else if (document.addEventListener)
  2239. {
  2240. document.addEventListener("mouseup", DragDropAction_onmouseup, false);
  2241. document.addEventListener("mousemove", DragDropAction_onmousemove, false);
  2242. }
  2243. },
  2244. removeDragAndDrop: function() {
  2245. if (window.detachEvent)
  2246. {
  2247. document.detachEvent("onmouseup", DragDropAction_onmouseup);
  2248. document.detachEvent("onmousemove", DragDropAction_onmousemove);
  2249. }
  2250. else if (document.removeEventListener)
  2251. {
  2252. document.removeEventListener("mouseup", DragDropAction_onmouseup, false);
  2253. document.removeEventListener("mousemove", DragDropAction_onmousemove, false);
  2254. }
  2255. },
  2256. onWidgetResize: function(evt) {
  2257. var resize = evt.payload.resize;
  2258. if (resize) {
  2259. /**
  2260. * We get multiple resize events from BUX on dashboard open. These are meant mostly for other widgets
  2261. * like text widgets. We can safely ignore these events if we're hidden or if it's the first resize event
  2262. * we get while visible. After, we'll only process the event if the height or width has changed.
  2263. */
  2264. if (!this.m_visible || (this.widgetSize && this.widgetSize.h === resize.h && this.widgetSize.w === resize.w)) {
  2265. return;
  2266. }
  2267. var bInitialResizeEvent = !this.widgetSize;
  2268. this.widgetSize = { h : resize.h, w : resize.w };
  2269. if (bInitialResizeEvent) {
  2270. return;
  2271. }
  2272. if (!resize.autoResize) {
  2273. //Don't resize charts when the autoResize flag is set (resize to fit content).
  2274. this.executeAction(evt, "ResizeChart");
  2275. }
  2276. var oCV = this.getViewerObject();
  2277. if (oCV && oCV.getPinFreezeManager()) {
  2278. if (resize.autoResize) {
  2279. //Update the last size processed by an autoresize to properly detect
  2280. //that size has changed on the next resize.
  2281. oCV.getPinFreezeManager().processAutoResize(resize.w, resize.h);
  2282. }
  2283. //HACK: See Task 236446 for an explanation:
  2284. setTimeout(
  2285. function() {
  2286. oCV.getPinFreezeManager().refresh();
  2287. }, 100
  2288. );
  2289. }
  2290. if (oCV.getTabController()) {
  2291. oCV.getTabController().onResize(evt);
  2292. }
  2293. }
  2294. },
  2295. getWidgetSize: function() {
  2296. return this.widgetSize;
  2297. },
  2298. refreshAnnotationData: function() {
  2299. return this.getAnnotationHelper().refreshAnnotationData();
  2300. },
  2301. fetchAnnotationData: function() {
  2302. this.getAnnotationHelper().fetchAnnotationData();
  2303. },
  2304. /**
  2305. * Return true iff the report contains any dijits.
  2306. */
  2307. reportContainsDijits: function() {
  2308. var store = this.getAnnotationStore();
  2309. var annotations = store.getAll();
  2310. for(var key in annotations) {
  2311. if(typeof annotations[key] !== "function") {
  2312. return true;
  2313. }
  2314. }
  2315. return false;
  2316. },
  2317. isSaveNecessary: function () {
  2318. var isNecessary = false;
  2319. if (this.isSavedOutput()) {
  2320. var sHasAlreadySaved = this.getAttributeValue("mostRecentSavedOutput");
  2321. //Item set should always return "true" or "false", but a BUX bug
  2322. //sometimes converts these strings to actual booleans. This should
  2323. //be fixed by BUX, see tasks 299654 and 299650, and then the
  2324. //boolean check here can be removed.
  2325. var bHasAlreadySaved = sHasAlreadySaved === "true" || sHasAlreadySaved === true;
  2326. var sSavedOutputSearchPath = this.getAttributeValue("savedOutputSearchPath");
  2327. isNecessary = !bHasAlreadySaved && sSavedOutputSearchPath == null;
  2328. } else {
  2329. var sOriginalItem = this.getAttributeValue("originalReport");
  2330. var sSavedItem = this.getAttributeValue("savedReportName") || this.getAttributeValue( "savedReportPath" );
  2331. if (!this.isSavedReport(sOriginalItem, sSavedItem)) {
  2332. isNecessary = true;
  2333. }
  2334. }
  2335. return isNecessary;
  2336. },
  2337. addAsNewComment: function(ctxId, text) {
  2338. this.getAnnotationHelper().addAsNewComment(ctxId, text);
  2339. },
  2340. onWidgetActionDone: function (iEvent) {
  2341. if (iEvent && iEvent.payload && iEvent.payload.status === true) {
  2342. this.getAnnotationHelper().addNewComment(this._pendingContextId, this._pendingCellValue);
  2343. }
  2344. this._pendingContextId = null;
  2345. this._pendingCellValue = null;
  2346. },
  2347. commitComment: function(annotation) {
  2348. if (!annotation.isNew) {
  2349. return null;
  2350. }
  2351. if (!annotation.isLoaded) {
  2352. return this.getAnnotationHelper().commitComment(annotation);
  2353. }
  2354. return null;
  2355. },
  2356. getAnnotationStore: function() {
  2357. if(!this.annotationStore) {
  2358. dojo["require"]("bux.data.AnnotationStore");
  2359. this.annotationStore = new bux.data.AnnotationStore(this, this.commitComment, this);
  2360. }
  2361. return this.annotationStore;
  2362. },
  2363. fireEvent: function(eventName, arg, payload) {
  2364. if (window.gViewerLogger) {
  2365. var id = this.getViewerObject() ? this.getViewerObject().getId() + " " : "";
  2366. window.gViewerLogger.log(id + eventName, payload, "json");
  2367. }
  2368. this.iContext.iEvents.fireEvent( eventName, arg, payload );
  2369. },
  2370. onGetFilterableItems: function( evt )
  2371. {
  2372. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  2373. var bRequestSentToServer = false;
  2374. var oCachedFilterableItems = this.getRAPCachedItem("filterableItems");
  2375. if( oCachedFilterableItems == null && this.isLiveReport() && (this.getViewerObject().getStatus() == "complete" || this.isFaultStatusWithSpec())) {
  2376. this.executeAction( evt, "GetFilterableItems" );
  2377. bRequestSentToServer = true;
  2378. } else {
  2379. if(!oCachedFilterableItems) {
  2380. oCachedFilterableItems = {
  2381. visible: [],
  2382. hidden: []
  2383. };
  2384. }
  2385. if(this.isLiveReport()) {
  2386. this.fireEvent("com.ibm.bux.filter.items.get.done", null, oCachedFilterableItems);
  2387. } else {
  2388. this.savedOutputResponseHandler("com.ibm.bux.filter.items.get.done", oCachedFilterableItems);
  2389. }
  2390. }
  2391. return bRequestSentToServer;
  2392. }));
  2393. },
  2394. /*Private function to check if the view has a "fault" status while the view ui.spec exits still
  2395. * for situations like dynamic slider missing members*/
  2396. isFaultStatusWithSpec: function(){
  2397. var oVO = this.getViewerObject();
  2398. if(oVO.getStatus() === "fault"){
  2399. if(oVO.envParams["ui.spec"]){
  2400. return true;
  2401. }
  2402. }
  2403. return false;
  2404. },
  2405. onGetFilterValues: function(oEvt) {
  2406. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  2407. //If the source is defined in the evt but not in the payload, transfer it....
  2408. var oPayload = oEvt.payload;
  2409. if (typeof oEvt.source != "undefined" && typeof oPayload != "undefined") {
  2410. if (typeof oPayload.payload != "undefined") {
  2411. oPayload = oPayload.payload;
  2412. }
  2413. if (typeof oPayload.source == "undefined") {
  2414. oPayload.source = oEvt.source;
  2415. }
  2416. }
  2417. var bRequestSentToServer = false;
  2418. var bIsLiveReport = this.isLiveReport();
  2419. var sViewerStatus = this.getViewerObject().getStatus();
  2420. var bIsFaultWithSpec = this.isFaultStatusWithSpec();
  2421. if (bIsLiveReport && (sViewerStatus === "complete" || bIsFaultWithSpec) ) {
  2422. var oCachedFilterValuesForItem=null;
  2423. if (!oPayload.forceRefresh && oPayload.name) {
  2424. oCachedFilterValuesForItem = this.getRAPCachedItem("filterValues." + oPayload.name);
  2425. }
  2426. if (oCachedFilterValuesForItem) {
  2427. this.fireEvent("com.ibm.bux.filter.values.get.done", null, oCachedFilterValuesForItem);
  2428. } else {
  2429. this.executeAction( oEvt, "GetFilterValues" );
  2430. bRequestSentToServer = true;
  2431. }
  2432. } else if (this.getViewerObject().isWorking(sViewerStatus)) {
  2433. //Still working. Retry after a delay.
  2434. var self = this;
  2435. var fnRetry = function() {
  2436. self.onGetFilterValues(oEvt);
  2437. };
  2438. setTimeout(fnRetry, 10);
  2439. } else {
  2440. var oResponsePayload = {};
  2441. if(oPayload.name) {
  2442. oResponsePayload.name = oPayload.name;
  2443. }
  2444. this.fireEvent("com.ibm.bux.filter.values.get.done", null, oResponsePayload);
  2445. }
  2446. return bRequestSentToServer;
  2447. }));
  2448. },
  2449. /**
  2450. * Called when the users hit cancel in the filter options dialog
  2451. */
  2452. onGetFilterValuesCancel: function(evt) {
  2453. if (evt && evt.payload) {
  2454. var oCV = this.getViewerObject();
  2455. // create a GetFilterValueAction object so that we can get rebuild the correct key used for
  2456. // the original request
  2457. var action = oCV.getAction("GetFilterValues");
  2458. action.setRequestParms( evt );
  2459. var requestKey = action.getActionKey();
  2460. if (requestKey) {
  2461. oCV.getViewerDispatcher().cancelRequest(requestKey);
  2462. }
  2463. }
  2464. },
  2465. savedOutputResponseHandler: function(sEventName, oPayload) {
  2466. var oCV = this.getViewerObject();
  2467. var sPayload = dojo.toJson(oPayload);
  2468. var sSavedOutputResponse = "window[\"oCV" + oCV.getId() + "\"].getViewerWidget().fireEvent(\"" + sEventName + "\", null, " + sPayload + ");";
  2469. if (oCV) {
  2470. var window_oCV = window["oCV" + oCV.getId()];
  2471. if (typeof window_oCV == "object") {
  2472. setTimeout(sSavedOutputResponse,1);
  2473. }
  2474. }
  2475. return sSavedOutputResponse;
  2476. },
  2477. handleGetFilterableItemsResponse: function( oResponse )
  2478. {
  2479. var payload = {};
  2480. var json = this.getJsonFromResponse(oResponse);
  2481. if (json) {
  2482. payload = json.filterableItems;
  2483. if(!payload){
  2484. payload = {"visible":[],"invisible":[]};
  2485. }
  2486. // cache the filterable items, so we can re-use later for filter actions or in case the slider dialog is re-launched
  2487. this.addToRAPCache("filterableItems", payload);
  2488. }
  2489. this.fireEvent("com.ibm.bux.filter.items.get.done", null, payload);
  2490. },
  2491. handleGetFilterValuesResponse: function(oResponse, oParams) {
  2492. var oPayload = {};
  2493. var json = this.getJsonFromResponse(oResponse);
  2494. if (json && json.filterValues ) {
  2495. oPayload = json.filterValues;
  2496. if (oPayload && oPayload.name) {
  2497. this.addToRAPCache("filterValues." + oPayload.name, oPayload);
  2498. }
  2499. }
  2500. if(oParams && oParams.name && !oPayload.name) {
  2501. oPayload.name = oParams.name;
  2502. }
  2503. //In order to ensure the internal value of payload stored in the cache
  2504. //isn't modified, send a copy of this data in the event.
  2505. oPayload = dojo.clone(oPayload);
  2506. this.fireEvent("com.ibm.bux.filter.values.get.done", null, oPayload);
  2507. },
  2508. getJsonFromResponse: function (oResponse) {
  2509. var json = null;
  2510. if (oResponse && oResponse.m_jsonResponse && oResponse.m_jsonResponse.json) {
  2511. json = dojo.eval("(" + oResponse.m_jsonResponse.json + ")");
  2512. } else if (oResponse && oResponse.responseText) {
  2513. json = dojo.eval("[" + oResponse.responseText + "]");
  2514. if (json && json[0]) {
  2515. json = json[0];
  2516. }
  2517. }
  2518. return json;
  2519. },
  2520. /**
  2521. * Generic contextChange event
  2522. */
  2523. onContextChanged: function(evt) {
  2524. // clone the event so we can filter out values which have
  2525. if(evt) {
  2526. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  2527. //we process event only when viewer is loaded
  2528. var bRequestSentToServer = false;
  2529. var clonedEvent = dojo.clone(evt);
  2530. //convert payload to seletValue
  2531. var payload = this._getFilterPayload( clonedEvent );
  2532. this.m_oWidgetContextManager.convertSelectionToSelectValueControlPayload(payload);
  2533. this.m_oWidgetContextManager.convertGenericToSelectValueControlPayload(payload);
  2534. //Process context filter by root member
  2535. var viewerObject = this.getViewerObject();
  2536. var oRAPReportInfo = viewerObject.getRAPReportInfo();
  2537. if (oRAPReportInfo && (oRAPReportInfo.containsFilters() || oRAPReportInfo.hasSlider())) {
  2538. var oCommonPartValues = payload["com.ibm.widget.context"].values;
  2539. var oPackage = this.m_oWidgetContextManager.getItemsInItemSpecification(payload);
  2540. var oOriginalPackage = dojo.clone(oPackage);
  2541. for(var itemName in oOriginalPackage) {
  2542. if (!oRAPReportInfo.isReferenced(itemName) && oPackage[itemName].values) {
  2543. var mun = oPackage[itemName].values[0].mun;
  2544. var newName = oRAPReportInfo.hunHasFilterOrSlider(mun);
  2545. //Rename
  2546. if (newName && !oPackage[newName]) {
  2547. oPackage[newName] = oPackage[itemName];
  2548. delete oPackage[itemName];
  2549. oCommonPartValues[newName] = oCommonPartValues[itemName];
  2550. delete oCommonPartValues[itemName];
  2551. }
  2552. }
  2553. }
  2554. }
  2555. clonedEvent.payload = payload;
  2556. /*
  2557. * We need to reset filterable items from source widget first because
  2558. * previous payload might have more items than current payload.
  2559. */
  2560. bRequestSentToServer = this.onGenericSelectValueControl(clonedEvent, /*bResetFirst*/ true);
  2561. //return value used by ViewerLoadManager.prototype.processQueue function
  2562. return bRequestSentToServer;
  2563. }), evt.source);
  2564. }
  2565. },
  2566. /**
  2567. * Public API to send a generic contextChanged event
  2568. */
  2569. broadcastParameterChange: function(payload) {
  2570. var eventPayload = {
  2571. "clientId" : this.getWidgetId(),
  2572. "com.ibm.widget.context" : payload
  2573. }
  2574. this.fireEvent( "com.ibm.widget.contextChanged.prompt", null, eventPayload);
  2575. },
  2576. /**
  2577. * Public API to send a generic contextChanged event
  2578. */
  2579. broadcastContextChange: function(payload) {
  2580. if (this.isSelectionFilterEnabled()) {
  2581. // Build up an event object so that we can re-use our regular filter code
  2582. var eventPayload = {
  2583. "clientId" : this.getWidgetId(),
  2584. "com.ibm.widget.context" : payload,
  2585. "com.ibm.widget.context.bux.selection": {"selection":{
  2586. "id":this.getWidgetId(),
  2587. "valueType":"string"
  2588. }}
  2589. }
  2590. this.m_oWidgetContextManager.updateFilterContext(eventPayload);
  2591. this.m_oWidgetContextManager.setSelectionFilterObjects(null);
  2592. this._fireContextChangedEvent(eventPayload, true);
  2593. }
  2594. },
  2595. onGenericDrill: function(evt)
  2596. {
  2597. this.m_handleDrill = false; //used for unit test only
  2598. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function() {
  2599. var bRequestSentToServer = false;
  2600. if( !(evt && evt.payload) || this.isLimitedInteractiveMode() )
  2601. {
  2602. return bRequestSentToServer;
  2603. }
  2604. //process event only if fired by different widget
  2605. if( evt.payload.cv_id === this.iContext.widgetId )
  2606. {
  2607. return bRequestSentToServer;
  2608. }
  2609. var sDrillAction = this.m_oWidgetContextManager.getDrillActionType(evt.payload);
  2610. var aDrillSpecObjects = this.m_oWidgetContextManager.genDrillSpecObjects(evt.payload);
  2611. var oDrillAction = null;
  2612. if( sDrillAction === "DrillDown")
  2613. {
  2614. oDrillAction = this.getViewerObject().getAction("DrillDown");
  2615. }
  2616. else if( sDrillAction === "DrillUp")
  2617. {
  2618. oDrillAction = this.getViewerObject().getAction("DrillUp");
  2619. }
  2620. else
  2621. {
  2622. return bRequestSentToServer;
  2623. }
  2624. oDrillAction.setKeepFocusOnWidget(false);
  2625. if (this.getViewerObject().isMetadataEmpty() || !this.shouldReportBeRunOnAction()) {
  2626. oDrillAction.setUseReportInfoSelection(true); //Must set before parsing the spec
  2627. }
  2628. if( oDrillAction.parseDrillSpecObjects(aDrillSpecObjects) ){
  2629. if (!this.shouldReportBeRunOnAction()) {
  2630. this.getLoadManager().getDelayedLoadingContext().setForceRunReport(true);
  2631. }
  2632. oDrillAction.execute();
  2633. bRequestSentToServer = true;
  2634. }
  2635. this.m_handleDrill = true;// for unit test only
  2636. return bRequestSentToServer;
  2637. }));
  2638. },
  2639. setDoGetParametersOnLoad : function( bFlag )
  2640. {
  2641. this.m_doGetParametersOnLoad = bFlag;
  2642. },
  2643. getDoGetParametersOnLoad : function()
  2644. {
  2645. return this.m_doGetParametersOnLoad;
  2646. },
  2647. /*
  2648. * Handles share prompt event.
  2649. * Returns true if sucessful, false otherwise, null if unknown.
  2650. * Note that the return value should only be used in testing.
  2651. */
  2652. onPromptLegacyPayload: function(evt) {
  2653. try {
  2654. //process event only if fired by different widget and we're not looking at saved output
  2655. if( evt.payload.cv_id === this.iContext.widgetId) {
  2656. return false;
  2657. }
  2658. var bRequestSentToServer = null;
  2659. this.getLoadManager().runWhenHasViewer(dojo.hitch(this, function(bIsSynchronous) {
  2660. bRequestSentToServer = false;
  2661. if (this.isSavedOutput()) {
  2662. return bRequestSentToServer;
  2663. }
  2664. if (this.promptParametersRetrieved === false) {
  2665. //run getParameters to get the prompt parameters for the current widget
  2666. var getParametersAction = this.getViewerObject().getAction("GetParameters");
  2667. getParametersAction.setRequestParms(evt.payload);
  2668. getParametersAction.execute();
  2669. bRequestSentToServer = true;
  2670. } else {
  2671. bRequestSentToServer = this.sharePrompts(evt.payload);
  2672. }
  2673. return bRequestSentToServer;
  2674. }));
  2675. return bRequestSentToServer;
  2676. } catch(e) {
  2677. return false;
  2678. }
  2679. },
  2680. sharePrompts: function(payload) {
  2681. var sharePromptAction = this.getViewerObject().getAction("SharePrompt");
  2682. sharePromptAction.setRequestParms(payload);
  2683. if( this.shouldReportBeRunOnAction() ) {
  2684. var aDrillResetHUNs = this.getViewerObject().getDrillResetHUNs( payload );
  2685. if( !aDrillResetHUNs || aDrillResetHUNs.length === 0 ){
  2686. return sharePromptAction.executePrompt();
  2687. }else{
  2688. var parms = { 'drilledResetHUNs' : aDrillResetHUNs,
  2689. 'promptValues' : sharePromptAction.getPromptValues() };
  2690. this.getViewerObject().executeAction( "DrillReset", parms );
  2691. }
  2692. return true;
  2693. }
  2694. var delayedLoadingContext = this.getLoadManager().getDelayedLoadingContext();
  2695. delayedLoadingContext.setPromptValues( sharePromptAction.getPromptValues() );
  2696. delayedLoadingContext.setCascadingPromptParamsToClear( payload.clearCascadePromptParams );
  2697. return false;
  2698. },
  2699. onGenericPrompt: function(evt) {
  2700. this.clearRAPCacheFilterValues();
  2701. this.m_oWidgetContextManager.handleIncomingPromptEvent(evt);
  2702. },
  2703. setPromptParametersRetrieved: function(promptParametersRetrieved)
  2704. {
  2705. this.promptParametersRetrieved = promptParametersRetrieved;
  2706. },
  2707. getEnvParam: function( paramName )
  2708. {
  2709. return this.getViewerObject().envParams[ paramName ];
  2710. },
  2711. destroy: function() {
  2712. var viewer = this.getViewerObject();
  2713. if (viewer) {
  2714. // Clear the selection and fire our contextChanged event
  2715. if (this.isSelectionFilterEnabled() ) {
  2716. if (this.selectionFilterSent()) {
  2717. this.clearSelectionFilter();
  2718. }
  2719. }
  2720. if( this.onUnloadInProgress ) {
  2721. //The viewer code specifies that if no callback is provided, the destroy function is synchronous
  2722. //when we are in window unload processing, we want the http requests sent for
  2723. //releasing conversations to be completed before window closes. Using async
  2724. //requests during such a situation results in http requests
  2725. //to be sent only for some before browser window closes.
  2726. viewer.destroy(false);
  2727. } else {
  2728. //The viewer code specifies that if no callback is provided, the destroy function is synchronous
  2729. //We don't want that, so just provide a dummy callback
  2730. viewer.destroy(true);
  2731. }
  2732. var rmItem = function(element) {
  2733. if (element && element.parentNode && element.parentNode.removeChild) {
  2734. element.parentNode.removeChild(element);
  2735. }
  2736. };
  2737. // Cleanup the markup that was added by this widget -- the nodes are identified by an attribute named namespaceId, first in the <head>, then the body children
  2738. var items = dojo.query("[namespaceId='" + this.getViewerId() + "'],[namespaceId='" + this.m_sScriptLoaderNamespace + "']", document.getElementsByTagName("head").item(0));
  2739. if (items && items.length > 0) {
  2740. items.forEach( rmItem );
  2741. }
  2742. items = dojo.query('> [namespaceId="' + this.getViewerId() + '"]', document.getElementsByTagName("body").item(0));
  2743. if (typeof items != "undefined" && items && items.length > 0) {
  2744. items.forEach( rmItem );
  2745. }
  2746. if (this.getAnnotationHelper()) {
  2747. this.getAnnotationHelper()._cleanupPreviousAnnotations();
  2748. }
  2749. }
  2750. if (this.annotationHelper) { this.annotationHelper.m_viewerIWidget = null; }
  2751. this.annotationHelper = null;
  2752. if (this.savedOutput) { this.savedOutput.iWidget = null; }
  2753. this.savedOutput = null;
  2754. if (this.m_oLoadManager) { this.m_oLoadManager.m_oWidget = null; }
  2755. this.m_oLoadManager = null;
  2756. if (this.m_oWidgetContextManager) { this.m_oWidgetContextManager.m_widget = null; }
  2757. this.m_oWidgetContextManager = null;
  2758. this.removeWindowEventListeners();
  2759. if (this.undoRedoQueue) {
  2760. GUtil.destroyProperties(this.undoRedoQueue);
  2761. delete this.undoRedoQueue;
  2762. }
  2763. GUtil.destroyProperties(this.getAnnotationStore());
  2764. delete this.getAnnotationStore();
  2765. GUtil.destroyProperties(this.savedOutput);
  2766. delete this.savedOutput;
  2767. delete this.m_oCV;
  2768. viewer = null;
  2769. },
  2770. setSavedOutputsCMResponse: function(cmResponse)
  2771. {
  2772. this.savedOutputsCMResponse = cmResponse;
  2773. if (cmResponse == null) {
  2774. var actionFactory = this.getViewerObject().getActionFactory();
  2775. var action = actionFactory.load("Snapshots");
  2776. action.resetMenu();
  2777. }
  2778. },
  2779. getSavedOutputsCMResponse: function()
  2780. {
  2781. if (typeof this.savedOutputsCMResponse == "undefined" || this.savedOutputsCMResponse == null)
  2782. {
  2783. return null;
  2784. }
  2785. return this.savedOutputsCMResponse;
  2786. },
  2787. setSavedOutputSearchPath: function(searchPath)
  2788. {
  2789. this.m_savedOutputSearchPath = searchPath;
  2790. },
  2791. getSavedOutputSearchPath: function()
  2792. {
  2793. if (typeof this.m_savedOutputSearchPath == "undefined")
  2794. {
  2795. return null;
  2796. }
  2797. return this.m_savedOutputSearchPath;
  2798. },
  2799. initializeProperties: function()
  2800. {
  2801. if( this.properties )
  2802. {
  2803. var viewerObject = this.getViewerObject();
  2804. this.properties.initialize( viewerObject.envParams );
  2805. }
  2806. },
  2807. addToRAPCache: function(name, value) {
  2808. if(!this.m_RAPCache) {
  2809. this.m_RAPCache = {};
  2810. }
  2811. this.m_RAPCache[name] = value;
  2812. },
  2813. getRAPCachedItem: function(name) {
  2814. if(this.m_RAPCache && typeof this.m_RAPCache[name] != "undefined") {
  2815. return this.m_RAPCache[name];
  2816. }
  2817. return null;
  2818. },
  2819. clearRAPCacheFilterValues: function() {
  2820. for (var key in this.m_RAPCache) {
  2821. if (key.indexOf("filterValues.") === 0) {
  2822. delete this.m_RAPCache[key];
  2823. }
  2824. }
  2825. },
  2826. clearRAPCache: function() {
  2827. this.m_RAPCache = null;
  2828. },
  2829. // called by ResetToOriginalAction to reset parameters, cache, queues, etc
  2830. reset: function() {
  2831. this.m_bCallGetAnnotations = true;//reset to 'true' so that we issue getAnnotation call
  2832. this.promptParametersRetrieved = false;
  2833. this.getViewerObject().envParams["reportPrompts"] = "";
  2834. // clear the cached CM response for available outputs since we're reseting to the original
  2835. this.setSavedOutputsCMResponse(null);
  2836. // clear the undo queue
  2837. this.getUndoRedoQueue().clearQueue();
  2838. if (this.isSelectionFilterEnabled) {
  2839. this.clearSelectionFilter();
  2840. }
  2841. this.m_bSelectionFilterSwitch = false;
  2842. },
  2843. handleFault: function() {
  2844. if (typeof console != "undefined" && console && console.log) {
  2845. console.log("ViewrIWidget:handle fault is deprecated and should not be used anymore.");
  2846. }
  2847. var viewerObject = this.getViewerObject();
  2848. var requestHandler = new RequestHandler(viewerObject);
  2849. requestHandler.onFault();
  2850. },
  2851. disableListenToForGlobalPrompt: function()
  2852. {
  2853. // TODO This method is obsolete, and should be removed and callers should use the disableListenToForEvent function
  2854. this.fireEvent("com.ibm.bux.widget.updateEventFilter", null, { "*": { blockedEvents: ['com.ibm.widget.contextChanged.prompt']} });
  2855. var viewerObject = this.getViewerObject();
  2856. if (window.gaRV_INSTANCES) {
  2857. var payload = {};
  2858. payload[ this.iContext.widgetId ] = { blockedEvents: ['com.ibm.widget.contextChanged.prompt']};
  2859. for (var iIndex=0; iIndex < window.gaRV_INSTANCES.length; iIndex++) {
  2860. if(window.gaRV_INSTANCES[iIndex].getId() != viewerObject.getId()) {
  2861. var viewerIWidget = window.gaRV_INSTANCES[iIndex].getViewerWidget();
  2862. if(viewerIWidget) {
  2863. viewerIWidget.iContext.iEvents.fireEvent("com.ibm.bux.widget.updateEventFilter", null, payload);
  2864. }
  2865. }
  2866. }
  2867. }
  2868. },
  2869. disableListenToForEvent: function(events)
  2870. {
  2871. this.fireEvent("com.ibm.bux.widget.updateEventFilter", null, { "*": { blockedEvents: events} });
  2872. var viewerObject = this.getViewerObject();
  2873. if (window.gaRV_INSTANCES) {
  2874. var payload = {};
  2875. payload[ this.iContext.widgetId ] = { blockedEvents: events};
  2876. for (var iIndex=0; iIndex < window.gaRV_INSTANCES.length; iIndex++) {
  2877. if(window.gaRV_INSTANCES[iIndex].getId() != viewerObject.getId()) {
  2878. var viewerIWidget = window.gaRV_INSTANCES[iIndex].getViewerWidget();
  2879. if(viewerIWidget) {
  2880. viewerIWidget.iContext.iEvents.fireEvent("com.ibm.bux.widget.updateEventFilter", null, payload);
  2881. }
  2882. }
  2883. }
  2884. }
  2885. },
  2886. handlePassportErrorFromDispatcher: function() {//Bug: COGCQ00261642
  2887. if (this.viewerWidgetLastAction) {
  2888. var okCallbackFunction = GUtil.generateCallback(this[this.viewerWidgetLastAction.functionName], this.viewerWidgetLastAction.param, this);
  2889. dojo["require"]("bux.dialogs.IFrameDialog"); //@lazyload
  2890. var dialog = new bux.dialogs.LogonDialog({
  2891. okHandler: okCallbackFunction,
  2892. cancelHandler: dojo.hitch(this, function() {this.fireEvent("com.ibm.bux.widget.action", null, { action: 'deleteWidget' } );})
  2893. });
  2894. dialog.startup();
  2895. dialog.show();
  2896. }
  2897. },
  2898. showErrorMessage: function(errorMessage) {
  2899. var viewerObject = this.getViewerObject();
  2900. if(viewerObject) {
  2901. this.m_widgetErrorDlg = new FaultMessageDialog(viewerObject, errorMessage);
  2902. this.m_widgetErrorDlg.renderInlineDialog();
  2903. }
  2904. },
  2905. getErrorDlg: function() {
  2906. if (this.m_widgetErrorDlg) {
  2907. return this.m_widgetErrorDlg;
  2908. }
  2909. return null;
  2910. },
  2911. setErrorDlg: function(dlg) {
  2912. this.m_widgetErrorDlg = dlg;
  2913. },
  2914. clearErrorDlg: function(dlg) {
  2915. if( this.getErrorDlg() !== null)
  2916. {
  2917. this.m_widgetErrorDlg.ok();
  2918. }
  2919. },
  2920. onOpen: function( evt )
  2921. {
  2922. if( evt && evt.payload && evt.payload.author )
  2923. {
  2924. this.m_sDashboardOwnerId = evt.payload.author.cm$searchPath;
  2925. }
  2926. },
  2927. onNotifyPreviousEventsAreDone: function(evt)
  2928. {
  2929. this.m_resizeReady = true;
  2930. },
  2931. isDashboardOwner: function()
  2932. {
  2933. if( typeof this.m_sDashboardOwnerId !== "undefined" && typeof this.m_sUserId !== "undefined")
  2934. {
  2935. return this.m_sDashboardOwnerId === this.m_sUserId;
  2936. }
  2937. },
  2938. /**
  2939. * Returns true iff the provided user search path matches
  2940. * that of the current user.
  2941. */
  2942. isCurrentUser: function(user)
  2943. {
  2944. return this.m_sUserId === user;
  2945. },
  2946. findContainerDiv : function()
  2947. {
  2948. var rvContentDiV = dojo.byId("RVContent" + this.getViewerObject().getId());
  2949. // we need to find the correct container div. It'll be the one with a height set in pixels
  2950. var containerDiv = rvContentDiV;
  2951. while (containerDiv) {
  2952. if (containerDiv.style && containerDiv.style.height && containerDiv.style.height.indexOf("px") != -1) {
  2953. return containerDiv;
  2954. }
  2955. containerDiv = containerDiv.parentNode;
  2956. }
  2957. if (typeof console != "undefined" && console && console.log)
  2958. {
  2959. console.log("ViewrIWidget: Could not find the container div.");
  2960. }
  2961. return rvContentDiV;
  2962. },
  2963. getPaneOnRight: function () {
  2964. //Preference coming from BUX. This is passed to BUA. Value is string "true" or "false"
  2965. return this.getAttributeValue( "paneOnRight");
  2966. },
  2967. getWidgetContextManager: function() {
  2968. return this.m_oWidgetContextManager;
  2969. },
  2970. getInfoBarRenderedState: function() {
  2971. return this.m_oInfoBarRenderedState;
  2972. },
  2973. /*
  2974. * m_oInfoBarRenderedState should keep only what is rendered.
  2975. */
  2976. refreshInfoBarRenderedState: function(aValidInfoBarIDs) {
  2977. var len = aValidInfoBarIDs.length;
  2978. var oNewState = {};
  2979. for(var idx = 0; idx < len; idx++) {
  2980. var sId = aValidInfoBarIDs[idx];
  2981. if (this.m_oInfoBarRenderedState[sId]) {
  2982. oNewState[sId] = this.m_oInfoBarRenderedState[sId];
  2983. }
  2984. }
  2985. this.m_oInfoBarRenderedState = oNewState;
  2986. },
  2987. /*
  2988. * Handler of 'com.ibm.widget.context.get' event
  2989. */
  2990. onGetWidgetContext: function(iEvent) {
  2991. var payload = this.getWidgetContextManager().getWidgetContextObject();
  2992. if (!payload) {
  2993. payload = {};
  2994. }
  2995. this.fireEvent( 'com.ibm.widget.context.get.done', null , payload);
  2996. },
  2997. /*
  2998. * Handler of com.ibm.bux.canvas.context.get.done event
  2999. */
  3000. onGetCanvasContextDone: function(evt) {
  3001. //do nothing for now.
  3002. },
  3003. onSetVisible: function(evt) {
  3004. //BEGIN DEBUG CODE (remove after delayed viewer loading complete)
  3005. if(this.m_debugDelayedViewerLoadingMode === 2) {
  3006. return;
  3007. }
  3008. //END DEBUG CODE
  3009. if(evt && evt.payload) {
  3010. this.m_visible = evt.payload.isVisible ? true : false;
  3011. if( !this.m_visible){
  3012. // If we're being hidden and we've reached the css limit already then cleanup any style that
  3013. // we've added
  3014. if (this._cssLimitReached) {
  3015. this.cleanupStyles();
  3016. }
  3017. return;
  3018. }
  3019. if(!this.getLoadManager().isViewerLoadInitiated()) {
  3020. //There is no Viewer object and this widget is visible, so post report as normal
  3021. this.postReport(null);
  3022. } else {
  3023. this._updateOnVisible();
  3024. }
  3025. }
  3026. },
  3027. _updateOnVisible: function() {
  3028. var oLoadManager = this.getLoadManager();
  3029. if(oLoadManager.isViewerReady()) {
  3030. var oCV = this.getViewerObject();
  3031. // If we've reached the css limit and we're being made visible
  3032. // then add back any styles that might have been removed
  3033. if (this._cssLimitReached) {
  3034. this.reloadStyles();
  3035. }
  3036. if (this.isSavedOutput()){
  3037. //fix for COGCQ0068371, we don't run pending updates for saved report
  3038. oLoadManager.getDelayedLoadingContext().setForceRunReport(false);
  3039. return;
  3040. }
  3041. if( !oLoadManager.getDelayedLoadingContext().isEmpty() ) {
  3042. //There are pending updates to the report: it needs to be run,
  3043. //based on the state of the DelayedLoadingContext.
  3044. oLoadManager.runWhenHasViewer(function() {
  3045. oLoadManager.runningReport();
  3046. var factory = oCV.getActionFactory();
  3047. var buxRunReportAction = factory.load( 'BuxRunReport');
  3048. var delayedLoadingContext = oLoadManager.getDelayedLoadingContext();
  3049. var requestParams = {
  3050. promptValues: delayedLoadingContext.getPromptValues(),
  3051. clearCascadeParamsList: delayedLoadingContext.getCascadingPromptParamsToClear()
  3052. };
  3053. buxRunReportAction.setRequestParams( requestParams );
  3054. // if it's the first time we run the report make sure we send all the parameter values (prompts) we got from CM
  3055. // when we queries for the report specification.
  3056. if (!oCV.getConversation()) {
  3057. buxRunReportAction.setSendParameterValues(true);
  3058. }
  3059. var bServerPending = buxRunReportAction.execute();
  3060. oLoadManager.getDelayedLoadingContext().reset();
  3061. return bServerPending;
  3062. });
  3063. } else {
  3064. //Refresh any frozen widgets. Webkit interferes with scroll position
  3065. //when DOM objects have display:none.
  3066. if (oCV.getPinFreezeManager()) {
  3067. oCV.getPinFreezeManager().onSetVisible();
  3068. }
  3069. }
  3070. } else {
  3071. //Once Viewer has been loaded and all delayed requests
  3072. //in the queue have been serviced, try again
  3073. oLoadManager.setOnEmptyCallback(dojo.hitch(this, function() {
  3074. if(this.isVisible()) {
  3075. this._updateOnVisible();
  3076. } //else, onSetVisible will be called the next time the widget is visible
  3077. }));
  3078. }
  3079. },
  3080. /**
  3081. * To be used only for event handlers to determine if report should be run when the action is executed.
  3082. * @return true iff the event handler should invoke a run on the report,
  3083. * i.e. it is possible to run the report at the moment (viewer loaded, etc.),
  3084. * and it is worth the cost of a run (the widget is visible).
  3085. */
  3086. shouldReportBeRunOnAction : function() {
  3087. return ( this.isVisible() && this.getLoadManager().isViewerLoaded() && this.getLoadManager().canRunReports() );
  3088. },
  3089. isVisible: function() {
  3090. //BEGIN DEBUG CODE (remove after delayed viewer loading complete)
  3091. if(this.m_debugDelayedViewerLoadingMode === 2) {
  3092. return true;
  3093. }
  3094. //END DEBUG CODE
  3095. if(this.m_visible === null) {
  3096. //Read from item set
  3097. var delayedLoad = this.iContext.getItemSet("buxdelayedload", false);
  3098. if(delayedLoad){
  3099. this.m_visible = (delayedLoad.getItemValue("widgetVisible") === "true");
  3100. } else {
  3101. //If no item set, default to visible
  3102. this.m_visible = true;
  3103. }
  3104. }
  3105. return this.m_visible;
  3106. },
  3107. isPastedWidget: function() {
  3108. return this._pastedWidget;
  3109. },
  3110. setWidgetCopyPasteParameters: function() {
  3111. //sets widget parametes from widget Copy/Paste action
  3112. this.copyPasteResource = this.getAttributeValue("resource");
  3113. if (this.copyPasteResource) {
  3114. this._pastedWidget = true;
  3115. if (this.getAttributeValue("copy.ciPublishedReportPath") && this.getAttributeValue("originalReport") == null && this.getSavedItem() == null) {
  3116. //copy/paste from not saved yet widget ci published widget copy
  3117. this.ciPublishedReportPath = this.getAttributeValue("copy.ciPublishedReportPath");
  3118. } else if (this.getAttributeValue("originalReport") == null) {
  3119. //ci published dashboard widget doesn't have originalReport value instead savedReportPath used
  3120. this.ciPublishedReportPath = this.getSavedItem();
  3121. //we set to in case if user copy/paste from copied and not yes saved widget
  3122. this.setAttributeValue("copy.ciPublishedReportPath", this.ciPublishedReportPath);
  3123. }
  3124. this.removeAttributeValue("savedReportPath");
  3125. this.removeAttributeValue("savedReportPath.resource");
  3126. this.removeAttributeValue("resource");
  3127. }
  3128. },
  3129. postSetWidgetCopyPasteParameters: function() {
  3130. //post sets widget copy/paste parameters
  3131. if (this.copyPasteResource) {
  3132. this.removeAttributeValue("copy.conversation");
  3133. this.copyPasteResource = null;
  3134. }
  3135. },
  3136. isSelectionFilterEnabled: function() {
  3137. return this.m_bSelectionFilterSwitch;
  3138. },
  3139. toggleSelectionFilterSwitch: function() {
  3140. this.m_bSelectionFilterSwitch = !this.isSelectionFilterEnabled();
  3141. var selectionController = this.getViewerObject().getSelectionController();
  3142. if( selectionController )
  3143. {
  3144. if( this.isSelectionFilterEnabled() )
  3145. {
  3146. selectionController.setSelectionStyles( selectionController.FILTER_SELECTION_STYLE );
  3147. selectionController.repaintSelections();
  3148. }else{
  3149. //clear the selections
  3150. selectionController.resetAll();
  3151. }
  3152. }
  3153. },
  3154. /**
  3155. * This function sets up selection controller to do master filter selection
  3156. */
  3157. preprocessPageClicked : function( bInvokingContextMenu, evt ) {
  3158. if( !this.isSelectionFilterEnabled() ){
  3159. return;
  3160. }
  3161. var selectionController = this.getViewerObject().getSelectionController();
  3162. selectionController.setAllowHorizontalDataValueSelection(true);
  3163. if( bInvokingContextMenu )
  3164. {
  3165. if( !selectionController.hasSavedSelections() ){
  3166. selectionController.saveSelections();
  3167. }
  3168. selectionController.setSelectionStyles( selectionController.FILTER_SELECTION_CONTEXT_MENU_STYLE );
  3169. } else {
  3170. selectionController.setSelectionStyles( selectionController.FILTER_SELECTION_STYLE );
  3171. selectionController.clearSavedSelections();
  3172. }
  3173. },
  3174. ignoreEvent : function(evt) {
  3175. stopEventBubble(evt);
  3176. },
  3177. /**
  3178. * When selection filter is turned on we need to hide the drill through links, and when
  3179. * it's turned off we need to put the drill through links back
  3180. */
  3181. updateDrillThroughLinks : function() {
  3182. var oCV = this.getViewerObject();
  3183. if (!oCV) {
  3184. return;
  3185. }
  3186. var selectionFilterEnabled = this.isSelectionFilterEnabled();
  3187. var isSavedOutput = oCV.envParams["ui.action"] == "view" || oCV.envParams["ui.action"] == "buxView";
  3188. var currentSuffix = selectionFilterEnabled ? "" : "_temp";
  3189. var newSuffix = selectionFilterEnabled ? "_temp" : "";
  3190. var attributesToRename = ["onclick", "onkeypress", "style"];
  3191. // Saved outputs their drill through links embeded in the report, so we need
  3192. // to find all the correct 'onclick' attributes.
  3193. var attributeToSearchFor = isSavedOutput ? "onclick" + currentSuffix : "dttargets";
  3194. var contentDiv = document.getElementById("RVContent" + oCV.getId());
  3195. var drillThroughNodes = getElementsByAttribute(contentDiv, "*", attributeToSearchFor);
  3196. if (!drillThroughNodes) {
  3197. return;
  3198. }
  3199. for (var i=0; i < drillThroughNodes.length; i++) {
  3200. var node = drillThroughNodes[i];
  3201. // Don't need to worry about drill through on charts since there's no special style
  3202. if (node.nodeName.toLowerCase() !== "area") {
  3203. if (isSavedOutput) {
  3204. // For saved output make sure this is a drill through link by looking at the onclick value
  3205. var onclickValue = node.getAttribute("onclick" + currentSuffix);
  3206. if (!onclickValue || (onclickValue.indexOf("doSingleDrillThrough") == -1 && onclickValue.indexOf("doMultipleDrillThrough"))) {
  3207. continue;
  3208. }
  3209. // Need to rename the onclick, style and onkeypress attributes
  3210. for (var ii=0; ii < attributesToRename.length; ii++) {
  3211. var attributeName = attributesToRename[ii];
  3212. if (node.getAttribute(attributeName + currentSuffix)) {
  3213. this._renameAttribute(node, attributeName + currentSuffix, attributeName + newSuffix);
  3214. }
  3215. }
  3216. }
  3217. this._updateCellStyle(node, selectionFilterEnabled);
  3218. }
  3219. }
  3220. },
  3221. /**
  3222. * Removes/adds the 'hy' (hyperlink) style which is used for dirll through links
  3223. */
  3224. _updateCellStyle : function(node, selectionFilterEnabled) {
  3225. // Don't bother with text nodes
  3226. if (node.nodeType == 3) {
  3227. return;
  3228. }
  3229. if (selectionFilterEnabled && node.className === "hy") {
  3230. this._renameAttribute(node, "class", "class_temp");
  3231. }
  3232. else if (!selectionFilterEnabled && node.getAttribute("class_temp")) {
  3233. this._renameAttribute(node, "class_temp", "class");
  3234. }
  3235. // Loop through all the child elements
  3236. if (node.childNodes) {
  3237. for (i=0; i < node.childNodes.length; i++) {
  3238. this._updateCellStyle(node.childNodes[i], selectionFilterEnabled);
  3239. }
  3240. }
  3241. },
  3242. _renameAttribute : function(node, originalName, newName) {
  3243. node.setAttribute(newName, node.getAttribute(originalName));
  3244. node.removeAttribute(originalName);
  3245. },
  3246. addButtonToSavedToolbarButtons: function(name, button, position) {
  3247. if (typeof name != "undefined" && name != null) {
  3248. this.savedToolbarButtons[name] = {};
  3249. this.savedToolbarButtons[name]["button"] = button;
  3250. this.savedToolbarButtons[name]["position"] = position;
  3251. }
  3252. },
  3253. getButtonFromSavedToolbarButtons: function(name) {
  3254. return this.savedToolbarButtons[name];
  3255. },
  3256. removeFromSavedToolbarButtons: function(name){
  3257. if(typeof this.savedToolbarButtons[name] != "undefined" && this.savedToolbarButtons[name] != null) {
  3258. delete this.savedToolbarButtons[name];
  3259. }
  3260. }
  3261. });
  3262. /**
  3263. * Helper class for the undo/redo queue
  3264. */
  3265. function UndoRedoQueue(oWidget)
  3266. {
  3267. this.m_queue = [];
  3268. this.m_queueLimit = 20;
  3269. this.m_iCurrentPos = 0;
  3270. this.m_widget = oWidget;
  3271. this.m_bUndoRedoCalled = false;
  3272. this.m_lastAction = null;
  3273. this.currentUndoObj = null;
  3274. this.beenUsed = false;
  3275. this.m_originalSpec = null;
  3276. }
  3277. UndoRedoQueue.prototype.setOriginalSpec = function(spec)
  3278. {
  3279. // only time we need an original spec if the queue is still empty.
  3280. if (this.m_queue.length == 0) {
  3281. this.m_originalSpec = spec;
  3282. }
  3283. };
  3284. UndoRedoQueue.prototype.clearQueue = function()
  3285. {
  3286. while (this.m_queue.length > 0)
  3287. {
  3288. this.m_queue.pop();
  3289. }
  3290. this.m_iCurrentPos = 0;
  3291. };
  3292. UndoRedoQueue.prototype.getPosition = function()
  3293. {
  3294. return this.m_iCurrentPos;
  3295. };
  3296. UndoRedoQueue.prototype.hasBeenUsed = function()
  3297. {
  3298. return this.beenUsed;
  3299. };
  3300. UndoRedoQueue.prototype.getLength = function()
  3301. {
  3302. return this.m_queue.length;
  3303. };
  3304. UndoRedoQueue.prototype.initUndoObj = function(obj)
  3305. {
  3306. // first time we add to the stack for an action, add the current specification/parameters to have the initial report
  3307. if (this.m_queue.length == 0)
  3308. {
  3309. var oCV = this.m_widget.getViewerObject();
  3310. var spec = this.m_originalSpec == null ? oCV.envParams["ui.spec"] : this.m_originalSpec;
  3311. this.m_originalSpec = null;
  3312. this.m_queue.push({"spec": spec,
  3313. "parameters": oCV.getExecutionParameters(),
  3314. "tooltip": obj.tooltip,
  3315. "infoBar": oCV.envParams["rapReportInfo"],
  3316. "widgetProperties" : this.m_widget.getProperties().getOldProperties(),
  3317. "hasAVSChart" : oCV.hasAVSChart(),
  3318. "undoType" : "server"
  3319. });
  3320. this.m_iCurrentPos = this.m_queue.length-1;
  3321. this.beenUsed = true;
  3322. }
  3323. this.currentUndoObj = obj;
  3324. };
  3325. UndoRedoQueue.prototype.add = function(obj)
  3326. {
  3327. // Make sure we don't add to the undo stack if the Viewer is getting refreshed
  3328. // because of an undo or redo
  3329. if (this.m_bUndoRedoCalled)
  3330. {
  3331. this.m_bUndoRedoCalled = false;
  3332. return;
  3333. }
  3334. else if (this.currentUndoObj == null)
  3335. {
  3336. return;
  3337. }
  3338. else if (obj.reportUpdated == true)
  3339. {
  3340. while (this.m_queue.length > this.m_queueLimit)
  3341. {
  3342. this.m_queue.shift();
  3343. }
  3344. this.clearEnd();
  3345. var viewer = this.m_widget.getViewerObject();
  3346. if (this.currentUndoObj.saveSpec == true || viewer.envParams["ui.doNotUseConversationForUndo"] === "true")
  3347. {
  3348. this.currentUndoObj.spec = viewer.envParams["ui.spec"];
  3349. this.currentUndoObj.parameters = viewer.getExecutionParameters();
  3350. }
  3351. else
  3352. {
  3353. this.currentUndoObj.conversation = viewer.getConversation();
  3354. }
  3355. if (viewer.envParams["rapReportInfo"])
  3356. {
  3357. this.currentUndoObj.infoBar = viewer.envParams["rapReportInfo"];
  3358. }
  3359. this.currentUndoObj.widgetProperties = this.m_widget.getProperties().getUndoInfo();
  3360. this.currentUndoObj.palette = viewer.m_sPalette;
  3361. if (this.m_widget.getProperties().getFlashCharts())
  3362. {
  3363. this.currentUndoObj.hasAVSChart = viewer.hasAVSChart();
  3364. }
  3365. this.currentUndoObj.undoType = "server";
  3366. this.finalizeAdd();
  3367. }
  3368. };
  3369. UndoRedoQueue.prototype.addClientSideUndo = function(obj) {
  3370. // Make sure we don't add to the undo stack if the Viewer is getting refreshed
  3371. // because of an undo or redo
  3372. if (this.m_bUndoRedoCalled) {
  3373. this.m_bUndoRedoCalled = false;
  3374. return;
  3375. }
  3376. if (obj.undoCallback && obj.redoCallback) {
  3377. this.initUndoObj(obj);
  3378. this.currentUndoObj.undoType = "client";
  3379. this.finalizeAdd();
  3380. }
  3381. };
  3382. UndoRedoQueue.prototype.finalizeAdd = function() {
  3383. this.m_queue.push(this.currentUndoObj);
  3384. this.m_iCurrentPos = this.m_queue.length-1;
  3385. this.m_bUndoRedoCalled = false;
  3386. this.m_lastAction = "";
  3387. this.currentUndoObj = null;
  3388. this.beenUsed = true;
  3389. };
  3390. UndoRedoQueue.prototype.moveBack = function()
  3391. {
  3392. if (this.m_iCurrentPos <= 0)
  3393. {
  3394. return null;
  3395. }
  3396. var sUndoType = this.m_queue[this.m_iCurrentPos].undoType;
  3397. this.m_bUndoRedoCalled = true;
  3398. this.m_lastAction = "undo";
  3399. this.m_iCurrentPos--;
  3400. this.m_viewerState = {"parameters" : this.m_widget.getViewerObject().getExecutionParameters(), "spec" : this.m_widget.getViewerObject().envParams["ui.spec"]};
  3401. if (typeof this.m_queue[this.m_iCurrentPos] != "undefined")
  3402. {
  3403. this.m_widget.getViewerObject().m_sPalette = this.m_queue[this.m_iCurrentPos].palette;
  3404. if (sUndoType == "client") {
  3405. return this.m_queue[this.m_iCurrentPos+1];
  3406. }
  3407. // if we're undoing a server type request, keep going back into the queue
  3408. // until we hit another server type request
  3409. var iIndex = this.m_iCurrentPos;
  3410. while (iIndex > 0 && this.m_queue[iIndex] && this.m_queue[iIndex].undoType != "server") {
  3411. iIndex--;
  3412. }
  3413. return this.m_queue[iIndex];
  3414. }
  3415. return null;
  3416. };
  3417. UndoRedoQueue.prototype.moveForward = function()
  3418. {
  3419. if (this.m_iCurrentPos >= this.m_queue.length)
  3420. {
  3421. return null;
  3422. }
  3423. this.m_bUndoRedoCalled = true;
  3424. this.m_iCurrentPos++;
  3425. this.m_lastAction = "redo";
  3426. this.m_viewerState = {"parameters" : this.m_widget.getViewerObject().getExecutionParameters(), "spec" : this.m_widget.getViewerObject().envParams["ui.spec"]};
  3427. if (typeof this.m_queue[this.m_iCurrentPos] != "undefined")
  3428. {
  3429. this.m_widget.getViewerObject().m_sPalette = this.m_queue[this.m_iCurrentPos].palette;
  3430. return this.m_queue[this.m_iCurrentPos];
  3431. }
  3432. return null;
  3433. };
  3434. UndoRedoQueue.prototype.clearEnd = function()
  3435. {
  3436. while (this.m_queue.length-1 > this.m_iCurrentPos)
  3437. {
  3438. this.m_queue.pop();
  3439. }
  3440. };
  3441. UndoRedoQueue.prototype.handleCancel = function()
  3442. {
  3443. if (this.m_lastAction == "undo")
  3444. {
  3445. this.m_iCurrentPos++;
  3446. }
  3447. else if (this.m_lastAction == "redo")
  3448. {
  3449. this.m_iCurrentPos--;
  3450. }
  3451. if (this.m_lastAction == "redo" || this.m_lastAction == "undo")
  3452. {
  3453. var widgetProperties = this.m_widget.getProperties();
  3454. var undoObj = this.m_queue[this.m_iCurrentPos];
  3455. if (widgetProperties && undoObj && undoObj.widgetProperties) {
  3456. widgetProperties.doUndo(undoObj.widgetProperties);
  3457. }
  3458. }
  3459. this.m_lastAction = "";
  3460. this.m_bUndoRedoCalled = false;
  3461. this.currentUndoObj = null;
  3462. };
  3463. UndoRedoQueue.prototype.handleFault = function()
  3464. {
  3465. this.currentUndoObj = null;
  3466. this.m_bUndoRedoCalled = false;
  3467. };
  3468. UndoRedoQueue.prototype.getUndoTooltip = function()
  3469. {
  3470. if (this.m_iCurrentPos > 0)
  3471. {
  3472. return RV_RES.IDS_JS_UNDO + " " + this.m_queue[this.m_iCurrentPos].tooltip;
  3473. }
  3474. return RV_RES.IDS_JS_UNDO;
  3475. };
  3476. UndoRedoQueue.prototype.getRedoTooltip = function()
  3477. {
  3478. if (this.m_iCurrentPos < (this.m_queue.length-1))
  3479. {
  3480. return RV_RES.IDS_JS_REDO + " " + this.m_queue[this.m_iCurrentPos+1].tooltip;
  3481. }
  3482. return RV_RES.IDS_JS_REDO;
  3483. };
  3484. /*
  3485. * Class to handle showing saved output in an iWidget
  3486. */
  3487. function CIWidgetSavedOutput(iWidget) {
  3488. this.iWidget = iWidget;
  3489. this.bContainsChart = false;
  3490. this.bContainsDrillThrough = false;
  3491. this.bPagedOutput = true;
  3492. }
  3493. CIWidgetSavedOutput.prototype.getIWidget = function() {
  3494. return this.iWidget;
  3495. };
  3496. CIWidgetSavedOutput.prototype.isPagedOutput = function() {
  3497. return this.bPagedOutput;
  3498. };
  3499. CIWidgetSavedOutput.prototype.setPagedOutput = function(pagedOutput) {
  3500. this.bPagedOutput = pagedOutput;
  3501. };
  3502. CIWidgetSavedOutput.prototype.getCognosViewer = function() {
  3503. return this.getIWidget().getViewerObject();
  3504. };
  3505. CIWidgetSavedOutput.prototype.getIframeWindow = function() {
  3506. return this.savedOutputWindow;
  3507. };
  3508. CIWidgetSavedOutput.prototype.getSavedOutputDiv = function() {
  3509. return this.savedOutputDiv;
  3510. };
  3511. CIWidgetSavedOutput.prototype.render = function() {
  3512. if (this.isPagedOutput() && this.getFirstPage()) {
  3513. this.currentPageIndex = 0;
  3514. this._showPages( [this.getFirstPage()] );
  3515. }
  3516. else {
  3517. // If the output has tabs show all the pages of the current tab
  3518. if (this.tabbedSavedOutput && this.currentPageIndex && this.pageNodes) {
  3519. var tabid = this.pageNodes[this.currentPageIndex].getAttribute("tabid");
  3520. this.switchSavedOutputTab(tabid);
  3521. }
  3522. else if (this.getCognosViewer() && this.getCognosViewer().getCurrentlySelectedTab()) {
  3523. this.switchSavedOutputTab(this.getCognosViewer().getCurrentlySelectedTab());
  3524. }
  3525. else {
  3526. this.showHTMLFragment(this.getIframeWindow().document.body.innerHTML);
  3527. }
  3528. }
  3529. };
  3530. CIWidgetSavedOutput.prototype.outputDoneLoading = function() {
  3531. if(window['gReportWidgetLoadQueue']) {
  3532. window['gReportWidgetLoadQueue'].widgetDoneLoading(this.getIWidget());
  3533. }
  3534. this.getIWidget().setOriginalFormFields(null);
  3535. var cognosViewerObject = this.getCognosViewer();
  3536. var sCVID = cognosViewerObject.getId();
  3537. this.savedOutputWindow = dojo.byId("CVHiddenIFrame" + sCVID).contentWindow;
  3538. this.savedOutputDiv = dojo.byId("CVSavedOutputDiv" + sCVID);
  3539. var sc = cognosViewerObject.getSelectionController();
  3540. if ( !sc.hasContextData() && this.savedOutputWindow.onLoadEvent ) {
  3541. this.savedOutputWindow.onLoadEvent();
  3542. }
  3543. // Create an array of all the page nodes in the saved output
  3544. this._populatePageNode();
  3545. // load all the style tags from the iframe
  3546. var oReportDiv = dojo.byId("_" + this.iWidget.iContext.widgetId + "_cv");
  3547. this.loadStyleInfoFromIframe(oReportDiv);
  3548. this.bContainsChart = typeof this.savedOutputWindow.displayChart == "function" ? true : false;
  3549. this.bContainsDrillThrough = typeof this.savedOutputWindow.drillThroughTarget != "undefined" ? true : false;
  3550. this.render();
  3551. this.getMetaDataFromIFrame();
  3552. if (this.bContainsDrillThrough) {
  3553. // get the drillTargets array from the iframe
  3554. window[sCVID + "drillTargets"] = this.getIframeWindow().drillTargets;
  3555. }
  3556. cognosViewerObject.fillInContextData();
  3557. cognosViewerObject.updateBorderCollapse();
  3558. this.getIWidget().updateToolbar();
  3559. cognosViewerObject.setReportRenderingDone(true);
  3560. var callback = GUtil.generateCallback(this.getIWidget().fetchAnnotationData, [], this.getIWidget());
  3561. var numMissing = this.getPageContextData(callback);
  3562. // if there isn't any missing context information then the callback won't be triggered
  3563. if (numMissing == 0) {
  3564. this.getIWidget().fetchAnnotationData();
  3565. }
  3566. this.fixDuplicateFormFields();
  3567. this.getIWidget().getLoadManager().processQueue();
  3568. // clear out the cv.outputKey and XNodeId
  3569. delete cognosViewerObject.envParams["cv.outputKey"];
  3570. this.getIWidget().setXNodeId(null);
  3571. var widget = this.getIWidget();
  3572. var callbackFunc = function() {
  3573. widget.iContext.iEvents.fireEvent("com.ibm.bux.widget.render.done", null, {});
  3574. // Need to call render tabs AFTER CW makes the Viewer visible or our size calculations will be wrong
  3575. cognosViewerObject.renderTabs();
  3576. // If we are showing tabs, switch to the first tab
  3577. if (cognosViewerObject.getCurrentlySelectedTab() != null) {
  3578. widget.getSavedOutput().tabbedSavedOutput = true;
  3579. widget.getSavedOutput().switchSavedOutputTab(cognosViewerObject.getCurrentlySelectedTab());
  3580. }
  3581. };
  3582. setTimeout(callbackFunc, 100);
  3583. };
  3584. /**
  3585. * Create an array of all the page nodes in the saved output
  3586. */
  3587. CIWidgetSavedOutput.prototype._populatePageNode = function() {
  3588. // Create an array of all the page nodes in the saved output
  3589. this.pageNodes = [];
  3590. var node = this.getIframeWindow().document.body.firstChild;
  3591. while (node) {
  3592. if (node.nodeName.toLowerCase() == "table") {
  3593. this.pageNodes.push(node);
  3594. }
  3595. node = node.nextSibling;
  3596. }
  3597. };
  3598. CIWidgetSavedOutput.prototype.switchSavedOutputTab = function(tabId, userInvoked) {
  3599. if (!this.pageNodes) {
  3600. return;
  3601. }
  3602. if (userInvoked) {
  3603. // lastVisitiedPage is used so that when you switch to a previously visited tab
  3604. // you'll be back to the same page on that tab
  3605. if (!this.lastVisitedPage) {
  3606. this.lastVisitedPage = {};
  3607. }
  3608. if (this.isPagedOutput()) {
  3609. // Save the page of the tab we're switching from
  3610. var oldTabId = this.pageNodes[this.currentPageIndex].getAttribute("tabid");
  3611. this.lastVisitedPage[oldTabId] = this.currentPageIndex;
  3612. // If we've already visited the tab we're switching to, use the stored page number
  3613. if (this.lastVisitedPage[tabId]) {
  3614. this.currentPageIndex = this.lastVisitedPage[tabId];
  3615. this._showPages([this.pageNodes[this.currentPageIndex]]);
  3616. return;
  3617. }
  3618. }
  3619. }
  3620. var pagesToDisplay = [];
  3621. // Loop through all the pages and find any that match the tab we're switching to
  3622. for (var i=0; i < this.pageNodes.length; i++) {
  3623. var node = this.pageNodes[i];
  3624. if (node && node.getAttribute && node.getAttribute("tabid") == tabId) {
  3625. pagesToDisplay.push(node);
  3626. this.currentPageIndex = i;
  3627. // We're paging the saved output, so only show the first page in the tab
  3628. if (this.isPagedOutput()) {
  3629. break;
  3630. }
  3631. }
  3632. }
  3633. this._showPages(pagesToDisplay);
  3634. };
  3635. /*
  3636. This is not pretty, but necessary. When rendering a saved output in BUX, we need
  3637. the response to contain a bunch of hidden form fields since there's saved output code that
  3638. relies on those form fields. Problem is, that we'll end up with duplicate hidden form fields.
  3639. This code loops through all the form fields and will remove any duplicates using the value from
  3640. the last one as the value of the form field.
  3641. */
  3642. CIWidgetSavedOutput.prototype.fixDuplicateFormFields = function() {
  3643. var formWarpRequest = document.getElementById("formWarpRequest" + this.getCognosViewer().getId());
  3644. if (formWarpRequest) {
  3645. for (var formFieldIndex=0; formFieldIndex < formWarpRequest.elements.length; formFieldIndex++) {
  3646. var name = formWarpRequest.elements[formFieldIndex].name;
  3647. if (name && name.length > 0) {
  3648. // if there's multiple form fields with the same name
  3649. if (formWarpRequest[name].length > 1) {
  3650. // get the value of the last form field with the name. It's the one we want
  3651. var value = formWarpRequest[name][formWarpRequest[name].length-1].value;
  3652. // delete all the duplicate form fields
  3653. while (formWarpRequest[name].length > 1) {
  3654. formWarpRequest[name][1].parentNode.removeChild(formWarpRequest[name][1]);
  3655. }
  3656. // some weird behavior with IE, if there's still an array of form fields set the value correctly.
  3657. if (formWarpRequest[name][0]) {
  3658. formWarpRequest[name][0].value = value;
  3659. }
  3660. formWarpRequest[name].value = value;
  3661. }
  3662. }
  3663. }
  3664. }
  3665. };
  3666. CIWidgetSavedOutput.prototype.getPageContextData = function(callback){
  3667. var items = {};
  3668. dojo.query('[ctx]', this.getSavedOutputDiv()).forEach(function(item){
  3669. var ctx = item.getAttribute("ctx");
  3670. var ctxIds = ctx.split(':');
  3671. for (var i = 0; i < ctxIds.length; i++) {
  3672. var value = ctxIds[i];
  3673. if (value && value.length > 0) {
  3674. items[value] = true;
  3675. }
  3676. }
  3677. });
  3678. var arrItems = [];
  3679. for (var item in items) {
  3680. arrItems.push(item);
  3681. }
  3682. return this.getCognosViewer().getSelectionController().fetchContextData(arrItems, callback);
  3683. };
  3684. CIWidgetSavedOutput.prototype.loadStyleInfoFromIframe = function(oReportDiv){
  3685. var htmlNode = null;
  3686. // For XHTML the first node is the doctype. Loop through the children of the document
  3687. // to find the first child that has children
  3688. var savedOutputDoc = this.savedOutputWindow.document;
  3689. for (var index=0; index < savedOutputDoc.childNodes.length; index++) {
  3690. if (savedOutputDoc.childNodes[index].childNodes && savedOutputDoc.childNodes[index].childNodes.length > 0) {
  3691. htmlNode = savedOutputDoc.childNodes[index];
  3692. break;
  3693. }
  3694. }
  3695. window.gScriptLoader.loadStyles(htmlNode.firstChild, this.iWidget.getViewerId());
  3696. var links = dojo.query("link", htmlNode);
  3697. var linkHTML = "";
  3698. for (i = 0; i < links.length; i++) {
  3699. var href = links[i].getAttribute("href");
  3700. if (href) {
  3701. linkHTML += '<link href="' + href + '" />';
  3702. }
  3703. }
  3704. window.gScriptLoader.loadCSS(linkHTML, oReportDiv, true, this.iWidget.getViewerId());
  3705. };
  3706. CIWidgetSavedOutput.prototype.getFirstPage = function() {
  3707. return this.pageNodes[0];
  3708. };
  3709. CIWidgetSavedOutput.prototype.getLastPage = function() {
  3710. return this.pageNodes ? this.pageNodes[this.pageNodes.length - 1] : null;
  3711. };
  3712. CIWidgetSavedOutput.prototype.writeNavLinks = function() {
  3713. var availablePageLinks = "";
  3714. if (this.isPagedOutput()) {
  3715. if (this.tabbedSavedOutput && !isNaN(this.currentPageIndex)) {
  3716. var tabId = this.pageNodes[this.currentPageIndex].getAttribute("tabid")
  3717. if (this.currentPageIndex > 0 && this.pageNodes[this.currentPageIndex - 1].getAttribute("tabid") == tabId) {
  3718. availablePageLinks += " firstPage previousPage ";
  3719. }
  3720. if (this.currentPageIndex < (this.pageNodes.length - 1) && this.pageNodes[this.currentPageIndex + 1].getAttribute("tabid") == tabId) {
  3721. availablePageLinks += " nextPage lastPage ";
  3722. }
  3723. }
  3724. else {
  3725. if (this.currentPageIndex > 0) {
  3726. availablePageLinks += " firstPage previousPage ";
  3727. }
  3728. if (this.currentPageIndex < (this.pageNodes.length - 1)) {
  3729. availablePageLinks += " nextPage lastPage ";
  3730. }
  3731. }
  3732. }
  3733. this.getCognosViewer().writeNavLinks(availablePageLinks, true);
  3734. };
  3735. CIWidgetSavedOutput.prototype.pageAction = function(action) {
  3736. switch(action) {
  3737. case "firstPage":
  3738. if (this.tabbedSavedOutput) {
  3739. var tabId = this.pageNodes[this.currentPageIndex].getAttribute("tabid")
  3740. // Find the first page for the tab
  3741. for (var i=0; i < this.pageNodes.length; i++) {
  3742. var node = this.pageNodes[i];
  3743. if (node && node.getAttribute && node.getAttribute("tabid") == tabId) {
  3744. this.currentPageIndex = i;
  3745. break;
  3746. }
  3747. }
  3748. }
  3749. else {
  3750. this.currentPageIndex = 0;
  3751. }
  3752. break;
  3753. case "previousPage":
  3754. this.currentPageIndex = this.currentPageIndex - 1;
  3755. break;
  3756. case "nextPage":
  3757. this.currentPageIndex = this.currentPageIndex + 1;
  3758. break;
  3759. case "lastPage":
  3760. if (this.tabbedSavedOutput) {
  3761. var tabId = this.pageNodes[this.currentPageIndex].getAttribute("tabid")
  3762. var foundTabSection = false;
  3763. // Find the last page for the tab
  3764. for (var i=0; i < this.pageNodes.length; i++) {
  3765. var node = this.pageNodes[i];
  3766. if (node && node.getAttribute && node.getAttribute("tabid") == tabId) {
  3767. foundTabSection = true;
  3768. }
  3769. else if (foundTabSection) {
  3770. this.currentPageIndex = i -1;
  3771. break;
  3772. }
  3773. }
  3774. }
  3775. else {
  3776. this.currentPageIndex = this.pageNodes.length - 1;
  3777. }
  3778. break;
  3779. }
  3780. this._showPages([this.pageNodes[this.currentPageIndex]]);
  3781. };
  3782. CIWidgetSavedOutput.prototype._showPages = function(aPages) {
  3783. var oCV = this.getCognosViewer();
  3784. oCV.getSelectionController().clearSelectedObjects();
  3785. if (aPages.length == 1) {
  3786. this.showHTMLFragment(aPages[0].innerHTML);
  3787. }
  3788. else {
  3789. // We're showing multiple pages, get all their HTML and send it all at once
  3790. var sHtml = "";
  3791. for (var i=0; i < aPages.length; i++) {
  3792. sHtml += aPages[i].innerHTML;
  3793. }
  3794. this.showHTMLFragment(sHtml);
  3795. }
  3796. this.writeNavLinks();
  3797. // If we're dealing with tabbed saved output and the user switched tabs then keep
  3798. // the tab control in focus
  3799. if (this.tabbedSavedOutput && this.lastVisitedPage) {
  3800. this.getIWidget().placeTabControlInView();
  3801. }
  3802. else {
  3803. oCV.setKeepFocus(true);
  3804. }
  3805. oCV.doneLoadingUpdateA11Y("complete");
  3806. var callback = GUtil.generateCallback(this.getIWidget().fetchAnnotationData, [], this.getIWidget());
  3807. var numMissing = this.getPageContextData(callback);
  3808. // if there isn't any missing context information then the callback won't be triggered
  3809. if (numMissing == 0) {
  3810. this.getIWidget().fetchAnnotationData();
  3811. }
  3812. };
  3813. CIWidgetSavedOutput.prototype.getMetaDataFromIFrame = function() {
  3814. if (typeof this.getIframeWindow().getSelectionController == "function") {
  3815. var iframeSelectionController = this.getIframeWindow().getSelectionController();
  3816. if (iframeSelectionController) {
  3817. var selectionController = this.getCognosViewer().getSelectionController();
  3818. selectionController.addMetaData(iframeSelectionController.getCCDManager().m_md);
  3819. selectionController.addContextData(iframeSelectionController.getCCDManager().m_cd);
  3820. selectionController.setSelectionBasedFeaturesEnabled(true);
  3821. }
  3822. }
  3823. };
  3824. CIWidgetSavedOutput.prototype.processDrillThrough = function(sHTML) {
  3825. if (this.bContainsDrillThrough && (typeof this.bOldOutput == "undefined" || this.bOldOutput == true)) {
  3826. var drillThroughRegEx = new RegExp('onclick=\"doSingleDrillThrough[^\"]*\"|onclick=\'doMultipleDrillThrough[^\']*\'', "gim");
  3827. var aM = sHTML.match(drillThroughRegEx);
  3828. if (aM)
  3829. {
  3830. if (typeof this.bOldOutput == "undefined" && aM.length > 0 && aM[0].indexOf("'_THIS_'") > 0) {
  3831. this.bOldOutput = false;
  3832. } else {
  3833. this.bOldOutput = true;
  3834. // singledrill and multipledrill use different quots (', ") for the onclick. So figure
  3835. // which one we're suppose to use
  3836. var endingQuot = "";
  3837. var quot = "'";
  3838. if (aM.length > 0) {
  3839. endingQuot = aM[0].charAt(aM[0].length - 1);
  3840. }
  3841. if (endingQuot == "'"){
  3842. quot = "\"";
  3843. }
  3844. for (var i = 0; i < aM.length; i++)
  3845. {
  3846. sHTML = sHTML.replace(aM[i], aM[i].substring(0, aM[i].length-3) + "," + quot + this.getCognosViewer().getId() + quot + ");" + endingQuot);
  3847. }
  3848. }
  3849. }
  3850. }
  3851. return sHTML;
  3852. };
  3853. CIWidgetSavedOutput.prototype.processChart = function(sHTML){
  3854. // The preSelectNode call is only for IE. Fix it so calls .pcc since we don't have a preSelectNode function,
  3855. // it's only available in saved output
  3856. if (isIE()) {
  3857. sHTML = sHTML.replace(/preSelectNode\(event\);/g, getCognosViewerObjectRefAsString(this.getCognosViewer().getId()) + ".pcc(event);");
  3858. } else {
  3859. sHTML = sHTML.replace(/preSelectNode\(event\);/g, "");
  3860. }
  3861. var cognosViewerID = this.getCognosViewer().getId();
  3862. var iframe = document.getElementById('CVHiddenIFrame' + cognosViewerID);
  3863. var iframeSrc = iframe.src;
  3864. if (iframeSrc.indexOf("repository") >= 0) {
  3865. //viewer uses CM's rest API
  3866. var indOfContent = iframeSrc.indexOf("content");
  3867. var gerURI = iframeSrc.substring(0, indOfContent);
  3868. sHTML = sHTML.replace(/src\=\"images\//g, "src=\"" + gerURI + "images/");
  3869. }
  3870. sHTML = this.fixupChartUseMapValue(sHTML);
  3871. // get rid of some chart js that's no longer needed.
  3872. return sHTML.replace(/displayChart[^;].*;|var graphicSrc[^;].*;|var graphicName[^;].*;/g, "");
  3873. };
  3874. /**
  3875. * Add namespace to map name and corresponding usemap value
  3876. */
  3877. CIWidgetSavedOutput.prototype.fixupChartUseMapValue = function( sHTML ){
  3878. var re = /usemap\s*=\s*"*#(\w+)"*/gi;
  3879. var match, params = [];
  3880. while( (match = re.exec( sHTML )) ){
  3881. params.push( match[1] );
  3882. }
  3883. for( var i = 0; i < params.length; i++){
  3884. //had to create RegExp obj because IE does not recognize the 'global'modifier when passed as a separate parameter into replace()
  3885. var strToMatch = new RegExp( params[i], 'g' );
  3886. sHTML = sHTML.replace( strToMatch, params[i] + this.getCognosViewer().getId());
  3887. }
  3888. return sHTML;
  3889. };
  3890. CIWidgetSavedOutput.prototype.showHTMLFragment = function(sHTML) {
  3891. if (this.bContainsChart) {
  3892. sHTML = this.processChart(sHTML);
  3893. }
  3894. sHTML = this.processDrillThrough(sHTML);
  3895. sHTML = sHTML.replace(/_THIS_/g,this.getCognosViewer().getId());
  3896. // we want to ignore all the document.writes when taking the HTML out of the iframe
  3897. // since it was already executed inside the iframe
  3898. this.getIWidget().loadStylesAndScripts(sHTML, this.getSavedOutputDiv(), false);
  3899. this.getIWidget().reselectSelectionFilterObjects();
  3900. this.getIWidget().addChromeWhitespaceHandler(this.getCognosViewer().getId());
  3901. };
  3902. /*
  3903. * Because of the way CScriptLoader loads and processes scripts (asynchronously with setInterval),
  3904. * this function is necessary. We don't want to have the toolbar initialize until all scripts
  3905. * have been loaded and executed. Otherwise, we may end up referencing variables that are not initialized.
  3906. */
  3907. function gInitializeViewer(obj)
  3908. {
  3909. if (window.gScriptLoader.hasCompletedExecution()) {
  3910. var viewerObject = obj.getViewerObject();
  3911. if(viewerObject && viewerObject.inlineScriptsDoneExecuting == true) {
  3912. clearInterval(obj.timer);
  3913. if(typeof viewerObject.errorOccured != "undefined") {
  3914. obj.fireEvent("com.ibm.bux.widget.render.done", null, {});
  3915. }
  3916. else if(typeof viewerObject.getToolbar() != "undefined") {
  3917. // associate the widget ref with the viewer object
  3918. viewerObject.setViewerWidget(obj);
  3919. if (obj.isSelectionFilterEnabled()) {
  3920. obj.updateDrillThroughLinks();
  3921. }
  3922. if( obj.isDashboardOwner() )
  3923. {
  3924. viewerObject.addReportInfo();
  3925. }
  3926. if (obj.promptParametersRetrieved == true) {
  3927. var reportPrompts = obj.getAttributeValue( "viewerReportPrompts");
  3928. viewerObject.envParams["reportPrompts"] = reportPrompts;
  3929. } else if (viewerObject.envParams && viewerObject.envParams["widget.promptParametersRetrievedOnDrop"] == "true") {
  3930. obj.promptParametersRetrieved = true;
  3931. }
  3932. var enablePromptAndDrillEventsByDefault = obj.getAttributeValue("syncNewWidgets");
  3933. if(enablePromptAndDrillEventsByDefault === null || enablePromptAndDrillEventsByDefault === "true") {
  3934. enablePromptAndDrillEventsByDefault = true;
  3935. } else {
  3936. enablePromptAndDrillEventsByDefault = false;
  3937. }
  3938. if(!enablePromptAndDrillEventsByDefault && (obj.isPastedWidget() || obj.isOpeningSavedDashboard() == false)) {
  3939. obj.disableListenToForEvent(['com.ibm.widget.contextChanged.drill', 'com.ibm.widget.contextChanged.prompt', 'com.ibm.widget.contextChanged']);
  3940. }
  3941. //Fire this now that we have the IWidget set.
  3942. obj.fireEvent("com.ibm.bux.widget.setShowBordersWhenInnactive", null, (viewerObject.m_flashChartsObjectIds.length !== 0));
  3943. }
  3944. }
  3945. }
  3946. }
  3947. function gVWEvent(sId, evt, sEvent) {
  3948. var oCV = window['oCV' + sId];
  3949. if (oCV) {
  3950. oCV.loadExtra();
  3951. var iWidget = oCV.getViewerWidget();
  3952. if (iWidget) {
  3953. iWidget[sEvent](evt);
  3954. }
  3955. }
  3956. }
  3957. function ReportWidgetLoadQueue(concurrentLoadSetting) {
  3958. this._concurrentLoadSetting = concurrentLoadSetting;
  3959. this._widgetsRunning = [];
  3960. this._queue = [];
  3961. }
  3962. ReportWidgetLoadQueue.prototype.add = function(reportWidget) {
  3963. this._queue.push(reportWidget);
  3964. this.loadNextWidget();
  3965. };
  3966. ReportWidgetLoadQueue.prototype.widgetDoneLoading = function(widget) {
  3967. for(var i = 0; i < this._widgetsRunning.length; ++i) {
  3968. var widgetToRemove = this._widgetsRunning[i];
  3969. if(widgetToRemove == widget) {
  3970. this._widgetsRunning.splice(i, 1);
  3971. break;
  3972. }
  3973. }
  3974. this.loadNextWidget();
  3975. };
  3976. ReportWidgetLoadQueue.prototype.loadNextWidget = function() {
  3977. if(this._widgetsRunning.length < this._concurrentLoadSetting) {
  3978. var widgetToLoad = this._queue.shift();
  3979. if(typeof widgetToLoad != "undefined") {
  3980. this._widgetsRunning.push(widgetToLoad);
  3981. widgetToLoad.postReport(null);
  3982. }
  3983. }
  3984. };