123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/commons/ui/core/Class', 'doT', 'text!bi/admin/globalparameters/helpers/templates/updateAccountUserProfileSettings.xml', 'text!bi/admin/globalparameters/helpers/templates/getAccountUserProfileSettings.xml', 'bi/admin/globalparameters/helpers/SoapHelper', 'bi/admin/common/utils/XMLUtils'], function (_, Class, doT, UpdateUserProfileSettingsTemplate, GetUserProfileSettingsTemplate, SoapHelper, XMLUtilsPlaceholder) {
- var _gCachedAccountUserProfileSettings = null;
- var AccountParameterValues = Class.extend({
- init: function init(options) {
- AccountParameterValues.inherited('init', this, arguments);
- _.extend(this, options);
- },
- _getUserProfileValues: function _getUserProfileValues() {
- if (_gCachedAccountUserProfileSettings) {
- return Promise.resolve(_gCachedAccountUserProfileSettings);
- } else {
- var getRequest = doT.template(GetUserProfileSettingsTemplate)({
- 'cafContextId': this.glassContext.authInfo.cafContextId
- });
- return this.glassContext.services.fetch.post('v1/reports', {
- 'headers': {
- 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
- },
- 'contentType': 'text/xml; charset=UTF-8',
- 'data': getRequest
- }).then(function (response) {
- var $accountProfileSettings = $(response.data).selectNode('Envelope').selectNode('Body').selectNode('queryResponse').selectNode('result').selectNode('item').selectNode('userProfileSettings').selectNode('value');
- var accountUserProfileSettingsText = $accountProfileSettings.text();
- if (accountUserProfileSettingsText !== '') {
- _gCachedAccountUserProfileSettings = JSON.parse(accountUserProfileSettingsText);
- } else {
- _gCachedAccountUserProfileSettings = {};
- }
- return _gCachedAccountUserProfileSettings;
- });
- }
- },
- reset: function reset() {
- return this._getUserProfileValues().then(function (currentAccountUserProfileValues) {
- currentAccountUserProfileValues.parameter_values = {};
- return this._sendUpdateRequest(currentAccountUserProfileValues);
- }.bind(this));
- },
- update: function update(parameter_values) {
- return this._getUserProfileValues().then(function (currentAccountUserProfileValues) {
- if (!currentAccountUserProfileValues.parameter_values) {
- currentAccountUserProfileValues.parameter_values = {};
- }
- _.each(parameter_values, function (parameter_value) {
- currentAccountUserProfileValues.parameter_values[parameter_value.name] = parameter_value;
- });
- return this._sendUpdateRequest(currentAccountUserProfileValues);
- }.bind(this));
- },
- _sendUpdateRequest: function _sendUpdateRequest(accountUserProfileValues) {
- var updateRequest = doT.template(UpdateUserProfileSettingsTemplate)({
- 'cafContextId': this.glassContext.authInfo.cafContextId,
- 'userProfileSettings': SoapHelper.xml_encode(JSON.stringify(accountUserProfileValues))
- });
- return this.glassContext.services.fetch.post('v1/reports', {
- 'headers': {
- 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
- },
- 'contentType': 'text/xml; charset=UTF-8',
- 'data': updateRequest
- }).then(function () {
- _gCachedAccountUserProfileSettings = accountUserProfileValues;
- return _gCachedAccountUserProfileSettings.parameter_values || {};
- });
- }
- });
- return AccountParameterValues;
- });
|