123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- // 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<actionObj.checkboxArray.length;i++) {
- checkboxParams+= '&actionResourceID_' + i + '=' + actionObj.checkboxArray[i][2];
- var cubeResIdTokens = actionObj.checkboxArray[i][2].split(':');
- checkboxParams+= '&errDet'+i+'='+ cubeResIdTokens[cubeResIdTokens.length-1];
- }
- if (checkboxParams == '') {
- alert(this.noSelectionString);
- return;
- }
- params += checkboxParams;
- }
- // if we have a target of Child, then fake a group action on all the visible children
- else if (actionObj.target == 'Child') {
- for (var i=1; i < this.resourceArray.length; i++) {
- params += '&actionResourceID_' + i + '=' + this.resourceArray[i].resourceID;
- }
- }
- else {
- params += '&actionResourceID=' + this.currentResourceID;
- }
-
- if (actionObj.qrbt && actionObj.qrbt != '') {
- params += '&actionQRBT=' + actionObj.qrbt;
- }
- if (actionObj.errorDetails) {
- for (i=0; i < actionObj.errorDetails.length;i++) {
- params+= '&errDet'+i+'='+ encodeURIComponent(actionObj.errorDetails[i]);
- }
- }
- this.previousActionObj = actionObj;
- this.doActionFragment.retrieve(params);
- }
- },
-
- switchRelationshipType: function(relationshipType) {
- if (this.breadcrumbArray[0]) {
- this.breadcrumbArray[0].relationshipType = relationshipType;
- this.breadcrumbArray[0].selectedResourceID = this.breadcrumbArray[0].resourceID;
- }
-
- },
-
- // builds the params to keep all the necessary state information
- buildURLParams: function(context) {
- var breadcrumbLength = this.breadcrumbArray.length - 1;
- var params = 'rootRelationshipType=' + encodeURIComponent(this.breadcrumbArray[0].relationshipType);
- params += '&selectedRelationshipType=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].relationshipType);
- params += '&relationshipResourceID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].resourceID);
- params += '&relationshipStoreID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].storeID);
- params += '¤tResourceID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].selectedResourceID);
- params += '¤tStoreID=' + encodeURIComponent(this.breadcrumbArray[breadcrumbLength].selectedStoreID);
-
- if (arguments.length > 0) {
- if (context.contextDef.sortColumn) {
- params += '&sort_column=' + context.contextDef.sortColumn;
- }
- if (context.contextDef.sortOrder) {
- params += '&sort_order=' + context.contextDef.sortOrder;
- }
- }
-
- for (i=1; i < this.breadcrumbArray.length; i ++) {
- params += '&bc_resid_' + i + '=' + encodeURIComponent(this.breadcrumbArray[i].resourceID);
- params += '&bc_id_' + i + '=' + encodeURIComponent(this.breadcrumbArray[i].storeID);
- }
-
- params += '&bcDepth=' + this.breadcrumbArray.length;
- return params;
- },
-
- createDetailedErrorDiv: function (msg, details, recovery) {
- var div = this.createActionDialog();
- var markup = '<table><tr><td style="vertical-align:top">';
- markup+= '<img src="' + _F_Config.webContent + '/ps/cogadmin/images/msg_' + (recovery.recoverable ? 'warning' : 'error') + '.gif" width="32" height="32" style="padding:10"/></td>';
- markup += '<td><div style="padding:5 5 10 5">'+msg+'</div>';
- for (var i=0; i < details.length;i++) {
- markup+='<div style="padding-left:15">'+details[i]+'</div>';
- }
- markup+='<div style="padding:10 5 5 5">';
- if (recovery.recoverable) {
- markup+=recovery.msg;
- }
- markup+='</div></td></tr></table>';
- 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;
- }
-
- }
|