app-project-form.js 1.9 KB

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