Skip to content
forms-raw_singleitemedit-icon
navigation
modification_btn
docs
messages
flatprojectmap.handlebars
Documentation Buttons
modificationbutton
docs_htmltables.handlebars

Documentation Buttons

docs_html.handlebars
documentation.handlebars

Doc-Slot Modal Loader — What This Code Does

This block adds a small, reusable “Docs” button to any page location you mark with .doc-slot. When clicked, it opens a Bootstrap 5 modal, fetches documentation from your server using a single /templateload endpoint, and renders the content neatly inside the modal. It supports two server response modes: JSON (preferred) and HTML (table-based).


Key Outcomes

  • Turns any <div class="doc-slot" ...> into a working “Open Docs” button.
  • Opens a modal and mounts a dynamic container (.ajax-table) bound to a specific document ID.
  • Fetches {route}/templateload?ids={identifier}&render=false and renders content:
    • JSON mode: Reads rows from query3, databaseitems, results, query1, or query and maps raw keys to human-friendly labels via query2.
    • HTML mode: Parses an HTML table (prefers .simple-grid) and extracts a Text column (sorted by an optional Order column).

What Each Part Is

1) The Placeholder

You place a lightweight marker in your HTML:

<div class="doc-slot"
                         data-route="/documentation"
                         data-identifier="68c1b46c9f37cf79db52b97e"
                         data-label="Docs"></div>
  • data-route: The base route that exposes /templateload (e.g., /documentation).
  • data-identifier: The document ID to fetch (passed as ?ids=...).
  • data-label (optional): Button caption. Defaults to the identifier string.

2) The Modal Shell

A standard Bootstrap 5 modal. The script injects content into #docModalBody and sets small metadata in #docMeta.

3) The Initializer Script

On DOM ready, it scans for .doc-slot elements, injects a small button into each, and wires click behavior:

  1. Create a button using slot attributes.
  2. On click, compose a modal body with a single .ajax-table block carrying the route & element ID.
  3. Open the modal and call window.buildAjaxTables() to render the content.

4) The Builder Script (window.buildAjaxTables)

This idempotent function finds all .ajax-table blocks inside the modal, shows a “pulse” loader, fetches content, and renders it.

  • JSON mode:
    • Rows detected in the first available array key among: query3, databaseitems, results, query1, query. If query is an object, it is wrapped as a single row.
    • Key → Label mapping: The builder uses query2 to build a map from elementID to entry.description and remaps each row’s entry keys accordingly (e.g., turns a raw key into “Text”).
    • Content extraction: picks from entry.Text, entry.text, entry.HTML, or entry.html.
    • Ordering: uses numeric entry.order (missing = Infinity → sorted last).
  • HTML mode:
    • Parses the first table (prefers table.simple-grid), reads header names.
    • Requires a Text column; optionally uses an Order column for sorting.
    • Renders each row’s Text cell HTML as a “doc chunk”.

Server Contract (Your Endpoint)

The builder requests:

GET {data-route}/templateload?ids={identifier}&render=false

You may return either:

  • JSON with:
    • Rows in any of: query3 / databaseitems / results / query1 / query.
    • Key labels in query2 as an array of objects like:
      {
                            "elementID": "text",
                            "entry": { "description": "Text" }
                          }
  • HTML containing a table with headers “Order” (optional) and “Text” (required).

Visuals & UX

  • Shows a subtle loader while fetching.
  • Renders content as clean stacked blocks (.doc-chunk) without borders/headers.
  • Minimal CSS is included; you can extend styling as needed.

Dependencies & Integration

  • jQuery is required by the initializer (for convenience).
  • Bootstrap 5 (bundle) is required for the modal.
  • Ensure your page loads jQuery and Bootstrap before this code.

Security & Safety

  • Client decodes HTML entities for intended “Text/HTML” fields only.
  • Server should sanitize any HTML originating from untrusted sources.
  • Fetch uses credentials: 'same-origin' to respect auth/CSRF cookie policies.

Error Handling

On failure (non-2xx or parsing error), the builder replaces the block with a warning and logs details to the console:

<div class="alert alert-warning mb-0">
                      Failed to load documentation for <code>{id}</code>.
                      <div class="small text-muted mt-1">{status/message}</div>
                    </div>

Common Customizations

  • Button style: Change the injected class (e.g., btn-outline-primary btn-sm).
  • Modal title/meta: Adjust via setModalContent(title, html, meta).
  • Ordering: Supply numeric order per content row (JSON) or add an “Order” column (HTML).
  • Key labels: Control human-readable field names through query2 mapping.

Quick Start Checklist

  1. Include jQuery and Bootstrap 5 (bundle) on the page.
  2. Paste the provided HTML (slot + modal) and scripts.
  3. Expose GET /documentation/templateload?ids={id}&render=false (or your chosen route) on the server.
  4. Return either JSON (with query2 for labels + rows) or an HTML table with “Text”.
  5. Click the injected button → modal opens → docs render.
modal1
modal2
modal3
docs_javascript
new_issue_button.handlebars
shortcut_edit