TreePartial.cshtml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. @*
  2. For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
  3. *@
  4. @using SuperAdmin.Controllers;
  5. @using SuperAdmin.Models.View;
  6. @using SuperAdmin.Models.Object;
  7. @model TreeViewModel
  8. @{
  9. for (int i = 0; i < Model.rows.data.Count; i++)
  10. {
  11. RowStructure row = Model.rows.data[i];
  12. <li id="replaceable-@row.id">
  13. <div class="caret caret-@row.id none-parent-style title clickable-@row.id" value="@row.id">
  14. @row.name_global
  15. </div>
  16. <ul class="nested">
  17. <li id="child-items-@row.id">
  18. </li>
  19. </ul>
  20. <script>
  21. var toggler = document.getElementsByClassName("caret-@row.id");
  22. var i;
  23. for (i = 0; i < toggler.length; i++) {
  24. toggler[i].addEventListener("click", function () {
  25. this.parentElement.querySelector(".nested").classList.toggle("active");
  26. this.classList.toggle("caret-down");
  27. });
  28. }
  29. var div_list = document.querySelectorAll('.clickable-@row.id'); // returns NodeList
  30. var div_array = [...div_list]; // converts NodeList to Array
  31. div_array.forEach(div => {
  32. // do something awesome with each div
  33. //div.addEventListener('contextmenu', e => {
  34. // e.preventDefault();
  35. // var itemID = e.target.getAttribute("value");
  36. // $("#itemID").val(itemID);
  37. // var w = $(window);
  38. // if (window.scrollY + e.clientY - w.scrollTop() < 700) {
  39. // menu.style.top = `${window.scrollY + e.clientY - 100}px`;
  40. // menu.style.left = `${window.scrollX + e.clientX - 200}px`;
  41. // menu.classList.add('show-top');
  42. // } else {
  43. // menu.style.top = `${window.scrollY + e.clientY - 200}px`;
  44. // menu.style.left = `${window.scrollX + e.clientX - 200}px`;
  45. // menu.classList.add('show-bottom');
  46. // }
  47. // //outClick.style.display = "block";
  48. //});
  49. });
  50. $(".clickable-@row.id").on("click", function () {
  51. var id = $(this).attr("value");
  52. $(this).removeClass("none-parent-style");
  53. $(this).addClass("parent-style");
  54. //console.log("clickable " + id);
  55. $.ajax({
  56. type: "POST",
  57. url: urlConfig("/Tree/GetTreeData"),
  58. headers: { 'RequestVerificationToken': $('input[name=__RequestVerificationToken]').val() },
  59. data: {
  60. "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val(),
  61. id: id,
  62. },
  63. success: function (data) {
  64. //console.log(data);
  65. $('#child-items-' + id).html(data);
  66. getTableAction(id);
  67. },
  68. failure: function (data) {
  69. console.log(data);
  70. alert(data);
  71. },
  72. error: function (data) {
  73. console.log(data);
  74. alert(data);
  75. }
  76. });
  77. })
  78. </script>
  79. </li>
  80. }
  81. }