add_to_collect_dlg.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function add_to_collect_dlg_init() {
  2. $("[vui='collect-dlg']").each(function () {
  3. $(this).css("position", "relative");
  4. let html = "";
  5. html += '<span class="icon_btn_div">';
  6. html += '<span class="icon_btn_tip">' + gLocal.gui.add_to + gLocal.gui.anthology + "</span>";
  7. html += "<button class='button_add_to_collect icon_btn' >";
  8. html += "<svg class='icon'>";
  9. html += "<use xlink:href='../studio/svg/icon.svg#add_to_anthology'></use>";
  10. html += "</svg>";
  11. html += "</button>";
  12. html += "<span class='float_dlg' style='top: 20px;' ></span>";
  13. html += "</span>";
  14. $(this).html(html);
  15. });
  16. $(".button_add_to_collect").click(function () {
  17. let html = "";
  18. let article_id = $(this).parent().parent().attr("a_id");
  19. html += "<div id='add_to_collect_dlg_" + article_id + "'>";
  20. html += "<div >";
  21. html += "<input type='input' placeholder='" + gLocal.gui.search + "' />";
  22. html += "</div>";
  23. html += "<div>";
  24. html += "<div class='exist'>";
  25. html += "</div>";
  26. html += "<div class='others'>";
  27. html += "</div>";
  28. html += "<div id='add_to_collection_msg'>";
  29. html += "<a href='../article/my_collect_index.php' target='_blank'>添加新的文集</a>";
  30. html += "</div>";
  31. html += "</div>";
  32. html += "<div style='display:flex;justify-content: space-between;'>";
  33. html +=
  34. "<button onclick=\"article_add_to_collect_cancel('" +
  35. article_id +
  36. "')\">" +
  37. gLocal.gui.cancel +
  38. "</button>";
  39. html +=
  40. "<button onclick=\"article_add_to_collect_ok('" + article_id + "')\">" + gLocal.gui.finish + "</button>";
  41. html += "</div>";
  42. html += "</div>";
  43. $(this).siblings(".float_dlg").first().html(html);
  44. $(this).siblings(".float_dlg").first().show();
  45. $.get(
  46. "../article/list_article_in_collect.php",
  47. {
  48. id: article_id,
  49. },
  50. function (data, status) {
  51. let collect_list = JSON.parse(data);
  52. let id = collect_list.article_id;
  53. let html_exist = "";
  54. for (const iterator of collect_list.exist) {
  55. html_exist +=
  56. "<div><input type='checkbox' class='collect' collect_id='" + iterator.id + "' checked />";
  57. html_exist += iterator.title;
  58. html_exist += "</div>";
  59. }
  60. $("#add_to_collect_dlg_" + id)
  61. .find(".exist")
  62. .first()
  63. .html(html_exist);
  64. if (collect_list.others) {
  65. let html_others = "";
  66. for (const iterator of collect_list.others) {
  67. html_others +=
  68. "<div><input type='checkbox' class='collect' collect_id='" + iterator.id + "' />";
  69. html_others += iterator.title;
  70. html_others += "</div>";
  71. }
  72. $("#add_to_collect_dlg_" + id)
  73. .find(".others")
  74. .first()
  75. .html(html_others);
  76. }
  77. }
  78. );
  79. });
  80. }
  81. function article_add_to_collect_ok(article_id) {
  82. let obj = document.querySelectorAll(".collect");
  83. let collect_id = new Array();
  84. for (const iterator of obj) {
  85. if (iterator.checked == true) {
  86. collect_id.push(iterator.getAttributeNode("collect_id").value);
  87. }
  88. }
  89. $.post(
  90. "../article/add_article_to_collect.php",
  91. {
  92. id: article_id,
  93. title: $("#input_article_title").val(),
  94. data: JSON.stringify(collect_id),
  95. },
  96. function (data) {
  97. let result = JSON.parse(data);
  98. if (result.status > 0) {
  99. alert(result.message);
  100. } else {
  101. add_to_collect_dlg_close(result.id);
  102. }
  103. }
  104. );
  105. }
  106. function article_add_to_collect_cancel(article_id) {
  107. add_to_collect_dlg_close(article_id);
  108. }
  109. function add_to_collect_dlg_close(article_id) {
  110. $("#add_to_collect_dlg_" + article_id)
  111. .parent()
  112. .hide();
  113. }