DataSourceListPane.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2015, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/common/slideout/BasePane', 'bi/admin/datasource/App', 'bi/admin/datasource/ui/DataSourceListView', 'bi/admin/common/utils/CapabilityHelper', 'bi/admin/nls/StringResource', 'bi/admin/datasource/services/DataSourceListController', 'bi/commons/ui/dialogs/ConfirmationDialog'], function (_, BasePane, App, DataSourceListView, CapabilityHelper, StringResource, DataSourceListController, ConfirmationDialog) {
  10. /**
  11. * Sample content view that extends the glass View class
  12. */
  13. var DataSourceListPane = BasePane.extend({
  14. init: function init(options) {
  15. DataSourceListPane.inherited('init', this, arguments);
  16. $.extend(this, options);
  17. this.dsController = this._getNewDataSourceListController({
  18. glassContext: this.glassContext
  19. });
  20. this._bindEvents();
  21. return App.getCurrentNameSpace().then(function (nsObj) {
  22. this.glassContext._currentNameSpace = nsObj;
  23. }.bind(this));
  24. },
  25. _bindEvents: function _bindEvents() {
  26. $(this.slideout.$el).on('com.ibm.cognos.bi.admin.refreshDataServerList', function (e) {
  27. this.refresh();
  28. }.bind(this));
  29. },
  30. _getNewDataSourceListController: function _getNewDataSourceListController(options) {
  31. return new DataSourceListController(options);
  32. },
  33. _getNewDataSourceListView: function _getNewDataSourceListView(options) {
  34. return new DataSourceListView(options);
  35. },
  36. renderListView: function renderListView($body, permission) {
  37. var traversePermission = permission && permission.indexOf('traverse') > -1 ? true : false;
  38. if (!traversePermission) {
  39. this.$body.html('<div class="bi-admin-access-denied-container">' + StringResource.get('accessDenied') + '</div>');
  40. return Promise.resolve();
  41. } else {
  42. var writePermission = permission && permission.indexOf('write') > -1 ? true : false;
  43. var _haveModelingCapabilities = CapabilityHelper.checkCapabilities('canUseWebBasedModeling') ? true : false;
  44. this.listView = this._getNewDataSourceListView({
  45. el: $body,
  46. showAddButton: writePermission || _haveModelingCapabilities,
  47. glassContext: this.glassContext,
  48. showListHeader: true,
  49. slideout: this.slideout,
  50. parentView: this
  51. });
  52. this._bindListViewEvents();
  53. return this.listView.render();
  54. }
  55. },
  56. _bindListViewEvents: function _bindListViewEvents() {
  57. $(this.listView).on('com.ibm.ds.selected', function (e, item) {
  58. this.doSetProperties(item);
  59. }.bind(this));
  60. this.listView.on('addItem', function () {
  61. if (this.slideout.child) {
  62. this.slideout.child.hide();
  63. }
  64. var vendorPane = this.glassContext.appController.showSlideOut({
  65. parent: this.slideout,
  66. content: {
  67. module: 'bi/admin/datasource/slideout/VendorListPane',
  68. id: 'VendorListPane'
  69. }
  70. });
  71. $(vendorPane).on("datasourceUpdate", function (e, updatedItem) {
  72. this.reOpenSlideout();
  73. }.bind(this));
  74. }.bind(this));
  75. },
  76. reOpenSlideout: function reOpenSlideout() {
  77. this.glassContext.appController.showSlideOut({
  78. parent: this.slideout.parent,
  79. overlay: true,
  80. width: "400px",
  81. label: this.title,
  82. content: {
  83. module: "bi/admin/datasource/slideout/DataSourceListPane",
  84. id: 'DataSourcePane',
  85. title: this.title,
  86. showGobackButton: true
  87. }
  88. });
  89. },
  90. renderBody: function renderBody($body) {
  91. // check if user has the permission to create a new
  92. // data source
  93. var url = 'v1/namespaces';
  94. return Promise.try(function () {
  95. return this.glassContext.services.ajax.ajax({
  96. 'dataType': 'json',
  97. 'type': 'GET',
  98. 'url': url
  99. }).then(function (data) {
  100. var permission = _.find(data.data, function (item) {
  101. return item.searchPath.split('"')[1] === ":";
  102. }).permissions;
  103. return this.renderListView($body, permission);
  104. }.bind(this));
  105. }.bind(this));
  106. },
  107. _getNewConfirmationDialog: function _getNewConfirmationDialog(sType, sTitle, sMessage) {
  108. return new ConfirmationDialog(sType, sTitle, sMessage);
  109. },
  110. doDelete: function doDelete(dataSource) {
  111. var oDialog = this._getNewConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage'));
  112. oDialog.confirm(function () {
  113. if (this.slideout.child) {
  114. this.slideout.child.hide();
  115. }
  116. return this.dsController.deleteDataSource(dataSource.id).then(function () {
  117. var sText = StringResource.get('deleteDataSourceMsg', {
  118. 'name': dataSource.defaultName
  119. });
  120. this.glassContext.appController.showToast(sText, {
  121. 'type': 'success'
  122. });
  123. return this.listView.render();
  124. }.bind(this), function (err) {
  125. this._glassContext.appController.showErrorMessage(err.responseJSON.messages.join('\n'), StringResource.get('error'));
  126. }.bind(this));
  127. }.bind(this));
  128. oDialog.renderContent($('<div>'));
  129. },
  130. doSetProperties: function doSetProperties(dataSource) {
  131. var dsPropertySlideout = this.glassContext.appController.showSlideOut({
  132. 'parent': this.slideout,
  133. 'width': "400px",
  134. 'onHide': function () {
  135. if (dsPropertySlideout && dsPropertySlideout.contentView && dsPropertySlideout.contentView.onHide) {
  136. return dsPropertySlideout.contentView.onHide().then(function () {
  137. dsPropertySlideout.hide();
  138. }.bind(this));
  139. } else {
  140. return Promise.resolve();
  141. }
  142. }.bind(this),
  143. 'content': {
  144. 'module': 'bi/admin/common/PropertiesPageView',
  145. 'parentView': this,
  146. 'listPane': this,
  147. 'objectInfo': dataSource,
  148. 'type': dataSource.type,
  149. 'glassContext': this._glassContext
  150. }
  151. });
  152. },
  153. refresh: function refresh() {
  154. this.$body.empty();
  155. this.render();
  156. }
  157. });
  158. return DataSourceListPane;
  159. });