// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2010 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // /** * This file defines all the actions available on a list of data source credentials. * Initially, only one is allowed: removeEntries */ com.cognos.admin.ObjectFactory("com.cognos.admin.extension"); /* This is a implementation of the extensive event handler. The impl need to have a method named "doAction" to * work as a mapping. * @param: env, context of the behaviour controller framework. * */ com.cognos.admin.extension.DataSourceCredentials = function (env) { this.env = env; this.state = this.env.state; this.fragment = this.env.fragment; this.toBeDeleted = this.state.getState("m_deletedIds"); if (!this.toBeDeleted) { this.toBeDeleted = []; this._updateClientStateForDelete(); } }; com.cognos.admin.extension.DataSourceCredentials.USER_PATH_PARAM = "m_userpath"; com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_FIELD_NAME = "m_dataSourceCredentialsToDelete"; com.cognos.admin.extension.DataSourceCredentials.WRITE_ACCESS_PARAM = "m_canwrite"; com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_PARAM = "m_deletedIds"; com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_PARAM_INFO = "Illegal argument exception: undefined param info"; com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_USER_PATH = "Illegal argument exception: undefined userpath"; com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_HTML_FORM = "Illegal argument exception: undefined or invalid html form"; com.cognos.admin.extension.DataSourceCredentials._isUserPathDefined = function(userPath) { return (typeof userPath == 'string') && userPath && userPath != ""; }; com.cognos.admin.extension.DataSourceCredentials._isHtmlFormDefined = function(htmlForm) { return htmlForm && typeof htmlForm.tagName == "string" && htmlForm.tagName.toLowerCase() === 'form'; }; com.cognos.admin.extension.DataSourceCredentials._canWrite = function(writeAccess) { var canWrite = false; if (writeAccess && typeof writeAccess == "string" && writeAccess.toLowerCase() === 'true') { canWrite = true; } return canWrite; }; com.cognos.admin.extension.DataSourceCredentials._retrieveDeleteIdsField = function(htmlForm) { var field = null; if (htmlForm.elements) { field = htmlForm.elements[com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_FIELD_NAME]; } return field; }; /** * This method builds the param string used when the fragment is retrieved * @param paramInfo object containing 2 properties: * - userPath: searchPath of the user for which the data source credentials are retrieved, * - htmlForm: form where the previously deleted entries are kept * @return the param string */ com.cognos.admin.extension.DataSourceCredentials.generateDataSourceParams = function(paramInfo) { var params = null; var toBeDeletedField = null; if (!paramInfo) { throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_PARAM_INFO; } if (!com.cognos.admin.extension.DataSourceCredentials._isUserPathDefined(paramInfo.userPath)) { throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_USER_PATH; } if (!com.cognos.admin.extension.DataSourceCredentials._isHtmlFormDefined(paramInfo.htmlForm)) { throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_HTML_FORM; } params = com.cognos.admin.extension.DataSourceCredentials.USER_PATH_PARAM + "=" + encodeURIComponent(paramInfo.userPath); toBeDeletedField = com.cognos.admin.extension.DataSourceCredentials._retrieveDeleteIdsField(paramInfo.htmlForm); if (toBeDeletedField && toBeDeletedField.value != null && toBeDeletedField.value != "") { params += "&" + com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_PARAM + "=" + encodeURIComponent(toBeDeletedField.value); } params += "&" + com.cognos.admin.extension.DataSourceCredentials.WRITE_ACCESS_PARAM + "=" + encodeURIComponent(com.cognos.admin.extension.DataSourceCredentials._canWrite(paramInfo.canWrite)); return params; }; com.cognos.admin.extension.DataSourceCredentials.prototype = { /* behaviour controller framework interface implementation * @param: e, the event trigger this action * @param: tag, the target of the event * @param: param, "cogParam" passing from the markup. */ doAction : function (e,tag,param) { switch (param.actionName){ case "removeEntries": this.removeEntries(); break; default: throw new Error("Unknown action name " + param.actionName + "; check your cogParam -> actionName."); } }, _showMessage: function(msg) { alert(msg); }, _updateToBeDeletedList : function() { var selectedEntries = null; var isListUpdated = false; selectedEntries = this.state.getState("grpActionRows",true); if (selectedEntries && selectedEntries.length > 0) { for (var i=0; i 0) { fields[0].value = com.cognos.admin.util.Tools.JSON.stringify(this.toBeDeleted); } }, removeEntries : function () { if (this._updateToBeDeletedList()) { this._updateClientStateForDelete(); this._updateHiddenFieldForDelete(); this._retrieveFragmentForDelete(); } } };