AdminTree.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //This class overides some default event handlers on the HAL tree
  9. function AdminTreeHandler(admCommands,ppesAdminEventHandler) {
  10. //Private Variables
  11. var adminCom = admCommands;
  12. var m_currentTreeView = null;
  13. var m_currentNode = null;
  14. var m_oEventHandler = ppesAdminEventHandler;
  15. var SORT_DEF = 0;
  16. var SORT_ASC = 1;
  17. var SORT_DESC = 2;
  18. //Event handlers
  19. this.F_ClearTree = function(v_oTreeView) {
  20. v_oTreeView.F_Clear();
  21. }
  22. this.setCurrentNode = function(v_nTreeNode) {
  23. m_currentNode = v_nTreeNode;
  24. }
  25. this.F_SelectNode = function(v_oTreeView,v_nTreeNode) {
  26. if (v_nTreeNode.getAttribute("objName")) {
  27. //Attach the current and previous selection to the tree view object for reference later
  28. if (v_oTreeView.ppesAdminCurrentSelection)
  29. v_oTreeView.ppesAdminPreviousSelection = v_oTreeView.ppesAdminCurrentSelection;
  30. v_oTreeView.ppesAdminCurrentSelection = v_nTreeNode;
  31. v_oTreeView.F_SelectNode(v_nTreeNode,true,true);
  32. }
  33. }
  34. this.F_returnToPreviousSelection = function(v_oTreeView) {
  35. v_oTreeView.ppesAdminCurrentSelection = v_oTreeView.ppesAdminPreviousSelection;
  36. v_oTreeView.ppesAdminPreviousSelection = null;
  37. v_oTreeView.F_SelectNode(v_oTreeView.ppesAdminCurrentSelection,true,false);
  38. }
  39. this.F_TreeView_OnNodeClick = function(v_oTreeView,v_nTreeNode,v_iMouseButton) {
  40. if (v_iMouseButton == U_DOM.K_iRightMouseButton) {
  41. m_currentNode = v_nTreeNode;
  42. m_currentTreeView = v_oTreeView;
  43. }
  44. else {
  45. if (v_nTreeNode.getAttribute("objName")) {
  46. //Attach the current and previous selection to the tree view object for reference later
  47. if (v_oTreeView.ppesAdminCurrentSelection)
  48. v_oTreeView.ppesAdminPreviousSelection = v_oTreeView.ppesAdminCurrentSelection;
  49. v_oTreeView.ppesAdminCurrentSelection = v_nTreeNode;
  50. if (v_nTreeNode.parentNode.tagName == "treeView") //root node, so no parent
  51. m_oEventHandler.F_TreeItemSelected(v_nTreeNode.getAttribute("objName"),null);
  52. else
  53. m_oEventHandler.F_TreeItemSelected(v_nTreeNode.getAttribute("objName"),v_nTreeNode.parentNode.getAttribute("objName"));
  54. }
  55. }
  56. }// F_TreeView_OnNodeClick()
  57. this.F_TreeView_OnPopulateChildren = function(v_oTreeView,v_nTreeNode) {
  58. m_currentNode = v_nTreeNode;
  59. m_currentTreeView = v_oTreeView;
  60. var sObjName = "";
  61. if ((typeof (v_nTreeNode.getAttribute("objName")) != "undefined") && v_nTreeNode.getAttribute("objName") != null)
  62. sObjName = v_nTreeNode.getAttribute("objName");
  63. var sortType = SORT_DEF;
  64. if (v_nTreeNode.getAttribute("sort") != null)
  65. sortType = parseInt(v_nTreeNode.getAttribute("sort"));
  66. if (m_currentNode.tagName == "treeView") //Initial Load
  67. m_oEventHandler.F_ShowProgressDialog(null,G_ResManager.F_GetString("IDS_PPESADMIN_WORKING"));
  68. var isSearch;
  69. if (m_currentNode.getAttribute("isSearch"))
  70. isSearch = true;
  71. //Send load command
  72. adminCom.GetObjChildren(sObjName, sortType, this.HandleGetChildrenResponse, isSearch);
  73. return true;
  74. //Load the children
  75. }
  76. this.HandleGetChildrenResponse = function(response) {
  77. if (response.getNode("error")) {
  78. switch (response.getString("error")) {
  79. case "PassportExpired":
  80. location.href = location.pathname + "?b_action=cogadmin";
  81. break;
  82. default:
  83. m_oEventHandler.F_HideProgressDialog();
  84. D_MsgBox.F_Show(null,response.getString("error")," ",D_MsgBox.K_iError);
  85. break;
  86. }
  87. }
  88. else {
  89. var content = response.getNode("Content");
  90. if (content && content.getChildren() && content.getChildren().length) {
  91. //Sort the children of content in alphabetical order
  92. content.sortChildren();
  93. var children = content.getChildren();
  94. //Re-order the content as folders and packages first, then reports.
  95. var contentArray = new Array();
  96. var sortType = SORT_DEF;
  97. if (m_currentNode.getAttribute("sort"))
  98. sortType = m_currentNode.getAttribute("sort");
  99. for (var i = 0; i < children.length; i++) { // User
  100. var classType = response.getString("Content." + children[i].name + ".Properties.objectClass","");
  101. if (classType == "user") {
  102. contentArray[contentArray.length] = children[i];
  103. }
  104. }
  105. for (var i = 0; i < children.length; i++) { //Packages and folders
  106. var classType = response.getString("Content." + children[i].name + ".Properties.objectClass","");
  107. if (classType == "package" || classType == "folder") {
  108. contentArray[contentArray.length] = children[i];
  109. }
  110. }
  111. for (var i = 0; i < children.length; i++) { //Reports
  112. var classType = response.getString("Content." + children[i].name + ".Properties.objectClass","");
  113. if (classType == "powerPlay8Report") {
  114. contentArray[contentArray.length] = children[i];
  115. }
  116. }
  117. for (var i = 0; i < children.length; i++) { //Others
  118. var classType = response.getString("Content." + children[i].name + ".Properties.objectClass","");
  119. if (classType != "powerPlay8Report" && classType != "package" && classType != "folder" && classType != "user") {
  120. contentArray[contentArray.length] = children[i];
  121. }
  122. }
  123. //We now have an ordered list of children containing packages and folders first.
  124. //Now populate the tree
  125. for (var i = 0; i < contentArray.length; i++) {
  126. var objName = decodeURIComponent(contentArray[i].name);
  127. var uniqueID = response.getString("Content." + contentArray[i].name + ".Properties.objectID","");
  128. var classType = response.getString("Content." + contentArray[i].name + ".Properties.objectClass","");
  129. var node = m_currentNode.appendChild( m_currentNode.ownerDocument.createElement( "treeNode" ) );
  130. node.setAttribute( "label", objName );
  131. node.setAttribute( "objName", uniqueID );
  132. node.setAttribute( "hideCheckbox" , "true" );
  133. node.setAttribute( "classType" , classType );
  134. switch (classType) {
  135. case "package": {
  136. node.setAttribute( "expandable", "true" );
  137. node.setAttribute( "smallIcon", "hal/../ps/portal/images/icon_package.gif" );
  138. node.setAttribute( "sort", sortType);
  139. } break;
  140. case "folder": {
  141. node.setAttribute( "expandable", "true" );
  142. node.setAttribute( "smallIcon", "hal/../ps/portal/images/icon_folder.gif" );
  143. node.setAttribute( "sort", sortType);
  144. } break;
  145. case "powerPlay8Report": {
  146. node.setAttribute( "expandable", "false" );
  147. node.setAttribute( "smallIcon", "hal/../ps/portal/images/icon_pp8_report.gif" );
  148. } break;
  149. case "content": {
  150. node.setAttribute( "expandable", "true" );
  151. node.setAttribute( "smallIcon", "hal/../ps/portal/images/icon_publicfolder.gif" );
  152. } break;
  153. case "user": {
  154. node.setAttribute( "expandable", "false" );
  155. node.setAttribute( "smallIcon", "hal/../ps/portal/images/icon_user.gif" );
  156. } break;
  157. }
  158. }
  159. }
  160. m_currentTreeView.F_EndAsyncLoad( true );
  161. if (m_currentNode.tagName == "treeView") {
  162. m_currentTreeView.F_Draw();
  163. m_oEventHandler.F_HideProgressDialog();
  164. m_oEventHandler.F_TreeInitialized();
  165. }
  166. }
  167. }
  168. /**
  169. *
  170. * Sorts or Refreshes the contents of a folder.
  171. *
  172. * @param {String} userRequest "ascending" or "descending" for sorts, blank for refresh
  173. *
  174. */
  175. this.ContextWindowRequest = function(userRequest){
  176. var sortType = parseInt(m_currentNode.getAttribute("sort"));
  177. if (userRequest == 0 || userRequest == 1 || userRequest == 2)
  178. sortType = parseInt(userRequest);
  179. m_currentNode.setAttribute("sort", sortType);
  180. m_currentTreeView.F_DrawNode(m_currentNode);
  181. }
  182. }