relationships.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2012
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. //----------------------------------------------------------
  13. // Obj to hold state information and to help with operations on the relationships fragment
  14. var COGADMIN_RELATIONSHIPS_DEFAULT_HEIGHT = 470;
  15. function relationships_context(contextDef) {
  16. this.contextDef = contextDef;
  17. }
  18. function breadcrumb(relationshipType, resourceID, storeID) {
  19. this.relationshipType=relationshipType;
  20. this.resourceID=resourceID;
  21. this.storeID=storeID;
  22. this.selectedResourceID=resourceID;
  23. this.selectedStoreID=storeID;
  24. }
  25. function resource(resourceID, storeID, objectClass, menuName) {
  26. this.resourceID = resourceID;
  27. this.storeID = storeID;
  28. this.objectClass = objectClass;
  29. this.menuName = menuName;
  30. }
  31. function cogadmin_relationships(fragObj, fragName, noSelectionString, resourceID) {
  32. this.fragmentObj = fragObj;
  33. this.fragmentName = fragName;
  34. this.mouseEvent = null;
  35. this.srcElement = null;
  36. this.actionContextID = null
  37. this.groupActionContextID = null;
  38. // array contains (resourceID, storeID, objectClass, actionMenu)
  39. this.resourceArray = new Array();
  40. // contains all the breadcrumb information ( relationshipType, resourceID, storeID)
  41. this.breadcrumbArray = new Array();
  42. this.groupActionMenu = null;
  43. this.menuDivName = fragName + 'menu_div';
  44. this.doActionsDivName = fragName + 'performActions';
  45. this.doActionFragment = createFragment(fragName + 'performActions', this.doActionsDivName, '/cogadmin/controls/dispatch_actions.xts');
  46. this.currentResourceID = resourceID;
  47. this.noSelectionString = noSelectionString;
  48. this.previousActionObj = null;
  49. this.env = window;
  50. }
  51. cogadmin_relationships.prototype = {
  52. // builds an array using the resource ID's to keep track of information for each resource
  53. // @array - array of resourceID, storeID pairs, objectClass
  54. setResourceArray: function (array) {
  55. // make sure the array is empty
  56. this.clearResourceArray();
  57. for (var i=0; i < array.length; i++) {
  58. this.resourceArray[i] = new resource(array[i].resourceID, array[i].storeID, array[i].objectClass, null);
  59. }
  60. },
  61. // empty the resource array
  62. clearResourceArray: function() {
  63. this.resourceArray.length=0;
  64. },
  65. // resets the obj clearing all the arrays
  66. clearResourceInfo: function() {
  67. this.clearResourceArray();
  68. this.groupActionsMenu = null;
  69. },
  70. refreshFragment: function() {
  71. alert('todo');
  72. },
  73. // store breadcrumb information
  74. addBreadcrumb: function(relationshipType, resourceID, storeID, depth) {
  75. this.breadcrumbArray[depth ? depth: this.breadcrumbArray.length] = new breadcrumb(relationshipType, resourceID, storeID);
  76. },
  77. // Only keep @keepCount number of breadcrumbs
  78. keepBreadcrumbs: function(keepCount) {
  79. this.breadcrumbArray.splice(keepCount,this.breadcrumbArray.length);
  80. },
  81. showActionsMenu: function(event, resourceID) {
  82. // keep track of the resourceID for the currently open menu
  83. this.currentResourceID = resourceID;
  84. // find the resource in our array
  85. for (var i=0; i < this.resourceArray.length; i++) {
  86. if (this.resourceArray[i].resourceID == resourceID) {
  87. break;
  88. }
  89. }
  90. // did we find the array entry?
  91. if (i >= this.resourceArray.length) {
  92. return;
  93. }
  94. var menuName = 'actionsMenu_' + i;
  95. // do we already have the menu?
  96. if (this.resourceArray[i].menuName) {
  97. ui_menuShow(event, window[menuName]);
  98. //event.cancelBubble = false; //override the ui_menuShow's "cancelBuble=true" which preventsthe row from being selected.
  99. return;
  100. }
  101. // don't have the menu yet, so go get it using a retrieve
  102. else {
  103. this.resourceArray[i].menuName = menuName;
  104. this.mouseEvent = event;
  105. this.srcElement = this.findObject(event);
  106. if (!document.getElementById(this.menuDivName)) {
  107. this.buildMenuDiv();
  108. }
  109. var params = 'objResourceID=' + this.resourceArray[i].resourceID + '&objStoreID=' + this.resourceArray[i].storeID + '&menuName=' + menuName + '&objectClass=' + this.resourceArray[i].objectClass;
  110. params += '&buildActionsMenu=true';
  111. params += '&actionType=resource';
  112. // if at the root and we're getting the actions for system,
  113. // then we need to add the action context id's to the URL
  114. if (this.breadcrumbArray.length == 1 && this.resourceArray[0].resourceID == resourceID && this.actionContextID != null ) {
  115. params += '&actionContextID=' + this.actionContextID;
  116. }
  117. this.fragmentObj.retrieve(params, this.menuDivName);
  118. }
  119. },
  120. showGroupActionsMenu: function(event) {
  121. var menuName = 'groupActions';
  122. if (this.groupActionsMenu != null && document.getElementById(menuName)) {
  123. ui_menuShow(event, window[menuName]);
  124. }
  125. else {
  126. this.groupActionsMenu = menuName;
  127. this.mouseEvent = event;
  128. this.srcElement = this.findObject(event);
  129. if (!document.getElementById(this.menuDivName)) {
  130. this.buildMenuDiv();
  131. }
  132. var params = 'menuName=' + menuName;
  133. params += '&objResourceID=' + this.resourceArray[0].resourceID;
  134. params += '&actionType=group';
  135. params += '&buildActionsMenu=true';
  136. // if we're at the root, then we need to add the action context id's to the URL
  137. if (this.breadcrumbArray.length == 1) {
  138. params += '&groupActionContextID=' + this.groupActionContextID;
  139. }
  140. this.fragmentObj.retrieve(params, this.menuDivName);
  141. }
  142. },
  143. buildMenuDiv: function() {
  144. var div = document.createElement('div');
  145. div.id = this.menuDivName;
  146. div.style.display = 'none';
  147. div.style.position = 'absolute';
  148. document.body.appendChild(div);
  149. },
  150. createActionDialog: function() {
  151. var div = document.getElementById(this.doActionsDivName);
  152. if (!div) {
  153. div = document.createElement('div');
  154. div.id = this.doActionsDivName;
  155. div.style.display = 'none';
  156. div.style.position = 'absolute';
  157. div.style.overflow = 'auto';
  158. div.style.backgroundColor = '#e3e9f3';
  159. div.style.borderColor = '#e3e9f3';
  160. div.style.border = '2px outset';
  161. document.body.appendChild(div);
  162. }
  163. return div;
  164. },
  165. //actionObj {isGroupAction, action, actionLabel, target, qrbt, capability, argument, confirm, confirmMsg}
  166. doAction: function(actionObj) {
  167. var confirmMsg = actionObj.confirmMsg ? actionObj.confirmMsg : actionObj.actionLabel + "?"
  168. if (!actionObj.confirm || confirm(confirmMsg)) {
  169. // make sure we have a div to show the perform actions modal dialog
  170. this.createActionDialog();
  171. var params = 'action=' + actionObj.action + '&actionLabel=' + encodeURIComponent(actionObj.actionLabel);
  172. if (actionObj.dispatchAction) {
  173. params+='&dispatchAction='+actionObj.dispatchAction;
  174. }
  175. if (actionObj.capability) {
  176. params+='&capability=' + actionObj.capability;
  177. }
  178. if (actionObj.argument) {
  179. params+='&argument=' + actionObj.argument;
  180. }
  181. if (actionObj.isGroupAction) {
  182. var checkboxParams = '';
  183. if (!actionObj.checkboxArray) {
  184. actionObj.checkboxArray = getCheckboxArray('table');
  185. }
  186. for (var i=0;i<actionObj.checkboxArray.length;i++) {
  187. checkboxParams+= '&actionResourceID_' + i + '=' + actionObj.checkboxArray[i][2];
  188. var cubeResIdTokens = actionObj.checkboxArray[i][2].split(':');
  189. checkboxParams+= '&errDet'+i+'='+ cubeResIdTokens[cubeResIdTokens.length-1];
  190. }
  191. if (checkboxParams == '') {
  192. alert(this.noSelectionString);
  193. return;
  194. }
  195. params += checkboxParams;
  196. }
  197. // if we have a target of Child, then fake a group action on all the visible children
  198. else if (actionObj.target == 'Child') {
  199. for (var i=1; i < this.resourceArray.length; i++) {
  200. params += '&actionResourceID_' + i + '=' + this.resourceArray[i].resourceID;
  201. }
  202. }
  203. else {
  204. params += '&actionResourceID=' + this.currentResourceID;
  205. }
  206. if (actionObj.qrbt && actionObj.qrbt != '') {
  207. params += '&actionQRBT=' + actionObj.qrbt;
  208. }
  209. if (actionObj.errorDetails) {
  210. for (i=0; i < actionObj.errorDetails.length;i++) {
  211. params+= '&errDet'+i+'='+ encodeURIComponent(actionObj.errorDetails[i]);
  212. }
  213. }
  214. this.previousActionObj = actionObj;
  215. this.doActionFragment.retrieve(params);
  216. }
  217. },
  218. switchRelationshipType: function(relationshipType) {
  219. if (this.breadcrumbArray[0]) {
  220. this.breadcrumbArray[0].relationshipType = relationshipType;
  221. this.breadcrumbArray[0].selectedResourceID = this.breadcrumbArray[0].resourceID;
  222. }
  223. },
  224. // builds the params to keep all the necessary state information
  225. buildURLParams: function(context) {
  226. var breadcrumbLength = this.breadcrumbArray.length - 1;
  227. var params = 'rootRelationshipType=' + encodeURIComponent(this.breadcrumbArray[0].relationshipType);
  228. params += '&selectedRelationshipType=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].relationshipType);
  229. params += '&relationshipResourceID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].resourceID);
  230. params += '&relationshipStoreID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].storeID);
  231. params += '&currentResourceID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].selectedResourceID);
  232. params += '&currentStoreID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].selectedStoreID);
  233. if (arguments.length > 0) {
  234. if (context.contextDef.sortColumn) {
  235. params += '&sort_column=' + context.contextDef.sortColumn;
  236. }
  237. if (context.contextDef.sortOrder) {
  238. params += '&sort_order=' + context.contextDef.sortOrder;
  239. }
  240. }
  241. for (i=1; i < this.breadcrumbArray.length; i ++) {
  242. params += '&bc_resid_' + i + '=' + encodeURIComponent(this.breadcrumbArray[i].resourceID);
  243. params += '&bc_id_' + i + '=' + encodeURIComponent(this.breadcrumbArray[i].storeID);
  244. }
  245. params += '&bcDepth=' + this.breadcrumbArray.length;
  246. return params;
  247. },
  248. createDetailedErrorDiv: function (msg, details, recovery) {
  249. var div = this.createActionDialog();
  250. var markup = '<table><tr><td style="vertical-align:top">';
  251. markup+= '<img src="' + _F_Config.webContent + '/ps/cogadmin/images/msg_' + (recovery.recoverable ? 'warning' : 'error') + '.gif" width="32" height="32" style="padding:10"/></td>';
  252. markup += '<td><div style="padding:5 5 10 5">'+msg+'</div>';
  253. for (var i=0; i < details.length;i++) {
  254. markup+='<div style="padding-left:15">'+details[i]+'</div>';
  255. }
  256. markup+='<div style="padding:10 5 5 5">';
  257. if (recovery.recoverable) {
  258. markup+=recovery.msg;
  259. }
  260. markup+='</div></td></tr></table>';
  261. div.innerHTML = markup;
  262. document.body.appendChild(div);
  263. return div;
  264. },
  265. showDetailedError: function(title, msg, details, recovery) {
  266. var actionObj = this.previousActionObj;
  267. if (actionObj) {
  268. actionObj.errorDetails = details;
  269. actionObj.confirm = false;
  270. }
  271. var self = this;
  272. var divId = this.createDetailedErrorDiv(msg, details, recovery).id;
  273. var uiDialog = showModalDialog(recovery.recoverable ? ui_dialog.style.BTN_OKCANCEL : ui_dialog.style.BTN_OK, divId, title);
  274. uiDialog.processCommand = function (btnType) {
  275. uiDialog.destroy();
  276. if (recovery.recoverable && (btnType == ui_dialog.button.OK)) {
  277. self.doAction(actionObj);
  278. } else {
  279. self.env.raiseReloadEvent(self.fragmentObj);
  280. }
  281. return true;
  282. }
  283. return uiDialog;
  284. },
  285. // build the params necessary to get the sibling menu for the breadcrumbs
  286. getSiblingMenu: function(event, position) {
  287. this.mouseEvent = event;
  288. this.srcElement = this.findObject(event);
  289. if (position > this.breadcrumbArray.length) {
  290. // this shouldn't happen
  291. return;
  292. }
  293. var params = 'parentResourceID=' + encodeURIComponent(this.breadcrumbArray[position-1].resourceID);
  294. params += '&currentResourceID=' + encodeURIComponent(this.breadcrumbArray[position].resourceID);
  295. params += '&selectedRelationshipType=' + encodeURIComponent(this.breadcrumbArray[position-1].relationshipType);
  296. params += '&breadcrumbPosition=' + position;
  297. params += '&buildSiblingMenu=true';
  298. // make sure we have the menu div
  299. if (!document.getElementById(this.menuDivName)) {
  300. this.buildMenuDiv();
  301. }
  302. this.fragmentObj.retrieve(params, this.menuDivName);
  303. },
  304. // when at the root we need to keep track of the action and group action context ID's
  305. // for the currently selected relationship
  306. setRootActionContext: function(actionID, groupActionID) {
  307. this.actionContextID = actionID;
  308. this.groupActionContextID = groupActionID;
  309. },
  310. findObject: function(evt) {
  311. var e=evt.srcElement ? evt.srcElement : evt.target;
  312. while (e != null) {
  313. if (e.onclick != undefined) {
  314. return e;
  315. }
  316. e = e.parentNode;
  317. }
  318. return e;
  319. },
  320. getMouseEvent: function() {
  321. return this.mouseEvent;
  322. }
  323. }