From 7f2f6aa74934a0f6ee91363052da98f33300ec77 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Tue, 31 Dec 2024 22:59:55 +0000 Subject: [PATCH] add js libraries --- assets/js/app/filter.js | 49 +++++++++++++++++++++++++++++++++ assets/js/app/itinerary.js | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 assets/js/app/filter.js create mode 100644 assets/js/app/itinerary.js diff --git a/assets/js/app/filter.js b/assets/js/app/filter.js new file mode 100644 index 0000000..4b29937 --- /dev/null +++ b/assets/js/app/filter.js @@ -0,0 +1,49 @@ +export function filterAddressesByCase() { + if (!document.getElementById('case-filter').value) { + return; + } + fetch('/index.php/api/filter-address-by-case/' + document.getElementById('case-filter').value, { + method: 'POST', + header: { + 'Content-Type': 'application/json' + } + }) + .then(response => response.json()) + .then(result => { + const addressList = document.getElementById('addressList'); + const origin = document.getElementById('origin'); + const destination = document.getElementById('destination'); + + origin.innerHTML = ''; + destination.innerHTML = ''; + addressList.innerHTML = ''; + + origin.innerHTML += ''; + destination.innerHTML += ''; + + result.forEach(a => { + origin.innerHTML += ``; + destination.innerHTML += ``; + addressList.innerHTML += ` + + +
+
+
+ ${a.name} +
+
+
+ + ${a.formattedAddress} + ${a.lat}/${a.lon} + + + edit + + + `; + }) + }); +} + diff --git a/assets/js/app/itinerary.js b/assets/js/app/itinerary.js new file mode 100644 index 0000000..a73ca72 --- /dev/null +++ b/assets/js/app/itinerary.js @@ -0,0 +1,56 @@ +export function createItinerary() { + if (!document.getElementById('case-filter').value) { + return; + } + + let date = document.getElementById('date'); + date.value = new Date().toLocaleDateString(); + + let btn = document.getElementById('create-itinerary'); + btn.setAttribute('data-bs-toggle', 'modal'); + btn.setAttribute('data-bs-target', '#exampleModalMessage'); + btn.click(); +} + +export function addLocationToItinerary() { + let date = document.getElementById('date').value; + let origin = document.getElementById('origin').value; + let destination = document.getElementById('destination').value; + let departure = document.getElementById('departure').value; + let arrival = document.getElementById('arrival').value; + let caseMileage = document.getElementById('case-mileage').checked; + let caseId = document.getElementById('case-filter').value; + + fetch('/index.php/api/add-location-to-itinerary', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + date: date, + origin: origin, + destination: destination, + departure: departure, + arrival: arrival, + caseMileage: caseMileage, + caseId: caseId + }) + }) + .then(response => response.json()) + .then(data => { + if (data.success === true) { + $('#close-modal').click(); + } + }); +} + +export function openMap() { + if (!document.getElementById('case-filter').value || !document.getElementById('date-filter').value) { + return false; + } + + document.getElementById('caseId').value = document.getElementById('case-filter').value; + document.getElementById('caseDate').value = document.getElementById('date-filter').value; + + document.getElementById('map-form').submit(); +} \ No newline at end of file