bbs_w_set.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. function opennamu_bbs_w_set_post() {
  3. let acl_set_list = [
  4. "bbs_view_acl",
  5. "bbs_acl",
  6. "bbs_edit_acl",
  7. "bbs_comment_acl",
  8. "bbs_markup"
  9. ];
  10. for(let for_a = 0; for_a < acl_set_list.length; for_a++) {
  11. let post_data = new FormData();
  12. post_data.append('data', document.getElementById('opennamu_' + acl_set_list[for_a]).value);
  13. fetch('/api/v2/setting/' + acl_set_list[for_a], {
  14. method : 'PUT',
  15. body : post_data,
  16. }).then(function(res) {
  17. return res.json();
  18. }).then(function(data) {
  19. history.go(0);
  20. });
  21. }
  22. }
  23. function opennamu_bbs_w_set_lang(lang, set_name) {
  24. if(set_name === "bbs_markup") {
  25. return lang["markup"];
  26. } else {
  27. return lang[set_name];
  28. }
  29. }
  30. function opennamu_bbs_w_set_select(acl_set_list, acl_set_list_h, acl_list, lang) {
  31. let acl_set_html = '';
  32. for(let for_b = 0; for_b < acl_set_list.length; for_b++) {
  33. acl_set_html += '<h' + acl_set_list_h[for_b] + '>' + opennamu_bbs_w_set_lang(lang, acl_set_list[for_b]) + '</h' + acl_set_list_h[for_b] + '>';
  34. acl_set_html += '<select id="opennamu_' + acl_set_list[for_b] + '">';
  35. let select = '';
  36. for(let for_a = 0; for_a < acl_list.length; for_a++) {
  37. let acl_list_view = acl_list[for_a];
  38. acl_list_view = acl_list_view === "" ? "normal" : acl_list_view;
  39. select += '<option value="' + acl_list[for_a] + '">' + acl_list_view + '</option>';
  40. }
  41. acl_set_html += select;
  42. acl_set_html += '</select>';
  43. }
  44. return acl_set_html;
  45. }
  46. function opennamu_bbs_w_set() {
  47. const url = window.location.pathname;
  48. const url_split = url.split('/');
  49. let set_id = url_split[3];
  50. let acl_set_list = ["bbs_view_acl", "bbs_acl", "bbs_edit_acl", "bbs_comment_acl"];
  51. let acl_set_list_h = [2, 3, 4, 4];
  52. let markup_set_list = ["bbs_markup"];
  53. let markup_set_list_h = [2];
  54. let lang_str = 'save reference markup';
  55. for(let for_a = 0; for_a < acl_set_list.length; for_a++) {
  56. lang_str += ' ' + acl_set_list[for_a];
  57. }
  58. let lang_data = new FormData();
  59. lang_data.append('data', lang_str);
  60. let make_html = '';
  61. fetch('/api/v2/lang', {
  62. method : 'POST',
  63. body : lang_data,
  64. }).then(function(res) {
  65. return res.json();
  66. }).then(function(lang) {
  67. lang = lang["data"];
  68. fetch('/api/v2/list/acl/normal').then(function(res) {
  69. return res.json();
  70. }).then(function(acl_list) {
  71. acl_list = acl_list["data"];
  72. let acl_set_html = '<a href="/acl/TEST#exp">(' + lang['reference'] + ')</a>';
  73. acl_set_html += opennamu_bbs_w_set_select(acl_set_list, acl_set_list_h, acl_list, lang);
  74. make_html += acl_set_html;
  75. return fetch('/api/v2/list/markup');
  76. }).then(function(res) {
  77. return res.json();
  78. }).then(function(markup_list) {
  79. markup_list = markup_list["data"];
  80. make_html += opennamu_bbs_w_set_select(markup_set_list, markup_set_list_h, markup_list, lang);
  81. return;
  82. }).then(function() {
  83. document.getElementById('opennamu_bbs_w_set').innerHTML = renderSimpleSet('' +
  84. make_html +
  85. '<hr class="main_hr">' +
  86. '<button onclick="opennamu_bbs_w_set_post();">' + lang['save'] + '</button>' +
  87. '');
  88. let total_set_list = [];
  89. total_set_list.concat(acl_set_list);
  90. total_set_list.concat(markup_set_list);
  91. for(let for_a = 0; for_a < total_set_list.length; for_a++) {
  92. fetch('/api/v2/bbs/set/' + set_id + '/' + total_set_list[for_a]).then(function(res) {
  93. return res.json();
  94. }).then(function(data) {
  95. data = data["data"][0];
  96. let select_element = document.getElementById('opennamu_' + total_set_list[for_a]);
  97. select_element.querySelector('option[value="' + data + '"]').selected = true;
  98. });
  99. }
  100. });
  101. });
  102. }