DataSourceCredentials.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2010
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. /**
  11. * This file defines all the actions available on a list of data source credentials.
  12. * Initially, only one is allowed: removeEntries
  13. */
  14. com.cognos.admin.ObjectFactory("com.cognos.admin.extension");
  15. /* This is a implementation of the extensive event handler. The impl need to have a method named "doAction" to
  16. * work as a mapping.
  17. * @param: env, context of the behaviour controller framework.
  18. *
  19. */
  20. com.cognos.admin.extension.DataSourceCredentials = function (env) {
  21. this.env = env;
  22. this.state = this.env.state;
  23. this.fragment = this.env.fragment;
  24. this.toBeDeleted = this.state.getState("m_deletedIds");
  25. if (!this.toBeDeleted) {
  26. this.toBeDeleted = [];
  27. this._updateClientStateForDelete();
  28. }
  29. };
  30. com.cognos.admin.extension.DataSourceCredentials.USER_PATH_PARAM = "m_userpath";
  31. com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_FIELD_NAME = "m_dataSourceCredentialsToDelete";
  32. com.cognos.admin.extension.DataSourceCredentials.WRITE_ACCESS_PARAM = "m_canwrite";
  33. com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_PARAM = "m_deletedIds";
  34. com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_PARAM_INFO = "Illegal argument exception: undefined param info";
  35. com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_USER_PATH = "Illegal argument exception: undefined userpath";
  36. com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_HTML_FORM = "Illegal argument exception: undefined or invalid html form";
  37. com.cognos.admin.extension.DataSourceCredentials._isUserPathDefined = function(userPath) {
  38. return (typeof userPath == 'string') && userPath && userPath != "";
  39. };
  40. com.cognos.admin.extension.DataSourceCredentials._isHtmlFormDefined = function(htmlForm) {
  41. return htmlForm && typeof htmlForm.tagName == "string" && htmlForm.tagName.toLowerCase() === 'form';
  42. };
  43. com.cognos.admin.extension.DataSourceCredentials._canWrite = function(writeAccess) {
  44. var canWrite = false;
  45. if (writeAccess && typeof writeAccess == "string" && writeAccess.toLowerCase() === 'true') {
  46. canWrite = true;
  47. }
  48. return canWrite;
  49. };
  50. com.cognos.admin.extension.DataSourceCredentials._retrieveDeleteIdsField = function(htmlForm) {
  51. var field = null;
  52. if (htmlForm.elements) {
  53. field = htmlForm.elements[com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_FIELD_NAME];
  54. }
  55. return field;
  56. };
  57. /**
  58. * This method builds the param string used when the fragment is retrieved
  59. * @param paramInfo object containing 2 properties:
  60. * - userPath: searchPath of the user for which the data source credentials are retrieved,
  61. * - htmlForm: form where the previously deleted entries are kept
  62. * @return the param string
  63. */
  64. com.cognos.admin.extension.DataSourceCredentials.generateDataSourceParams = function(paramInfo) {
  65. var params = null;
  66. var toBeDeletedField = null;
  67. if (!paramInfo) {
  68. throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_PARAM_INFO;
  69. }
  70. if (!com.cognos.admin.extension.DataSourceCredentials._isUserPathDefined(paramInfo.userPath)) {
  71. throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_USER_PATH;
  72. }
  73. if (!com.cognos.admin.extension.DataSourceCredentials._isHtmlFormDefined(paramInfo.htmlForm)) {
  74. throw com.cognos.admin.extension.DataSourceCredentials.ERROR_UNDEFINED_HTML_FORM;
  75. }
  76. params = com.cognos.admin.extension.DataSourceCredentials.USER_PATH_PARAM + "=" + encodeURIComponent(paramInfo.userPath);
  77. toBeDeletedField = com.cognos.admin.extension.DataSourceCredentials._retrieveDeleteIdsField(paramInfo.htmlForm);
  78. if (toBeDeletedField && toBeDeletedField.value != null && toBeDeletedField.value != "") {
  79. params += "&" + com.cognos.admin.extension.DataSourceCredentials.DELETED_IDS_PARAM + "=" + encodeURIComponent(toBeDeletedField.value);
  80. }
  81. params += "&" + com.cognos.admin.extension.DataSourceCredentials.WRITE_ACCESS_PARAM + "="
  82. + encodeURIComponent(com.cognos.admin.extension.DataSourceCredentials._canWrite(paramInfo.canWrite));
  83. return params;
  84. };
  85. com.cognos.admin.extension.DataSourceCredentials.prototype = {
  86. /* behaviour controller framework interface implementation
  87. * @param: e, the event trigger this action
  88. * @param: tag, the target of the event
  89. * @param: param, "cogParam" passing from the markup.
  90. */
  91. doAction : function (e,tag,param) {
  92. switch (param.actionName){
  93. case "removeEntries":
  94. this.removeEntries();
  95. break;
  96. default:
  97. throw new Error("Unknown action name " + param.actionName + "; check your cogParam -> actionName.");
  98. }
  99. },
  100. _showMessage: function(msg) {
  101. alert(msg);
  102. },
  103. _updateToBeDeletedList : function() {
  104. var selectedEntries = null;
  105. var isListUpdated = false;
  106. selectedEntries = this.state.getState("grpActionRows",true);
  107. if (selectedEntries && selectedEntries.length > 0) {
  108. for (var i=0; i<selectedEntries.length; i++){
  109. this.toBeDeleted.push({"storeID":selectedEntries[i]});
  110. }
  111. isListUpdated = true;
  112. } else {
  113. this._showMessage(ADM.DSC.IDS_NO_SELECTED_ENTRY_FOR_DELETE);
  114. }
  115. this.state.clearState("grpActionRows",true);
  116. return isListUpdated;
  117. },
  118. _isToBeDeletedListEmpty : function() {
  119. return this.toBeDeleted.length == 0;
  120. },
  121. _updateClientStateForDelete : function() {
  122. this.state.setState("m_deletedIds",this.toBeDeleted);
  123. },
  124. _retrieveFragmentForDelete: function() {
  125. if (!this._isToBeDeletedListEmpty()) {
  126. this.fragment.retrieve();
  127. }
  128. },
  129. _updateHiddenFieldForDelete: function() {
  130. var fields = null;
  131. fields = document.getElementsByName("m_dataSourceCredentialsToDelete");
  132. if (fields && fields.length > 0) {
  133. fields[0].value = com.cognos.admin.util.Tools.JSON.stringify(this.toBeDeleted);
  134. }
  135. },
  136. removeEntries : function () {
  137. if (this._updateToBeDeletedList()) {
  138. this._updateClientStateForDelete();
  139. this._updateHiddenFieldForDelete();
  140. this._retrieveFragmentForDelete();
  141. }
  142. }
  143. };