89 lines
2.5 KiB
Swift
89 lines
2.5 KiB
Swift
import Elementary
|
|
import ElementaryHTMX
|
|
import SharedModels
|
|
import Vapor
|
|
|
|
struct EmployeeSelect: HTML {
|
|
|
|
let employees: [Employee]?
|
|
let context: SelectContext
|
|
|
|
var content: some HTML {
|
|
if let employees {
|
|
select(.name("createdForID"), .class(context.classString)) {
|
|
for employee in employees {
|
|
option(.value(employee.id.uuidString)) { employee.fullName }
|
|
}
|
|
}
|
|
.attributes(.style("margin-left: 15px;"), when: context == .purchaseOrderSearch)
|
|
} else {
|
|
div(
|
|
.hx.get("/select/employee?context=\(context.rawValue)"),
|
|
.hx.target("this"),
|
|
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
|
.hx.indicator("next .hx-indicator"),
|
|
.hx.trigger(.event(.revealed)),
|
|
.style("display: inline;")
|
|
) {
|
|
Img.spinner().attributes(.class("hx-indicator"))
|
|
}
|
|
}
|
|
}
|
|
|
|
static func purchaseOrderForm(employees: [Employee]? = nil) -> Self {
|
|
.init(employees: employees, context: .purchaseOrderForm)
|
|
}
|
|
|
|
static func purchaseOrderSearch(employees: [Employee]? = nil) -> Self {
|
|
.init(employees: employees, context: .purchaseOrderSearch)
|
|
}
|
|
|
|
}
|
|
|
|
struct VendorBranchSelect: HTML {
|
|
let branches: [VendorBranch.Detail]?
|
|
let context: SelectContext
|
|
|
|
var content: some HTML {
|
|
if let branches {
|
|
select(.name("vendorBranchID"), .class(context.classString)) {
|
|
for branch in branches {
|
|
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
|
}
|
|
}
|
|
.attributes(.style("margin-left: 15px;"), when: context == .purchaseOrderSearch)
|
|
} else {
|
|
div(
|
|
.hx.get("/select/vendor-branches?context=\(context.rawValue)"),
|
|
.hx.target("this"),
|
|
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
|
.hx.indicator("next .hx-indicator"),
|
|
.hx.trigger(.event(.revealed)),
|
|
.style("display: inline;")
|
|
) {
|
|
Img.spinner().attributes(.class("hx-indicator"))
|
|
}
|
|
}
|
|
}
|
|
|
|
static func purchaseOrderForm(branches: [VendorBranch.Detail]? = nil) -> Self {
|
|
.init(branches: branches, context: .purchaseOrderForm)
|
|
}
|
|
|
|
static func purchaseOrderSearch(branches: [VendorBranch.Detail]? = nil) -> Self {
|
|
.init(branches: branches, context: .purchaseOrderSearch)
|
|
}
|
|
}
|
|
|
|
enum SelectContext: String, Codable, Content {
|
|
case purchaseOrderForm
|
|
case purchaseOrderSearch
|
|
|
|
var classString: String {
|
|
switch self {
|
|
case .purchaseOrderForm: return "col-3"
|
|
case .purchaseOrderSearch: return "col-6"
|
|
}
|
|
}
|
|
}
|