RegionalSettingsTab.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/common/ui/RegionalOptionsModule', 'bi/admin/multitenancy/services/TenantsCustomizationService'], function (_, ContentView, StringResource, PropertyUIControl, RegionalOptionsModule, TenantsCustomizationService) {
  9. 'use strict'; //NOSONAR: meant to be strict
  10. var RegionalSettingsTab = ContentView.extend({
  11. /**
  12. @paran options.el {node} - container dom node
  13. **/
  14. init: function init(options) {
  15. RegionalSettingsTab.inherited('init', this, arguments);
  16. _.extend(this, options);
  17. this.regionalOptions = new RegionalOptionsModule({
  18. $el: this.$el,
  19. glassContext: this.glassContext,
  20. objectInfo: this.objectInfo,
  21. slideout: this.slideout,
  22. parent: this
  23. });
  24. this.tenantsController = new TenantsCustomizationService({
  25. glassContext: this.glassContext
  26. });
  27. this.tenant = this.objectInfo;
  28. this._customizations = null;
  29. },
  30. render: function render() {
  31. //NOSONAR
  32. return Promise.resolve(this.tenantsController.getTenantPreferences(this.tenant.tenantID)).then(function (result) {
  33. this._customizations = result.data;
  34. return Promise.resolve(this.regionalOptions.getRegionalOptions(this._customizations)).then(function (customSettings) {
  35. var regionalSettings = customSettings;
  36. this._oPropertyUIControl = new PropertyUIControl({
  37. 'el': this.$el,
  38. 'glassContext': this.glassContext,
  39. 'slideout': this.slideout,
  40. 'items': regionalSettings
  41. });
  42. return this._oPropertyUIControl.render();
  43. }.bind(this));
  44. }.bind(this));
  45. },
  46. onClose: function onClose() {
  47. this._oPropertyUIControl.onClose().then(function (data) {
  48. var props = this._oPropertyUIControl.getModifiedProperties();
  49. if (!_.isEmpty(props)) {
  50. this.setRegionalSettings(props).then(function (response) {
  51. this.glassContext.appController.showToast(StringResource.get("tenantSavePreferencesToast", {
  52. 'tenantName': this.tenant.defaultName
  53. }));
  54. }.bind(this)).catch(function (response) {
  55. this.glassContext.appController.showErrorMessage(StringResource.get("tenantSavePreferencesErrorToast", {
  56. 'tenantName': this.tenant.defaultName
  57. }));
  58. }.bind(this));
  59. }
  60. }.bind(this));
  61. },
  62. setRegionalSettings: function setRegionalSettings(props) {
  63. if (!_.isEmpty(props)) {
  64. return this.tenantsController.setTenantPreferences(this.tenant.tenantID, props);
  65. } else {
  66. var promise = new Promise(function (resolve) {
  67. return true;
  68. });
  69. return promise;
  70. }
  71. }
  72. });
  73. return RegionalSettingsTab;
  74. });