app-project-form.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. });
  6. function handleSelectButton() {
  7. let lgi = $(this).closest(".list-group-item");
  8. let button = this;
  9. lgi.slideUp("fast", function() {
  10. $(button).text("Deselect");
  11. $(button).removeClass("btn-outline-success");
  12. $(button).addClass("btn-outline-danger");
  13. lgi.detach();
  14. $("#selected-locations-list-group").append(lgi);
  15. let lgis = $("#selected-locations-list-group .list-group-item");
  16. lgis.sort(function(a, b) {
  17. let aName = $(a).data("name").toLowerCase();
  18. let bName = $(b).data("name").toLowerCase();
  19. if(aName == bName) return 0;
  20. return (aName > bName) ? 1 : -1;
  21. }).detach();
  22. $("#selected-locations-list-group").append(lgis);
  23. lgi.slideDown("fast");
  24. refreshLocationAlerts();
  25. refreshLocationIds();
  26. });
  27. }
  28. function handleDeselectButton() {
  29. let lgi = $(this).closest(".list-group-item");
  30. let button = this;
  31. lgi.slideUp("fast", function() {
  32. $(button).text("Select");
  33. $(button).removeClass("btn-outline-danger");
  34. $(button).addClass("btn-outline-success");
  35. lgi.detach();
  36. $("#not-selected-locations-list-group").append(lgi);
  37. let lgis = $("#not-selected-locations-list-group .list-group-item");
  38. lgis.sort(function(a, b) {
  39. let aName = $(a).data("name").toLowerCase();
  40. let bName = $(b).data("name").toLowerCase();
  41. if(aName == bName) return 0;
  42. return (aName > bName) ? 1 : -1;
  43. });
  44. $("#not-selected-locations-list-group").append(lgis);
  45. lgi.slideDown("fast");
  46. refreshLocationAlerts();
  47. refreshLocationIds();
  48. });
  49. }
  50. function refreshLocationIds() {
  51. let lgis = $("#selected-locations-list-group .list-group-item");
  52. let ids = [];
  53. lgis.each(function(index, lgi) {
  54. ids.push($(lgi).data("location-id"));
  55. });
  56. $("#location-ids").val(ids.join(", "));
  57. }
  58. function refreshLocationAlerts() {
  59. let count = 0;
  60. count = $("#not-selected-locations-list-group .list-group-item").length;
  61. if(count > 0) {
  62. $("#not-selected-locations-alert").hide();
  63. }
  64. else {
  65. $("#not-selected-locations-alert").show();
  66. }
  67. count = $("#selected-locations-list-group .list-group-item").length;
  68. if(count > 0) {
  69. $("#selected-locations-alert").hide();
  70. }
  71. else {
  72. $("#selected-locations-alert").show();
  73. }
  74. }