Class EditableModule

All Implemented Interfaces:
Component

public class EditableModule extends Div
Decorator that wraps a module/component with edit/delete controls.

Lifecycle: wrapper markup is built lazily once on first render via buildWrapper(). Configure all options before first render.

Security boundary: this class emits client-side controls and HTMX attributes only. Endpoint authorization, CSRF handling, and edit policy enforcement remain application responsibilities.

Mutability and thread-safety: mutable and not thread-safe. Use request-scoped wrappers and avoid concurrent mutation/reuse after render.

  • Method Details

    • wrap

      public static EditableModule wrap(Component module)
      Wraps a module with edit/delete functionality.
      Parameters:
      module - the module to wrap
      Returns:
      new EditableModule instance
    • withModuleId

      public EditableModule withModuleId(String id)
      Sets a custom module ID for this wrapper. This ID is used for HTMX targeting and as the DOM id attribute.
      Parameters:
      id - the module ID
      Returns:
      this EditableModule for method chaining
    • getModuleId

      public String getModuleId()
      Returns the module ID used for targeting.
      Returns:
      the module ID
    • withCanEdit

      public EditableModule withCanEdit(boolean canEdit)
      Sets whether this module can be edited. If false, the edit button will not be displayed even if editUrl is set.
      Parameters:
      canEdit - true to allow editing, false to lock editing
      Returns:
      this EditableModule for method chaining
    • withCanDelete

      public EditableModule withCanDelete(boolean canDelete)
      Sets whether this module can be deleted. If false, the delete button will not be displayed even if deleteUrl is set.
      Parameters:
      canDelete - true to allow deletion, false to lock deletion
      Returns:
      this EditableModule for method chaining
    • withEditMode

      public EditableModule withEditMode(EditMode editMode)
      Sets the edit mode for this module.

      The edit mode is appended as a query parameter before any fragment in edit/delete URLs so the server can apply appropriate approval workflows. Existing parameters (including editMode) and fragment text are retained; null mode leaves the complete URL unchanged.

      Parameters:
      editMode - the edit mode (USER_EDIT requires approval, OWNER_EDIT is immediate)
      Returns:
      this EditableModule for method chaining
    • withEditUrl

      public EditableModule withEditUrl(String editUrl)
      Sets the complete caller URL for editing this module (HTMX hx-get). No template substitution or identifier encoding is applied; a configured edit mode is appended to its pre-fragment query.
      Parameters:
      editUrl - the endpoint to fetch edit modal from
      Returns:
      this EditableModule for method chaining
    • withEditButton

      public EditableModule withEditButton(String label)
      Sets custom label for the edit button (default: "✏").
      Parameters:
      label - the button label (emoji or text)
      Returns:
      this EditableModule for method chaining
    • withEditTarget

      public EditableModule withEditTarget(String target)
      Sets the HTMX target for edit operations (default: "#edit-modal-container").
      Parameters:
      target - the CSS selector for the target element
      Returns:
      this EditableModule for method chaining
    • withEditSwap

      public EditableModule withEditSwap(String swap)
      Sets the HTMX swap strategy for edit operations (default: "innerHTML").
      Parameters:
      swap - the swap strategy
      Returns:
      this EditableModule for method chaining
    • withEditTitle

      public EditableModule withEditTitle(String title)
      Sets the title attribute for the edit button (default: "Edit").
      Parameters:
      title - the tooltip text
      Returns:
      this EditableModule for method chaining
    • withDeleteUrl

      public EditableModule withDeleteUrl(String deleteUrl)
      Sets the complete caller URL for deleting this module (HTMX hx-delete). No template substitution or identifier encoding is applied; a configured edit mode is appended to its pre-fragment query.
      Parameters:
      deleteUrl - the endpoint to delete the module
      Returns:
      this EditableModule for method chaining
    • withDeleteButton

      public EditableModule withDeleteButton(String label)
      Sets custom label for the delete button (default: "🗑").
      Parameters:
      label - the button label (emoji or text)
      Returns:
      this EditableModule for method chaining
    • withDeleteTarget

      public EditableModule withDeleteTarget(String target)
      Sets the HTMX target for delete operations. If not set, the module itself will be swapped out.
      Parameters:
      target - the CSS selector for the target element
      Returns:
      this EditableModule for method chaining
    • withDeleteSwap

      public EditableModule withDeleteSwap(String swap)
      Sets the HTMX swap strategy for delete operations (default: "outerHTML").
      Parameters:
      swap - the swap strategy
      Returns:
      this EditableModule for method chaining
    • withDeleteConfirm

      public EditableModule withDeleteConfirm(String message)
      Sets a confirmation message for delete operations.
      Parameters:
      message - the confirmation prompt text
      Returns:
      this EditableModule for method chaining
    • withDeleteTitle

      public EditableModule withDeleteTitle(String title)
      Sets the title attribute for the delete button (default: "Delete").
      Parameters:
      title - the tooltip text
      Returns:
      this EditableModule for method chaining
    • render

      public String render(RenderContext context)
      Renders this EditableModule and its wrapped module with context.
      Specified by:
      render in interface Component
      Overrides:
      render in class HtmlTag
      Parameters:
      context - the render context
      Returns:
      HTML string with wrapper, buttons, and module