toolbar.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: HTS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2021 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var HTS_MENU_STATE = "hts_menu_state";
  11. var HTS_FOCUS_ID = "hts_focus_id";
  12. function hts_getMenuStateObjectFromCookie(){
  13. var menuStateObjectStr = _F_Document.getCookie(HTS_MENU_STATE);
  14. var menuStateObject;
  15. if(menuStateObjectStr){
  16. menuStateObjectStr = _F_Strings.urlDecode(menuStateObjectStr);
  17. menuStateObject = JSON.parse(menuStateObjectStr);
  18. }else{
  19. //new boy
  20. menuStateObject = new Object();
  21. }
  22. return menuStateObject;
  23. }
  24. function hts_setMenuStateObjectToCookie(menuStateObject){
  25. var menuStateObjectStr = dojo.toJson(menuStateObject);
  26. menuStateObjectStr = _F_Strings.urlEncode(menuStateObjectStr);
  27. _F_Document.setCookie(HTS_MENU_STATE, menuStateObjectStr, '', _F_Config.gateway, '', '');
  28. }
  29. function hts_updateMenuStateCookie(filterType,jsonStr){
  30. var menuStateObject = hts_getMenuStateObjectFromCookie();
  31. menuStateObject[filterType] = jsonStr;
  32. hts_setMenuStateObjectToCookie(menuStateObject);
  33. }
  34. function hts_getMenuStateCookieValue(filterType){
  35. var menuStateObject = hts_getMenuStateObjectFromCookie();
  36. return menuStateObject[filterType];
  37. }
  38. function hts_setFocusCookie(focusId) {
  39. focusIdStr = _F_Strings.urlEncode(focusId);
  40. _F_Document.setCookie(HTS_FOCUS_ID, focusIdStr, '', _F_Config.gateway, '', '');
  41. }
  42. function hts_getFocusCookie() {
  43. var focusId = _F_Document.getCookie(HTS_FOCUS_ID);
  44. return focusId;
  45. }
  46. /*
  47. * Set the filter. Update the UI and store the filter value into a fragment transient variable
  48. * frag - The fragment containing the menu
  49. * filterType - Three filter types defined : Task.Status, Task.Priority and Task.CreatedOn
  50. * newValueIndex - The menu item index (starts at zero)
  51. * value - optional value which overrides the menu value. Useful when generating dynamic values based on the menu action
  52. */
  53. function setFilter(frag,filterType,newValueIndex,value) {
  54. var menu = this.ui_curmenu;
  55. //update the menu title with the current filter
  56. var filterValue = updateFilterMenuTitle(menu,newValueIndex);
  57. //set the value if it has been overridden, ignore the menu item value
  58. if (value!= undefined) {
  59. filterValue=value;
  60. }
  61. //flag the menu to be rebuilt the next time it is opened. This will ensure the
  62. //checkbox is shown next to the new filter
  63. menu.rebuild=true;
  64. /*
  65. * Create the placeholder in JSON format. Holds the menu index and it's value. Note that
  66. * the date filter dynamically creates it's value while the others are static
  67. */
  68. var jsonObj = new Object();
  69. jsonObj.name=newValueIndex;
  70. jsonObj.value=filterValue;
  71. var jsonStr = dojo.toJson(jsonObj);
  72. hts_updateMenuStateCookie(filterType, jsonStr);
  73. //set the filter value, this will call the server-side interaction stage
  74. frag.transientUpdate(filterType,jsonStr,'application');
  75. }
  76. /*
  77. * Update the menu with the new filter and set the title to reflect the new item
  78. * returns the new value
  79. * menu - The menu
  80. * newValueIndex = the position of the selected menu item, can also pass in the menu title
  81. */
  82. function updateFilterMenuTitle(menu,newValueIndex) {
  83. //select the new item in the menu
  84. var def = menu.menudef;
  85. var newValue=null;
  86. for(var i = 0; i < def.items.length; i++) {
  87. var item = def.items[i];
  88. if (newValueIndex==i) {
  89. item.selected=true;
  90. if (item.image) {
  91. //We have text, but we need to display an image.
  92. var menuDivTxt = dojo.byId(def.id+"_div_text");
  93. if (menuDivTxt) {
  94. dojo.attr(def.id+"_div_text","style",{display:"none"});
  95. }
  96. dojo.attr(def.id+"_img", {
  97. src: item.pre+item.image+item.post,
  98. alt: item.title,
  99. title: item.title,
  100. style: {display:''}
  101. });
  102. } else {
  103. var menuDiv = dojo.byId(def.id+"_img");
  104. //We have an image, but we need to display text.
  105. if (menuDiv) {
  106. dojo.attr(def.id+"_img","style",{display:"none"});
  107. }
  108. menuDiv = dojo.byId(def.id+"_div_text");
  109. dojo.attr(menuDiv,{innerHTML:item.title,style: {display:''}});
  110. }
  111. newValue=item.value;
  112. //change the alt/title of the arrow image to reflect the new filter name
  113. dojo.attr(def.id+"_downarrow_img_id", {
  114. alt: item.title,
  115. title: item.title
  116. });
  117. }
  118. else {
  119. item.selected=false;
  120. }
  121. }
  122. return newValue;
  123. }
  124. /*
  125. * Initialise the filter menu
  126. * menu - the filter menu
  127. * filter - the filter details in JSON format
  128. */
  129. function initFilter(menu,filter) {
  130. if (filter!= undefined && filter!='') {
  131. //eval the JSON object
  132. var nameValue = eval('(' + filter + ')');
  133. //set the index
  134. updateFilterMenuTitle(menu,nameValue.name);
  135. }
  136. }
  137. function hts_getSelectedMenuItem(menu) {
  138. //select the new item in the menu
  139. var def = menu.menudef
  140. var selectedItem=null;
  141. for(var i = 0; i < def.items.length; i++) {
  142. var item = def.items[i];
  143. if (item.selected==true) {
  144. selectedItem = item;
  145. }
  146. }
  147. return selectedItem;
  148. }