CustomizationTab.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/BaseCustomizationTab', 'bi/admin/account/services/RoleCustomizationService'], function (_, StringResource, BaseCustomizationTab, RoleCustomizationService) {
  10. 'use strict'; //NOSONAR
  11. var SYSTEM_ADMIN_ID = "xOjpTeXN0ZW0gQWRtaW5pc3RyYXRvcnM_";
  12. var CustomizationTab = BaseCustomizationTab.extend({
  13. init: function init(options) {
  14. CustomizationTab.inherited('init', this, arguments);
  15. _.extend(this, options);
  16. this._customizationService = this._getNewRoleCustomizationService({
  17. 'glassContext': this.glassContext
  18. });
  19. this._modified = false;
  20. },
  21. _getNewRoleCustomizationService: function _getNewRoleCustomizationService(options) {
  22. return new RoleCustomizationService(options);
  23. },
  24. onClose: function onClose() {
  25. CustomizationTab.inherited('remove', this, arguments);
  26. if (this._modified) {
  27. this._customizationService.saveRoleRank(this.objectInfo.id);
  28. }
  29. },
  30. _showGlobalParametersPanel: function _showGlobalParametersPanel() {
  31. this._parametersSlideout = this.glassContext.appController.showSlideOut({
  32. 'parent': this.slideout,
  33. 'width': '400px',
  34. 'label': StringResource.get('globalParameters'),
  35. 'content': {
  36. 'module': 'bi/admin/account/slideout/ParametersPane',
  37. 'parentView': this,
  38. 'glassContext': this.glassContext,
  39. 'parameter_values': this._getParameterValues(),
  40. 'onSave': this.saveRoleParameters.bind(this)
  41. }
  42. });
  43. },
  44. _getAdvancedPropertyControlItem: function _getAdvancedPropertyControlItem() {
  45. return {
  46. 'type': 'CollapsibleSection',
  47. 'name': 'customizeRoleAdvanced',
  48. 'id': 'admin-role-customization-advanced',
  49. 'label': StringResource.get('advancedProperties'),
  50. 'onOpenChange': function (name, opening) {
  51. var advancedSection = this._propertyUIControl.getProperty(name);
  52. if (opening && advancedSection.isEmpty()) {
  53. return this._customizationService.getRoleRank(this.objectInfo.id).then(function (rank) {
  54. advancedSection.refreshProperties(this._getAdvancedPropertyItems(rank));
  55. }.bind(this));
  56. }
  57. }.bind(this)
  58. };
  59. },
  60. _getAdvancedPropertyItems: function _getAdvancedPropertyItems(currentRank) {
  61. var options = [];
  62. if (this.objectInfo.id === SYSTEM_ADMIN_ID) {
  63. options.push({
  64. 'label': currentRank,
  65. 'value': currentRank,
  66. 'selected': true
  67. });
  68. } else {
  69. for (var i = 0; i <= 10; ++i) {
  70. options.push({
  71. 'label': i === 0 ? i + ' ' + StringResource.get('defaultPriority') : i === 10 ? i + ' ' + StringResource.get('highPriority') : i,
  72. 'value': i,
  73. 'selected': i === currentRank
  74. });
  75. }
  76. }
  77. return [{
  78. 'module': 'bi/admin/common/ui/properties/Text',
  79. 'name': 'priorityTitle',
  80. 'text': StringResource.get('roleProfile'),
  81. 'additionalClass': 'admin-role-customization-profile-title'
  82. }, {
  83. 'module': 'bi/admin/common/ui/properties/Text',
  84. 'name': 'priorityMsg',
  85. 'text': StringResource.get('rolePriorityHelpMsg'),
  86. 'additionalClass': 'admin-role-customization-profile-message'
  87. }, {
  88. 'name': 'rank',
  89. 'id': 'admin-role-priority-ctrl',
  90. 'label': StringResource.get('priority'),
  91. 'value': currentRank,
  92. 'type': 'DropDown',
  93. 'options': options,
  94. 'readOnly': this.objectInfo.id === SYSTEM_ADMIN_ID,
  95. 'onChange': this.updateRolePriority.bind(this)
  96. }, {
  97. 'type': 'Separator',
  98. 'indent': 0
  99. }];
  100. },
  101. saveRoleParameters: function saveRoleParameters(parameter_values) {
  102. return this._customizationService.setParameterValues(this.objectInfo.id, parameter_values).then(function (result) {
  103. this.glassContext.appController.showToast(StringResource.get('parametersSet'), {
  104. type: 'success'
  105. });
  106. this._customizations = null;
  107. return this._getCustomizations();
  108. }.bind(this));
  109. },
  110. _refresh: function _refresh() {
  111. return this._customizationService.getRoleRank(this.objectInfo.id).then(function (roleRank) {
  112. var $rolePriorityControl = this.$el.find('#control_rank_admin-role-priority-ctrl');
  113. if ($rolePriorityControl.length) {
  114. $rolePriorityControl.val(roleRank);
  115. }
  116. }.bind(this));
  117. },
  118. updateRolePriority: function updateRolePriority(control, value) {
  119. this._customizationService.setRoleRank(parseInt(value));
  120. this._modified = true;
  121. }
  122. });
  123. return CustomizationTab;
  124. });