mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 20:42:59 +00:00
tetsteststestste
This commit is contained in:
+1
-1
@@ -415,7 +415,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<main class="container mx-auto px-4 py-4">
|
<main class="container mx-auto px-20 py-4">
|
||||||
<!-- Banner will be inserted here by JavaScript -->
|
<!-- Banner will be inserted here by JavaScript -->
|
||||||
|
|
||||||
<!-- Search -->
|
<!-- Search -->
|
||||||
|
|||||||
@@ -1271,27 +1271,44 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM
|
|||||||
// Add these new handler functions before the existing banner handlers
|
// Add these new handler functions before the existing banner handlers
|
||||||
|
|
||||||
func handleUpdateReservation(w http.ResponseWriter, r *http.Request) {
|
func handleUpdateReservation(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
// Set CORS headers
|
||||||
reservationID := vars["id"]
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "PUT, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
// Handle preflight
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
id := vars["id"]
|
||||||
|
if id == "" {
|
||||||
|
http.Error(w, "Missing reservation ID", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the updated reservation from request body
|
||||||
var updatedReservation Reservation
|
var updatedReservation Reservation
|
||||||
if err := json.NewDecoder(r.Body).Decode(&updatedReservation); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&updatedReservation); err != nil {
|
||||||
http.Error(w, "Invalid reservation data", http.StatusBadRequest)
|
http.Error(w, "Invalid reservation data: "+err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing reservations
|
// Load existing reservations
|
||||||
reservations, err := loadReservations()
|
reservations, err := loadReservations()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to load reservations", http.StatusInternalServerError)
|
http.Error(w, "Failed to load reservations: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find and update the reservation
|
// Find and update the reservation
|
||||||
found := false
|
found := false
|
||||||
for i, res := range reservations {
|
for i, res := range reservations {
|
||||||
if res.ID == reservationID {
|
if res.ID == id {
|
||||||
updatedReservation.ID = reservationID // Ensure ID remains unchanged
|
updatedReservation.ID = id // Ensure ID remains the same
|
||||||
reservations[i] = updatedReservation
|
reservations[i] = updatedReservation
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@@ -1305,22 +1322,38 @@ func handleUpdateReservation(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Save updated reservations
|
// Save updated reservations
|
||||||
if err := saveReservations(reservations); err != nil {
|
if err := saveReservations(reservations); err != nil {
|
||||||
http.Error(w, "Failed to save reservation", http.StatusInternalServerError)
|
http.Error(w, "Failed to save reservations: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
// Return the updated reservation
|
||||||
json.NewEncoder(w).Encode(updatedReservation)
|
json.NewEncoder(w).Encode(updatedReservation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleDeleteReservation(w http.ResponseWriter, r *http.Request) {
|
func handleDeleteReservation(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Set CORS headers
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "DELETE, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
// Handle preflight
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
reservationID := vars["id"]
|
id := vars["id"]
|
||||||
|
if id == "" {
|
||||||
|
http.Error(w, "Missing reservation ID", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Load existing reservations
|
// Load existing reservations
|
||||||
reservations, err := loadReservations()
|
reservations, err := loadReservations()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to load reservations", http.StatusInternalServerError)
|
http.Error(w, "Failed to load reservations: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1328,9 +1361,9 @@ func handleDeleteReservation(w http.ResponseWriter, r *http.Request) {
|
|||||||
found := false
|
found := false
|
||||||
var updatedReservations []Reservation
|
var updatedReservations []Reservation
|
||||||
for _, res := range reservations {
|
for _, res := range reservations {
|
||||||
if res.ID == reservationID {
|
if res.ID == id {
|
||||||
found = true
|
found = true
|
||||||
continue
|
continue // Skip this reservation to remove it
|
||||||
}
|
}
|
||||||
updatedReservations = append(updatedReservations, res)
|
updatedReservations = append(updatedReservations, res)
|
||||||
}
|
}
|
||||||
@@ -1342,9 +1375,10 @@ func handleDeleteReservation(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Save updated reservations
|
// Save updated reservations
|
||||||
if err := saveReservations(updatedReservations); err != nil {
|
if err := saveReservations(updatedReservations); err != nil {
|
||||||
http.Error(w, "Failed to save reservations", http.StatusInternalServerError)
|
http.Error(w, "Failed to save reservations: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return success with no content
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1554,11 +1554,12 @@
|
|||||||
reservationModal.style.display = 'none';
|
reservationModal.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure modal is defined before using it in the window.onclick handler
|
||||||
|
const modal = document.getElementById('eventModal');
|
||||||
|
|
||||||
// Close modal when clicking outside
|
// Close modal when clicking outside
|
||||||
window.onclick = function(event) {
|
window.onclick = function(event) {
|
||||||
if (event.target == reservationModal) {
|
if (event.target === modal) {
|
||||||
reservationModal.style.display = 'none';
|
|
||||||
} else if (event.target == modal) {
|
|
||||||
modal.style.display = 'none';
|
modal.style.display = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user