Work Permit Template Setting
Last Updated: 2026-02-26 Status: In Review
Feature Summary
- Manage work permit templates (ต้นแบบใบอนุญาตปฏิบัติงาน) for the employer
- Configure pre-work checklist items per permit type
- Configure PPE (Personal Protective Equipment) items per permit type
- Set default PPE selections for new work permit forms
- Activate/deactivate templates to control availability when creating work permits
Role Matrix
| Action | Admin | Safety Officer | Purchasing | Work Owner | Workspace Owner | Contractor |
|---|---|---|---|---|---|---|
| View all templates | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Create template | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Edit template | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Delete template | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
Location
Tools > กำหนดค่า > ต้นแบบใบอนุญาตปฏิบัติงาน
Template Structure
Each work permit template contains:
| Section | Description |
|---|---|
| Basic Info | Name (Thai/English), icon, sort order, active status |
| Checklist Items | Pre-work checklist items (รายการตรวจสอบก่อนปฏิบัติงาน) with Thai/English names |
| PPE Items | Personal protective equipment items with Thai/English names and default checked flag |
Icon
Each template has an icon displayed in the template list and permit type selection dialog. Icons can be:
| Type | Examples | How it works |
|---|---|---|
| Material Icon | build, local_fire_department, bolt | Rendered via <mat-icon> |
| Unicode / Emoji | ☢, ⚡, 🔥 | Rendered as plain text (detected by isUnicodeIcon() helper) |
The form provides preset Material Icons (16) and preset Emoji (16), plus a custom input field for any Unicode character or Material Icon name.
Checklist Items Table
| Column | Thai Label | Description |
|---|---|---|
| ลำดับ | Sequence number | Auto-numbered |
| รายการ (ภาษาไทย) | Item name (Thai) | Required |
| รายการ (ภาษาอังกฤษ) | Item name (English) | Required |
PPE Items Table
| Column | Thai Label | Description |
|---|---|---|
| ลำดับ | Sequence number | Auto-numbered |
| อุปกรณ์ (ภาษาไทย) | Equipment name (Thai) | Required |
| อุปกรณ์ (ภาษาอังกฤษ) | Equipment name (English) | Required |
| เลือกเป็นค่าเริ่มต้น | Default checked | Pre-selects PPE when creating new work permit forms |
Validation
When saving a template, the following rules are validated:
| Rule | Error Message |
|---|---|
| Thai name required | กรุณากรอกชื่อต้นแบบ (ภาษาไทย) |
| English name required | กรุณากรอกชื่อต้นแบบ (ภาษาอังกฤษ) |
Validation errors are shown in a dialog with row-by-row messages (same pattern as JSA workflow approval).
API Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /api/work-permit-templates/search | Search templates by keyword |
| GET | /api/work-permit-templates/get/{id} | Get single template by ID |
| POST | /api/work-permit-templates/save | Create or update template |
| POST | /api/work-permit-templates/remove | Soft delete template |
What to Test
Navigation & Access
- Admin can access the page from Tools > กำหนดค่า > ต้นแบบใบอนุญาตปฏิบัติงาน
- Safety Officer can access the page
- Other roles (Purchasing, Work Owner, Workspace Owner, Contractor) cannot see the menu card
List View
- Templates list shows all existing templates
- Table shows columns: #, ชื่อ (TH), ชื่อ (EN), รายการตรวจสอบ (count), PPE (count), สถานะ, Actions
- Search by keyword filters the list
- Click template name opens edit view
- 3-dot menu shows Edit and Delete options
- Refresh button reloads the list
Create Template
- Click "เพิ่มต้นแบบ" opens empty form
- Sort order auto-fills with next available number
- Active status defaults to ON
- Icon defaults to "build" (Material Icon)
- Can select icon from Material Icon presets or Emoji presets
- Can enter custom icon via text input
- Icon preview updates live when selecting/typing
- Can add checklist items with Thai/English names
- Can add PPE items with Thai/English names and default checked
- Save with empty Thai name shows validation dialog
- Save with empty English name shows validation dialog
- Save with both names filled succeeds with "บันทึกสำเร็จ" toast
- New template appears in list after navigating back
Edit Template
- Click edit on existing template loads the form with data
- All fields show current values (names, sort order, active status)
- Checklist items show current items
- PPE items show current items with correct default checked state
- Can add new checklist/PPE items
- Can remove existing checklist/PPE items
- Save persists all changes
- Items remain after save (no disappearing bug)
Delete Template
- Click delete shows confirmation dialog with template name
- Confirm removes the template
- Cancel keeps the template
- Deleted template no longer appears in list
Preview Dialog
- Click preview button on list toolbar → Opens preview dialog
- Preview shows template name, icon, checklist items, PPE items (read-only)
- Dialog closes on "ปิด" button
Permit Type Selection (Icon Integration)
- Create new Work Permit → Permit type selection dialog shows icons from templates
- Each permit type displays its configured icon (Material Icon or Unicode/Emoji)
- Icons match what was configured in the template setting
Unsaved Changes
- Make changes → Click back → Warning dialog appears
- Confirm back → Returns to list without saving
- Cancel back → Stays on form with changes intact
- Save → Click back → No warning (form is clean)