add_to_collect_dlg.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. function add_to_collect_dlg_init() {
  2. $("[vui='collect-dlg']").each(function () {
  3. $(this).css("position", "relative");
  4. $(this).html(
  5. "<span class='button_add_to_collect'>添加到作品集</span><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 += "<button onclick='article_add_to_collect_cancel()'>Cancel</button>";
  28. html += "</div>";
  29. html += "</div>";
  30. $(this).siblings(".float_dlg").first().append(html);
  31. $(this).siblings(".float_dlg").first().show();
  32. $.get(
  33. "../article/list_article_in_collect.php",
  34. {
  35. id: article_id,
  36. },
  37. function (data, status) {
  38. let collect_list = JSON.parse(data);
  39. let id = collect_list.article_id;
  40. let html_exist = "";
  41. for (const iterator of collect_list.exist) {
  42. html_exist +=
  43. "<div><input type='checkbox' class='collect' collect_id='" +
  44. iterator.id +
  45. "' checked />";
  46. html_exist += iterator.title;
  47. html_exist += "</div>";
  48. }
  49. $("#add_to_collect_dlg_" + id)
  50. .find(".exist")
  51. .first()
  52. .html(html_exist);
  53. let html_others = "";
  54. for (const iterator of collect_list.others) {
  55. html_others +=
  56. "<div><input type='checkbox' class='collect' collect_id='" +
  57. iterator.id +
  58. "' />";
  59. html_others += iterator.title;
  60. html_others += "</div>";
  61. }
  62. $("#add_to_collect_dlg_" + id)
  63. .find(".others")
  64. .first()
  65. .html(html_others);
  66. }
  67. );
  68. });
  69. }
  70. function article_add_to_collect_ok(article_id) {
  71. let obj = document.querySelectorAll(".collect");
  72. let collect_id = new Array();
  73. for (const iterator of obj) {
  74. if (iterator.checked == true) {
  75. collect_id.push(iterator.getAttributeNode("collect_id").value);
  76. }
  77. }
  78. $.post(
  79. "../article/add_article_to_collect.php",
  80. {
  81. id: article_id,
  82. title: $("#input_article_title").val(),
  83. data: JSON.stringify(collect_id),
  84. },
  85. function (data) {
  86. let result = JSON.parse(data);
  87. }
  88. );
  89. }
  90. function article_add_to_collect_cancel() {}