123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2021
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- 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) {
- 'use strict'; //NOSONAR: meant to be strict
- var DataSourceListView = View.extend({
- filterTips: StringResource.get('filterTips'),
- contextMenuTips: StringResource.get('moreInContext'),
- addButtonTip: StringResource.get('addButtonTip'),
- /**
- * @constructor
- */
- init: function init(options) {
- DataSourceListView.inherited('init', this, arguments);
- _.extend(this, options);
- this.listAdaptor = this._getNewDatasourceListAdapter({
- glassContext: this.glassContext,
- objectInfo: {},
- removeSelf: false,
- showContextMenu: true
- });
- },
- _getNewDatasourceListAdapter: function _getNewDatasourceListAdapter(options) {
- return new DatasourceListAdapter(options);
- },
- _getTemplateOptions: function _getTemplateOptions(items) {
- var groupedData = DataSourceListView.inherited('_getTemplateOptions', this, arguments);
- if (groupedData) {
- groupedData.nullOwnerLabel = StringResource.get('unknown');
- }
- return groupedData;
- },
- _getNewActionHandler: function _getNewActionHandler() {
- return new ActionHandler();
- },
- _getNewListView: function _getNewListView(options) {
- return new ListView(options);
- },
- _renderListView: function _renderListView() {
- var elList = this.$el.find('.bi-admin-datasource-list');
- elList.empty();
- this.listView = this._getNewListView({
- el: elList,
- dataAdaptor: this.listAdaptor,
- glassContext: this.glassContext,
- accessibleLabel: this.title,
- activeInputForm: null,
- multiSelect: false
- });
- this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
- this.listView.contextMenuCallback = function (e) {
- var handler = this._getNewActionHandler();
- var args = {
- "position": e.position,
- "menuId": "com.ibm.bi.admin.datasourceMenu",
- "activeObject": {
- handler: handler,
- data: e.selectedObject[0],
- parentView: this.parentView
- }
- };
- this.glassContext.appController.showContextMenu(args);
- }.bind(this);
- return this.listView.render();
- },
- render: function render() {
- this._renderTemplate();
- return this._renderSearch().then(this._renderListView.bind(this)).then(this._bindEvents.bind(this));
- },
- _renderTemplate: function _renderTemplate() {
- var paneInfo = {
- 'strings': {
- 'addDatasource': StringResource.get('addDatasource')
- }
- };
- var sHtml = dot.template(DataSourceListTemplate)(paneInfo);
- this.$el.html(sHtml);
- BidiUtil.initElementForBidi(this.$el.find(".bi-admin-input.bi-admin-input-search")[0]);
- },
- _renderSearch: function _renderSearch() {
- return MagicWand.searchInput(this.$el).then(function (widgets) {
- if (widgets.length === 1) {
- this._searchInput = widgets[0];
- this._searchInput.options.hint = StringResource.get('filterTips');
- this._searchInput.on('changed', function (e) {
- var trimmed = e.text.trim();
- if (trimmed.length > 0 || e.text === '') {
- this.listView.setPaging(false);
- this.listView.filter(trimmed, 'defaultName');
- }
- }.bind(this));
- }
- }.bind(this));
- },
- _bindEvents: function _bindEvents() {
- if (this.showAddButton) {
- this.$el.find('#button_add').on('primaryaction', function (event) {
- event.stopPropagation();
- this.trigger('addItem');
- }.bind(this));
- }
- },
- _rowClickHandler: function _rowClickHandler(oData) {
- if (this.listAdaptor.rowClickHandler) {
- this.listAdaptor.rowClickHandler(this, oData);
- }
- }
- });
- return DataSourceListView;
- });
|