PluginsPane.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2016, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'q', 'jquery', 'bi/admin/common/slideout/BasePane', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/common/utils/CapabilityHelper', 'bi/admin/multitenancy/services/TenantsCustomizationService', 'bi/admin/common/utils/parameters/GlobalParameters', 'bi/admin/system/slideout/PluginsDefinition'], function (_, Q, $, BasePane, PropertyUIControl, CapabilityHelper, TenantsCustomizationService, GlobalParameters, PluginsDefinition) {
  10. var PluginsPane = BasePane.extend({
  11. init: function init(options) {
  12. PluginsPane.inherited('init', this, arguments);
  13. $.extend(this, options);
  14. this.glassContext = options.glassContext;
  15. CapabilityHelper.glassContext = this.glassContext;
  16. this.isPortalAdmin = false;
  17. this.canUseUsersGroupsAndRoles = false;
  18. this.canManageVisualizations = false;
  19. this.tenantID = null;
  20. this.listController = new TenantsCustomizationService({
  21. glassContext: this.glassContext
  22. });
  23. this.globalParametersController = new GlobalParameters({
  24. 'glassContext': this.glassContext
  25. });
  26. },
  27. _getNewPropertyUIControl: function _getNewPropertyUIControl(spec) {
  28. return new PropertyUIControl(spec);
  29. },
  30. renderBody: function renderBody() {
  31. return this.listController.getTenantIDForUser(this.glassContext.profile.account.id).then(function (data) {
  32. this.tenantID = data.data[0].tenantID;
  33. this.isSysAdmin().then(function (isSysAdmin) {
  34. // get all the plugin definition - with full info
  35. var tabControlItems = PluginsDefinition.getPlugins(isSysAdmin, this.tenantID, this.glassContext, {
  36. // definition used in all tabs
  37. slideout: this.slideout,
  38. // callbacks for theme tab
  39. getDefaultTheme: this.getDefaultTheme.bind(this),
  40. setDefaultTheme: this.setDefaultTheme.bind(this),
  41. // callbacks for parameters tab
  42. getParameters: function (isSystemAdmin, isPortalAdmin, tenantID) {
  43. return this.globalParametersController.getParameters(isSystemAdmin, isPortalAdmin, tenantID);
  44. }.bind(this),
  45. updateParameters: function (parameters, isSystemAdmin, isPortalAdmin, tenantID) {
  46. return this.globalParametersController.updateParameters(parameters, isSystemAdmin, isPortalAdmin, tenantID);
  47. }.bind(this),
  48. listController: this.listController
  49. });
  50. this.$body.addClass('bi-admin-plugins-pane');
  51. this._oPropertyUIControl = this._getNewPropertyUIControl({
  52. 'glassContext': this.glassContext,
  53. 'el': this.$body,
  54. 'items': [{
  55. 'type': 'TabControl',
  56. 'items': tabControlItems
  57. }]
  58. });
  59. return this._oPropertyUIControl.render();
  60. }.bind(this));
  61. }.bind(this));
  62. },
  63. setDefaultTheme: function setDefaultTheme(defaultTheme) {
  64. var ui_theme = {
  65. 'ui_theme': defaultTheme
  66. };
  67. var options = {
  68. 'contentType': 'application/json',
  69. 'url': 'v1/system_profile_settings',
  70. 'type': 'PUT',
  71. 'data': JSON.stringify(ui_theme)
  72. };
  73. return this.glassContext.services.ajax.ajax(options);
  74. },
  75. remove: function remove() {
  76. this._oPropertyUIControl.remove();
  77. },
  78. getDefaultTheme: function getDefaultTheme() {
  79. return this.glassContext.services.ajax.ajax({
  80. 'type': 'GET',
  81. 'url': 'v1/system_profile_settings'
  82. }).then(function (response) {
  83. return response.ui_theme;
  84. });
  85. }
  86. });
  87. return PluginsPane;
  88. });