Marking a resercation as processed

This commit is contained in:
vinchent 2024-07-25 13:51:31 +02:00
parent ca1e72c676
commit fcd29cc082
5 changed files with 54 additions and 6 deletions

View File

@ -44,6 +44,7 @@ func routes(app *config.AppConfig) http.Handler {
mux.Get("/reservations-new", handlers.Repo.AdminNewReservations)
mux.Get("/reservations-all", handlers.Repo.AdminAllReservations)
mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar)
mux.Get("/process-reservation/{src}/{id}", handlers.Repo.AdminProcessReservation)
mux.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation)
mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation)

View File

@ -16,6 +16,8 @@ import (
"strconv"
"strings"
"time"
"github.com/go-chi/chi/v5"
)
// Repo the repository used by the handlers
@ -616,3 +618,15 @@ func (m *Repository) AdminPostShowReservation(w http.ResponseWriter, r *http.Req
func (m *Repository) AdminReservationsCalendar(w http.ResponseWriter, r *http.Request) {
render.Template(w, r, "admin-reservations-calendar.page.tmpl", &models.TemplateData{})
}
// AdminProcessReservation marks a reservation as processed
func (m *Repository) AdminProcessReservation(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
src := chi.URLParam(r, "src")
_ = m.DB.UpdateProcessedForReservation(id, 1)
m.App.Session.Put(r.Context(), "flash", "Reservation marked as processed")
http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther)
}

View File

@ -97,12 +97,6 @@ function Prompt() {
c.didOpen();
}
},
preConfirm: () => {
return [
document.getElementById('start').value,
document.getElementById('end').value,
]
},
})
if (c.callback !== undefined) {

View File

@ -50,7 +50,25 @@ Reservation
<input type="submit" class="btn btn-primary" value="Save">
<a href="/admin/reservations-{{$src}}" class="btn btn-warning">Cancel</a>
<a href="#" class="btn btn-info" onclick="processRes({{$res.ID}})">Mark as Processed</a>
</form>
</div>
{{end}}
{{define "js"}}
{{$src := index .StringMap "src"}}
<script>
function processRes(id) {
attention.custom({
icon: 'warning',
msg: 'Are you sure?',
callback: function(result) {
if (result != false) {
window.location.href = "/admin/process-reservation/{{$src}}/" + id;
}
}
})
}
</script>
{{end}}

View File

@ -14,6 +14,7 @@
<!-- plugin css for this page -->
<!-- End plugin css for this page -->
<!-- inject:css -->
<link rel="stylesheet" type="text/css" href="https://unpkg.com/notie/dist/notie.min.css">
<link rel="stylesheet" href="/static/admin/css/style.css">
<!-- endinject -->
<link rel="shortcut icon" href="/static/admin/images/favicon.png" />
@ -25,6 +26,9 @@
label {
font-weight: bold;
}
.notie-container {
z-index: 50000;
}
</style>
{{block "css" .}}
@ -132,8 +136,25 @@
<script src="/static/admin/js/todolist.js"></script>
<!-- endinject -->
<!-- Custom js for this page-->
<script src="https://unpkg.com/notie"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="/static/js/app.js"></script>
<script src="/static/admin/js/dashboard.js"></script>
<!-- End custom js for this page-->
<script>
let attention = Prompt()
{{with .Error}}
notify("{{.}}", "error")
{{end}}
{{with .Warning}}
notify("{{.}}", "warning")
{{end}}
{{with .Flash}}
notify("{{.}}", "success")
{{end}}
</script>
{{block "js" .}}
{{end}}