DataSourceListView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2021
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'doT', 'bi/admin/common/ui/MagicWand', 'bi/commons/ui/AccessibleView', 'bi/admin/nls/StringResource', 'bi/admin/datasource/services/DatasourceListAdapter', 'bi/admin/common/ui/listview/ListView', 'text!bi/admin/datasource/templates/DataSourceListTemplate.html', 'bi/commons/utils/BidiUtil', 'bi/admin/datasource/ActionHandler'], function (_, dot, MagicWand, View, StringResource, DatasourceListAdapter, ListView, DataSourceListTemplate, BidiUtil, ActionHandler) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var DataSourceListView = View.extend({
  12. filterTips: StringResource.get('filterTips'),
  13. contextMenuTips: StringResource.get('moreInContext'),
  14. addButtonTip: StringResource.get('addButtonTip'),
  15. /**
  16. * @constructor
  17. */
  18. init: function init(options) {
  19. DataSourceListView.inherited('init', this, arguments);
  20. _.extend(this, options);
  21. this.listAdaptor = this._getNewDatasourceListAdapter({
  22. glassContext: this.glassContext,
  23. objectInfo: {},
  24. removeSelf: false,
  25. showContextMenu: true
  26. });
  27. },
  28. _getNewDatasourceListAdapter: function _getNewDatasourceListAdapter(options) {
  29. return new DatasourceListAdapter(options);
  30. },
  31. _getTemplateOptions: function _getTemplateOptions(items) {
  32. var groupedData = DataSourceListView.inherited('_getTemplateOptions', this, arguments);
  33. if (groupedData) {
  34. groupedData.nullOwnerLabel = StringResource.get('unknown');
  35. }
  36. return groupedData;
  37. },
  38. _getNewActionHandler: function _getNewActionHandler() {
  39. return new ActionHandler();
  40. },
  41. _getNewListView: function _getNewListView(options) {
  42. return new ListView(options);
  43. },
  44. _renderListView: function _renderListView() {
  45. var elList = this.$el.find('.bi-admin-datasource-list');
  46. elList.empty();
  47. this.listView = this._getNewListView({
  48. el: elList,
  49. dataAdaptor: this.listAdaptor,
  50. glassContext: this.glassContext,
  51. accessibleLabel: this.title,
  52. activeInputForm: null,
  53. multiSelect: false
  54. });
  55. this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
  56. this.listView.contextMenuCallback = function (e) {
  57. var handler = this._getNewActionHandler();
  58. var args = {
  59. "position": e.position,
  60. "menuId": "com.ibm.bi.admin.datasourceMenu",
  61. "activeObject": {
  62. handler: handler,
  63. data: e.selectedObject[0],
  64. parentView: this.parentView
  65. }
  66. };
  67. this.glassContext.appController.showContextMenu(args);
  68. }.bind(this);
  69. return this.listView.render();
  70. },
  71. render: function render() {
  72. this._renderTemplate();
  73. return this._renderSearch().then(this._renderListView.bind(this)).then(this._bindEvents.bind(this));
  74. },
  75. _renderTemplate: function _renderTemplate() {
  76. var paneInfo = {
  77. 'strings': {
  78. 'addDatasource': StringResource.get('addDatasource')
  79. }
  80. };
  81. var sHtml = dot.template(DataSourceListTemplate)(paneInfo);
  82. this.$el.html(sHtml);
  83. BidiUtil.initElementForBidi(this.$el.find(".bi-admin-input.bi-admin-input-search")[0]);
  84. },
  85. _renderSearch: function _renderSearch() {
  86. return MagicWand.searchInput(this.$el).then(function (widgets) {
  87. if (widgets.length === 1) {
  88. this._searchInput = widgets[0];
  89. this._searchInput.options.hint = StringResource.get('filterTips');
  90. this._searchInput.on('changed', function (e) {
  91. var trimmed = e.text.trim();
  92. if (trimmed.length > 0 || e.text === '') {
  93. this.listView.setPaging(false);
  94. this.listView.filter(trimmed, 'defaultName');
  95. }
  96. }.bind(this));
  97. }
  98. }.bind(this));
  99. },
  100. _bindEvents: function _bindEvents() {
  101. if (this.showAddButton) {
  102. this.$el.find('#button_add').on('primaryaction', function (event) {
  103. event.stopPropagation();
  104. this.trigger('addItem');
  105. }.bind(this));
  106. }
  107. },
  108. _rowClickHandler: function _rowClickHandler(oData) {
  109. if (this.listAdaptor.rowClickHandler) {
  110. this.listAdaptor.rowClickHandler(this, oData);
  111. }
  112. }
  113. });
  114. return DataSourceListView;
  115. });