"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/nls/StringResource', 'bi/admin/common/ui/BaseCustomizationTab', 'bi/admin/account/services/RoleCustomizationService'], function (_, StringResource, BaseCustomizationTab, RoleCustomizationService) { 'use strict'; //NOSONAR var SYSTEM_ADMIN_ID = "xOjpTeXN0ZW0gQWRtaW5pc3RyYXRvcnM_"; var CustomizationTab = BaseCustomizationTab.extend({ init: function init(options) { CustomizationTab.inherited('init', this, arguments); _.extend(this, options); this._customizationService = this._getNewRoleCustomizationService({ 'glassContext': this.glassContext }); this._modified = false; }, _getNewRoleCustomizationService: function _getNewRoleCustomizationService(options) { return new RoleCustomizationService(options); }, onClose: function onClose() { CustomizationTab.inherited('remove', this, arguments); if (this._modified) { this._customizationService.saveRoleRank(this.objectInfo.id); } }, _showGlobalParametersPanel: function _showGlobalParametersPanel() { this._parametersSlideout = this.glassContext.appController.showSlideOut({ 'parent': this.slideout, 'width': '400px', 'label': StringResource.get('globalParameters'), 'content': { 'module': 'bi/admin/account/slideout/ParametersPane', 'parentView': this, 'glassContext': this.glassContext, 'parameter_values': this._getParameterValues(), 'onSave': this.saveRoleParameters.bind(this) } }); }, _getAdvancedPropertyControlItem: function _getAdvancedPropertyControlItem() { return { 'type': 'CollapsibleSection', 'name': 'customizeRoleAdvanced', 'id': 'admin-role-customization-advanced', 'label': StringResource.get('advancedProperties'), 'onOpenChange': function (name, opening) { var advancedSection = this._propertyUIControl.getProperty(name); if (opening && advancedSection.isEmpty()) { return this._customizationService.getRoleRank(this.objectInfo.id).then(function (rank) { advancedSection.refreshProperties(this._getAdvancedPropertyItems(rank)); }.bind(this)); } }.bind(this) }; }, _getAdvancedPropertyItems: function _getAdvancedPropertyItems(currentRank) { var options = []; if (this.objectInfo.id === SYSTEM_ADMIN_ID) { options.push({ 'label': currentRank, 'value': currentRank, 'selected': true }); } else { for (var i = 0; i <= 10; ++i) { options.push({ 'label': i === 0 ? i + ' ' + StringResource.get('defaultPriority') : i === 10 ? i + ' ' + StringResource.get('highPriority') : i, 'value': i, 'selected': i === currentRank }); } } return [{ 'module': 'bi/admin/common/ui/properties/Text', 'name': 'priorityTitle', 'text': StringResource.get('roleProfile'), 'additionalClass': 'admin-role-customization-profile-title' }, { 'module': 'bi/admin/common/ui/properties/Text', 'name': 'priorityMsg', 'text': StringResource.get('rolePriorityHelpMsg'), 'additionalClass': 'admin-role-customization-profile-message' }, { 'name': 'rank', 'id': 'admin-role-priority-ctrl', 'label': StringResource.get('priority'), 'value': currentRank, 'type': 'DropDown', 'options': options, 'readOnly': this.objectInfo.id === SYSTEM_ADMIN_ID, 'onChange': this.updateRolePriority.bind(this) }, { 'type': 'Separator', 'indent': 0 }]; }, saveRoleParameters: function saveRoleParameters(parameter_values) { return this._customizationService.setParameterValues(this.objectInfo.id, parameter_values).then(function (result) { this.glassContext.appController.showToast(StringResource.get('parametersSet'), { type: 'success' }); this._customizations = null; return this._getCustomizations(); }.bind(this)); }, _refresh: function _refresh() { return this._customizationService.getRoleRank(this.objectInfo.id).then(function (roleRank) { var $rolePriorityControl = this.$el.find('#control_rank_admin-role-priority-ctrl'); if ($rolePriorityControl.length) { $rolePriorityControl.val(roleRank); } }.bind(this)); }, updateRolePriority: function updateRolePriority(control, value) { this._customizationService.setRoleRank(parseInt(value)); this._modified = true; } }); return CustomizationTab; });