807 lines
24 KiB
Cheetah
807 lines
24 KiB
Cheetah
{{define "prompts"}}
|
|
<div class="sg-container">
|
|
<h1 style="font-size: 2.5rem; font-weight: 700;">Daily Check-in</h1>
|
|
<p class="intro" style="font-size: 1.15rem; font-weight: 300; line-height: 1.8;">Track daily measurements and observations</p>
|
|
|
|
{{if .Error}}<div class="msg msg-error">{{.Error}}</div>{{end}}
|
|
{{if .Success}}<div class="msg msg-success">{{.Success}}</div>{{end}}
|
|
|
|
<!-- Processing Toast -->
|
|
<div id="processing-toast" class="processing-toast">
|
|
<div class="processing-spinner"></div>
|
|
<span id="processing-text">Processing...</span>
|
|
</div>
|
|
|
|
<!-- TODAY Section -->
|
|
<div class="data-card">
|
|
<div class="prompt-section-header">
|
|
<div class="prompt-section-bar"></div>
|
|
<div class="prompt-section-info">
|
|
<div class="prompt-section-title">TODAY</div>
|
|
<div class="prompt-section-subtitle">{{.DueCount}} items due</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="prompt-list" id="today-list">
|
|
<!-- Entries (readonly) -->
|
|
{{range .Entries}}
|
|
<div class="prompt-item entry-item" data-entry-id="{{.ID}}">
|
|
<a href="#" class="prompt-dismiss" onclick="deleteEntry('{{.ID}}'); return false;" title="Delete">✕</a>
|
|
<div class="prompt-header">
|
|
<span class="prompt-question">{{.Question}}</span>
|
|
<span class="prompt-saved-time">{{.TimeFormatted}}</span>
|
|
</div>
|
|
<div class="prompt-body entry-readonly">
|
|
{{range .Fields}}
|
|
<div class="prompt-field-row">
|
|
{{if eq .Type "number"}}
|
|
<span class="entry-value">{{.Value}}</span>
|
|
{{if .Unit}}<span class="prompt-unit">{{.Unit}}</span>{{end}}
|
|
{{else if eq .Type "checkbox"}}
|
|
<span class="entry-check">{{if .Value}}✓{{else}}—{{end}}</span>
|
|
{{if .Label}}<span class="prompt-checkbox-label">{{.Label}}</span>{{end}}
|
|
{{else}}
|
|
<span class="entry-value">{{.Value}}</span>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
<div class="prompt-saved-footer">
|
|
<a href="#" class="prompt-edit" onclick="editEntry(this); return false;">edit</a>
|
|
</div>
|
|
{{if .SourceInput}}<div class="prompt-source">↳ "{{.SourceInput}}"</div>{{end}}
|
|
</div>
|
|
{{end}}
|
|
|
|
<!-- Due Prompts (interactive) -->
|
|
{{range .DuePrompts}}
|
|
<div class="prompt-item" data-prompt-id="{{.ID}}">
|
|
<a href="#" class="prompt-dismiss" onclick="showDismissConfirm(this, '{{.ID}}'); return false;" title="Don't ask again">✕</a>
|
|
<div class="dismiss-confirm">
|
|
<span>Stop tracking?</span>
|
|
<a href="#" onclick="confirmDismiss('{{.ID}}'); return false;">Yes</a>
|
|
<a href="#" onclick="hideDismissConfirm(this); return false;">No</a>
|
|
</div>
|
|
|
|
<!-- Saved state -->
|
|
<div class="prompt-saved" style="display: {{if .HasResponse}}block{{else}}none{{end}};">
|
|
<div class="prompt-saved-header">
|
|
<span class="prompt-question">{{.Question}}</span>
|
|
<span class="prompt-saved-value">{{.LastResponseRaw}}</span>
|
|
</div>
|
|
<div class="prompt-saved-footer">
|
|
<span class="prompt-saved-time">{{if .LastResponseFormatted}}{{.LastResponseFormatted}}{{else}}just now{{end}}</span>
|
|
<a href="#" class="prompt-edit" onclick="editPrompt(this); return false;">edit</a>
|
|
</div>
|
|
{{if .SourceInput}}<div class="prompt-source">↳ "{{.SourceInput}}"</div>{{end}}
|
|
</div>
|
|
|
|
<!-- Input form -->
|
|
<form class="prompt-form" data-prompt-id="{{.ID}}" data-is-freeform="{{.IsFreeform}}"{{if .HasResponse}} style="display: none;"{{end}}>
|
|
<div class="prompt-header">
|
|
<span class="prompt-question">{{.Question}}</span>
|
|
{{if .IsFreeform}}<span class="prompt-due">optional</span>{{else if .NextAsk}}<span class="prompt-due{{if .IsOverdue}} prompt-overdue{{end}}">{{.NextAskFormatted}}</span>{{end}}
|
|
</div>
|
|
|
|
<div class="prompt-body">
|
|
{{if .Fields}}
|
|
{{if eq (len .Fields) 1}}
|
|
{{with index .Fields 0}}
|
|
{{if eq .Type "number"}}
|
|
<div class="prompt-input-row">
|
|
<input type="number" name="field_{{.Key}}"
|
|
{{if .Min}}min="{{.Min}}"{{end}}
|
|
{{if .Max}}max="{{.Max}}"{{end}}
|
|
{{if .Step}}step="{{.Step}}"{{end}}
|
|
{{if .Value}}value="{{.Value}}"{{end}}
|
|
class="prompt-input-number">
|
|
{{if .Unit}}<span class="prompt-unit">{{.Unit}}</span>{{end}}
|
|
</div>
|
|
{{else if eq .Type "checkbox"}}
|
|
<label class="prompt-checkbox">
|
|
<input type="checkbox" name="field_{{.Key}}" value="1" {{if .Value}}checked{{end}}>
|
|
<span class="prompt-checkbox-box"></span>
|
|
<span class="prompt-checkbox-label">{{if .Label}}{{.Label}}{{else}}Yes{{end}}</span>
|
|
</label>
|
|
{{else if eq .Type "scale"}}
|
|
<div class="prompt-scale">
|
|
{{if .Label}}<span class="prompt-scale-label">{{.Label}}</span>{{end}}
|
|
<div class="prompt-scale-buttons">
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="0">0</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="1">1</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="2">2</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="3">3</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="4">4</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="5">5</button>
|
|
</div>
|
|
<input type="hidden" name="field_{{.Key}}" value="">
|
|
</div>
|
|
{{else if eq .Type "select"}}
|
|
<div class="prompt-field-inline">
|
|
{{if .Label}}<span class="prompt-scale-label">{{.Label}}</span>{{end}}
|
|
<select name="field_{{.Key}}" class="prompt-select">
|
|
<option value="">--</option>
|
|
{{range .Options}}<option value="{{.}}">{{.}}</option>{{end}}
|
|
</select>
|
|
</div>
|
|
{{else}}
|
|
<input type="text" name="field_{{.Key}}" value="{{.Value}}" class="prompt-input-text">
|
|
{{end}}
|
|
{{end}}
|
|
{{else}}
|
|
{{range .Fields}}
|
|
<div class="prompt-field-row">
|
|
{{if .Label}}<label class="prompt-field-label">{{.Label}}</label>{{end}}
|
|
{{if eq .Type "number"}}
|
|
<input type="number" name="field_{{.Key}}"
|
|
{{if .Min}}min="{{.Min}}"{{end}}
|
|
{{if .Max}}max="{{.Max}}"{{end}}
|
|
{{if .Step}}step="{{.Step}}"{{end}}
|
|
{{if .Value}}value="{{.Value}}"{{end}}
|
|
class="prompt-input-number">
|
|
{{if .Unit}}<span class="prompt-unit">{{.Unit}}</span>{{end}}
|
|
{{else if eq .Type "checkbox"}}
|
|
<label class="prompt-checkbox">
|
|
<input type="checkbox" name="field_{{.Key}}" value="1">
|
|
<span class="prompt-checkbox-box"></span>
|
|
</label>
|
|
{{else if eq .Type "scale"}}
|
|
<div class="prompt-scale-buttons">
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="0">0</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="1">1</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="2">2</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="3">3</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="4">4</button>
|
|
<button type="button" class="prompt-scale-btn" data-field="{{.Key}}" data-value="5">5</button>
|
|
</div>
|
|
<input type="hidden" name="field_{{.Key}}" value="">
|
|
{{else if eq .Type "select"}}
|
|
<select name="field_{{.Key}}" class="prompt-select">
|
|
<option value="">--</option>
|
|
{{range .Options}}<option value="{{.}}">{{.}}</option>{{end}}
|
|
</select>
|
|
{{else}}
|
|
<input type="text" name="field_{{.Key}}" class="prompt-input-text">
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
{{end}}
|
|
{{else}}
|
|
<div class="freeform-input-row">
|
|
<textarea name="response_raw" class="prompt-textarea" rows="2" placeholder="Type anything... (press Enter to submit)"></textarea>
|
|
<button type="button" class="freeform-submit-btn" onclick="submitFreeform(this)">→</button>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- UPCOMING Section -->
|
|
{{if .UpcomingPrompts}}
|
|
<div class="data-card" style="margin-top: 24px;">
|
|
<div class="prompt-section-header">
|
|
<div class="prompt-section-bar" style="background: var(--text-muted);"></div>
|
|
<div class="prompt-section-info">
|
|
<div class="prompt-section-title">UPCOMING</div>
|
|
<div class="prompt-section-subtitle">{{len .UpcomingPrompts}} scheduled</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="prompt-list">
|
|
{{range .UpcomingPrompts}}
|
|
<div class="prompt-item prompt-item-upcoming" data-prompt-id="{{.ID}}">
|
|
<a href="#" class="prompt-dismiss" onclick="showDismissConfirm(this, '{{.ID}}'); return false;" title="Don't ask again">✕</a>
|
|
<div class="dismiss-confirm">
|
|
<span>Stop tracking?</span>
|
|
<a href="#" onclick="confirmDismiss('{{.ID}}'); return false;">Yes</a>
|
|
<a href="#" onclick="hideDismissConfirm(this); return false;">No</a>
|
|
</div>
|
|
<div class="prompt-header">
|
|
<span class="prompt-question">{{.Question}}</span>
|
|
<span class="prompt-due">{{.NextAskFormatted}}</span>
|
|
</div>
|
|
{{if .LastResponseRaw}}
|
|
<div class="prompt-body">
|
|
<span class="prompt-last-value">Last: {{.LastResponseRaw}}</span>
|
|
</div>
|
|
{{end}}
|
|
{{if .SourceInput}}<div class="prompt-source">↳ "{{.SourceInput}}"</div>{{end}}
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
|
|
<div style="margin-top: 24px;">
|
|
<a href="/dossier/{{.TargetHex}}" class="btn btn-secondary">← Back to dossier</a>
|
|
</div>
|
|
|
|
{{template "footer"}}
|
|
</div>
|
|
|
|
<style>
|
|
.processing-toast {
|
|
display: none;
|
|
position: fixed;
|
|
top: 20px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
background: var(--text);
|
|
color: white;
|
|
padding: 12px 24px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
z-index: 1000;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
.processing-toast.show {
|
|
display: flex;
|
|
animation: toastIn 0.2s ease-out;
|
|
}
|
|
@keyframes toastIn {
|
|
from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
|
|
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
}
|
|
.processing-spinner {
|
|
width: 18px;
|
|
height: 18px;
|
|
border: 2px solid rgba(255,255,255,0.3);
|
|
border-top-color: white;
|
|
border-radius: 50%;
|
|
animation: spin 0.8s linear infinite;
|
|
}
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
.freeform-input-row {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-items: flex-start;
|
|
}
|
|
.freeform-input-row .prompt-textarea {
|
|
flex: 1;
|
|
}
|
|
.freeform-submit-btn {
|
|
padding: 8px 16px;
|
|
background: var(--accent);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1.1rem;
|
|
cursor: pointer;
|
|
transition: background 0.15s;
|
|
}
|
|
.freeform-submit-btn:hover {
|
|
background: #9a4408;
|
|
}
|
|
.prompt-section-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 16px 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
.prompt-section-bar {
|
|
width: 4px;
|
|
height: 36px;
|
|
background: var(--accent);
|
|
border-radius: 2px;
|
|
}
|
|
.prompt-section-title {
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.05em;
|
|
color: var(--text);
|
|
}
|
|
.prompt-section-subtitle {
|
|
font-size: 0.875rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-list {
|
|
padding: 0;
|
|
}
|
|
.prompt-item {
|
|
position: relative;
|
|
padding: 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
.prompt-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
.prompt-item-upcoming {
|
|
opacity: 0.6;
|
|
background: #fafafa;
|
|
}
|
|
.prompt-last-value {
|
|
font-size: 0.9rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-dismiss {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 20px;
|
|
font-size: 0.9rem;
|
|
color: #ccc;
|
|
text-decoration: none;
|
|
}
|
|
.prompt-dismiss:hover {
|
|
color: #999;
|
|
}
|
|
.dismiss-confirm {
|
|
display: none;
|
|
position: absolute;
|
|
top: 12px;
|
|
right: 12px;
|
|
background: white;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
padding: 8px 12px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
z-index: 10;
|
|
font-size: 0.85rem;
|
|
}
|
|
.dismiss-confirm span {
|
|
color: var(--text-muted);
|
|
}
|
|
.dismiss-confirm a {
|
|
margin-left: 8px;
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
}
|
|
.dismiss-confirm a:last-child {
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: 12px;
|
|
}
|
|
.prompt-question {
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
color: var(--text);
|
|
}
|
|
.prompt-due {
|
|
font-size: 0.875rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-overdue {
|
|
color: var(--accent);
|
|
}
|
|
.prompt-body {
|
|
margin-top: 8px;
|
|
}
|
|
.prompt-input-row {
|
|
display: flex;
|
|
align-items: flex-end;
|
|
gap: 8px;
|
|
}
|
|
.prompt-field-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
.prompt-field-row:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
.prompt-field-row .prompt-field-label {
|
|
min-width: 120px;
|
|
}
|
|
.prompt-field-label {
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
}
|
|
.prompt-input-number {
|
|
width: 80px;
|
|
padding: 8px 12px;
|
|
font-size: 1rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
text-align: right;
|
|
}
|
|
.prompt-input-number:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
.prompt-input-text {
|
|
width: 100%;
|
|
max-width: 300px;
|
|
padding: 8px 12px;
|
|
font-size: 1rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
}
|
|
.prompt-textarea {
|
|
width: 100%;
|
|
padding: 10px 12px;
|
|
font-size: 1rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
resize: vertical;
|
|
font-family: inherit;
|
|
}
|
|
.prompt-textarea:focus,
|
|
.prompt-input-text:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
.prompt-unit {
|
|
font-size: 0.875rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-checkbox {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
cursor: pointer;
|
|
}
|
|
.prompt-checkbox input {
|
|
display: none;
|
|
}
|
|
.prompt-checkbox-box {
|
|
width: 24px;
|
|
height: 24px;
|
|
border: 2px solid var(--border);
|
|
border-radius: 4px;
|
|
position: relative;
|
|
transition: all 0.15s;
|
|
}
|
|
.prompt-checkbox input:checked + .prompt-checkbox-box {
|
|
background: var(--accent);
|
|
border-color: var(--accent);
|
|
}
|
|
.prompt-checkbox input:checked + .prompt-checkbox-box::after {
|
|
content: '✓';
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
color: white;
|
|
font-size: 14px;
|
|
}
|
|
.prompt-checkbox-label {
|
|
font-size: 0.9rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-scale {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
}
|
|
.prompt-scale-label {
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
margin-right: 8px;
|
|
}
|
|
.prompt-scale-buttons {
|
|
display: flex;
|
|
gap: 4px;
|
|
}
|
|
.prompt-scale-btn {
|
|
width: 36px;
|
|
height: 36px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
background: white;
|
|
font-size: 0.9rem;
|
|
font-weight: 500;
|
|
color: var(--text);
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
}
|
|
.prompt-scale-btn:hover {
|
|
border-color: var(--accent);
|
|
background: #fff8f6;
|
|
}
|
|
.prompt-scale-btn.selected {
|
|
background: var(--accent);
|
|
border-color: var(--accent);
|
|
color: white;
|
|
}
|
|
.prompt-select {
|
|
padding: 8px 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
font-size: 0.95rem;
|
|
background: white;
|
|
min-width: 150px;
|
|
}
|
|
.prompt-select:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
.prompt-saved {
|
|
display: none;
|
|
}
|
|
.prompt-saved-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
padding-right: 40px;
|
|
gap: 20px;
|
|
}
|
|
.prompt-saved-value {
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
text-align: right;
|
|
max-width: 50%;
|
|
word-break: break-word;
|
|
}
|
|
.prompt-saved-footer {
|
|
margin-top: 8px;
|
|
display: flex;
|
|
gap: 12px;
|
|
align-items: center;
|
|
}
|
|
.prompt-saved-time {
|
|
font-size: 0.875rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.prompt-edit {
|
|
font-size: 0.875rem;
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
}
|
|
.prompt-source {
|
|
margin-top: 8px;
|
|
font-size: 0.85rem;
|
|
color: var(--text-muted);
|
|
font-style: italic;
|
|
}
|
|
.entry-item {
|
|
background: #f9f9f9;
|
|
}
|
|
.entry-readonly .prompt-field-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.entry-value {
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
color: var(--text);
|
|
}
|
|
.entry-check {
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
color: var(--accent);
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
const targetHex = '{{.TargetHex}}';
|
|
|
|
// Processing toast
|
|
function showProcessing(text) {
|
|
const toast = document.getElementById('processing-toast');
|
|
document.getElementById('processing-text').textContent = text || 'Processing...';
|
|
toast.classList.add('show');
|
|
}
|
|
function hideProcessing() {
|
|
document.getElementById('processing-toast').classList.remove('show');
|
|
}
|
|
|
|
// Initialize all prompt items
|
|
document.querySelectorAll('.prompt-item').forEach(item => {
|
|
const form = item.querySelector('.prompt-form');
|
|
if (!form) return;
|
|
|
|
// Handle blur for non-freeform
|
|
if (form.dataset.isFreeform !== 'true') {
|
|
item.addEventListener('focusout', (e) => {
|
|
setTimeout(() => {
|
|
if (!item.contains(document.activeElement)) {
|
|
saveItem(item);
|
|
}
|
|
}, 100);
|
|
});
|
|
}
|
|
|
|
// Checkbox auto-save
|
|
item.querySelectorAll('input[type=checkbox]').forEach(cb => {
|
|
cb.addEventListener('change', () => saveItem(item));
|
|
});
|
|
|
|
// Scale buttons
|
|
item.querySelectorAll('.prompt-scale-btn').forEach(btn => {
|
|
btn.addEventListener('click', () => {
|
|
btn.parentElement.querySelectorAll('.prompt-scale-btn').forEach(b => b.classList.remove('selected'));
|
|
btn.classList.add('selected');
|
|
const hidden = item.querySelector('input[name="field_' + btn.dataset.field + '"]');
|
|
if (hidden) hidden.value = btn.dataset.value;
|
|
saveItem(item);
|
|
});
|
|
});
|
|
|
|
// Select auto-save
|
|
item.querySelectorAll('.prompt-select').forEach(sel => {
|
|
sel.addEventListener('change', () => saveItem(item));
|
|
});
|
|
|
|
// Freeform Enter key
|
|
const textarea = item.querySelector('.prompt-textarea');
|
|
if (textarea && form.dataset.isFreeform === 'true') {
|
|
textarea.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
e.preventDefault();
|
|
submitFreeform(textarea);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
function showDismissConfirm(btn, promptId) {
|
|
const item = btn.closest('.prompt-item');
|
|
btn.style.display = 'none';
|
|
item.querySelector('.dismiss-confirm').style.display = 'block';
|
|
}
|
|
|
|
function hideDismissConfirm(link) {
|
|
const item = link.closest('.prompt-item');
|
|
item.querySelector('.dismiss-confirm').style.display = 'none';
|
|
item.querySelector('.prompt-dismiss').style.display = 'block';
|
|
}
|
|
|
|
async function confirmDismiss(promptId) {
|
|
try {
|
|
await fetch('/dossier/' + targetHex + '/prompts/respond', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
body: new URLSearchParams({ prompt_id: promptId, action: 'dismiss' })
|
|
});
|
|
document.querySelector('.prompt-item[data-prompt-id="' + promptId + '"]').style.display = 'none';
|
|
} catch (err) {
|
|
console.error('Dismiss failed:', err);
|
|
}
|
|
}
|
|
|
|
async function deleteEntry(entryId) {
|
|
if (!confirm('Delete this entry?')) return;
|
|
try {
|
|
await fetch('/dossier/' + targetHex + '/entries/' + entryId, { method: 'DELETE' });
|
|
document.querySelector('.entry-item[data-entry-id="' + entryId + '"]').style.display = 'none';
|
|
} catch (err) {
|
|
console.error('Delete failed:', err);
|
|
}
|
|
}
|
|
|
|
function editEntry(btn) {
|
|
alert('Entry editing coming soon');
|
|
}
|
|
|
|
function editPrompt(btn) {
|
|
const item = btn.closest('.prompt-item');
|
|
item.querySelector('.prompt-saved').style.display = 'none';
|
|
item.querySelector('.prompt-form').style.display = 'block';
|
|
item.querySelector('.prompt-form input:not([type=hidden]), .prompt-form textarea')?.focus();
|
|
}
|
|
|
|
async function submitFreeform(el) {
|
|
const item = el.closest('.prompt-item');
|
|
const form = item.querySelector('.prompt-form');
|
|
const textarea = form.querySelector('textarea[name="response_raw"]');
|
|
const value = textarea.value.trim();
|
|
|
|
if (!value) return;
|
|
|
|
showProcessing('Processing "' + value.substring(0, 30) + (value.length > 30 ? '...' : '') + '"');
|
|
|
|
try {
|
|
const res = await fetch('/dossier/' + targetHex + '/prompts/respond', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'Accept': 'application/json'
|
|
},
|
|
body: new URLSearchParams({
|
|
prompt_id: form.dataset.promptId,
|
|
action: 'respond',
|
|
response: '{}',
|
|
response_raw: value
|
|
})
|
|
});
|
|
|
|
if (res.ok) {
|
|
const data = await res.json();
|
|
textarea.value = '';
|
|
|
|
hideProcessing();
|
|
|
|
// Show success briefly then reload
|
|
if (data.new_prompt) {
|
|
showProcessing('Created: ' + data.new_prompt.question);
|
|
setTimeout(() => {
|
|
hideProcessing();
|
|
window.location.reload();
|
|
}, 1500);
|
|
}
|
|
} else {
|
|
hideProcessing();
|
|
}
|
|
} catch (err) {
|
|
console.error('Submit failed:', err);
|
|
hideProcessing();
|
|
}
|
|
}
|
|
|
|
async function saveItem(item) {
|
|
const form = item.querySelector('.prompt-form');
|
|
if (!form) return;
|
|
|
|
const promptId = form.dataset.promptId;
|
|
const inputs = form.querySelectorAll('input:not([type=hidden]), textarea');
|
|
|
|
const response = {};
|
|
let hasValue = false;
|
|
let displayValue = '';
|
|
let responseRaw = '';
|
|
|
|
inputs.forEach(input => {
|
|
const key = input.name.replace('field_', '').replace('response_raw', 'raw');
|
|
if (input.type === 'checkbox') {
|
|
if (input.checked) {
|
|
response[key] = true;
|
|
hasValue = true;
|
|
displayValue = '✓';
|
|
responseRaw = 'yes';
|
|
}
|
|
} else if (input.value) {
|
|
response[key] = input.value;
|
|
hasValue = true;
|
|
displayValue += (displayValue ? ' / ' : '') + input.value;
|
|
responseRaw += (responseRaw ? ' / ' : '') + input.value;
|
|
}
|
|
});
|
|
|
|
// Also check hidden inputs for scale values
|
|
form.querySelectorAll('input[type=hidden]').forEach(hidden => {
|
|
if (hidden.value) {
|
|
const key = hidden.name.replace('field_', '');
|
|
response[key] = hidden.value;
|
|
hasValue = true;
|
|
displayValue += (displayValue ? ' / ' : '') + hidden.value;
|
|
responseRaw += (responseRaw ? ' / ' : '') + hidden.value;
|
|
}
|
|
});
|
|
|
|
if (!hasValue) return;
|
|
|
|
try {
|
|
const res = await fetch('/dossier/' + targetHex + '/prompts/respond', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'Accept': 'application/json'
|
|
},
|
|
body: new URLSearchParams({
|
|
prompt_id: promptId,
|
|
action: 'respond',
|
|
response: JSON.stringify(response),
|
|
response_raw: responseRaw
|
|
})
|
|
});
|
|
|
|
if (res.ok) {
|
|
form.style.display = 'none';
|
|
const saved = item.querySelector('.prompt-saved');
|
|
if (saved) {
|
|
saved.querySelector('.prompt-saved-value').textContent = displayValue;
|
|
saved.style.display = 'block';
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error('Save failed:', err);
|
|
}
|
|
}
|
|
</script>
|
|
{{end}}
|