app-project-form.js 3.2 KB

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