1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/admin/common/services/BaseCustomizationService', 'bi/admin/common/utils/AJAXUtils', 'bi/admin/nls/StringResource'], function (_, BaseCustomizationService, AJAXUtils, StringResource) {
- var RoleCustomizationService = BaseCustomizationService.extend({
- init: function init(options) {
- RoleCustomizationService.inherited('init', this, arguments);
- _.extend(this, options);
- this._roleRank = null;
- },
- getCustomizations: function getCustomizations(id) {
- return this._getCustomizations(AJAXUtils.getPath('getUserProfileSettings', id));
- },
- saveCustomizations: function saveCustomizations(id) {
- return this.getRoleRank(id).then(function (roleRank) {
- if (roleRank === 0) {
- this.setRoleRank(1);
- return this.saveRoleRank(id);
- }
- }.bind(this)).then(function () {
- return this._saveCustomizations(AJAXUtils.getPath('getUserProfileSettings', id));
- }.bind(this));
- },
- _saveCustomizations: function _saveCustomizations(url) {
- if (this._customizations.fileUpload_location === ".my_folders") {
- delete this._customizations.fileUpload_location;
- url = url + "?fields=fileUpload_location";
- return this._ajaxDelete(url, 'DELETE');
- }
- if (this._customizations.ui_teamFolders && _.isEmpty(this._customizations.ui_teamFolders)) {
- delete this._customizations.ui_teamFolders;
- url = url + "?fields=ui_teamFolders";
- return this._ajaxDelete(url, 'DELETE');
- }
- return this._ajaxPut(url, this._customizations);
- },
- _getCustomizationsWithDefaults: function _getCustomizationsWithDefaults() {
- var returnValue = {
- 'ui_theme': RoleCustomizationService.DEFAULT,
- 'ui_homePage': {
- 'perspective': RoleCustomizationService.DEFAULT
- },
- 'ui_excludedFeatures': {
- 'ids': []
- },
- 'ui_teamFolders': {},
- 'parameter_values': {},
- 'fileUpload_location': null
- };
- if (this._customizations) {
- Object.keys(returnValue).forEach(this._replaceDefaultsWCustomValues.bind(this, returnValue, this._customizations));
- }
- return returnValue;
- },
- getRoleRank: function getRoleRank(id) {
- return Promise.try(function () {
- if (this._roleRank === null) {
- return this._ajaxGet(AJAXUtils.getPath('updateRole', id) + '?fields=profileRank').then(function (result) {
- if (result.data && result.data.length === 1) {
- this._roleRank = result.data[0].profileRank;
- } else {
- this._roleRank = 0;
- }
- }.bind(this));
- }
- }.bind(this)).then(function () {
- return this._roleRank;
- }.bind(this));
- },
- setRoleRank: function setRoleRank(rank) {
- if (rank >= 0 && rank <= 10) {
- this._roleRank = rank;
- }
- },
- saveRoleRank: function saveRoleRank(id) {
- return Promise.try(function () {
- return this._ajaxPut(AJAXUtils.getPath('updateRole', id), {
- 'type': 'role',
- 'profileRank': this._roleRank
- });
- }.bind(this));
- }
- });
- RoleCustomizationService.DEFAULT = StringResource.get('default');
- return RoleCustomizationService;
- });
|