75 lines
2.0 KiB
Swift
75 lines
2.0 KiB
Swift
import Elementary
|
|
import ElementaryHTMX
|
|
import SharedModels
|
|
import Vapor
|
|
|
|
struct PurchaseOrderSearch: HTML {
|
|
|
|
let context: PurchaseOrderSearchContext
|
|
|
|
init(context: PurchaseOrderSearchContext? = nil) {
|
|
self.context = context ?? .employee
|
|
}
|
|
|
|
var content: some HTML {
|
|
form(
|
|
.id(.search),
|
|
.hx.post(route: .purchaseOrders(.search())),
|
|
.hx.target(.purchaseOrders()),
|
|
.hx.swap(.outerHTML)
|
|
) {
|
|
div(.class("btn-row")) {
|
|
button(
|
|
.class("btn-secondary"), .style("position: absolute; top: 80px; right: 20px;"),
|
|
.hx.get(route: .purchaseOrders()), .hx.pushURL(true), .hx.target("body")
|
|
)
|
|
{ "x" }
|
|
}
|
|
div(.class("row")) {
|
|
select(
|
|
.name("context"), .class("col-3"),
|
|
.hx.get(route: .purchaseOrders(.search())),
|
|
.hx.target(.search),
|
|
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
|
.hx.pushURL(true)
|
|
) {
|
|
for context in PurchaseOrderSearchContext.allCases {
|
|
option(.value(context.rawValue)) { context.rawValue.capitalized }
|
|
.attributes(.selected, when: self.context == context)
|
|
}
|
|
}
|
|
|
|
if context == .employee {
|
|
EmployeeSelect.purchaseOrderSearch()
|
|
} else if context == .customer {
|
|
input(
|
|
.type(.text), .class("col-6"), .style("margin-left: 60px; margin-top: 18px;"),
|
|
.name("search"), .placeholder("Search"), .required
|
|
)
|
|
} else if context == .vendor {
|
|
VendorBranchSelect.purchaseOrderSearch()
|
|
}
|
|
}
|
|
|
|
div(.class("btn-row")) {
|
|
button(.type(.submit), .class("btn-primary"))
|
|
{ "Search" }
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
enum PurchaseOrderSearchContext: String, Codable, Content, CaseIterable {
|
|
case employee
|
|
case customer
|
|
case vendor
|
|
}
|
|
|
|
struct PurchaseOrderSearchContent: Content {
|
|
let context: PurchaseOrderSearchContext
|
|
let createdForID: Employee.ID?
|
|
let search: String?
|
|
let vendorBranchID: VendorBranch.ID?
|
|
}
|