AddOpenIdPane.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use strict";
  2. /**
  3.  * Licensed Materials - Property of IBM
  4.  * IBM Cognos Products: Cognos Analytics
  5.  * Copyright IBM Corp. 2017,2018
  6.  * US Government Users Restricted Rights -
  7. * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8.  */
  9. define(['underscore', 'bi/admin/common/slideout/BasePane', 'bi/admin/nls/StringResource', 'bi/admin/common/utils/AJAXUtils', 'bi/commons/ui/properties/PropertyUIControl', 'ba-react-admin/ba-react-admin.min'], function (_, BasePane, StringResource, AJAXUtils, PropertyUIControl, AdminReact) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var AddOpenIdPane = BasePane.extend({
  12. /**
  13. * @constructor
  14. * @param options.$el - JQuery node to append the table HTML
  15. * @param options.items {object} - An array of tab metadata. Must provide name,
  16. * module, and objectInfo (containing all the basic properties of the object)
  17. */
  18. init: function init(options) {
  19. AddOpenIdPane.inherited('init', this, arguments);
  20. _.extend(this, options);
  21. this.title = StringResource.get('addUsers');
  22. },
  23. _getNewPropertyUIControl: function _getNewPropertyUIControl(options) {
  24. return new PropertyUIControl(options);
  25. },
  26. renderBody: function renderBody($body) {
  27. this._propertyUIControl = this._getNewPropertyUIControl({
  28. 'el': this.$el.find(".bi-admin-pane-body"),
  29. 'glassContext': this.glassContext,
  30. 'items': [{
  31. 'id': 'admin-user-email',
  32. 'name': 'userEmail',
  33. 'label': StringResource.get('camIdentity'),
  34. 'type': 'TextArea',
  35. 'multiline': false,
  36. 'editable': true,
  37. 'value': ""
  38. }, {
  39. 'id': 'admin-user-preferred-name',
  40. 'name': 'userPreferredName',
  41. 'label': StringResource.get('preferredName'),
  42. 'type': 'TextArea',
  43. 'multiline': false,
  44. 'editable': true,
  45. 'value': ""
  46. }, {
  47. 'name': 'footer',
  48. 'type': 'Footer',
  49. 'items': [{
  50. 'name': 'Add',
  51. 'type': 'Button',
  52. 'label': StringResource.get('add'),
  53. 'onSelect': this._addUser.bind(this),
  54. 'primary': true
  55. }, {
  56. 'name': 'cancel',
  57. 'type': 'Button',
  58. 'label': StringResource.get('cancel'),
  59. 'onSelect': this.close.bind(this)
  60. }]
  61. }]
  62. });
  63. return this._propertyUIControl.render();
  64. },
  65. _addUser: function _addUser() {
  66. var mp = this._propertyUIControl.getModifiedProperties();
  67. var userEmail = mp.userEmail;
  68. var userPreferredName = mp.userPreferredName;
  69. if (!this._validate(userEmail)) {
  70. return;
  71. }
  72. var payload = {
  73. 'camIdentity': userEmail,
  74. 'defaultName': userPreferredName
  75. };
  76. var options = {
  77. method: 'POST',
  78. contentType: 'application/json; charset=utf-8',
  79. data: JSON.stringify(payload),
  80. url: 'v1/users?pid=' + this.pid
  81. };
  82. this.glassContext.getCoreSvc('.Ajax').ajax(options).then(function (resp, a1, a2) {
  83. var sText = StringResource.get('userToastCreateMsg', {
  84. 'name': userEmail
  85. });
  86. this.glassContext.appController.showToast(sText, {
  87. type: 'success'
  88. });
  89. this._refreshAccountListPane();
  90. this._clearInputFields();
  91. }.bind(this), function (e) {
  92. this.glassContext.appController.showErrorMessage(e.jqXHR.responseJSON.messages.join('\n'), StringResource.get('error'));
  93. }.bind(this));
  94. },
  95. _validate: function _validate(userEmail) {
  96. if (!userEmail || userEmail.length === 0) {
  97. this.glassContext.appController.showErrorMessage(StringResource.get('uniqueIdentifierRequiredErrorMsg'), StringResource.get('error'));
  98. return false;
  99. }
  100. return true;
  101. },
  102. _refreshAccountListPane: function _refreshAccountListPane() {
  103. if (this.parentView.pagingEnabled) {
  104. AdminReact.PaginationHelper.reloadListViewinPagingContext(this.parentView.glassContext, this.parentView._accountExplorer, this.parentView.listView, this.parentView.listAdaptor, true);
  105. } else {
  106. this.parentView.listAdaptor.sortChanged = true;
  107. this.parentView.listView.reload(false);
  108. }
  109. ;
  110. this.close();
  111. },
  112. _clearInputFields: function _clearInputFields() {
  113. this._propertyUIControl.$el.find('#control_userEmail_admin-user-email').val('');
  114. this._propertyUIControl.$el.find('#control_userPreferredName_admin-user-preferred-name').val('');
  115. }
  116. });
  117. return AddOpenIdPane;
  118. });