give_auth.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. "use strict";
  2. function opennamu_give_auth_submit() {
  3. const url = window.location.pathname;
  4. const url_split = url.split('/');
  5. if(url_split.length === 3) {
  6. if(url_split[2] === 'give_total') {
  7. let auth = document.getElementById('opennamu_give_auth_select_org').value;
  8. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  9. let send_data = new FormData();
  10. send_data.append('auth', auth);
  11. send_data.append('change_auth', change_auth);
  12. fetch('/api/v2/auth/give', {
  13. method : 'PATCH',
  14. body : send_data,
  15. });
  16. } else {
  17. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  18. let user_name_data = document.getElementById('opennamu_give_auth_user_name').value;
  19. user_name_data = user_name_data.replace('\r', '');
  20. let user_name_arr = user_name_data.split("\n");
  21. for(let for_a = 0; for_a < user_name_arr.length; for_a++) {
  22. let send_data = new FormData();
  23. send_data.append('user_name', user_name_arr[for_a]);
  24. send_data.append('change_auth', change_auth);
  25. fetch('/api/v2/auth/give', {
  26. method : 'PATCH',
  27. body : send_data,
  28. });
  29. }
  30. }
  31. } else {
  32. let user_name = url_split[3];
  33. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  34. let send_data = new FormData();
  35. send_data.append('user_name', user_name);
  36. send_data.append('change_auth', change_auth);
  37. fetch('/api/v2/auth/give', {
  38. method : 'PATCH',
  39. body : send_data,
  40. });
  41. }
  42. history.go(0);
  43. }
  44. function opennamu_give_auth() {
  45. const url = window.location.pathname;
  46. const url_split = url.split('/');
  47. let mode = 0;
  48. if(url_split.length === 3) {
  49. if(url_split[2] === 'give_total') {
  50. mode = 1;
  51. }
  52. }
  53. let html_data = '';
  54. let user_name = '';
  55. fetch('/api/v2/list/auth').then(function(res) {
  56. return res.json();
  57. }).then(function(data) {
  58. let lang = data["language"];
  59. let data_list = data["data"];
  60. if(mode === 0) {
  61. if(url_split.length === 3) {
  62. html_data += '<textarea id="opennamu_give_auth_user_name" class="opennamu_textarea_100" placeholder="' + lang["many_delete_help"] + '"></textarea>';
  63. html_data += '<hr class="main_hr">';
  64. } else {
  65. user_name = url_split[3];
  66. html_data += '<div id="opennamu_get_user_info">' + opennamu_xss_filter(user_name) + '</div>';
  67. html_data += '<hr class="main_hr">';
  68. }
  69. } else {
  70. html_data += '<select id="opennamu_give_auth_select_org">';
  71. for(let for_a = 0; for_a < data_list.length; for_a++) {
  72. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  73. }
  74. html_data += '</select>';
  75. html_data += '<hr class="main_hr">';
  76. }
  77. html_data += '<select id="opennamu_give_auth_select">';
  78. for(let for_a = 0; for_a < data_list.length; for_a++) {
  79. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  80. }
  81. html_data += '</select>';
  82. html_data += '<hr class="main_hr">';
  83. html_data += '<button onclick="opennamu_give_auth_submit();">' + lang["send"] + '</button>';
  84. document.getElementById('opennamu_give_auth').innerHTML = html_data;
  85. if(user_name !== '') {
  86. fetch('/api/v2/auth/' + opennamu_do_url_encode(user_name)).then(function(res) {
  87. return res.json();
  88. }).then(function(data) {
  89. document.getElementById('opennamu_give_auth_select').value = data["name"];
  90. });
  91. }
  92. do_insert_user_info();
  93. });
  94. }