123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['bi/admin/nls/StringResource', 'bi/glass/app/ContentView', 'bi/admin/common/ui/RegionalOptionsModule', 'bi/admin/common/utils/AJAXUtils', 'bi/commons/ui/properties/PropertyUIControl', 'q', 'underscore', 'bi/admin/account/ui/PersonalTab', 'bi/admin/system/services/SystemCustomizationService'], function (StringResource, ContentView, RegionalOptionsModule, AJAXUtils, PropertyUIControl, Q, _, PersonalTab, SystemCustomizationService) {
- 'use strict'; //NOSONAR: meant to be strict
- var ProfileTab = PersonalTab.extend({
- init: function init(options) {
- ProfileTab.inherited('init', this, arguments);
- _.extend(this, options);
- this._customizationService = this._getNewSystemCustomizationService({
- 'glassContext': this.glassContext
- });
- this._customizations = null;
- },
- _getNewSystemCustomizationService: function _getNewSystemCustomizationService(options) {
- return new SystemCustomizationService(options);
- },
- _shouldShowHidden: function _shouldShowHidden(obj) {
- return {
- value: obj.showHiddenObjects ? obj.showHiddenObjects : false
- };
- },
- _shouldUseA11y: function _shouldUseA11y(obj) {
- return {
- value: obj.accessibilityFeatures ? true : false
- };
- },
- _shouldBidiEnabled: function _shouldBidiEnabled(obj) {
- return {
- value: obj.biDirectionalFeaturesEnabled ? true : false
- };
- },
- _getTextDir: function _getTextDir(obj) {
- return {
- value: obj.baseTextDirection
- };
- },
- render: function render() {
- // NOSONAR
- this._oPropertyUIControlHeader = this._createPropertyUIControlHeader();
- var defaultProfileObjPromise = this._getDefaultProfileObj();
- var defaultProfileDescriptionPromise = this._oPropertyUIControlHeader.render();
- var profileTabPromise = ProfileTab.inherited('render', this, arguments);
- var getCustomizations = this._getCustomizations();
- return Promise.all([defaultProfileObjPromise, profileTabPromise, defaultProfileDescriptionPromise, getCustomizations]).then(function (responses) {
- var defaultProfileObject = responses[0];
- this._oPropertyUIControlFooter = new PropertyUIControl({
- 'el': this.$el,
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'items': [{
- 'type': 'Separator'
- }, {
- 'label': StringResource.get('defaultUploadLocation'),
- 'type': 'SectionLabel'
- }, {
- 'name': 'uploadLocation',
- 'type': 'SingleLineValue',
- 'value': this._getCustomSaveLocationLabel(this._getCustomSaveLocation()),
- 'label': StringResource.get('setDefaultUploadLocation'),
- 'editCallback': function () {
- this._CustomSaveLocationSlideout = this.glassContext.appController.showSlideOut({
- parent: this.slideout,
- label: 'Permissions',
- width: '450px',
- closeSlideouts: true,
- 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
- }
- });
- }.bind(this)
- }, {
- 'type': 'Separator'
- }, {
- 'label': StringResource.get('permission'),
- 'type': 'SectionLabel'
- }, {
- 'name': 'default_profile_permissions',
- 'type': 'SingleLineValue',
- 'value': StringResource.get('edit'),
- 'label': StringResource.get('editDefaultUserProfilePermissionsMsg'),
- 'editCallback': function () {
- this.homePageSlideout = this.glassContext.appController.showSlideOut({
- parent: this.slideout,
- label: 'Permissions',
- width: '450px',
- closeSlideouts: true,
- content: {
- 'module': 'bi/admin/common/PropertiesPageView',
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'objectInfo': defaultProfileObject,
- 'propertiesPageViewDefinition': this._getDefaultProfilePermissionTabJsonSpec()
- }
- });
- }.bind(this)
- }, {
- 'type': 'Separator'
- }, {
- 'type': 'Footer',
- 'name': 'themes-footer',
- 'items': [{
- 'type': 'Button',
- 'name': 'profile-tab-update-button',
- 'label': StringResource.get('apply'),
- 'onSelect': this._updateDefaultUserProfile.bind(this),
- 'primary': true
- }]
- }]
- });
- return this._oPropertyUIControlFooter.render();
- }.bind(this));
- },
- _getCustomizations: function _getCustomizations() {
- if (this._customizations === null) {
- return this._customizationService.getCustomizations(this.objectInfo.id).then(function (result) {
- this._customizations = result;
- }.bind(this));
- }
- },
- _fomatA11yProps: function _fomatA11yProps(props) {
- if (!_.isUndefined(props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'])) {
- props.accessibilityFeatures = props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'];
- delete props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'];
- }
- },
- _updateDefaultUserProfile: function _updateDefaultUserProfile() {
- var props = this._oPropertyUIControl.getModifiedProperties();
- if (!_.isEmpty(props)) {
- this._fomatA11yProps(props);
- this.objectInfo = _.extend(this.objectInfo, props);
- var requestOptions = {
- method: 'PUT',
- contentType: 'application/json; charset=utf-8',
- data: JSON.stringify(this.objectInfo),
- url: AJAXUtils.getPath('update_default_user_profile')
- };
- this.glassContext.getCoreSvc('.Ajax').ajax(requestOptions).then(function (response) {
- this.glassContext.appController.showToast(StringResource.get('successfulUpdateDefaultUserProfileToast'));
- }.bind(this)).catch(function (response) {
- this.glassContext.appController.showErrorMessage(StringResource.get('failedUpdateDefaultUserProfile'));
- }.bind(this));
- }
- },
- _getDefaultProfileObj: function _getDefaultProfileObj() {
- var defaultProfileSearchPath = encodeURIComponent("/configuration/account[@name='User Profile']");
- var fields = encodeURIComponent("email,surname,givenName,userName,format,options,contentLocale,productLocale,timeZoneID,searchPath,tenantID,ancestors,permissions,disabled,defaultName,defaultDescription,creationTime,modificationTime,owner.defaultName");
- var endpoint = "v1/search_path?searchPath=" + defaultProfileSearchPath + "&fields=" + fields;
- var requestOptions = {
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- var defaultProfilePromise = this.glassContext.services.fetch.get(endpoint, requestOptions);
- return defaultProfilePromise.then(function (response) {
- return response.data.data[0];
- });
- },
- _getDefaultProfilePermissionTabJsonSpec: function _getDefaultProfilePermissionTabJsonSpec() {
- return {
- 'tabs': {
- 'account': [{
- "name": "permission",
- "module": "bi/content_apps/PropertiesPermissionsTab",
- "requiredPermissions": ["setPolicy"]
- }]
- }
- };
- },
- _createPropertyUIControlHeader: function _createPropertyUIControlHeader() {
- return new PropertyUIControl({
- 'el': this.$el,
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'items': [{
- 'id': 'descriptionText',
- 'label': StringResource.get('defaultUserProfileDescription'),
- 'type': 'SectionLabel'
- }]
- });
- },
- _getCustomSaveLocation: function _getCustomSaveLocation() {
- return this._customizations ? this._customizations.fileUpload_location : null;
- },
- 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._oPropertyUIControlFooter.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));
- },
- _getCustomSaveLocationLabel: function _getCustomSaveLocationLabel(customSaveLocation) {
- return customSaveLocation && customSaveLocation !== ".my_folders" ? StringResource.get('customized') : StringResource.get('default');
- }
- });
- return ProfileTab;
- });
|