1
0

app-project-form.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. $(function() {
  2. refreshLocationAlerts();
  3. $(document).on("click", "#not-selected-locations-list-group button", handleSelectButton);
  4. $(document).on("click", "#selected-locations-list-group button", handleDeselectButton);
  5. $("input[data-filter-target]").keyup(function(event) {
  6. let value = $(this).val().toLowerCase();
  7. let target = $(this).data("filter-target");
  8. if(value.length == 0) {
  9. $(target).children().show();
  10. return true;
  11. }
  12. $(target).children().each(function() {
  13. let number = parseInt(value);
  14. var show;
  15. if(isNaN(number)) {
  16. show = $(this).data("filter-value").indexOf(value) != -1;
  17. }
  18. else {
  19. let test1 = (number == $(this).data("location-id"));
  20. let test2 = (number == $(this).data("internal-id"));
  21. show = test1 || test2;
  22. }
  23. if(show) {
  24. $(this).show();
  25. }
  26. else {
  27. $(this).hide();
  28. }
  29. });
  30. return true;
  31. });
  32. });
  33. function handleSelectButton() {
  34. let lgi = $(this).closest(".list-group-item");
  35. let button = this;
  36. lgi.slideUp("fast", function() {
  37. $(button).find("span").text("Deselect");
  38. $(button).removeClass("btn-outline-success").addClass("btn-outline-danger");
  39. $(button).find("[data-icon]").attr("data-icon", "times");
  40. lgi.detach();
  41. $("#selected-locations-list-group").append(lgi);
  42. let lgis = $("#selected-locations-list-group .list-group-item");
  43. lgis.sort(function(a, b) {
  44. let aName = $(a).data("name").toLowerCase();
  45. let bName = $(b).data("name").toLowerCase();
  46. if(aName == bName) return 0;
  47. return (aName > bName) ? 1 : -1;
  48. }).detach();
  49. $("#selected-locations-list-group").append(lgis);
  50. lgi.slideDown("fast");
  51. refreshLocationAlerts();
  52. refreshLocationIds();
  53. });
  54. }
  55. function handleDeselectButton() {
  56. let lgi = $(this).closest(".list-group-item");
  57. let button = this;
  58. lgi.slideUp("fast", function() {
  59. $(button).find("span").text("Select");
  60. $(button).removeClass("btn-outline-danger").addClass("btn-outline-success");
  61. $(button).find("[data-icon]").attr("data-icon", "check");
  62. lgi.detach();
  63. $("#not-selected-locations-list-group").append(lgi);
  64. let lgis = $("#not-selected-locations-list-group .list-group-item");
  65. lgis.sort(function(a, b) {
  66. let aName = $(a).data("name").toLowerCase();
  67. let bName = $(b).data("name").toLowerCase();
  68. if(aName == bName) return 0;
  69. return (aName > bName) ? 1 : -1;
  70. });
  71. $("#not-selected-locations-list-group").append(lgis);
  72. lgi.slideDown("fast");
  73. refreshLocationAlerts();
  74. refreshLocationIds();
  75. });
  76. }
  77. function refreshLocationIds() {
  78. let lgis = $("#selected-locations-list-group .list-group-item");
  79. let ids = [];
  80. lgis.each(function(index, lgi) {
  81. ids.push($(lgi).data("location-id"));
  82. });
  83. $("#location-ids").val(ids.join(", "));
  84. }
  85. function refreshLocationAlerts() {
  86. let count = 0;
  87. count = $("#not-selected-locations-list-group .list-group-item").length;
  88. if(count > 0) {
  89. $("#not-selected-locations-alert").hide();
  90. }
  91. else {
  92. $("#not-selected-locations-alert").show();
  93. }
  94. count = $("#selected-locations-list-group .list-group-item").length;
  95. if(count > 0) {
  96. $("#selected-locations-alert").hide();
  97. }
  98. else {
  99. $("#selected-locations-alert").show();
  100. }
  101. }