"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * Copyright IBM Corp. 2017, 2017 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/admin/nls/StringResource', 'bi/glass/app/ContentView', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/admin/common/utils/AJAXUtils', 'ba-react-admin/ba-react-admin.min'], function (_, StringResource, ContentView, PropertyUIControl, ConfirmationDialog, AJAXUtils, AdminReact) { 'use strict'; //NOSONAR var BaseCustomizationTab = ContentView.extend({ init: function init(options) { BaseCustomizationTab.inherited('init', this, arguments); _.extend(this, options); this._customizationService = null; this._customizations = null; }, _getNewPropertyUIControl: function _getNewPropertyUIControl(options) { return new PropertyUIControl(options); }, render: function render() { return this._getCustomizations().then(function () { this._propertyUIControl = this._getNewPropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'slideout': this.slideout, 'items': this._getPropertyControlItems() }); return this._propertyUIControl.render(); }.bind(this)); }, _getCustomizations: function _getCustomizations() { return Promise.try(function () { if (this._customizations === null) { return this._customizationService.getCustomizations(this.objectInfo.id).then(function (result) { this._customizations = result; if (result.ui_excludedFeatures && result.ui_excludedFeatures.ids) { AdminReact.FeaturesTreeStore.setDisabledOptions(result.ui_excludedFeatures.ids); } return this._setHomeViewValue(); }.bind(this)); } }.bind(this)); }, _getPropertyControlItems: function _getPropertyControlItems() { var propertyControlItems = []; propertyControlItems.push(this._getHomePagePropertyControlItem()); propertyControlItems.push(this._getFeaturesPropertyControlItem()); propertyControlItems.push(this._getThemesPropertyControlItem()); propertyControlItems.push(this._getTeamFoldersPropertyControlItem()); propertyControlItems.push(this._getCustomSaveLocationControlItem()); propertyControlItems.push(this._getGlobalParametersControlItem()); var advancedProps = this._getAdvancedPropertyControlItem(); if (advancedProps !== undefined) { propertyControlItems.push(advancedProps); } return propertyControlItems; }, _getHomePagePropertyControlItem: function _getHomePagePropertyControlItem() { return { 'name': 'homePage', 'label': StringResource.get('homePage'), 'value': this.homeViewValue, 'type': 'SingleLineValue', 'ellipses': true, 'editCallback': this._showHomePagePanel.bind(this) }; }, _getFeaturesPropertyControlItem: function _getFeaturesPropertyControlItem() { var excludedFeatures = this._getExcludedFeatures(); return { 'name': 'features', 'label': StringResource.get('features'), 'value': excludedFeatures.ids.length > 0 ? StringResource.get('customized') : StringResource.get('default'), 'type': 'SingleLineValue', 'disabled': false, 'ellipses': true, 'editCallback': this._showFeaturesPanel.bind(this) }; }, _getThemesPropertyControlItem: function _getThemesPropertyControlItem() { var customizedTheme = this._getTheme(); return { 'name': 'themes', 'label': StringResource.get('themes'), 'value': customizedTheme, 'type': 'SingleLineValue', 'disabled': false, 'ellipses': true, 'editCallback': this._showThemesPanel.bind(this) }; }, _getTeamFoldersPropertyControlItem: function _getTeamFoldersPropertyControlItem() { var teamFolders = this._getTeamFolders(); return { 'name': 'teamFolders', 'label': StringResource.get('teamFolders'), 'value': this._getTeamFoldersLabel(teamFolders), 'type': 'SingleLineValue', 'disabled': false, 'ellipses': true, 'editCallback': this._showTeamFoldersPanel.bind(this) }; }, _getCustomSaveLocationControlItem: function _getCustomSaveLocationControlItem() { var CustomSaveLocation = this._getCustomSaveLocation(); return { 'name': 'uploadLocation', 'label': StringResource.get('defaultUploadLocation'), 'value': this._getCustomSaveLocationLabel(CustomSaveLocation), // default or customized 'type': 'SingleLineValue', 'disabled': false, 'ellipses': true, 'editCallback': this._showCustomSaveLocationPanel.bind(this) }; }, _getGlobalParametersControlItem: function _getGlobalParametersControlItem() { return { 'name': 'roleParameters', 'label': StringResource.get('globalParameters'), 'value': StringResource.get('connection_details'), 'type': 'SingleLineValue', 'disabled': false, 'ellipses': true, 'editCallback': this._showGlobalParametersPanel.bind(this) }; }, _showFeaturesPanel: function _showFeaturesPanel() { this._featuresSlideout = this.glassContext.appController.showSlideOut({ 'parent': this.slideout, 'width': '400px', 'label': StringResource.get('features'), 'content': { 'module': 'bi/admin/account/slideout/features/FeaturesPane', 'parentView': this, 'glassContext': this.glassContext, 'objectInfo': this.objectInfo, 'onReset': this.confirmResetFeature.bind(this), 'onApply': this.applyFeatureLensing.bind(this), 'isCustomized': this._getExcludedFeatures().ids.length > 0, 'getExcludeList': this._getExcludedFeatures.bind(this), 'getPerspectives': this.getLensiblePerspectives.bind(this) } }); }, _showHomePagePanel: function _showHomePagePanel() { this._homeSlideout = this.glassContext.appController.showSlideOut({ parent: this.slideout, width: '400px', label: StringResource.get('homePage'), content: { 'module': 'bi/admin/system/HomePerspectiveListView', 'glassContext': this.glassContext, 'title': StringResource.get('homePage'), 'currentValue': this._getHomePage(), 'homeViewValue': this.homeViewValue, 'perspectivesURL': 'v1/perspectives', 'onApplyCallback': this.setHomePage.bind(this), 'global': false } }); }, _showThemesPanel: function _showThemesPanel() { this._themesSlideout = this.glassContext.appController.showSlideOut({ parent: this.slideout, width: '400px', label: StringResource.get('themes'), content: { module: 'bi/admin/system/ThemesTab', showTitle: true, glassContext: this.glassContext, title: StringResource.get('themes'), getDefaultThemeCallback: function () { return $.when(this._getTheme()); }.bind(this), setDefaultThemeCallback: this.setTheme.bind(this), global: false } }); }, _showTeamFoldersPanel: function _showTeamFoldersPanel() { this._teamFoldersSlideout = this.glassContext.appController.showSlideOut({ parent: this.slideout, width: '400px', label: StringResource.get('teamFolders'), content: { 'module': 'bi/admin/account/slideout/teamfolders/TeamFoldersPane', 'glassContext': this.glassContext, 'title': StringResource.get('teamFolders'), 'currentValue': this._getTeamFolders(), 'onApplyCallback': this.setTeamFolders.bind(this), 'global': false, 'teamContentOnly': true } }); }, _showCustomSaveLocationPanel: function _showCustomSaveLocationPanel() { this._CustomSaveLocationSlideout = this.glassContext.appController.showSlideOut({ parent: this.slideout, width: '400px', label: StringResource.get('uploadLocation'), content: { 'module': 'bi/admin/account/slideout/teamfolders/CustomSaveLocationPane', 'glassContext': this.glassContext, 'title': StringResource.get('defaultUploadLocation'), 'currentValue': this._getCustomSaveLocation(), 'onApplyCallback': this.setCustomSaveLocation.bind(this), 'global': false, 'teamContentOnly': true } }); }, _setHomeViewValue: function _setHomeViewValue() { return Promise.try(function () { var defaultHome = this._getHomePage(); if (_.isUndefined(defaultHome.content)) { this.homeViewValue = defaultHome.perspective; } else { return this.glassContext.services.ajax.ajax({ type: 'GET', url: 'v1/path?path=' + encodeURIComponent(defaultHome.content.pathRef) }).then(function (object) { this.homeViewValue = _.isUndefined(object.data[0]) ? StringResource.get('unavailable') : object.data[0].defaultName; }.bind(this)); } }.bind(this)).catch(function (err) { this.homeViewValue = StringResource.get('unavailable'); this.logger.error(err); }.bind(this)); }, _getExcludedFeatures: function _getExcludedFeatures() { var excludedFeatures = { ids: AdminReact.FeaturesTreeStore.disabledOptions.slice() }; return this._customizations ? excludedFeatures : null; }, _getParameters: function _getParameters() { return this._customizations ? this._customizations.parameters : {}; }, _getParameterValues: function _getParameterValues() { return this._customizations ? this._customizations.parameter_values : {}; }, _getHomePage: function _getHomePage() { return this._customizations ? this._customizations.ui_homePage : null; }, _getTheme: function _getTheme() { return this._customizations ? this._customizations.ui_theme : null; }, _getTeamFolders: function _getTeamFolders() { return this._customizations ? this._customizations.ui_teamFolders : null; }, _getCustomSaveLocation: function _getCustomSaveLocation() { return this._customizations ? this._customizations.fileUpload_location : null; }, getLensiblePerspectives: function getLensiblePerspectives() { return this.glassContext.services.ajax.ajax({ 'method': 'GET', 'contentType': 'application/json; charset=utf-8', 'dataType': 'json', 'url': AJAXUtils.getPath('getPerspective') + '?fields=definition&lensable=true' }); }, applyFeatureLensing: function applyFeatureLensing() { return this._customizationService.setExcludedFeatures(this.objectInfo.id, this._getExcludedFeatures()).then(function (result) { this._customizations = result; this._updateFeatureControlItem(); if (this._featuresSlideout) { this._featuresSlideout.hide(); } this.glassContext.appController.showToast(StringResource.get('featuresSetMsg'), { type: 'success' }); return this._refresh(); }.bind(this)); }, confirmResetFeature: function confirmResetFeature() { var oDialog = this._getNewConfirmationDialog('confirmApplyChanges', StringResource.get('confirmDefaultTitle'), StringResource.get('confirmDefaultMessage')); oDialog.confirm(this.resetFeatureLensing.bind(this)); }, _getNewConfirmationDialog: function _getNewConfirmationDialog(type, title, message) { return new ConfirmationDialog(type, title, message); }, resetFeatureLensing: function resetFeatureLensing() { return this._customizationService.resetFeatures(this.objectInfo.id).then(function (result) { this._customizations = result; AdminReact.FeaturesTreeStore.clearDisabledOptions(); this._updateFeatureControlItem(); this.glassContext.appController.showToast(StringResource.get('featuresResetMsg'), { type: 'success' }); if (this._featuresSlideout) { this._featuresSlideout.hide(); this._showFeaturesPanel(); } }.bind(this)); }, _updateFeatureControlItem: function _updateFeatureControlItem() { if (this._propertyUIControl) { var excludedFeatures = this._customizations.ui_excludedFeatures; var value = excludedFeatures.ids.length > 0 ? StringResource.get('customized') : StringResource.get('default'); this._propertyUIControl.getProperty('features').setValue(value); } }, setHomePage: function setHomePage(homePage) { return this._customizationService.setHomePage(this.objectInfo.id, homePage.value).then(function (result) { this._customizations = result; this._propertyUIControl.getProperty('homePage').setValue(homePage.name); this.homeViewValue = homePage.name; if (this._homeSlideout) { this._homeSlideout.hide(); } this.glassContext.appController.showToast(StringResource.get('defaultHomeViewSet'), { type: 'success' }); return this._refresh(); }.bind(this)); }, setTheme: function setTheme(theme) { return this._customizationService.setTheme(this.objectInfo.id, theme).then(function (result) { this._customizations = result; this._propertyUIControl.getProperty('themes').setValue(theme || StringResource.get('default')); if (this._themesSlideout) { this._themesSlideout.hide(); } return this._refresh(); }.bind(this)); }, setTeamFolders: function setTeamFolders(teamFolders) { return this._customizationService.setTeamFolders(this.objectInfo.id, teamFolders).then(function (result) { this._customizations = result; var label = this._getTeamFoldersLabel(this._customizations.ui_teamFolders); this._propertyUIControl.getProperty('teamFolders').setValue(label); if (this._teamFoldersSlideout) { this._teamFoldersSlideout.hide(); } var message = this._customizations.ui_teamFolders.pathRef ? StringResource.get('teamFoldersSetMsg') : StringResource.get('teamFoldersResetMsg'); this.glassContext.appController.showToast(message, { type: 'success' }); return this._refresh(); }.bind(this)); }, setCustomSaveLocation: function setCustomSaveLocation(customSaveLocation) { return this._customizationService.setCustomSaveLocation(this.objectInfo.id, customSaveLocation).then(function (result) { this._customizations = result; var label = this._getCustomSaveLocationLabel(this._customizations.fileUpload_location); this._propertyUIControl.getProperty('uploadLocation').setValue(label); if (this._CustomSaveLocationSlideout) { this._CustomSaveLocationSlideout.hide(); } var message = this._customizations.fileUpload_location !== ".my_folders" ? StringResource.get('fileUpload_locationSetMsg') : StringResource.get('fileUpload_locationResetMsg'); this.glassContext.appController.showToast(message, { type: 'success' }); return this._refresh(); }.bind(this)); }, _getTeamFoldersLabel: function _getTeamFoldersLabel(teamFolders) { return teamFolders && teamFolders.pathRef ? StringResource.get('customized') : ''; }, _getCustomSaveLocationLabel: function _getCustomSaveLocationLabel(customSaveLocation) { return customSaveLocation && customSaveLocation !== ".my_folders" ? StringResource.get('customized') : StringResource.get('default'); } }); return BaseCustomizationTab; });