feat: Working on search for purchase orders.
This commit is contained in:
@@ -25,11 +25,11 @@ struct PurchaseOrderForm: HTML {
|
||||
}
|
||||
form(
|
||||
.hx.post("/purchase-orders"),
|
||||
.hx.target("purchase-order-table"),
|
||||
.hx.swap(.afterBegin.transition(true).swap("1s")),
|
||||
.hx.target("#purchase-order-table"),
|
||||
.hx.swap(.afterBegin),
|
||||
.custom(
|
||||
name: "hx-on::after-request",
|
||||
value: "if (event.detail.successful) toggleContent('float'); window.location.href='/purchase-orders';"
|
||||
value: "if(event.detail.successful) toggleContent('float')"
|
||||
)
|
||||
) {
|
||||
div(.class("row")) {
|
||||
@@ -139,7 +139,7 @@ struct PurchaseOrderForm: HTML {
|
||||
let vendorBranches: [VendorBranch.Detail]
|
||||
|
||||
var content: some HTML<HTMLTag.select> {
|
||||
select(.name("vendorBranchID"), .class("col-3")) {
|
||||
select(.name("vendorBranchID"), .class("col-4")) {
|
||||
for branch in vendorBranches {
|
||||
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
||||
}
|
||||
|
||||
50
Sources/App/Views/PurchaseOrders/PurchaseOrderSearch.swift
Normal file
50
Sources/App/Views/PurchaseOrders/PurchaseOrderSearch.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
||||
@@ -23,7 +23,7 @@ struct PurchaseOrderTable: HTML {
|
||||
.attributes(
|
||||
.hx.get("/purchase-orders/create"),
|
||||
.hx.target("#float"),
|
||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.pushURL(true)
|
||||
)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ struct PurchaseOrderTable: HTML {
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
||||
.hx.target("this"),
|
||||
.hx.indicator(".htmx-indicator")
|
||||
.hx.indicator("next .htmx-indicator")
|
||||
) {
|
||||
img(.src("/images/spinner.svg"), .class("htmx-indicator"), .width(60), .height(60))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user