AccountPickerSlideoutView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * Licensed Materials - Property of IBM
  3. * IBM Cognos Products: Cognos Analytics
  4. * Copyright IBM Corp. 2018, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure
  6. * restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define([
  9. 'react',
  10. 'react-dom',
  11. 'ba-react-admin/ba-react-admin.min',
  12. 'underscore',
  13. 'bi/glass/app/ContentView',
  14. 'bi/admin/nls/StringResource'
  15. ], function (React, ReactDOM, AdminReact, _, ContentView, StringResource) {
  16. 'use strict'; //NOSONAR: meant to be strict
  17. var ADD_MEMBER_FIELDS = ['defaultName', 'disabled', 'hidden', 'permissions', 'searchPath', 'type'];
  18. var ADD_MEMBER_TYPES = ['distributionList', 'contact', 'namespaceFolder', 'account', 'role', 'group', 'namespace'];
  19. var AccountPickerSlideoutView = ContentView.extend({
  20. init: function (options) {
  21. AccountPickerSlideoutView.inherited('init', this, arguments);
  22. _.extend(this, options);
  23. this.ajaxService = this.glassContext.getCoreSvc('.Ajax');
  24. this.logger = this.glassContext.getCoreSvc('.Logger');
  25. },
  26. _isActiveItem: function (obj) {
  27. return obj.type === 'namespaceFolder' || (obj.type === 'namespace' && _.contains(obj.permissions, 'traverse')) ||
  28. ((obj.type === 'role' || obj.type === 'group') && obj.hasChildren);
  29. },
  30. _getMembers: function (storeID) {
  31. return AdminReact.AdminSvc.getNamespaceObjItems(this.ajaxService, storeID, {
  32. types: ADD_MEMBER_TYPES,
  33. fields: ADD_MEMBER_FIELDS
  34. });
  35. },
  36. _doSearch: function (storeId, searchTerm) {
  37. return AdminReact.AdminSvc.getSearchNamespace(this.ajaxService, storeId, {
  38. types: ADD_MEMBER_TYPES,
  39. method: 'contains',
  40. filter: searchTerm,
  41. limit: 100,
  42. offset: 0,
  43. fields: ADD_MEMBER_FIELDS
  44. });
  45. },
  46. remove: function () {
  47. AccountPickerSlideoutView.inherited('remove', this, arguments);
  48. ReactDOM.unmountComponentAtNode(this.$el[0]);
  49. },
  50. openFilterlideout: function (aStore) {
  51. var menuContentCheckbox = [{
  52. label: StringResource.get('contact'),
  53. value: 'contact'
  54. }, {
  55. label: StringResource.get('distributionList'),
  56. value: 'distributionList'
  57. }, {
  58. label: StringResource.get('account'),
  59. value: 'account'
  60. }, {
  61. label: StringResource.get('role'),
  62. value: 'role'
  63. }, {
  64. label: StringResource.get('group'),
  65. value: 'group'
  66. }];
  67. this.glassContext.appController.showSlideOut({
  68. parent: this.slideout,
  69. content: {
  70. module: 'bi/admin/common/slideout/FilterSlideout',
  71. id: 'FilterAddToContent',
  72. glassContext: this.glassContext,
  73. StringResource: StringResource,
  74. controllerStore: aStore,
  75. menuContentCheckbox: menuContentCheckbox
  76. }
  77. });
  78. },
  79. openSortSlideout: function (aStore) {
  80. var sortCols = [{
  81. value: 'defaultName',
  82. label: StringResource.get('name')
  83. }, {
  84. value: 'modificationTime',
  85. label: StringResource.get('modified')
  86. }, {
  87. value: 'objectClass',
  88. label: StringResource.get('type')
  89. }];
  90. this.glassContext.appController.showSlideOut({
  91. parent: this.slideout,
  92. content: {
  93. module: 'bi/admin/common/slideout/SortSlideout',
  94. id: 'SortAddToContent',
  95. glassContext: this.glassContext,
  96. StringResource: StringResource,
  97. controllerStore: aStore,
  98. sortContent: sortCols
  99. }
  100. });
  101. },
  102. render: function () {
  103. var dPagingEnabled = AdminReact.AdminSvc.getConfiguration_EnableNamespaceChildrenPaging(this.ajaxService);
  104. var dItemsPerPage = AdminReact.AdminSvc.getConfiguration_NamespaceChildrenPerPage(this.ajaxService);
  105. return Promise.all([dPagingEnabled, dItemsPerPage]).catch(function (e) {
  106. this.logger.error(e);
  107. return [false, 0];
  108. }.bind(this)).then(function (aResp) {
  109. var addMemberToPanel = React.createElement(AdminReact.AddMembersToPanel, {
  110. closePanel: function () {
  111. this.slideout.hide();
  112. }.bind(this),
  113. addMembersTo: this.addCallback.bind(this),
  114. isActive: this._isActiveItem.bind(this),
  115. selectableTypes: ['distributionList', 'contact', 'account', 'role', 'group'],
  116. glassContext: this.glassContext,
  117. StringResource: StringResource,
  118. dialog: this,
  119. hideSearchAtRoot: true,
  120. wrapper: this,
  121. parent: this,
  122. store: AdminReact.DistListSelectableMembers.create({
  123. itemsPerPage: aResp[0] === 'true' ? parseInt(aResp[1]) : 0,
  124. ancestors: [{
  125. id: '',
  126. type: 'directory',
  127. defaultName: StringResource.get('directory')
  128. }]
  129. })
  130. });
  131. ReactDOM.render(addMemberToPanel, this.$el[0]);
  132. }.bind(this));
  133. }
  134. });
  135. return AccountPickerSlideoutView;
  136. });