123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- // 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<selectedEntries.length; i++){
- this.toBeDeleted.push({"storeID":selectedEntries[i]});
- }
- isListUpdated = true;
- } else {
- this._showMessage(ADM.DSC.IDS_NO_SELECTED_ENTRY_FOR_DELETE);
- }
- this.state.clearState("grpActionRows",true);
- return isListUpdated;
- },
-
- _isToBeDeletedListEmpty : function() {
- return this.toBeDeleted.length == 0;
- },
-
- _updateClientStateForDelete : function() {
- this.state.setState("m_deletedIds",this.toBeDeleted);
- },
-
- _retrieveFragmentForDelete: function() {
- if (!this._isToBeDeletedListEmpty()) {
- this.fragment.retrieve();
- }
- },
-
- _updateHiddenFieldForDelete: function() {
- var fields = null;
- fields = document.getElementsByName("m_dataSourceCredentialsToDelete");
- if (fields && fields.length > 0) {
- fields[0].value = com.cognos.admin.util.Tools.JSON.stringify(this.toBeDeleted);
- }
- },
-
-
- removeEntries : function () {
- if (this._updateToBeDeletedList()) {
- this._updateClientStateForDelete();
- this._updateHiddenFieldForDelete();
- this._retrieveFragmentForDelete();
- }
- }
-
- };
|