"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: admin * Copyright IBM Corp. 2015, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ 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) { /** * Sample content view that extends the glass View class */ var DataSourceListPane = BasePane.extend({ init: function init(options) { DataSourceListPane.inherited('init', this, arguments); $.extend(this, options); this.dsController = this._getNewDataSourceListController({ glassContext: this.glassContext }); this._bindEvents(); return App.getCurrentNameSpace().then(function (nsObj) { this.glassContext._currentNameSpace = nsObj; }.bind(this)); }, _bindEvents: function _bindEvents() { $(this.slideout.$el).on('com.ibm.cognos.bi.admin.refreshDataServerList', function (e) { this.refresh(); }.bind(this)); }, _getNewDataSourceListController: function _getNewDataSourceListController(options) { return new DataSourceListController(options); }, _getNewDataSourceListView: function _getNewDataSourceListView(options) { return new DataSourceListView(options); }, renderListView: function renderListView($body, permission) { var traversePermission = permission && permission.indexOf('traverse') > -1 ? true : false; if (!traversePermission) { this.$body.html('
' + StringResource.get('accessDenied') + '
'); return Promise.resolve(); } else { var writePermission = permission && permission.indexOf('write') > -1 ? true : false; var _haveModelingCapabilities = CapabilityHelper.checkCapabilities('canUseWebBasedModeling') ? true : false; this.listView = this._getNewDataSourceListView({ el: $body, showAddButton: writePermission || _haveModelingCapabilities, glassContext: this.glassContext, showListHeader: true, slideout: this.slideout, parentView: this }); this._bindListViewEvents(); return this.listView.render(); } }, _bindListViewEvents: function _bindListViewEvents() { $(this.listView).on('com.ibm.ds.selected', function (e, item) { this.doSetProperties(item); }.bind(this)); this.listView.on('addItem', function () { if (this.slideout.child) { this.slideout.child.hide(); } var vendorPane = this.glassContext.appController.showSlideOut({ parent: this.slideout, content: { module: 'bi/admin/datasource/slideout/VendorListPane', id: 'VendorListPane' } }); $(vendorPane).on("datasourceUpdate", function (e, updatedItem) { this.reOpenSlideout(); }.bind(this)); }.bind(this)); }, reOpenSlideout: function reOpenSlideout() { this.glassContext.appController.showSlideOut({ parent: this.slideout.parent, overlay: true, width: "400px", label: this.title, content: { module: "bi/admin/datasource/slideout/DataSourceListPane", id: 'DataSourcePane', title: this.title, showGobackButton: true } }); }, renderBody: function renderBody($body) { // check if user has the permission to create a new // data source var url = 'v1/namespaces'; return Promise.try(function () { return this.glassContext.services.ajax.ajax({ 'dataType': 'json', 'type': 'GET', 'url': url }).then(function (data) { var permission = _.find(data.data, function (item) { return item.searchPath.split('"')[1] === ":"; }).permissions; return this.renderListView($body, permission); }.bind(this)); }.bind(this)); }, _getNewConfirmationDialog: function _getNewConfirmationDialog(sType, sTitle, sMessage) { return new ConfirmationDialog(sType, sTitle, sMessage); }, doDelete: function doDelete(dataSource) { var oDialog = this._getNewConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage')); oDialog.confirm(function () { if (this.slideout.child) { this.slideout.child.hide(); } return this.dsController.deleteDataSource(dataSource.id).then(function () { var sText = StringResource.get('deleteDataSourceMsg', { 'name': dataSource.defaultName }); this.glassContext.appController.showToast(sText, { 'type': 'success' }); return this.listView.render(); }.bind(this), function (err) { this._glassContext.appController.showErrorMessage(err.responseJSON.messages.join('\n'), StringResource.get('error')); }.bind(this)); }.bind(this)); oDialog.renderContent($('
')); }, doSetProperties: function doSetProperties(dataSource) { var dsPropertySlideout = this.glassContext.appController.showSlideOut({ 'parent': this.slideout, 'width': "400px", 'onHide': function () { if (dsPropertySlideout && dsPropertySlideout.contentView && dsPropertySlideout.contentView.onHide) { return dsPropertySlideout.contentView.onHide().then(function () { dsPropertySlideout.hide(); }.bind(this)); } else { return Promise.resolve(); } }.bind(this), 'content': { 'module': 'bi/admin/common/PropertiesPageView', 'parentView': this, 'listPane': this, 'objectInfo': dataSource, 'type': dataSource.type, 'glassContext': this._glassContext } }); }, refresh: function refresh() { this.$body.empty(); this.render(); } }); return DataSourceListPane; });