main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //Init des settings
  2. function init_setting_activedirectory(parameter){
  3. switch(parameter.section){
  4. case 'activedirectory':
  5. $(document).ready(function(){
  6. var form = $('#activedirectory-setting-form');
  7. //usersRoot
  8. var usersInput = $('input[data-root="users"]', form);
  9. if(usersInput.length>0){
  10. $.each(usersInput.val().split(';'), function(i, value){
  11. var usersClone = i==0 ? usersInput : usersInput.clone();
  12. usersClone.val(value);
  13. if(i!=0) usersInput.after(usersClone);
  14. });
  15. }
  16. //groupsRoot
  17. var groupsInput = $('input[data-root="groups"]', form);
  18. if(groupsInput.length>0){
  19. $.each(groupsInput.val().split(';'), function(i, value){
  20. var groupsClone = i==0 ? groupsInput : groupsInput.clone();
  21. groupsClone.val(value);
  22. if(i!=0) groupsInput.after(groupsClone);
  23. });
  24. }
  25. });
  26. activedirectory_group_search();
  27. break;
  28. }
  29. }
  30. /* ACTIVEDIRECTORY GROUP */
  31. //SEARCH
  32. function activedirectory_group_search(callback){
  33. $('#group-rank-firm').fill({
  34. action:'activedirectory_group_search',
  35. }, function(){
  36. if(callback!=null) callback();
  37. });
  38. }
  39. //SAVE
  40. function activedirectory_group_save(){
  41. var form = $('#ad-correspondance');
  42. var data = $.getForm(form);
  43. data.id = form.attr('data-id');
  44. $.action(data,function(r){
  45. $.message('success','Enregistré');
  46. activedirectory_group_search();
  47. $('input, select', form).val('');
  48. form.attr('data-id','');
  49. });
  50. }
  51. //EDIT
  52. function activedirectory_group_edit(element){
  53. var line = $(element).closest('tr');
  54. $.action({
  55. action:'activedirectory_group_edit',
  56. id:line.attr('data-id')
  57. },function(r){
  58. $.setForm('#ad-correspondance',r);
  59. $('#ad-correspondance').attr('data-id',r.id);
  60. });
  61. }
  62. //DELETE
  63. function activedirectory_group_delete(element){
  64. if(!confirm('Êtes-vous sûr de vouloir supprimer cette correspondance ?')) return;
  65. var line = $(element).closest('tr');
  66. $.action({
  67. action: 'activedirectory_group_delete',
  68. id: line.attr('data-id')
  69. },function(r){
  70. line.remove();
  71. $.message('info','Correspondance Groupe/Rang/Établissement supprimée');
  72. });
  73. }
  74. /* ACTIVEDIRECTORY SETTING */
  75. // ADD USER/GROUP ROOTS
  76. function activedirectory_activedirectory_add_roots(element){
  77. var btn = $(element);
  78. var input = btn.parent().next('td').find('input:eq(0)');
  79. var clone = input.clone();
  80. clone.val('');
  81. input.parent().append(clone);
  82. }
  83. //SAVE
  84. function activedirectory_setting_save(callback){
  85. //On est obligé de passer par là pour utiliser
  86. //le tableau de configuration auto-généré avec
  87. //les champs un peu customs
  88. var fields = $('#activedirectory-setting-form').toJson();
  89. fields['activedirectory_users_root'] = [];
  90. $.each($('input[data-root="users"]'), function(i, input){
  91. // if(!$(input).val().length) return;
  92. fields['activedirectory_users_root'].push($(input).val());
  93. });
  94. fields['activedirectory_groups_root'] = [];
  95. $.each($('input[data-root="groups"]'), function(i, input){
  96. // if(!$(input).val().length) return;
  97. fields['activedirectory_groups_root'].push($(input).val());
  98. });
  99. $.action({
  100. action: 'activedirectory_setting_save',
  101. fields: fields
  102. }, function(r){
  103. $.message('success', 'Enregistré');
  104. if(callback!=null) callback();
  105. });
  106. }
  107. //CHECK CONNECTION
  108. function activedirectory_connection_check(){
  109. activedirectory_setting_save(function(){
  110. $('.activedirectory-test-connection').load(document.URL + ' .activedirectory-test-connection>*', function(){
  111. $('.activedirectory-test-connection .card-icon > i').attr('class', 'fas fa-spinner fa-pulse ');
  112. $.action({
  113. action: 'activedirectory_connection_check'
  114. }, function(r){
  115. $.each(r.tests, function(id, result){
  116. var card = $('#'+id);
  117. card.addClass(result?'border-success':'border-danger');
  118. $('.card-icon > i', card).attr('class', (result?'text-success fas fa-check-circle':'text-danger fas fa-times-circle'));
  119. $('.label', card).addClass(result?'text-success':'text-danger');
  120. });
  121. });
  122. });
  123. });
  124. }