give_auth.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. }).then(() => {
  16. history.go(0);
  17. }).catch(err => {
  18. console.error(err);
  19. });;
  20. } else {
  21. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  22. let user_name_data = document.getElementById('opennamu_give_auth_user_name').value;
  23. user_name_data = user_name_data.replace('\r', '');
  24. let user_name_arr = user_name_data.split("\n");
  25. for(let for_a = 0; for_a < user_name_arr.length; for_a++) {
  26. let send_data = new FormData();
  27. send_data.append('user_name', user_name_arr[for_a]);
  28. send_data.append('change_auth', change_auth);
  29. fetch('/api/v2/auth/give', {
  30. method : 'PATCH',
  31. body : send_data,
  32. }).then(() => {
  33. history.go(0);
  34. }).catch(err => {
  35. console.error(err);
  36. });;
  37. }
  38. }
  39. } else {
  40. let user_name = url_split[3];
  41. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  42. let send_data = new FormData();
  43. send_data.append('user_name', user_name);
  44. send_data.append('change_auth', change_auth);
  45. fetch('/api/v2/auth/give', {
  46. method : 'PATCH',
  47. body : send_data,
  48. }).then(() => {
  49. history.go(0);
  50. }).catch(err => {
  51. console.error(err);
  52. });
  53. }
  54. }
  55. function opennamu_give_auth() {
  56. const url = window.location.pathname;
  57. const url_split = url.split('/');
  58. let mode = 0;
  59. if(url_split.length === 3) {
  60. if(url_split[2] === 'give_total') {
  61. mode = 1;
  62. }
  63. }
  64. let html_data = '';
  65. let user_name = '';
  66. let lang_data = new FormData();
  67. lang_data.append('data', ["data", "many_delete_help", "send", ].join(' '));
  68. fetch('/api/v2/lang', {
  69. method : 'POST',
  70. body : lang_data,
  71. }).then(function(res) {
  72. return res.json();
  73. }).then(function(lang) {
  74. lang = lang["data"];
  75. fetch('/api/v2/list/auth').then(function(res) {
  76. return res.json();
  77. }).then(function(data) {
  78. let data_list = data["data"];
  79. if(mode === 0) {
  80. if(url_split.length === 3) {
  81. html_data += '<textarea id="opennamu_give_auth_user_name" class="opennamu_textarea_100" placeholder="' + lang["many_delete_help"] + '"></textarea>';
  82. html_data += '<hr class="main_hr">';
  83. } else {
  84. user_name = url_split[3];
  85. html_data += '<div id="opennamu_get_user_info">' + opennamu_xss_filter(user_name) + '</div>';
  86. html_data += '<hr class="main_hr">';
  87. }
  88. } else {
  89. html_data += '<select id="opennamu_give_auth_select_org">';
  90. for(let for_a = 0; for_a < data_list.length; for_a++) {
  91. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  92. }
  93. html_data += '</select>';
  94. html_data += '<hr class="main_hr">';
  95. }
  96. html_data += '<select id="opennamu_give_auth_select">';
  97. for(let for_a = 0; for_a < data_list.length; for_a++) {
  98. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  99. }
  100. html_data += '</select>';
  101. html_data += '<hr class="main_hr">';
  102. html_data += '<button onclick="opennamu_give_auth_submit();">' + lang["send"] + '</button>';
  103. document.getElementById('opennamu_give_auth').innerHTML = html_data;
  104. if(user_name !== '') {
  105. fetch('/api/v2/auth/' + opennamu_do_url_encode(user_name)).then(function(res) {
  106. return res.json();
  107. }).then(function(data) {
  108. document.getElementById('opennamu_give_auth_select').value = data["name"];
  109. });
  110. }
  111. do_insert_user_info();
  112. });
  113. });
  114. }