UserProfileSettingsView.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. 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) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var ProfileTab = PersonalTab.extend({
  12. init: function init(options) {
  13. ProfileTab.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. this._customizationService = this._getNewSystemCustomizationService({
  16. 'glassContext': this.glassContext
  17. });
  18. this._customizations = null;
  19. },
  20. _getNewSystemCustomizationService: function _getNewSystemCustomizationService(options) {
  21. return new SystemCustomizationService(options);
  22. },
  23. _shouldShowHidden: function _shouldShowHidden(obj) {
  24. return {
  25. value: obj.showHiddenObjects ? obj.showHiddenObjects : false
  26. };
  27. },
  28. _shouldUseA11y: function _shouldUseA11y(obj) {
  29. return {
  30. value: obj.accessibilityFeatures ? true : false
  31. };
  32. },
  33. _shouldBidiEnabled: function _shouldBidiEnabled(obj) {
  34. return {
  35. value: obj.biDirectionalFeaturesEnabled ? true : false
  36. };
  37. },
  38. _getTextDir: function _getTextDir(obj) {
  39. return {
  40. value: obj.baseTextDirection
  41. };
  42. },
  43. render: function render() {
  44. // NOSONAR
  45. this._oPropertyUIControlHeader = this._createPropertyUIControlHeader();
  46. var defaultProfileObjPromise = this._getDefaultProfileObj();
  47. var defaultProfileDescriptionPromise = this._oPropertyUIControlHeader.render();
  48. var profileTabPromise = ProfileTab.inherited('render', this, arguments);
  49. var getCustomizations = this._getCustomizations();
  50. return Promise.all([defaultProfileObjPromise, profileTabPromise, defaultProfileDescriptionPromise, getCustomizations]).then(function (responses) {
  51. var defaultProfileObject = responses[0];
  52. this._oPropertyUIControlFooter = new PropertyUIControl({
  53. 'el': this.$el,
  54. 'glassContext': this.glassContext,
  55. 'slideout': this.slideout,
  56. 'items': [{
  57. 'type': 'Separator'
  58. }, {
  59. 'label': StringResource.get('defaultUploadLocation'),
  60. 'type': 'SectionLabel'
  61. }, {
  62. 'name': 'uploadLocation',
  63. 'type': 'SingleLineValue',
  64. 'value': this._getCustomSaveLocationLabel(this._getCustomSaveLocation()),
  65. 'label': StringResource.get('setDefaultUploadLocation'),
  66. 'editCallback': function () {
  67. this._CustomSaveLocationSlideout = this.glassContext.appController.showSlideOut({
  68. parent: this.slideout,
  69. label: 'Permissions',
  70. width: '450px',
  71. closeSlideouts: true,
  72. content: {
  73. 'module': 'bi/admin/account/slideout/teamfolders/CustomSaveLocationPane',
  74. 'glassContext': this.glassContext,
  75. 'title': StringResource.get('defaultUploadLocation'),
  76. 'currentValue': this._getCustomSaveLocation(),
  77. 'onApplyCallback': this.setCustomSaveLocation.bind(this),
  78. 'global': false,
  79. 'teamContentOnly': true
  80. }
  81. });
  82. }.bind(this)
  83. }, {
  84. 'type': 'Separator'
  85. }, {
  86. 'label': StringResource.get('permission'),
  87. 'type': 'SectionLabel'
  88. }, {
  89. 'name': 'default_profile_permissions',
  90. 'type': 'SingleLineValue',
  91. 'value': StringResource.get('edit'),
  92. 'label': StringResource.get('editDefaultUserProfilePermissionsMsg'),
  93. 'editCallback': function () {
  94. this.homePageSlideout = this.glassContext.appController.showSlideOut({
  95. parent: this.slideout,
  96. label: 'Permissions',
  97. width: '450px',
  98. closeSlideouts: true,
  99. content: {
  100. 'module': 'bi/admin/common/PropertiesPageView',
  101. 'glassContext': this.glassContext,
  102. 'slideout': this.slideout,
  103. 'objectInfo': defaultProfileObject,
  104. 'propertiesPageViewDefinition': this._getDefaultProfilePermissionTabJsonSpec()
  105. }
  106. });
  107. }.bind(this)
  108. }, {
  109. 'type': 'Separator'
  110. }, {
  111. 'type': 'Footer',
  112. 'name': 'themes-footer',
  113. 'items': [{
  114. 'type': 'Button',
  115. 'name': 'profile-tab-update-button',
  116. 'label': StringResource.get('apply'),
  117. 'onSelect': this._updateDefaultUserProfile.bind(this),
  118. 'primary': true
  119. }]
  120. }]
  121. });
  122. return this._oPropertyUIControlFooter.render();
  123. }.bind(this));
  124. },
  125. _getCustomizations: function _getCustomizations() {
  126. if (this._customizations === null) {
  127. return this._customizationService.getCustomizations(this.objectInfo.id).then(function (result) {
  128. this._customizations = result;
  129. }.bind(this));
  130. }
  131. },
  132. _fomatA11yProps: function _fomatA11yProps(props) {
  133. if (!_.isUndefined(props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'])) {
  134. props.accessibilityFeatures = props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'];
  135. delete props['http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures'];
  136. }
  137. },
  138. _updateDefaultUserProfile: function _updateDefaultUserProfile() {
  139. var props = this._oPropertyUIControl.getModifiedProperties();
  140. if (!_.isEmpty(props)) {
  141. this._fomatA11yProps(props);
  142. this.objectInfo = _.extend(this.objectInfo, props);
  143. var requestOptions = {
  144. method: 'PUT',
  145. contentType: 'application/json; charset=utf-8',
  146. data: JSON.stringify(this.objectInfo),
  147. url: AJAXUtils.getPath('update_default_user_profile')
  148. };
  149. this.glassContext.getCoreSvc('.Ajax').ajax(requestOptions).then(function (response) {
  150. this.glassContext.appController.showToast(StringResource.get('successfulUpdateDefaultUserProfileToast'));
  151. }.bind(this)).catch(function (response) {
  152. this.glassContext.appController.showErrorMessage(StringResource.get('failedUpdateDefaultUserProfile'));
  153. }.bind(this));
  154. }
  155. },
  156. _getDefaultProfileObj: function _getDefaultProfileObj() {
  157. var defaultProfileSearchPath = encodeURIComponent("/configuration/account[@name='User Profile']");
  158. var fields = encodeURIComponent("email,surname,givenName,userName,format,options,contentLocale,productLocale,timeZoneID,searchPath,tenantID,ancestors,permissions,disabled,defaultName,defaultDescription,creationTime,modificationTime,owner.defaultName");
  159. var endpoint = "v1/search_path?searchPath=" + defaultProfileSearchPath + "&fields=" + fields;
  160. var requestOptions = {
  161. contentType: 'application/json; charset=utf-8',
  162. dataType: 'json'
  163. };
  164. var defaultProfilePromise = this.glassContext.services.fetch.get(endpoint, requestOptions);
  165. return defaultProfilePromise.then(function (response) {
  166. return response.data.data[0];
  167. });
  168. },
  169. _getDefaultProfilePermissionTabJsonSpec: function _getDefaultProfilePermissionTabJsonSpec() {
  170. return {
  171. 'tabs': {
  172. 'account': [{
  173. "name": "permission",
  174. "module": "bi/content_apps/PropertiesPermissionsTab",
  175. "requiredPermissions": ["setPolicy"]
  176. }]
  177. }
  178. };
  179. },
  180. _createPropertyUIControlHeader: function _createPropertyUIControlHeader() {
  181. return new PropertyUIControl({
  182. 'el': this.$el,
  183. 'glassContext': this.glassContext,
  184. 'slideout': this.slideout,
  185. 'items': [{
  186. 'id': 'descriptionText',
  187. 'label': StringResource.get('defaultUserProfileDescription'),
  188. 'type': 'SectionLabel'
  189. }]
  190. });
  191. },
  192. _getCustomSaveLocation: function _getCustomSaveLocation() {
  193. return this._customizations ? this._customizations.fileUpload_location : null;
  194. },
  195. setCustomSaveLocation: function setCustomSaveLocation(customSaveLocation) {
  196. return this._customizationService.setCustomSaveLocation(this.objectInfo.id, customSaveLocation).then(function (result) {
  197. this._customizations = result;
  198. var label = this._getCustomSaveLocationLabel(this._customizations.fileUpload_location);
  199. this._oPropertyUIControlFooter.getProperty('uploadLocation').setValue(label);
  200. if (this._CustomSaveLocationSlideout) {
  201. this._CustomSaveLocationSlideout.hide();
  202. }
  203. var message = this._customizations.fileUpload_location !== ".my_folders" ? StringResource.get('fileUpload_locationSetMsg') : StringResource.get('fileUpload_locationResetMsg');
  204. this.glassContext.appController.showToast(message, {
  205. type: 'success'
  206. });
  207. return this._refresh();
  208. }.bind(this));
  209. },
  210. _getCustomSaveLocationLabel: function _getCustomSaveLocationLabel(customSaveLocation) {
  211. return customSaveLocation && customSaveLocation !== ".my_folders" ? StringResource.get('customized') : StringResource.get('default');
  212. }
  213. });
  214. return ProfileTab;
  215. });