app-project-form.js 2.1 KB

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