123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- "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('<div class="bi-admin-access-denied-container">' + StringResource.get('accessDenied') + '</div>');
- 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($('<div>'));
- },
- 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;
- });
|