25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

172 lines
7.6 KiB

  1. const SettingsAccess = {
  2. route : 'settings/access/:groupId',
  3. isDefault : true,
  4. templateUrl : 'js/app/views/settings/settings-access.html',
  5. navigatioData : null,
  6. redirectUrl : 'auth/login',
  7. canAccess : function()
  8. {
  9. return this.app.user.isLoggedIn();
  10. },
  11. create : function( p )
  12. {
  13. this.container = this.app.UI.getContentContainer();
  14. const $container = $( this.container ),
  15. app = this.app,
  16. admins = [],
  17. self = this,
  18. groupId = p.get( 'groupId' );
  19. this.render();
  20. app.rpc.call(
  21. 'Team',
  22. 'getDetails',
  23. {
  24. teamId : groupId,
  25. includeMembers: true
  26. },
  27. function( res )
  28. {
  29. if ( res && res.hasOwnProperty( 'data' ) && res.data.hasOwnProperty( 'members' ) )
  30. {
  31. let m;
  32. for ( let mi = 0; mi < res.data.members.length; mi++ )
  33. {
  34. m = self.createInstance( 'UserProfile', res.data.members[ mi ] );
  35. if ( m.isAdminOfGroup( groupId ) )
  36. {
  37. m.setContextGroupId( groupId );
  38. admins.push( m );
  39. }
  40. }
  41. let adt = self.createComponent(
  42. 'access-data-table',
  43. $container.find( '[data-id="container-access-data-table"]' ).first().get( 0 ),
  44. {
  45. members : admins
  46. }
  47. );
  48. $container.find( '[data-id="ibox-access-data-table"]' ).toggleClass( 'sk-loading' );
  49. adt.addEventListener( 'grantManagerAccess', function( e )
  50. {
  51. let memberId = e.data.memberId;
  52. let $modalRoot = $container.find( '[data-id="modal-confirm-grant-manager-access"]' ).first();
  53. $modalRoot.find( '[data-id="section-confirm-manager-access"]' ).first().show();
  54. $modalRoot.find( '[data-id="section-loader"]' ).first().hide();
  55. $modalRoot.on( 'shown.bs.modal', function()
  56. {
  57. $modalRoot.find( '[data-id="btnSubmitGrant"]' ).first().off( "click" );
  58. $modalRoot.find( '[data-id="btnSubmitGrant"]' ).first().click( function()
  59. {
  60. $(this).off( "click" );
  61. $modalRoot.find( '[data-id="section-confirm-manager-access"]' ).first().hide();
  62. $modalRoot.find( '[data-id="section-loader"]' ).first().show();
  63. app.rpc.call(
  64. 'Profile',
  65. 'grantManagerAccess',
  66. {
  67. profileId : memberId,
  68. teamId : groupId
  69. },
  70. function( resp )
  71. {
  72. if ( resp && resp.hasOwnProperty( 'code' ) && resp.code == 200 )
  73. {
  74. app.UI.toastSuccess( 'Aktion erfolgreich.' );
  75. app.reload();
  76. }
  77. else
  78. {
  79. app.UI.toastError();
  80. }
  81. $modalRoot.modal( 'hide' );
  82. }
  83. );
  84. });
  85. });
  86. $modalRoot.on( 'hidden.bs.modal', function()
  87. {
  88. $modalRoot.modal( 'dispose' );
  89. });
  90. $modalRoot.modal( 'show' );
  91. });
  92. adt.addEventListener( 'removeManagerAccess', function( e )
  93. {
  94. let memberId = e.data.memberId;
  95. let $modalRoot = $container.find( '[data-id="modal-confirm-remove-manager-access"]' ).first();
  96. $modalRoot.find( '[data-id="section-confirm-manager-access"]' ).first().show();
  97. $modalRoot.find( '[data-id="section-loader"]' ).first().hide();
  98. $modalRoot.on( 'shown.bs.modal', function()
  99. {
  100. $modalRoot.find( '[data-id="btnSubmitRemove"]' ).first().off( "click" );
  101. $modalRoot.find( '[data-id="btnSubmitRemove"]' ).first().click( function()
  102. {
  103. $(this).off( "click" );
  104. $modalRoot.find( '[data-id="section-confirm-manager-access"]' ).first().hide();
  105. $modalRoot.find( '[data-id="section-loader"]' ).first().show();
  106. app.rpc.call(
  107. 'Profile',
  108. 'removeManagerAccess',
  109. {
  110. profileId : memberId,
  111. teamId : groupId
  112. },
  113. function( resp )
  114. {
  115. if ( resp && resp.hasOwnProperty( 'code' ) && resp.code == 200 )
  116. {
  117. if ( app.user.userProfile.get( 'id' ) == memberId )
  118. {
  119. app.UI.toastWarning( 'Sie haben sich selbt den Zugriff entzogen und werden ausgeloggt.' );
  120. setTimeout( function()
  121. {
  122. app.user.logout();
  123. }, 1000 );
  124. }
  125. else
  126. {
  127. app.UI.toastSuccess( 'Aktion erfolgreich.' );
  128. app.reload();
  129. }
  130. }
  131. else
  132. {
  133. app.UI.toastError();
  134. }
  135. $modalRoot.modal( 'hide' );
  136. }
  137. );
  138. });
  139. });
  140. $modalRoot.on( 'hidden.bs.modal', function()
  141. {
  142. $modalRoot.modal( 'dispose' );
  143. });
  144. $modalRoot.modal( 'show' );
  145. });
  146. }
  147. }
  148. );
  149. },
  150. destroy : function()
  151. {
  152. }
  153. };
  154. export { SettingsAccess };