123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- "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(['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) {
- 'use strict'; //NOSONAR: meant to be strict
- var ConnectionListView = View.extend({
- items: null,
- template: listTemp,
- contextMenuTips: StringResource.get('moreInContext'),
- sortOrder: [1, 'asc'],
- /**
- * @constructor
- */
- init: function init(options) {
- ConnectionListView.inherited('init', this, arguments);
- _.extend(this, options);
- this.listAdaptor = this._getNewConnectionListAdapter({
- glassContext: this.glassContext,
- objectInfo: this.objectInfo,
- removeSelf: false,
- showContextMenu: true
- });
- this.connectionsController = this._getNewConnectionListController({
- glassContext: this.glassContext
- });
- this._bindEvents();
- },
- _getNewConnectionListController: function _getNewConnectionListController(options) {
- return new ConnectionListController(options);
- },
- _getNewConnectionListAdapter: function _getNewConnectionListAdapter(options) {
- return new ConnectionListAdapter(options);
- },
- _bindEvents: function _bindEvents() {
- this.slideout.$el.on('com.ibm.cognos.bi.admin.refreshDataServerList', function (e) {
- return this.reload();
- }.bind(this));
- },
- /**
- * Main entry point - will render the form view
- */
- render: function render() {
- this._renderTemplate();
- if (this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") === -1) {
- var addButton = this.$el.find('.dataserver-connection-addBtn');
- if (addButton) {
- addButton.hide();
- }
- }
- this.$el.find('.dataserver-connection-addBtn').on('primaryaction', this._showVendorPane.bind(this));
- return this._renderListView();
- },
- reload: function reload() {
- this.$el.empty();
- return this.render();
- },
- _renderTemplate: function _renderTemplate() {
- var paneInfo = {
- 'strings': {
- 'addConnection': StringResource.get('addConnection')
- }
- };
- var sHtml = dot.template(listTemp)(paneInfo);
- this.$el.html(sHtml);
- },
- getColumnSpecs: function getColumnSpecs() {
- var colSpecs = [{
- 'type': 'Icon'
- }, {
- 'type': 'MultipleProperties',
- 'label': StringResource.get('name'),
- 'sortable': true,
- 'scope': 'row',
- 'items': [{
- 'type': 'Text',
- 'label': StringResource.get('name'),
- 'propertyName': 'defaultName',
- 'sortable': true,
- 'scope': 'row',
- 'clickCallback': function clickCallback() {}
- }]
- }, {
- 'type': 'Time',
- 'label': StringResource.get('lastModified'),
- 'propertyName': 'modificationTime',
- 'sortable': true
- }];
- if (this.showContextMenu) {
- colSpecs.push({
- 'type': 'ContextMenu',
- 'width': '10%',
- 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
- });
- }
- ;
- return colSpecs;
- },
- _getNewListView: function _getNewListView(options) {
- return new ListView(options);
- },
- _getNewActionHandler: function _getNewActionHandler() {
- return new ActionHandler();
- },
- _renderListView: function _renderListView() {
- var elList = this.$el.find('.bi-admin-connection-list');
- elList.empty();
- this.listView = this._getNewListView({
- el: elList,
- dataAdaptor: this.listAdaptor,
- glassContext: this.glassContext,
- accessibleLabel: this.title,
- activeInputForm: null,
- multiSelect: false
- });
- $(this.listView).on('com.ibm.connection.selected', function (e, item) {
- this.showDataConnectionProperty(item);
- }.bind(this));
- this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
- this.listView.contextMenuCallback = function (e) {
- var actionHandler = this._getNewActionHandler();
- var args = {
- "position": e.position,
- "menuId": "com.ibm.bi.admin.connectionMenu",
- "activeObject": {
- handler: actionHandler,
- data: e.selectedObject[0],
- parentView: this
- }
- };
- this.glassContext.appController.showContextMenu(args);
- }.bind(this);
- return this.listView.render();
- },
- _showVendorPane: function _showVendorPane() {
- if (this.slideout.child) {
- this.slideout.child.hide();
- }
- this.objectInfo.newConnection = true;
- var vendorPane = this.glassContext.appController.showSlideOut({
- parent: this.slideout,
- content: {
- module: 'bi/admin/datasource/slideout/VendorListPane',
- id: 'VendorListPane',
- objectInfo: this.objectInfo
- }
- });
- $(vendorPane).on("datasourceUpdate", function (e, updatedItem) {
- this.reOpenSlideout();
- }.bind(this));
- },
- _getItemById: function _getItemById(id) {
- var item = _.find(this.items, function (item) {
- return id === item.id;
- });
- return item;
- },
- _getItemByConnId: function _getItemByConnId(id) {
- var item = _.find(this.items, function (item) {
- return id === item.connId;
- });
- return item;
- },
- selectById: function selectById(id) {
- var item = this._getItemById(id) || this._getItemByConnId(id);
- this.trigger('selected', item);
- },
- selectByIndex: function selectByIndex(index) {
- var item = this.items[index];
- this.trigger('selected', item);
- },
- _rowClickHandler: function _rowClickHandler(item) {
- this.showDataConnectionProperty(item);
- },
- removeSelectedRowById: function removeSelectedRowById(id) {
- this._getRow().remove();
- if ($('#workPane').is(":visible")) {
- $('#workPane').addClass('hide');
- }
- },
- insertCopyRowById: function insertCopyRowById(copyRow, id) {
- var copySource = this._getRow();
- var targetSource = _.clone(copySource);
- targetSource.id = id;
- targetSource.insertAfter(copySource);
- },
- _getRow: function _getRow() {
- return _.find(this.$el.find('tr.list-item'), function (item) {
- if (item.id === id) {
- return item;
- }
- });
- },
- showDataConnectionProperty: function showDataConnectionProperty(item, tabName) {
- item.type = 'connection';
- item.dataSourceId = this.objectInfo.id;
- item.id = item.dataSourceId;
- this.dcPropertySlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.slideout,
- 'width': "450px",
- 'onHide': function () {
- if (this.dcPropertySlideout && this.dcPropertySlideout.contentView && this.dcPropertySlideout.contentView.onHide) {
- this.dcPropertySlideout.contentView.onHide();
- }
- }.bind(this),
- 'content': {
- 'module': 'bi/admin/common/PropertiesPageView',
- 'parentView': this,
- 'objectInfo': item,
- 'type': item.type,
- 'selectedTabName': tabName,
- 'glassContext': this.glassContext,
- 'connectionsController': this.connectionsController
- }
- });
- $(this.dcPropertySlideout).on('updateObject', function (e, connections) {
- this.render(connections.data);
- }.bind(this));
- },
- refresh: function refresh() {},
- deleteConnection: function deleteConnection(dataSource) {
- var oDialog = new ConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage'));
- oDialog.confirm(function () {
- if (this.slideout.child) {
- this.slideout.child.hide();
- }
- this.listAdaptor.listController.deleteConnection(dataSource.connId, this.objectInfo.id).then(function () {
- this.listView.render();
- var sText = StringResource.get('deleteConnectionMsg', {
- 'name': dataSource.defaultName
- });
- this.glassContext.appController.showToast(sText, {
- 'type': 'success'
- });
- }.bind(this), function (err) {
- this._glassContext.appController.showErrorMessage(err.responseJSON.messages.join('\n'), StringResource.get('error'));
- }.bind(this));
- }.bind(this));
- oDialog.renderContent($('<div>'));
- }
- });
- return ConnectionListView;
- });
|