123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2017, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'doT', 'bi/content_apps/PropertiesTab', 'bi/admin/nls/StringResource', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/admin/datasource/services/ConnectionUtils', 'text!bi/admin/datasource/templates/TestResultTemplate.html', 'react-dom', 'react', 'mobx', 'ba-react-admin/ba-react-admin.min', 'bi/commons/utils/Utils', 'baglass/core-client/js/core-client/utils/BidiUtil', 'bi/commons/ui/content/dialog/SignOnDialog'], function (_, dot, PropertiesTab, StringResource, ConfirmationDialog, ConnectionUtils, TestResultTemplate, ReactDOM, React, mobx, AdminReact, Utils, BidiUtil, SignOnDialog) {
- 'use strict'; //NOSONAR: meant to be strict
- var PropertiesConnectionTab = PropertiesTab.extend({
- init: function init(options) {
- PropertiesConnectionTab.inherited('init', this, arguments);
- _.extend(this, options);
- this.removedSignons = [];
- if (this.objectInfo.isNew) {
- this.hasChanged = true;
- }
- if (!this.objectInfo.connId) {
- this.objectInfo.connId = this.objectInfo.id;
- }
- this._setValidateInitialWhiteSpaceInput();
- this.selectedSignonFromReact = null;
- this.myDSSignon = null;
- },
- _setValidateInitialWhiteSpaceInput: function _setValidateInitialWhiteSpaceInput() {
- var elem = this.slideout.$el.find(".propertiesBannerLabel.v_defaultName");
- elem.on("keyup", function () {
- if (elem.val() < 1) {
- elem.val(elem.val().trim());
- }
- if (elem[0].value.length === 0) {
- elem.on("keydown", function (event) {
- if (event.which === 32) {
- event.preventDefault();
- }
- });
- } else {
- elem.off("keydown");
- }
- });
- this.slideout.$el.end();
- },
- _getContent: function _getContent() {
- return ConnectionUtils.getSignons(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo.dataSourceId, this.objectInfo.id);
- },
- _getConnectionParamsItems: function _getConnectionParamsItems(items) {
- items.push({
- 'name': 'connectionInfo',
- 'label': StringResource.get('connectionInformation'),
- 'value': this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") === -1 ? StringResource.get('viewConnectionInformation') : StringResource.get('editConnectionInformation'),
- 'type': 'SingleLineValue',
- 'ellipses': true,
- 'editCallback': this._openConnectionInformation.bind(this)
- });
- items.push({
- 'type': 'Separator'
- });
- },
- _resetConnectionInformationSlideout: function _resetConnectionInformationSlideout() {
- if (this.connectionEditorSlideout) {
- return this.connectionEditorSlideout.hide({
- force: true
- });
- } else {
- return Promise.resolve();
- }
- },
- _openConnectionInformation: function _openConnectionInformation() {
- if (this.connectionEditorSlideout) {
- //the slide out is already opened
- return;
- }
- this.hasChanged = this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") !== -1;
- this.connectionEditorSlideout = this.glassContext.appController.showSlideOut({
- 'pinning': {
- 'isPinned': true,
- 'display': false
- },
- 'parent': this.slideout,
- 'width': "550px",
- 'content': {
- 'showGobackButton': false,
- 'module': this.parseResult.metadata.module,
- 'parentView': this,
- 'objectInfo': this.objectInfo,
- 'parseInfo': this.parseResult,
- 'glassContext': this.glassContext
- }
- });
- this.connectionEditorSlideout.onHide = function () {
- delete this.connectionEditorSlideout;
- }.bind(this);
- },
- _openSignonPropertiesSlideout: function _openSignonPropertiesSlideout(signon, signonList) {
- this.signonListFromReact = mobx.toJS(signonList);
- this._resetConnectionInformationSlideout().then(function () {
- var selectedTab = "bi/admin/common/GeneralPropertiesTab";
- if (signon.isNew) {
- selectedTab = "bi/admin/datasource/ui/PropertiesSignonTab";
- }
- var slideout = this.glassContext.appController.showSlideOut({
- 'parent': this.slideout,
- 'width': "450px",
- 'content': {
- 'module': 'bi/admin/common/PropertiesPageView',
- 'parentView': this,
- 'listPane': this,
- 'objectInfo': signon,
- 'glassContext': this._glassContext,
- 'selectedTabModule': selectedTab,
- 'tabChanged': function () {
- var signonUICon = slideout.contentView.getPropertyUIControl();
- var modProperties = signonUICon.getModifiedProperties();
- _.extend(signon, modProperties);
- if (modProperties.defaultName) {
- this._modifySignon(signon);
- }
- }.bind(this)
- },
- 'onHide': function () {
- var signonUICon = slideout.contentView.getPropertyUIControl();
- var modProperties = signonUICon.getModifiedProperties();
- delete modProperties.credentialsEx;
- _.extend(signon, modProperties);
- this._modifySignon(signon);
- }.bind(this)
- });
- slideout.$el.on("credentialChanged", this.updateSignon.bind(this, slideout));
- }.bind(this));
- },
- _confirmUnsavedChanged: function _confirmUnsavedChanged() {
- var oDialog = this._newConfirmationDialog('confirmApplyChanges', StringResource.get('confirmChange'), StringResource.get('datasourceConfirmApply'));
- oDialog.confirm(this._saveConnection.bind(this));
- },
- _newConfirmationDialog: function _newConfirmationDialog(sType, sTitle, sMessage) {
- return new ConfirmationDialog(sType, sTitle, sMessage);
- },
- onClose: function onClose() {
- if (this.hasChanged) {
- this.hasChanged = false;
- this._confirmUnsavedChanged();
- }
- ReactDOM.unmountComponentAtNode(this.$el.find('#myReactElement')[0]);
- return this._oPropertyUIControl.onClose();
- },
- updateConnectionString: function updateConnectionString() {
- if (this.parseResult.metadata.code === 'EXTCATALOG') {
- delete this.parseResult.jdbcURL;
- } else if (this.parseResult.metadata.categoryId === 'jdbc' && (this.parseResult.jdbcURL === '' || _.isUndefined(this.parseResult.jdbcURL))) {
- this.parseResult.jdbcURL = this.parseResult.metadata.urlTemplate;
- }
- var connString = ConnectionUtils.buildConnection(this.parseResult, this.objectInfo);
- this.objectInfo.connectionString = ConnectionUtils.getUpdatedConnectionString(this.parseResult, connString);
- },
- _modifySignon: function _modifySignon(localSignOn) {
- var tempSignonArray = [];
- var tempSignonObject = {};
- var indexToChange;
- this.signonListFromReact.forEach(function (item, index) {
- if (item.id === localSignOn.id) {
- tempSignonObject = {
- label: localSignOn.defaultName,
- value: index,
- id: localSignOn.id
- };
- indexToChange = index;
- }
- tempSignonArray.push(this.signonListFromReact[index]);
- }.bind(this));
- if (_.isEmpty(tempSignonObject)) {
- tempSignonObject = {
- label: localSignOn.defaultName,
- value: tempSignonArray.length,
- id: localSignOn.id
- };
- }
- if (indexToChange > -1) {
- tempSignonArray.splice(indexToChange, 1, tempSignonObject);
- } else {
- tempSignonArray.push(tempSignonObject);
- }
- this.myDSSignon.updateSignons(tempSignonArray);
- this.myDSSignon.updateSelectedSignon(tempSignonObject);
- },
- updateSignon: function updateSignon(signonSlideout, evt, localSignOn) {
- var signonUICon = signonSlideout.contentView.getPropertyUIControl();
- var modProperties = signonUICon.getModifiedProperties();
- if (modProperties.credentialUserName !== localSignOn.newUser) {
- localSignOn.credentialsEx.username = localSignOn.newUser;
- } else if (modProperties.credentialUserName) {
- localSignOn.credentialsEx.username = modProperties.credentialUserName;
- delete modProperties.credentialUserName;
- }
- if (modProperties.credentialPassword !== localSignOn.newPassword) {
- localSignOn.credentialsEx.password = localSignOn.newPassword;
- } else if (modProperties.credentialPassword) {
- localSignOn.credentialsEx.password = modProperties.credentialPassword;
- delete modProperties.credentialPassword;
- }
- delete localSignOn.newUser;
- delete localSignOn.newPassword;
- _.extend(localSignOn, modProperties);
- this._modifySignon(localSignOn);
- localSignOn.credentialsEx.updatedSignon = 'updated';
- localSignOn.updated = true;
- },
- _getTestItems: function _getTestItems(items) {
- items.push({
- 'type': 'Separator'
- });
- items.push({
- 'name': 'testGroup',
- 'type': 'SingleLineLinks',
- 'items': [{
- 'align': 'left',
- 'items': [{
- 'type': 'icon',
- 'svgIcon': 'common-run',
- 'clickCallback': this._executeTest.bind(this),
- 'iconTooltip': StringResource.get('test'),
- 'role': 'button',
- 'class': 'testButton'
- }]
- }, {
- 'align': 'right',
- 'items': []
- }]
- });
- items.push({
- 'type': 'Separator'
- });
- },
- _getFooter: function _getFooter(items) {
- items.push({
- 'type': 'Footer',
- 'items': [{
- 'type': 'Button',
- 'label': StringResource.get('dataServerSave'),
- 'primary': true,
- 'onSelect': this._saveConnection.bind(this)
- }]
- });
- },
- _saveConnection_error: function _saveConnection_error(key) {
- return this.glassContext.appController.showToast(StringResource.get(key), {
- 'type': 'error',
- 'onHidden': function (event) {
- this.slideout.contentView.getPropertyUIControl().getProperty('defaultName').value = '';
- this.setFocus();
- }.bind(this)
- });
- },
- _saveConnection: function _saveConnection() {
- var modProperties = this.slideout.contentView.getPropertyUIControl().getModifiedProperties();
- _.extend(this.objectInfo, modProperties);
- this.hasChanged = false;
- this.updateConnectionString();
- this.slideout.connectionSignons = this.connectionSignons;
- this.slideout.removedSignons = this.removedSignons;
- delete this.objectInfo.searchPath;
- delete this.objectInfo.owner;
- delete this.objectInfo._meta;
- delete this.objectInfo.ancestors;
- delete this.objectInfo.version;
- if (this.objectInfo.defaultName === '') {
- return this._saveConnection_error('emptyConnectionName');
- }
- if (this.objectInfo.isNew && _.isUndefined(modProperties.defaultName)) {
- return this._saveConnection_error('unmodifiedConnectionName');
- }
- return this._save().then(function () {
- return ConnectionUtils.getSignons(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo.dataSourceId, this.objectInfo.id).then(function (signons) {
- this.connectionSignons = signons;
- this._updateDatasourceList();
- }.bind(this));
- }.bind(this));
- },
- _updateDatasourceList: function _updateDatasourceList() {
- $(this.slideout.$el).trigger('com.ibm.cognos.bi.admin.refreshDataServerList');
- },
- _save: function _save() {
- if (this.objectInfo.gatewayDestination && this.objectInfo.gatewayDestination[0]) {
- this.objectInfo.gatewayDestination = [{
- type: 'gatewayDestination',
- searchPath: "storeID('" + this.objectInfo.gatewayDestination[0].id + "')"
- }];
- }
- if (this.objectInfo.isNew) {
- return this._saveNewConnection();
- } else {
- return this._saveExistingConnection();
- }
- },
- _saveNewConnection: function _saveNewConnection() {
- var savePromise;
- var isNewConnection = false;
- if (this.objectInfo.newConnection) {
- isNewConnection = true;
- delete this.objectInfo.newConnection;
- savePromise = ConnectionUtils.createNewConnection(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo, this.connectionSignons);
- } else {
- savePromise = ConnectionUtils.createNewDataSource(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo, this.connectionSignons);
- }
- savePromise.then(function () {
- var sText = StringResource.get('datasourceConnectionToastUpdateMsg', {
- 'name': this.objectInfo.defaultName
- });
- this.glassContext.appController.showToast(sText, {
- type: 'success'
- });
- this.slideout.contentView.selectedTabModule = "bi/admin/datasource/ui/PropertiesConnectionTab";
- if (this.$el.find('#myReactElement')[0]) {
- ReactDOM.unmountComponentAtNode(this.$el.find('#myReactElement')[0]);
- }
- delete this.objectInfo.isNew;
- this.slideout.contentView.reload();
- if (this.parseResult && this.parseResult.gwStringUpdated) {
- delete this.parseResult.gwStringUpdated;
- }
- }.bind(this)).catch(function (error) {
- if (isNewConnection) {
- this.objectInfo.newConnection = true;
- }
- this._errorResponseCheck(error);
- }.bind(this));
- return savePromise;
- },
- setFocus: function setFocus() {
- var bannerLabel = this.slideout.$el.find(".propertiesBannerLabel.v_defaultName");
- if (bannerLabel.length > 0) {
- bannerLabel[0].focus();
- }
- },
- _saveExistingConnection: function _saveExistingConnection() {
- return ConnectionUtils.saveConnection(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo, this.connectionSignons, this.removedSignons).then(function () {
- var sText = StringResource.get('datasourceConnectionToastUpdateMsg', {
- 'name': this.objectInfo.defaultName
- });
- this.glassContext.appController.showToast(sText, {
- type: 'success'
- });
- this.slideout.contentView.selectedTabModule = "bi/admin/datasource/ui/PropertiesConnectionTab";
- if (this.$el.find('#myReactElement')[0]) {
- ReactDOM.unmountComponentAtNode(this.$el.find('#myReactElement')[0]);
- }
- this.slideout.contentView.reload();
- this.connectionSignons.forEach(function (signon) {
- delete signon.isNew;
- });
- if (this.parseResult && this.parseResult.gwStringUpdated) {
- delete this.parseResult.gwStringUpdated;
- }
- if (this.parseResult && this.parseResult.apiToken) {
- delete this.parseResult.apiToken;
- }
- this.removedSignons = [];
- }.bind(this)).catch(this._errorResponseCheck.bind(this));
- },
- _errorResponseCheck: function _errorResponseCheck(error) {
- var errorCode;
- if (error.jqXHR && error.jqXHR.responseJSON) {
- if (error.jqXHR.responseJSON.errors && error.jqXHR.responseJSON.errors[0].errorCode) {
- errorCode = error.jqXHR.responseJSON.errors[0].errorCode;
- } else if (error.jqXHR.responseJSON.errorCode) {
- errorCode = error.jqXHR.responseJSON.errorCode;
- } else {
- errorCode = StringResource.get('internalErrorMsg');
- }
- } else {
- errorCode = StringResource.get('internalErrorMsg');
- }
- var toastMsg;
- if (errorCode.includes("cmDuplicateName")) {
- toastMsg = StringResource.get('duplicateDSExists');
- } else {
- toastMsg = StringResource.get('dataServerError', {
- errorCode: errorCode
- });
- }
- this.glassContext.appController.showToast(toastMsg, {
- 'type': 'error',
- 'onHidden': function (event) {
- this.setFocus();
- }.bind(this)
- });
- },
- _renderProperties: function _renderProperties() {
- var items = [];
- this._getConnectionParamsItems(items);
- this._getTestItems(items);
- if (this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") !== -1) {
- this._getFooter(items);
- }
- return this.renderPropertyUIControl({
- 'el': this.$el,
- 'glassContext': this.glassContext,
- 'items': items
- }).then(function () {
- $(this.$el.find('.separator')[0]).after($('<div id=myReactElement>'));
- ReactDOM.unmountComponentAtNode(this.$el.find('#myReactElement')[0]);
- var dsSignon = React.createElement(AdminReact.DataServSignOn, {
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'StringResource': StringResource,
- 'ConnectionUtils': ConnectionUtils,
- 'objectInfo': this.objectInfo,
- 'authMethod': this.parseResult.authMethod,
- 'connectionSignons': this.connectionSignons,
- 'removedSignons': this.removedSignons,
- 'textDir': BidiUtil.userPreferredTextDir,
- 'parent': this
- });
- this.myDSSignon = ReactDOM.render(dsSignon, this.$el.find('#myReactElement')[0]);
- }.bind(this));
- },
- render: function render() {
- this._id = _.uniqueId('prop_');
- this.$el.addClass("admin_datasource_slideout");
- if (this.objectInfo.isNew) {
- if (!this.objectInfo.vendor.module) {
- this.objectInfo.vendor.module = ConnectionUtils._DEFAULTCONNECTIONSTRINGMODULE;
- }
- this.parseResult = {
- metadata: this.objectInfo.vendor,
- connStringTemplate: ConnectionUtils._connStringTemplateToken,
- authMethod: "anon"
- };
- if (ConnectionUtils.isTMRConnection(this.objectInfo)) {
- this.parseResult.tm1Params = {
- tm1AdminHost: '',
- tm1Port: '',
- tm1ServerName: '',
- tm1UseSSL: false,
- tm1Language: ''
- };
- } else if (ConnectionUtils.isOLAPConnection(this.objectInfo)) {
- this.parseResult.msasVersion = '';
- this.parseResult.serverUrl = '';
- this.parseResult.namedInstance = '';
- }
- this.updateConnectionString();
- } else {
- this.parseResult = ConnectionUtils.parseConnectionString(this.objectInfo);
- }
- return this._getContent().then(function (signons) {
- this.connectionSignons = signons;
- ConnectionUtils.resolveAuthMethod(this.parseResult, this.objectInfo, signons); //this code is important because this is a reload situation where the signon was saved
- //we need to update the selectedSignon to be passed to test/
- //if this doesn't happen - the selected signon does not get updated on a save and we use invalid
- //creds for the test connection
- if (this.selectedSignonFromReact) {
- this.connectionSignons.forEach(function (item) {
- if (item.id === signon.id) {
- return this.selectedSignonFromReact = item;
- }
- }.bind(this));
- }
- return this._renderProperties();
- }.bind(this)).then(function () {
- this._completeTestButtonRender();
- if (this.slideout && this.slideout.contentView) {
- $(this.slideout.contentView).on("tabChanged", this._resetConnectionInformationSlideout.bind(this));
- }
- if (this.objectInfo.isNew) {
- this._openConnectionInformation();
- }
- }.bind(this));
- },
- _completeTestButtonRender: function _completeTestButtonRender() {
- var $resultSec = $(this._getTestResultsSection());
- var $testSec = $(this._getTestButtonsSection());
- var $testButton = $($testSec.find(".testButton"));
- var $testLabel = $('<div role="presentation" class="testText">' + StringResource.get('test') + '</div>');
- $testButton.append($testLabel);
- $testSec.addClass("testResultSection");
- $resultSec.append('<div class="notTestedText">' + StringResource.get('notTested') + '</div>');
- },
- _openTestResultsSlideout: function _openTestResultsSlideout(results) {
- this._resetConnectionInformationSlideout().then(function () {
- this.glassContext.appController.showSlideOut({
- 'parent': this.slideout,
- 'width': "450px",
- 'content': {
- 'showGobackButton': true,
- 'module': 'bi/admin/datasource/slideout/TestResultSlideout',
- 'parentView': this,
- 'objectInfo': this.objectInfo,
- 'results': results,
- 'glassContext': this.glassContext
- }
- });
- }.bind(this));
- },
- _getTestGroup: function _getTestGroup() {
- var testSection = this.getPropertyUIControl().getProperty('testGroup');
- if (!testSection) {
- this.logger.error("could not find test result section");
- return;
- }
- return testSection.getPropertyNode();
- },
- _getTestButtonsSection: function _getTestButtonsSection() {
- var $testSection = $(this._getTestGroup());
- return $testSection.find(".left");
- },
- _getTestResultsSection: function _getTestResultsSection() {
- var $testSection = $(this._getTestGroup());
- return $testSection.find(".right");
- },
- _showTestExecuting: function _showTestExecuting($testSec) {
- var loadingAnimation = Utils.getLoadingAnimation(1);
- var $container = $('<div class="emptyTableContent bi-admin-working"><a class="testCancel">' + StringResource.get('cancel') + '</a></div>');
- $container.append(loadingAnimation);
- $testSec.append($container);
- $container.find(".testCancel").on("primaryaction", this._cancelTesting.bind(this));
- },
- _cancelTesting: function _cancelTesting() {
- if (this.testingPromise) {
- this.testingPromise.cancelled = true;
- } else {
- this.testingPromise = new Promise(function (resolve, reject) {});
- this.testingPromise.cancelled = true;
- }
- this._showTestResult(this.testingPromise);
- },
- _stopTestExecuting: function _stopTestExecuting($testSec) {
- $testSec.empty();
- },
- _createResultUI: function _createResultUI(message, icon, resultClass, $root, isCancel) {
- var htmlStr = dot.template(TestResultTemplate)({
- message: message,
- icon: icon,
- resultClass: resultClass,
- isCancel: isCancel ? true : false,
- openResultLabel: StringResource.get('openResultPane')
- });
- $root.append(htmlStr);
- },
- _showTestResult: function _showTestResult(testingPromise, results) {
- var $testResultSec = this._getTestResultsSection();
- if (testingPromise && testingPromise.objectInfo && testingPromise.objectInfo.connectionString === 'undefined') {
- this._createResultUI(StringResource.get('connection_empty'), 'common-error', 'testFailed', $testResultSec, true);
- return;
- }
- this._stopTestExecuting($testResultSec);
- if (testingPromise.cancelled) {
- this._createResultUI(StringResource.get('canceled'), '', 'canceled', $testResultSec, true);
- return;
- } else {
- var responsePromise = results.jqXHR;
- if (responsePromise.status === 200) {
- this._createResultUI(StringResource.get('success'), 'common-success', 'testSuccess', $testResultSec);
- } else {
- this._createResultUI(StringResource.get('testingFailed'), 'common-error', 'testFailed', $testResultSec);
- }
- var testResInfoEl = $testResultSec.find(".testResultInfoIcon");
- $(testResInfoEl).on("primaryaction", this._openTestResultsSlideout.bind(this, responsePromise));
- }
- },
- _getNewSignOnDialog: function _getNewSignOnDialog(spec) {
- return new SignOnDialog(spec);
- },
- _getSelectedSignonFromPrompt: function _getSelectedSignonFromPrompt() {
- return new Promise(function (resolve, reject) {
- var signonPrompt = this._getNewSignOnDialog({
- 'dataSourceName': "",
- 'dataSourceConnectionName': "",
- 'glassContext': this.glassContext,
- 'displayErrMsg': true,
- 'canSaveCredentials': false,
- 'onSubmit': function (Object) {
- var creds = signonPrompt.view.getCredentialsInfo();
- resolve({
- credentialsEx: {
- username: creds.userID,
- password: creds.password,
- updatedSignon: 'testDialog'
- }
- });
- }.bind(this),
- 'onCancel': function () {
- this._cancelTesting();
- reject();
- }.bind(this)
- });
- signonPrompt.view.canSaveCredentials = false;
- signonPrompt.open();
- }.bind(this));
- },
- _executeTest: function _executeTest() {
- var testResultSec = this._getTestResultsSection();
- $(testResultSec).empty();
- var jdbcString = ConnectionUtils.buildConnection(this.parseResult, this.objectInfo);
- this.objectInfo.connectionString = ConnectionUtils.getUpdatedConnectionString(this.parseResult, jdbcString);
- if (this.objectInfo.connectionString === 'undefined' || this.objectInfo.connectionString === '') {
- return this._showTestResult(this, this.testingPromise);
- }
- this._showTestExecuting($(testResultSec));
- var selectedSignon;
- if (this.parseResult.authMethod === 'prompt') {
- selectedSignon = this._getSelectedSignonFromPrompt();
- } else {
- var signOn;
- if (this.parseResult.authMethod === 'ucac') {
- signOn = {
- namespace: this.objectInfo.credentialNamespaces[0].searchPath
- };
- } else {
- if (this.selectedSignonFromReact) {
- signOn = this.selectedSignonFromReact;
- } else {
- signOn = this.connectionSignons[0];
- }
- }
- selectedSignon = Promise.resolve(signOn);
- }
- return selectedSignon.then(this._completeTesting.bind(this));
- },
- _completeTesting: function _completeTesting(selectedSignon) {
- this.testingPromise = ConnectionUtils.test(this.glassContext.getCoreSvc('.Ajax'), this.objectInfo.connectionString, selectedSignon, this.objectInfo.apiToken);
- this.testingPromise.then(this._showTestResult.bind(this, this.testingPromise));
- this.testingPromise.fail(this._showTestResult.bind(this, this.testingPromise));
- return this.testingPromise;
- },
- //Calls from React
- addSignonFromReact: function addSignonFromReact(signonList) {
- //There is a chance that the connection name has been set so lets use that
- var connName = this.slideout.$el.find(".v_defaultName");
- if (connName.length > 0) {
- this.objectInfo.defaultName = connName[0].value;
- }
- var newSignon = {
- id: _.uniqueId('signon_'),
- defaultName: this.objectInfo.defaultName,
- permissions: ["execute", "read", "setPolicy", "traverse", "write"],
- disabled: false,
- hidden: false,
- isNew: true,
- type: 'dataSourceSignon',
- credentialsEx: {
- password: "###PASSWORD###",
- username: StringResource.get('NewSigonUserName')
- }
- };
- this.connectionSignons.push(newSignon);
- this.hasChanged = true;
- this._openSignonPropertiesSlideout(newSignon, signonList);
- },
- editSignonFromReact: function editSignonFromReact(signonList, reactSignon) {
- var signon;
- this.connectionSignons.forEach(function (item) {
- if (item.id === reactSignon.id) {
- signon = item;
- }
- }.bind(this));
- signon.isEdited = true;
- this._openSignonPropertiesSlideout(signon, signonList, reactSignon);
- },
- setSelectedSignonFromReact: function setSelectedSignonFromReact(signon) {
- if (signon) {
- this.connectionSignons.forEach(function (item) {
- if (item.id === signon.id) {
- return this.selectedSignonFromReact = item;
- }
- }.bind(this));
- } else {
- if (this.connectionSignons.length > 0) {
- this.selectedSignonFromReact = this.connectionSignons[0];
- } else {
- this.selectedSignonFromReact = null;
- }
- }
- },
- updateAuthFromReact: function updateAuthFromReact(signonOption) {
- this.hasChanged = this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") !== -1;
- this.parseResult.authMethod = signonOption;
- this.objectInfo.signonOption = signonOption;
- if (this.objectInfo.signonOption !== 'ucac') {
- this.objectInfo.credentialNamespaces = [];
- }
- },
- updateUCACfromReact: function updateUCACfromReact(chosenNamespace) {
- this.objectInfo.credentialNamespaces = [];
- this.objectInfo.credentialNamespaces.push(chosenNamespace);
- },
- moveSignonToDeletedFromReact: function moveSignonToDeletedFromReact(selSignon) {
- this.hasChanged = true;
- if (selSignon.id.substring(0, 7) !== 'signon_') {
- this.removedSignons.push(selSignon);
- }
- this.connectionSignons = _.reject(this.connectionSignons, function (item) {
- return item.id === selSignon.id;
- });
- if (this.connectionSignons && this.connectionSignons.length === 0) {
- this.selectedSignonFromReact = null;
- }
- },
- deleteSignonsFromReact: function deleteSignonsFromReact() {
- this.connectionSignons.forEach(function (signon) {
- if (signon.id.substring(0, 7) !== 'signon_') {
- this.removedSignons.push(signon);
- }
- }.bind(this));
- this.connectionSignons = [];
- this.selectedSignonFromReact = null;
- }
- });
- return PropertiesConnectionTab;
- });
|