Files
vapor-po/Sources/App/Views/PurchaseOrders/PurchaseOrderSearch.swift

51 lines
1.3 KiB
Swift

import Elementary
import ElementaryHTMX
import SharedModels
import Vapor
struct PurchaseOrderSearch: HTML {
let context: PurchaseOrderSearchContext?
init(context: PurchaseOrderSearchContext? = nil) {
self.context = context
}
var content: some HTML {
form(
.id("search"),
.hx.post("/purchase-orders/search"),
.hx.target("#purchase-order-table"),
.hx.swap(.outerHTML.transition(true).swap("1s"))
) {
select(
.name("context"), .class("col-3"),
.hx.get("/purchase-orders/search"),
.hx.target("#search"),
.hx.swap(.outerHTML)
) {
option(.value("employee")) { "Employee" }
.attributes(.selected, when: context == .employee || context == nil)
option(.value("customer")) { "Customer" }
.attributes(.selected, when: context == .customer)
}
if context == .employee || context == nil {
EmployeeSelect.purchaseOrderSearch()
} else if context == .customer {
input(.type(.text), .name("search"), .placeholder("Search"), .required)
}
button(.type(.submit), .class("btn-primary")) { "Search" }
// Img.spinner().attributes(.class("hx-indicator"))
}
}
}
enum PurchaseOrderSearchContext: String, Codable, Content {
case employee
case customer
}