ConnectionListView.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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(['doT', 'underscore', 'bi/glass/app/util/View', 'bi/admin/nls/StringResource', 'bi/admin/datasource/services/ConnectionListAdapter', 'bi/admin/common/ui/listview/ListView', 'bi/commons/ui/dialogs/ConfirmationDialog', 'text!bi/admin/datasource/templates/ConnectionListTemplate.html', 'bi/admin/datasource/services/ConnectionListController', 'bi/admin/datasource/ActionHandler'], function (dot, _, View, StringResource, ConnectionListAdapter, ListView, ConfirmationDialog, listTemp, ConnectionListController, ActionHandler) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var ConnectionListView = View.extend({
  12. items: null,
  13. template: listTemp,
  14. contextMenuTips: StringResource.get('moreInContext'),
  15. sortOrder: [1, 'asc'],
  16. /**
  17. * @constructor
  18. */
  19. init: function init(options) {
  20. ConnectionListView.inherited('init', this, arguments);
  21. _.extend(this, options);
  22. this.listAdaptor = this._getNewConnectionListAdapter({
  23. glassContext: this.glassContext,
  24. objectInfo: this.objectInfo,
  25. removeSelf: false,
  26. showContextMenu: true
  27. });
  28. this.connectionsController = this._getNewConnectionListController({
  29. glassContext: this.glassContext
  30. });
  31. this._bindEvents();
  32. },
  33. _getNewConnectionListController: function _getNewConnectionListController(options) {
  34. return new ConnectionListController(options);
  35. },
  36. _getNewConnectionListAdapter: function _getNewConnectionListAdapter(options) {
  37. return new ConnectionListAdapter(options);
  38. },
  39. _bindEvents: function _bindEvents() {
  40. this.slideout.$el.on('com.ibm.cognos.bi.admin.refreshDataServerList', function (e) {
  41. return this.reload();
  42. }.bind(this));
  43. },
  44. /**
  45. * Main entry point - will render the form view
  46. */
  47. render: function render() {
  48. this._renderTemplate();
  49. if (this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") === -1) {
  50. var addButton = this.$el.find('.dataserver-connection-addBtn');
  51. if (addButton) {
  52. addButton.hide();
  53. }
  54. }
  55. this.$el.find('.dataserver-connection-addBtn').on('primaryaction', this._showVendorPane.bind(this));
  56. return this._renderListView();
  57. },
  58. reload: function reload() {
  59. this.$el.empty();
  60. return this.render();
  61. },
  62. _renderTemplate: function _renderTemplate() {
  63. var paneInfo = {
  64. 'strings': {
  65. 'addConnection': StringResource.get('addConnection')
  66. }
  67. };
  68. var sHtml = dot.template(listTemp)(paneInfo);
  69. this.$el.html(sHtml);
  70. },
  71. getColumnSpecs: function getColumnSpecs() {
  72. var colSpecs = [{
  73. 'type': 'Icon'
  74. }, {
  75. 'type': 'MultipleProperties',
  76. 'label': StringResource.get('name'),
  77. 'sortable': true,
  78. 'scope': 'row',
  79. 'items': [{
  80. 'type': 'Text',
  81. 'label': StringResource.get('name'),
  82. 'propertyName': 'defaultName',
  83. 'sortable': true,
  84. 'scope': 'row',
  85. 'clickCallback': function clickCallback() {}
  86. }]
  87. }, {
  88. 'type': 'Time',
  89. 'label': StringResource.get('lastModified'),
  90. 'propertyName': 'modificationTime',
  91. 'sortable': true
  92. }];
  93. if (this.showContextMenu) {
  94. colSpecs.push({
  95. 'type': 'ContextMenu',
  96. 'width': '10%',
  97. 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
  98. });
  99. }
  100. ;
  101. return colSpecs;
  102. },
  103. _getNewListView: function _getNewListView(options) {
  104. return new ListView(options);
  105. },
  106. _getNewActionHandler: function _getNewActionHandler() {
  107. return new ActionHandler();
  108. },
  109. _renderListView: function _renderListView() {
  110. var elList = this.$el.find('.bi-admin-connection-list');
  111. elList.empty();
  112. this.listView = this._getNewListView({
  113. el: elList,
  114. dataAdaptor: this.listAdaptor,
  115. glassContext: this.glassContext,
  116. accessibleLabel: this.title,
  117. activeInputForm: null,
  118. multiSelect: false
  119. });
  120. $(this.listView).on('com.ibm.connection.selected', function (e, item) {
  121. this.showDataConnectionProperty(item);
  122. }.bind(this));
  123. this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
  124. this.listView.contextMenuCallback = function (e) {
  125. var actionHandler = this._getNewActionHandler();
  126. var args = {
  127. "position": e.position,
  128. "menuId": "com.ibm.bi.admin.connectionMenu",
  129. "activeObject": {
  130. handler: actionHandler,
  131. data: e.selectedObject[0],
  132. parentView: this
  133. }
  134. };
  135. this.glassContext.appController.showContextMenu(args);
  136. }.bind(this);
  137. return this.listView.render();
  138. },
  139. _showVendorPane: function _showVendorPane() {
  140. if (this.slideout.child) {
  141. this.slideout.child.hide();
  142. }
  143. this.objectInfo.newConnection = true;
  144. var vendorPane = this.glassContext.appController.showSlideOut({
  145. parent: this.slideout,
  146. content: {
  147. module: 'bi/admin/datasource/slideout/VendorListPane',
  148. id: 'VendorListPane',
  149. objectInfo: this.objectInfo
  150. }
  151. });
  152. $(vendorPane).on("datasourceUpdate", function (e, updatedItem) {
  153. this.reOpenSlideout();
  154. }.bind(this));
  155. },
  156. _getItemById: function _getItemById(id) {
  157. var item = _.find(this.items, function (item) {
  158. return id === item.id;
  159. });
  160. return item;
  161. },
  162. _getItemByConnId: function _getItemByConnId(id) {
  163. var item = _.find(this.items, function (item) {
  164. return id === item.connId;
  165. });
  166. return item;
  167. },
  168. selectById: function selectById(id) {
  169. var item = this._getItemById(id) || this._getItemByConnId(id);
  170. this.trigger('selected', item);
  171. },
  172. selectByIndex: function selectByIndex(index) {
  173. var item = this.items[index];
  174. this.trigger('selected', item);
  175. },
  176. _rowClickHandler: function _rowClickHandler(item) {
  177. this.showDataConnectionProperty(item);
  178. },
  179. removeSelectedRowById: function removeSelectedRowById(id) {
  180. this._getRow().remove();
  181. if ($('#workPane').is(":visible")) {
  182. $('#workPane').addClass('hide');
  183. }
  184. },
  185. insertCopyRowById: function insertCopyRowById(copyRow, id) {
  186. var copySource = this._getRow();
  187. var targetSource = _.clone(copySource);
  188. targetSource.id = id;
  189. targetSource.insertAfter(copySource);
  190. },
  191. _getRow: function _getRow() {
  192. return _.find(this.$el.find('tr.list-item'), function (item) {
  193. if (item.id === id) {
  194. return item;
  195. }
  196. });
  197. },
  198. showDataConnectionProperty: function showDataConnectionProperty(item, tabName) {
  199. item.type = 'connection';
  200. item.dataSourceId = this.objectInfo.id;
  201. item.id = item.dataSourceId;
  202. this.dcPropertySlideout = this.glassContext.appController.showSlideOut({
  203. 'parent': this.slideout,
  204. 'width': "450px",
  205. 'onHide': function () {
  206. if (this.dcPropertySlideout && this.dcPropertySlideout.contentView && this.dcPropertySlideout.contentView.onHide) {
  207. this.dcPropertySlideout.contentView.onHide();
  208. }
  209. }.bind(this),
  210. 'content': {
  211. 'module': 'bi/admin/common/PropertiesPageView',
  212. 'parentView': this,
  213. 'objectInfo': item,
  214. 'type': item.type,
  215. 'selectedTabName': tabName,
  216. 'glassContext': this.glassContext,
  217. 'connectionsController': this.connectionsController
  218. }
  219. });
  220. $(this.dcPropertySlideout).on('updateObject', function (e, connections) {
  221. this.render(connections.data);
  222. }.bind(this));
  223. },
  224. refresh: function refresh() {},
  225. deleteConnection: function deleteConnection(dataSource) {
  226. var oDialog = new ConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage'));
  227. oDialog.confirm(function () {
  228. if (this.slideout.child) {
  229. this.slideout.child.hide();
  230. }
  231. this.listAdaptor.listController.deleteConnection(dataSource.connId, this.objectInfo.id).then(function () {
  232. this.listView.render();
  233. var sText = StringResource.get('deleteConnectionMsg', {
  234. 'name': dataSource.defaultName
  235. });
  236. this.glassContext.appController.showToast(sText, {
  237. 'type': 'success'
  238. });
  239. }.bind(this), function (err) {
  240. this._glassContext.appController.showErrorMessage(err.responseJSON.messages.join('\n'), StringResource.get('error'));
  241. }.bind(this));
  242. }.bind(this));
  243. oDialog.renderContent($('<div>'));
  244. }
  245. });
  246. return ConnectionListView;
  247. });