app-project-form.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. initialiseTooltips();
  33. });
  34. function handleSelectButton() {
  35. let lgi = $(this).closest(".list-group-item");
  36. let button = this;
  37. lgi.slideUp("fast", function() {
  38. $(button).find("span").text("Deselect");
  39. $(button).removeClass("btn-outline-success").addClass("btn-outline-danger");
  40. $(button).find("[data-icon]").attr("data-icon", "times");
  41. lgi.detach();
  42. $("#selected-locations-list-group").append(lgi);
  43. let lgis = $("#selected-locations-list-group .list-group-item");
  44. lgis.sort(function(a, b) {
  45. let aName = $(a).data("name").toLowerCase();
  46. let bName = $(b).data("name").toLowerCase();
  47. if(aName == bName) return 0;
  48. return (aName > bName) ? 1 : -1;
  49. }).detach();
  50. $("#selected-locations-list-group").append(lgis);
  51. lgi.slideDown("fast");
  52. refreshLocationAlerts();
  53. refreshLocationIds();
  54. });
  55. }
  56. function handleDeselectButton() {
  57. let lgi = $(this).closest(".list-group-item");
  58. let button = this;
  59. lgi.slideUp("fast", function() {
  60. $(button).find("span").text("Select");
  61. $(button).removeClass("btn-outline-danger").addClass("btn-outline-success");
  62. $(button).find("[data-icon]").attr("data-icon", "check");
  63. lgi.detach();
  64. $("#not-selected-locations-list-group").append(lgi);
  65. let lgis = $("#not-selected-locations-list-group .list-group-item");
  66. lgis.sort(function(a, b) {
  67. let aName = $(a).data("name").toLowerCase();
  68. let bName = $(b).data("name").toLowerCase();
  69. if(aName == bName) return 0;
  70. return (aName > bName) ? 1 : -1;
  71. });
  72. $("#not-selected-locations-list-group").append(lgis);
  73. lgi.slideDown("fast");
  74. refreshLocationAlerts();
  75. refreshLocationIds();
  76. });
  77. }
  78. function refreshLocationIds() {
  79. let lgis = $("#selected-locations-list-group .list-group-item");
  80. let ids = [];
  81. lgis.each(function(index, lgi) {
  82. ids.push($(lgi).data("location-id"));
  83. });
  84. $("#location-ids").val(ids.join(", "));
  85. }
  86. function refreshLocationAlerts() {
  87. let count = 0;
  88. count = $("#not-selected-locations-list-group .list-group-item").length;
  89. if(count > 0) {
  90. $("#not-selected-locations-alert").hide();
  91. }
  92. else {
  93. $("#not-selected-locations-alert").show();
  94. }
  95. count = $("#selected-locations-list-group .list-group-item").length;
  96. if(count > 0) {
  97. $("#selected-locations-alert").hide();
  98. }
  99. else {
  100. $("#selected-locations-alert").show();
  101. }
  102. }