// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2012 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). //---------------------------------------------------------- // Obj to hold state information and to help with operations on the relationships fragment var COGADMIN_RELATIONSHIPS_DEFAULT_HEIGHT = 470; function relationships_context(contextDef) { this.contextDef = contextDef; } function breadcrumb(relationshipType, resourceID, storeID) { this.relationshipType=relationshipType; this.resourceID=resourceID; this.storeID=storeID; this.selectedResourceID=resourceID; this.selectedStoreID=storeID; } function resource(resourceID, storeID, objectClass, menuName) { this.resourceID = resourceID; this.storeID = storeID; this.objectClass = objectClass; this.menuName = menuName; } function cogadmin_relationships(fragObj, fragName, noSelectionString, resourceID) { this.fragmentObj = fragObj; this.fragmentName = fragName; this.mouseEvent = null; this.srcElement = null; this.actionContextID = null this.groupActionContextID = null; // array contains (resourceID, storeID, objectClass, actionMenu) this.resourceArray = new Array(); // contains all the breadcrumb information ( relationshipType, resourceID, storeID) this.breadcrumbArray = new Array(); this.groupActionMenu = null; this.menuDivName = fragName + 'menu_div'; this.doActionsDivName = fragName + 'performActions'; this.doActionFragment = createFragment(fragName + 'performActions', this.doActionsDivName, '/cogadmin/controls/dispatch_actions.xts'); this.currentResourceID = resourceID; this.noSelectionString = noSelectionString; this.previousActionObj = null; this.env = window; } cogadmin_relationships.prototype = { // builds an array using the resource ID's to keep track of information for each resource // @array - array of resourceID, storeID pairs, objectClass setResourceArray: function (array) { // make sure the array is empty this.clearResourceArray(); for (var i=0; i < array.length; i++) { this.resourceArray[i] = new resource(array[i].resourceID, array[i].storeID, array[i].objectClass, null); } }, // empty the resource array clearResourceArray: function() { this.resourceArray.length=0; }, // resets the obj clearing all the arrays clearResourceInfo: function() { this.clearResourceArray(); this.groupActionsMenu = null; }, refreshFragment: function() { alert('todo'); }, // store breadcrumb information addBreadcrumb: function(relationshipType, resourceID, storeID, depth) { this.breadcrumbArray[depth ? depth: this.breadcrumbArray.length] = new breadcrumb(relationshipType, resourceID, storeID); }, // Only keep @keepCount number of breadcrumbs keepBreadcrumbs: function(keepCount) { this.breadcrumbArray.splice(keepCount,this.breadcrumbArray.length); }, showActionsMenu: function(event, resourceID) { // keep track of the resourceID for the currently open menu this.currentResourceID = resourceID; // find the resource in our array for (var i=0; i < this.resourceArray.length; i++) { if (this.resourceArray[i].resourceID == resourceID) { break; } } // did we find the array entry? if (i >= this.resourceArray.length) { return; } var menuName = 'actionsMenu_' + i; // do we already have the menu? if (this.resourceArray[i].menuName) { ui_menuShow(event, window[menuName]); //event.cancelBubble = false; //override the ui_menuShow's "cancelBuble=true" which preventsthe row from being selected. return; } // don't have the menu yet, so go get it using a retrieve else { this.resourceArray[i].menuName = menuName; this.mouseEvent = event; this.srcElement = this.findObject(event); if (!document.getElementById(this.menuDivName)) { this.buildMenuDiv(); } var params = 'objResourceID=' + this.resourceArray[i].resourceID + '&objStoreID=' + this.resourceArray[i].storeID + '&menuName=' + menuName + '&objectClass=' + this.resourceArray[i].objectClass; params += '&buildActionsMenu=true'; params += '&actionType=resource'; // if at the root and we're getting the actions for system, // then we need to add the action context id's to the URL if (this.breadcrumbArray.length == 1 && this.resourceArray[0].resourceID == resourceID && this.actionContextID != null ) { params += '&actionContextID=' + this.actionContextID; } this.fragmentObj.retrieve(params, this.menuDivName); } }, showGroupActionsMenu: function(event) { var menuName = 'groupActions'; if (this.groupActionsMenu != null && document.getElementById(menuName)) { ui_menuShow(event, window[menuName]); } else { this.groupActionsMenu = menuName; this.mouseEvent = event; this.srcElement = this.findObject(event); if (!document.getElementById(this.menuDivName)) { this.buildMenuDiv(); } var params = 'menuName=' + menuName; params += '&objResourceID=' + this.resourceArray[0].resourceID; params += '&actionType=group'; params += '&buildActionsMenu=true'; // if we're at the root, then we need to add the action context id's to the URL if (this.breadcrumbArray.length == 1) { params += '&groupActionContextID=' + this.groupActionContextID; } this.fragmentObj.retrieve(params, this.menuDivName); } }, buildMenuDiv: function() { var div = document.createElement('div'); div.id = this.menuDivName; div.style.display = 'none'; div.style.position = 'absolute'; document.body.appendChild(div); }, createActionDialog: function() { var div = document.getElementById(this.doActionsDivName); if (!div) { div = document.createElement('div'); div.id = this.doActionsDivName; div.style.display = 'none'; div.style.position = 'absolute'; div.style.overflow = 'auto'; div.style.backgroundColor = '#e3e9f3'; div.style.borderColor = '#e3e9f3'; div.style.border = '2px outset'; document.body.appendChild(div); } return div; }, //actionObj {isGroupAction, action, actionLabel, target, qrbt, capability, argument, confirm, confirmMsg} doAction: function(actionObj) { var confirmMsg = actionObj.confirmMsg ? actionObj.confirmMsg : actionObj.actionLabel + "?" if (!actionObj.confirm || confirm(confirmMsg)) { // make sure we have a div to show the perform actions modal dialog this.createActionDialog(); var params = 'action=' + actionObj.action + '&actionLabel=' + encodeURIComponent(actionObj.actionLabel); if (actionObj.dispatchAction) { params+='&dispatchAction='+actionObj.dispatchAction; } if (actionObj.capability) { params+='&capability=' + actionObj.capability; } if (actionObj.argument) { params+='&argument=' + actionObj.argument; } if (actionObj.isGroupAction) { var checkboxParams = ''; if (!actionObj.checkboxArray) { actionObj.checkboxArray = getCheckboxArray('table'); } for (var i=0;i'; markup+= ''; markup += '
'+msg+'
'; for (var i=0; i < details.length;i++) { markup+='
'+details[i]+'
'; } markup+='
'; if (recovery.recoverable) { markup+=recovery.msg; } markup+='
'; div.innerHTML = markup; document.body.appendChild(div); return div; }, showDetailedError: function(title, msg, details, recovery) { var actionObj = this.previousActionObj; if (actionObj) { actionObj.errorDetails = details; actionObj.confirm = false; } var self = this; var divId = this.createDetailedErrorDiv(msg, details, recovery).id; var uiDialog = showModalDialog(recovery.recoverable ? ui_dialog.style.BTN_OKCANCEL : ui_dialog.style.BTN_OK, divId, title); uiDialog.processCommand = function (btnType) { uiDialog.destroy(); if (recovery.recoverable && (btnType == ui_dialog.button.OK)) { self.doAction(actionObj); } else { self.env.raiseReloadEvent(self.fragmentObj); } return true; } return uiDialog; }, // build the params necessary to get the sibling menu for the breadcrumbs getSiblingMenu: function(event, position) { this.mouseEvent = event; this.srcElement = this.findObject(event); if (position > this.breadcrumbArray.length) { // this shouldn't happen return; } var params = 'parentResourceID=' + encodeURIComponent(this.breadcrumbArray[position-1].resourceID); params += '¤tResourceID=' + encodeURIComponent(this.breadcrumbArray[position].resourceID); params += '&selectedRelationshipType=' + encodeURIComponent(this.breadcrumbArray[position-1].relationshipType); params += '&breadcrumbPosition=' + position; params += '&buildSiblingMenu=true'; // make sure we have the menu div if (!document.getElementById(this.menuDivName)) { this.buildMenuDiv(); } this.fragmentObj.retrieve(params, this.menuDivName); }, // when at the root we need to keep track of the action and group action context ID's // for the currently selected relationship setRootActionContext: function(actionID, groupActionID) { this.actionContextID = actionID; this.groupActionContextID = groupActionID; }, findObject: function(evt) { var e=evt.srcElement ? evt.srcElement : evt.target; while (e != null) { if (e.onclick != undefined) { return e; } e = e.parentNode; } return e; }, getMouseEvent: function() { return this.mouseEvent; } }