TenantsDetailPane.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017
  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/admin/common/slideout/BasePane', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/multitenancy/services/TenantsCustomizationService', 'bi/admin/common/utils/AJAXUtils'], function (StringResource, BasePane, PropertyUIControl, TenantsCustomizationService, AJAXUtils) {
  10. var TenantsDetailPane = BasePane.extend({
  11. init: function init(options) {
  12. TenantsDetailPane.inherited('init', this, arguments);
  13. $.extend(this, options);
  14. this.tenantsController = this._getNewTenantsCustomizationService({
  15. glassContext: this.glassContext
  16. });
  17. if (this.tenant) {
  18. this.title = this.tenant.defaultName;
  19. } else {
  20. this.title = StringResource.get('addTenantTitle');
  21. }
  22. },
  23. _getNewTenantsCustomizationService: function _getNewTenantsCustomizationService(options) {
  24. return new TenantsCustomizationService(options);
  25. },
  26. renderBody: function renderBody($body) {
  27. this.$el.addClass("adm-tenant-addtenant");
  28. var tenantItems = [{
  29. 'id': 'tenantName',
  30. 'name': 'tenantName',
  31. 'label': StringResource.get('tenantName'),
  32. 'value': this.tenant && this.tenant.defaultName ? this.tenant.defaultName : "",
  33. 'editable': true,
  34. 'type': 'SingleLineValue',
  35. 'staticValidationCallback': {},
  36. 'validationAriaLabel': StringResource.get('tenantNameRequired'),
  37. 'isString': true
  38. }, {
  39. 'id': 'tenantId',
  40. 'name': 'tenantId',
  41. 'label': StringResource.get('tenantId'),
  42. 'value': this.tenant && this.tenant.tenantID ? this.tenant.tenantID.toString() : "",
  43. 'editable': !(this.tenant && this.tenant.tenantID),
  44. 'type': 'SingleLineValue',
  45. 'staticValidationCallback': {},
  46. 'validationAriaLabel': StringResource.get('tenantIdRequired'),
  47. 'isString': true
  48. }, {
  49. 'id': 'tenantDescription',
  50. 'name': 'tenantDescription',
  51. 'label': StringResource.get('tenantDescription'),
  52. 'value': this.tenant && this.tenant.defaultDescription ? this.tenant.defaultDescription : "",
  53. 'editable': true,
  54. 'multiline': true,
  55. 'type': 'TextArea'
  56. }, {
  57. 'type': 'Footer',
  58. 'items': this._getFooterItems()
  59. }];
  60. this.addTenantPropControl = this._getNewPropertyUIControl({
  61. 'glassContext': this.glassContext,
  62. 'el': $body,
  63. 'staticValidationMode': true,
  64. 'items': tenantItems
  65. });
  66. return this.addTenantPropControl.render().then(function () {
  67. $("div.property_tenantName div.validationIcon").attr('title', StringResource.get('tenantNameRequired'));
  68. $("div.property_tenantId div.validationIcon").attr('title', StringResource.get('tenantIdRequired'));
  69. return this.addTenantPropControl;
  70. }.bind(this));
  71. },
  72. _getNewPropertyUIControl: function _getNewPropertyUIControl(options) {
  73. return new PropertyUIControl(options);
  74. },
  75. setFocus: function setFocus() {
  76. this.$el.find('#control_tenantName_tenantName').focus();
  77. },
  78. _getFooterItems: function _getFooterItems() {
  79. return [{
  80. 'label': this.tenant ? StringResource.get('update') : StringResource.get('add'),
  81. 'onSelect': this.tenant ? this.updateTenant.bind(this) : this.addTenant.bind(this),
  82. 'primary': true,
  83. 'type': 'Button'
  84. }, {
  85. 'label': StringResource.get('close'),
  86. 'onSelect': this.closeSlideout.bind(this),
  87. 'primary': false,
  88. 'type': 'Button'
  89. }];
  90. },
  91. addTenant: function addTenant() {
  92. try {
  93. var tenantName = this.addTenantPropControl.getProperty('tenantName').getModifiedProperties().tenantName.toString();
  94. var tenantID = this.addTenantPropControl.getProperty('tenantId').getModifiedProperties().tenantId.toString();
  95. } catch (error) {
  96. if (error.name === "TypeError") {
  97. this.glassContext.appController.showErrorMessage(StringResource.get("enterRequiredFields"));
  98. return;
  99. }
  100. }
  101. return this.tenantsController.addTenant({
  102. 'defaultName': tenantName,
  103. 'tenantID': tenantID,
  104. 'defaultDescription': this.addTenantPropControl.getProperty('tenantDescription').getModifiedProperties().tenantDescription,
  105. 'disabled': true
  106. }).then(function (data) {
  107. this.glassContext.appController.showToast(StringResource.get("multitenancySuccessAdd", {
  108. 'tenantName': tenantName
  109. }));
  110. this.slideout.hide();
  111. if (this.onUpdate) {
  112. this.onUpdate(data);
  113. }
  114. this.slideout.$el.trigger('com.ibm.cognos.bi.admin.updatetenantlist');
  115. }.bind(this), function (ajaxOptions, error) {
  116. this.glassContext.appController.showErrorMessage(StringResource.get("multitenacyFailedAdd", {
  117. 'tenantName': tenantName
  118. }) + ", " + AJAXUtils.buildErrorMessage(error.responseJSON.errors));
  119. }.bind(this));
  120. },
  121. updateTenant: function updateTenant() {
  122. var tenantName = this.addTenantPropControl.getProperty('tenantName').getModifiedProperties().tenantName;
  123. tenantName = tenantName ? tenantName.toString() : this.tenant.defaultName;
  124. var tenantDescription = this.addTenantPropControl.getProperty('tenantDescription').getModifiedProperties().tenantDescription;
  125. return this.tenantsController.updateTenant(this.tenant.tenantID, {
  126. 'defaultName': tenantName,
  127. 'defaultDescription': tenantDescription ? tenantDescription : this.tenant.defaultDescription
  128. }).then(function (data) {
  129. this.glassContext.appController.showToast(StringResource.get("multitenancySuccessUpdate", {
  130. 'tenantName': tenantName
  131. }));
  132. this.slideout.hide();
  133. this.slideout.$el.trigger('com.ibm.cognos.bi.admin.updatetenantlist');
  134. }.bind(this), function (ajaxOptions, error) {
  135. this.glassContext.appController.showErrorMessage(StringResource.get("multitenacyFailedUpdate", {
  136. 'tenantName': tenantName
  137. }) + ", " + AJAXUtils.buildErrorMessage(error.responseJSON.errors));
  138. }.bind(this));
  139. },
  140. closeSlideout: function closeSlideout() {
  141. this.slideout.hide();
  142. }
  143. });
  144. return TenantsDetailPane;
  145. });