VendorListPane.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8.  */
  9. define(['jquery', 'bi/admin/common/slideout/BasePane', 'bi/admin/datasource/App', 'bi/admin/common/utils/AJAXUtils', 'bi/admin/datasource/ui/VendorListView', 'bi/admin/nls/StringResource', 'text!bi/admin/datasource/services/datasources.json'], function ($, BasePane, App, AJAXUtils, VendorListView, StringResource, datasources) {
  10. /**
  11. * Sample content view that extends the glass View class
  12. *
  13. */
  14. var VendorListPane = BasePane.extend({
  15. title: StringResource.get('vendorListPaneTitle'),
  16. init: function init(options) {
  17. VendorListPane.inherited('init', this, arguments);
  18. $.extend(this, options);
  19. this._stringResource = StringResource;
  20. this.slideout.$el.addClass('vendor-list-panel');
  21. },
  22. _openNewConnectionDialog: function _openNewConnectionDialog(selectedVendor) {
  23. var connection = {
  24. defaultName: StringResource.get('newDataServerConnection'),
  25. type: 'dataSourceConnection',
  26. permissions: ["execute", "read", "setPolicy", "traverse", "write"],
  27. disabled: false,
  28. hidden: false,
  29. isNew: true,
  30. dataSourceId: this.objectInfo.id,
  31. newConnection: true,
  32. signonOption: "anon",
  33. vendor: selectedVendor,
  34. connectionString: ""
  35. };
  36. return this._openConnectionDialog(connection);
  37. },
  38. _openNewDataServerConnectionDialog: function _openNewDataServerConnectionDialog(selectedVendor) {
  39. var dataSourceConnection = {
  40. defaultName: StringResource.get('newDataServerConnection'),
  41. type: 'dataSourceConnection',
  42. permissions: ["execute", "read", "setPolicy", "traverse", "write"],
  43. disabled: false,
  44. hidden: false,
  45. isNew: true,
  46. signonOption: "anon",
  47. vendor: selectedVendor,
  48. connectionString: ""
  49. };
  50. return this._openConnectionDialog(dataSourceConnection);
  51. },
  52. _openConnectionDialog: function _openConnectionDialog(connection) {
  53. var slideout = this.glassContext.appController.showSlideOut({
  54. 'parent': this.slideout,
  55. 'width': "400px",
  56. 'content': {
  57. 'module': 'bi/admin/common/PropertiesPageView',
  58. 'parentView': this,
  59. 'objectInfo': connection,
  60. 'glassContext': this._glassContext,
  61. 'selectedTabModule': 'bi/admin/datasource/ui/PropertiesConnectionTab',
  62. 'type': 'connection'
  63. }
  64. });
  65. slideout.onHide = function () {
  66. if (slideout && slideout.contentView && slideout.contentView.onHide) {
  67. return slideout.contentView.onHide();
  68. }
  69. }.bind(this);
  70. return slideout;
  71. },
  72. renderBody: function renderBody($body) {
  73. var listView = this._getNewVendorListView($body);
  74. listView.on('selected', function (item) {
  75. if (this.slideout.child) {
  76. this.slideout.child.hide();
  77. }
  78. var detailsPane;
  79. if (this.objectInfo && this.objectInfo.newConnection) {
  80. detailsPane = this._openNewConnectionDialog(item);
  81. } else {
  82. detailsPane = this._openNewDataServerConnectionDialog(item);
  83. }
  84. $(detailsPane).on("updateObject", function (e, updatedItem) {
  85. $(this.slideout).trigger("datasourceUpdate", updatedItem);
  86. }.bind(this));
  87. }.bind(this));
  88. var $spanEl = this.$el.find('div.goback .goback-icon');
  89. $spanEl.attr('role', 'button');
  90. $spanEl.attr('title', StringResource.get('goBack')).on('primaryaction', function () {
  91. if (this.slideout.child) {
  92. this.slideout.child.hide();
  93. }
  94. App.SlideOutDataSourceList(this.glassContext);
  95. }.bind(this));
  96. return this._getSortedItems().then(function (sortedItems) {
  97. listView.items = sortedItems;
  98. return listView.render(sortedItems);
  99. }.bind(this));
  100. },
  101. _getMtCloudConfigStatus: function _getMtCloudConfigStatus() {
  102. return this.glassContext.services.ajax.ajax({
  103. 'type': 'GET',
  104. 'url': AJAXUtils.getPath('getMtCloudBuild')
  105. }).then(function (response) {
  106. return response;
  107. });
  108. },
  109. _getSortedItems: function _getSortedItems() {
  110. var ds;
  111. try {
  112. ds = JSON.parse(datasources);
  113. } catch (err) {
  114. this.logger.error("could not load datasource metadata " + err);
  115. }
  116. return this._getMtCloudConfigStatus().then(function (response) {
  117. // only show supported data server connections if environment is multitenant cloud
  118. if (response && response.mtCloudBuild === 'true') {
  119. ds.data = ds.data.filter(function (item) {
  120. return item.multitenantCloud === true;
  121. });
  122. }
  123. ds.data.forEach(function (item, index) {
  124. if (item.versions) {
  125. item.code = item.versions[0].code;
  126. }
  127. item.id = item.code;
  128. });
  129. return _.sortBy(ds.data, function (item) {
  130. return item.title.toLowerCase();
  131. });
  132. });
  133. },
  134. _getNewVendorListView: function _getNewVendorListView($el) {
  135. return new VendorListView({
  136. $el: $el,
  137. glassContext: this.glassContext
  138. });
  139. },
  140. setFocus: function setFocus() {
  141. var $firstFocus = this.$el.find(":input[type=search]:first");
  142. if ($firstFocus.length > 0) {
  143. $firstFocus.focus();
  144. }
  145. }
  146. });
  147. return VendorListPane;
  148. });