<% Class CardsController_Class Private m_useLayout Private m_title Private Sub Class_Initialize() m_useLayout = False m_title = "Cards" End Sub Public Property Get useLayout() : useLayout = m_useLayout : End Property Public Property Let useLayout(v) : m_useLayout = v : End Property Public Property Get Title() : Title = m_title : End Property Public Property Let Title(v) : m_title = v : End Property ' POST /cards Public Sub Store() Response.ContentType = "application/json" If Not KeycloakIsLoggedIn() Then Response.Write "{""ok"":false,""error"":""Unauthorized""}" Exit Sub End If Dim boardId, columnId, swimLaneId, jobNum, jobName boardId = CLng(Request.Form("board_id")) columnId = CLng(Request.Form("column_id")) swimLaneId = CLng(Request.Form("swim_lane_id")) jobNum = Trim(CStr(Request.Form("job_number"))) jobName = Trim(CStr(Request.Form("job_name"))) If boardId = 0 Or columnId = 0 Or swimLaneId = 0 Then Response.Write "{""ok"":false,""error"":""board_id, column_id, and swim_lane_id are required""}" Exit Sub End If Dim nextPos : nextPos = cards_Repository().MaxPosition(columnId, swimLaneId) + 1 Dim username : username = GetCurrentUsername() Dim card : Set card = New POBO_cards card.board_id = boardId card.column_id = columnId card.swim_lane_id = swimLaneId card.job_number = jobNum card.job_name = jobName card.customer_name = Trim(CStr(Request.Form("customer_name") & "")) card.delivery_date = Trim(CStr(Request.Form("delivery_date") & "")) card.quantity = Trim(CStr(Request.Form("quantity") & "")) card.notes = Trim(CStr(Request.Form("notes") & "")) card.full_note = CStr(Request.Form("full_note") & "") card.position = nextPos card.created_at = Now() card.created_by = username card.updated_at = Now() card.updated_by = username On Error Resume Next cards_Repository().AddNew card If Err.Number <> 0 Then Response.Write "{""ok"":false,""error"":" & JsonString(Err.Description) & "}" Err.Clear Exit Sub End If On Error GoTo 0 Response.Write "{""ok"":true,""id"":" & card.id & "," & _ """job_number"":" & JsonString(card.job_number) & "," & _ """job_name"":" & JsonString(card.job_name) & "," & _ """customer_name"":" & JsonString(card.customer_name) & "," & _ """delivery_date"":" & JsonDateStr(card.delivery_date) & "," & _ """quantity"":" & JsonString(card.quantity) & "," & _ """notes"":" & JsonString(card.notes) & "," & _ """full_note"":" & JsonString(card.full_note) & "," & _ """column_id"":" & card.column_id & "," & _ """swim_lane_id"":" & card.swim_lane_id & "," & _ """position"":" & card.position & "}" End Sub ' POST /cards/:id Public Sub Update(id) Response.ContentType = "application/json" If Not KeycloakIsLoggedIn() Then Response.Write "{""ok"":false,""error"":""Unauthorized""}" Exit Sub End If On Error Resume Next Dim card : Set card = cards_Repository().FindByID(CLng(id)) If Err.Number <> 0 Then Err.Clear Response.Write "{""ok"":false,""error"":""Not found""}" Exit Sub End If On Error GoTo 0 card.job_number = Trim(CStr(Request.Form("job_number"))) card.job_name = Trim(CStr(Request.Form("job_name"))) card.customer_name = Trim(CStr(Request.Form("customer_name") & "")) card.delivery_date = Trim(CStr(Request.Form("delivery_date") & "")) card.quantity = Trim(CStr(Request.Form("quantity") & "")) card.notes = Trim(CStr(Request.Form("notes") & "")) card.full_note = CStr(Request.Form("full_note") & "") card.updated_at = Now() card.updated_by = GetCurrentUsername() On Error Resume Next cards_Repository().Update card If Err.Number <> 0 Then Response.Write "{""ok"":false,""error"":" & JsonString(Err.Description) & "}" Err.Clear Exit Sub End If On Error GoTo 0 Response.Write "{""ok"":true," & _ """job_number"":" & JsonString(card.job_number) & "," & _ """job_name"":" & JsonString(card.job_name) & "," & _ """customer_name"":" & JsonString(card.customer_name) & "," & _ """delivery_date"":" & JsonDateStr(card.delivery_date) & "," & _ """quantity"":" & JsonString(card.quantity) & "," & _ """notes"":" & JsonString(card.notes) & "," & _ """full_note"":" & JsonString(card.full_note) & "}" End Sub ' POST /cards/:id/move — form: column_id, swim_lane_id, position, [sibling_ids CSV for reorder] Public Sub Move(id) Response.ContentType = "application/json" If Not KeycloakIsLoggedIn() Then Response.Write "{""ok"":false,""error"":""Unauthorized""}" Exit Sub End If Dim columnId, swimLaneId, position columnId = CLng(Request.Form("column_id")) swimLaneId = CLng(Request.Form("swim_lane_id")) position = CLng(Request.Form("position")) Dim username : username = GetCurrentUsername() cards_Repository().Move CLng(id), columnId, swimLaneId, position, Now(), username ' Reorder siblings if provided Dim siblings : siblings = Trim(CStr(Request.Form("sibling_ids"))) If Len(siblings) > 0 Then Dim ids, idx ids = Split(siblings, ",") For idx = 0 To UBound(ids) Dim sibId : sibId = CLng(Trim(ids(idx))) If sibId > 0 Then cards_Repository().UpdatePosition sibId, idx, Now(), username End If Next End If Response.Write "{""ok"":true}" End Sub ' POST /cards/:id/delete Public Sub Destroy(id) Response.ContentType = "application/json" If Not KeycloakIsLoggedIn() Then Response.Write "{""ok"":false,""error"":""Unauthorized""}" Exit Sub End If cards_Repository().Delete CLng(id) Response.Write "{""ok"":true}" End Sub Private Function GetCurrentUsername() Dim u : Set u = KeycloakCurrentUser() Dim name : name = "" If Not u Is Nothing Then On Error Resume Next name = CStr(u.Item("preferred_username")) If Err.Number <> 0 Then name = "" Err.Clear End If On Error GoTo 0 End If GetCurrentUsername = name End Function Private Function JsonString(s) Dim v : v = CStr(s & "") v = Replace(v, "\", "\\") v = Replace(v, """", "\""") v = Replace(v, vbCrLf, "\n") v = Replace(v, vbLf, "\n") v = Replace(v, vbCr, "\n") JsonString = """" & v & """" End Function Private Function JsonDateStr(d) If IsNull(d) Or IsEmpty(d) Then JsonDateStr = "null" Exit Function End If On Error Resume Next Dim dt, s dt = CDate(d) s = Year(dt) & "-" & Right("0" & Month(dt), 2) & "-" & Right("0" & Day(dt), 2) If Err.Number <> 0 Then Err.Clear JsonDateStr = "null" Else JsonDateStr = """" & s & """" End If On Error GoTo 0 End Function End Class Dim CardsController_Class__Singleton Function CardsController() If IsEmpty(CardsController_Class__Singleton) Then Set CardsController_Class__Singleton = New CardsController_Class End If Set CardsController = CardsController_Class__Singleton End Function %>