add_to_collect_dlg.js 3.3 KB

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