wizardTabExpert.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. OCA = OCA || {};
  7. (function() {
  8. /**
  9. * @classdesc This class represents the view belonging to the expert tab
  10. * in the LDAP wizard.
  11. */
  12. var WizardTabExpert = OCA.LDAP.Wizard.WizardTabGeneric.subClass({
  13. /**
  14. * initializes the instance. Always call it after initialization.
  15. *
  16. * @param {any} tabIndex -
  17. * @param {any} tabID -
  18. */
  19. init: function (tabIndex, tabID) {
  20. this._super(tabIndex, tabID);
  21. var items = {
  22. ldap_expert_username_attr: {
  23. $element: $('#ldap_expert_username_attr'),
  24. setMethod: 'setUsernameAttribute'
  25. },
  26. ldap_expert_uuid_user_attr: {
  27. $element: $('#ldap_expert_uuid_user_attr'),
  28. setMethod: 'setUserUUIDAttribute'
  29. },
  30. ldap_expert_uuid_group_attr: {
  31. $element: $('#ldap_expert_uuid_group_attr'),
  32. setMethod: 'setGroupUUIDAttribute'
  33. },
  34. //Buttons
  35. ldap_action_clear_user_mappings: {
  36. $element: $('#ldap_action_clear_user_mappings')
  37. },
  38. ldap_action_clear_group_mappings: {
  39. $element: $('#ldap_action_clear_group_mappings')
  40. }
  41. };
  42. this.setManagedItems(items);
  43. _.bindAll(this, 'onClearUserMappingsClick', 'onClearGroupMappingsClick');
  44. this.managedItems.ldap_action_clear_user_mappings.$element.click(this.onClearUserMappingsClick);
  45. this.managedItems.ldap_action_clear_group_mappings.$element.click(this.onClearGroupMappingsClick);
  46. },
  47. /**
  48. * Sets the config model for this view and subscribes to some events.
  49. * Also binds the config chooser to the model
  50. *
  51. * @param {OCA.LDAP.Wizard.ConfigModel} configModel
  52. */
  53. setModel: function(configModel) {
  54. this._super(configModel);
  55. this.configModel.on('configLoaded', this.onConfigLoaded, this);
  56. this.configModel.on('receivedLdapFeature', this.onResultReceived, this);
  57. },
  58. /**
  59. * sets the attribute to be used to create an Nextcloud ID (username)
  60. *
  61. * @param {string} attribute
  62. */
  63. setUsernameAttribute: function(attribute) {
  64. this.setElementValue(this.managedItems.ldap_expert_username_attr.$element, attribute);
  65. },
  66. /**
  67. * sets the attribute that provides an unique identifier per LDAP user
  68. * entry
  69. *
  70. * @param {string} attribute
  71. */
  72. setUserUUIDAttribute: function(attribute) {
  73. this.setElementValue(this.managedItems.ldap_expert_uuid_user_attr.$element, attribute);
  74. },
  75. /**
  76. * sets the attribute that provides an unique identifier per LDAP group
  77. * entry
  78. *
  79. * @param {string} attribute
  80. */
  81. setGroupUUIDAttribute: function(attribute) {
  82. this.setElementValue(this.managedItems.ldap_expert_uuid_group_attr.$element, attribute);
  83. },
  84. /**
  85. * requests clearing of all user mappings
  86. */
  87. onClearUserMappingsClick: function() {
  88. this.configModel.requestWizard('ldap_action_clear_user_mappings', {ldap_clear_mapping: 'user'});
  89. },
  90. /**
  91. * requests clearing of all group mappings
  92. */
  93. onClearGroupMappingsClick: function() {
  94. this.configModel.requestWizard('ldap_action_clear_group_mappings', {ldap_clear_mapping: 'group'});
  95. },
  96. /**
  97. * deals with the result of the Test Connection test
  98. *
  99. * @param {WizardTabAdvanced} view
  100. * @param {FeaturePayload} payload
  101. */
  102. onResultReceived: function(view, payload) {
  103. if(payload.feature === 'ClearMappings') {
  104. var message;
  105. if(payload.data.status === 'success') {
  106. message = t('user_ldap', 'Mappings cleared successfully!');
  107. } else {
  108. message = t('user_ldap', 'Error while clearing the mappings.');
  109. }
  110. OC.Notification.showTemporary(message);
  111. }
  112. }
  113. });
  114. OCA.LDAP.Wizard.WizardTabExpert = WizardTabExpert;
  115. })();