Files
2026-06-09 22:28:39 -07:00

1131 lines
60 KiB
HTML

{{define "title"}}{{T "app.title.assets"}}{{end}}
{{define "content"}}
{{if .FormMode}}
{{if .EditingItem}}
<!-- ================== ASSET EDIT / CREATE FORM ================== -->
<div class="page-header">
<div class="page-title">
<h1>{{T "items.edit.title_prefix"}}: {{.EditingItem.Name}}</h1>
<p>{{T "items.edit.subtitle"}}</p>
</div>
<div>
<a href="/admin" class="btn btn-secondary">{{T "common.cancel"}}</a>
</div>
</div>
<div class="card">
<form action="/admin/items/edit/{{.EditingItem.ID}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<h3 style="font-weight: 700; margin-bottom: 1.5rem; color: var(--color-brand-primary); border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem;">{{T "items.edit.basic_info"}}</h3>
<div class="form-grid form-grid--2-1">
<div class="form-group">
<label for="name" class="form-label">{{T "items.edit.asset_name"}}</label>
<input type="text" id="name" name="name" class="form-control" placeholder="e.g. Cordless Hammer Drill" value="{{.EditingItem.Name}}" required>
</div>
<div class="form-group">
<label for="quantity" class="form-label">{{T "items.edit.quantity"}}</label>
<input type="number" id="quantity" name="quantity" class="form-control" min="1" value="{{.EditingItem.Quantity}}" required>
</div>
</div>
<div class="form-group">
<label for="description" class="form-label">{{T "items.edit.description"}}</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. Brushless motor hammer drill, includes two 18V Li-ion batteries">{{.EditingItem.Description}}</textarea>
</div>
<div class="form-grid form-grid--3">
<div class="form-group">
<label for="model_number" class="form-label">{{T "items.edit.model_number"}}</label>
<input type="text" id="model_number" name="model_number" class="form-control" placeholder="e.g. DCD796" value="{{.EditingItem.ModelNumber}}">
</div>
<div class="form-group">
<label for="serial_number" class="form-label">{{T "items.edit.serial_number"}}</label>
<input type="text" id="serial_number" name="serial_number" class="form-control" placeholder="e.g. 2018-W42-9988" value="{{.EditingItem.SerialNumber}}">
</div>
<div class="form-group">
<label for="status" class="form-label">{{T "items.edit.status"}}</label>
<select id="status" name="status" class="form-control">
<option value="In Use" {{if eq .EditingItem.Status "In Use"}}selected{{end}}>{{T "status.in_use"}}</option>
<option value="In Storage" {{if eq .EditingItem.Status "In Storage"}}selected{{end}}>{{T "status.in_storage"}}</option>
<option value="Borrowed" {{if eq .EditingItem.Status "Borrowed"}}selected{{end}}>{{T "status.borrowed"}}</option>
<option value="Lost" {{if eq .EditingItem.Status "Lost"}}selected{{end}}>{{T "status.lost"}}</option>
<option value="Disposed" {{if eq .EditingItem.Status "Disposed"}}selected{{end}}>{{T "status.disposed"}}</option>
</select>
</div>
</div>
<div class="form-grid form-grid--2" style="margin-bottom: 2rem;">
<div class="form-group">
<label for="location_id" class="form-label">{{T "items.edit.location"}}</label>
<select id="location_id" name="location_id" class="form-control" required>
{{range .Locations}}
<option value="{{.ID}}" {{if $.EditingItem.LocationID.Valid}}{{if eq .ID $.EditingItem.LocationID.Int64}}selected{{end}}{{end}}>
{{.Name}}
</option>
{{end}}
</select>
</div>
<div class="form-group">
<label class="form-label">{{T "items.edit.tags"}}</label>
<div style="display: flex; flex-wrap: wrap; gap: 0.75rem; border: 1px solid var(--color-border); padding: 0.625rem; border-radius: var(--radius-sm); background-color: var(--color-bg-base); max-height: 110px; overflow-y: auto;">
{{range .Tags}}
<label style="display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; font-weight: 500; cursor: pointer;">
<input type="checkbox" name="tag_ids" value="{{.ID}}" data-tag-name="{{.Name}}" {{if hasTag $.EditingItem.Tags .ID}}checked{{end}}>
<span class="tag-pill" style="background-color: {{.Color}};">{{.Name}}</span>
</label>
{{end}}
</div>
</div>
</div>
<h3 style="font-weight: 700; margin-bottom: 1.5rem; color: var(--color-brand-primary); border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; margin-top: 2rem;">{{T "items.edit.purchase_warranty"}}</h3>
<div class="form-grid form-grid--4">
<div class="form-group">
<label for="purchase_price" class="form-label">{{T "items.edit.purchase_price"}}</label>
<input type="number" id="purchase_price" name="purchase_price" class="form-control" step="0.01" min="0" placeholder="e.g. 149.99" value="{{if .EditingItem.PurchasePrice.Valid}}{{.EditingItem.PurchasePrice.Float64}}{{end}}">
</div>
<div class="form-group">
<label for="purchase_date" class="form-label">{{T "items.edit.purchase_date"}}</label>
<input type="date" id="purchase_date" name="purchase_date" class="form-control" value="{{if .EditingItem.PurchaseDate.Valid}}{{.EditingItem.PurchaseDate.String}}{{end}}">
</div>
<div class="form-group">
<label for="warranty_months" class="form-label">{{T "items.edit.warranty_months"}}</label>
<input type="number" id="warranty_months" name="warranty_months" class="form-control" min="0" placeholder="e.g. 24" value="{{if .EditingItem.WarrantyMonths.Valid}}{{.EditingItem.WarrantyMonths.Int64}}{{end}}">
</div>
<div class="form-group">
<label for="supplier" class="form-label">{{T "items.edit.supplier"}}</label>
<input type="text" id="supplier" name="supplier" class="form-control" placeholder="e.g. Home Depot" value="{{.EditingItem.Supplier}}">
</div>
</div>
<h3 style="font-weight: 700; margin-bottom: 1.5rem; color: var(--color-brand-primary); border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; margin-top: 2rem;">{{T "items.edit.docs_visuals"}}</h3>
<div class="form-grid form-grid--2">
<div class="form-group">
<label for="image" class="form-label">{{T "items.edit.photo"}}</label>
<input type="file" id="image" name="image" class="form-control" accept="image/*">
{{if .EditingItem.ImagePath}}
<span style="font-size: 0.8rem; color: var(--color-brand-primary); margin-top: 0.25rem; display: block;">{{T "items.edit.active_image"}}: {{.EditingItem.ImagePath}}</span>
{{end}}
</div>
<div class="form-group">
<label for="receipt" class="form-label">{{T "items.edit.receipt"}}</label>
<input type="file" id="receipt" name="receipt" class="form-control" accept="image/*,application/pdf">
{{if .EditingItem.ReceiptPath}}
<span style="font-size: 0.8rem; color: var(--color-brand-primary); margin-top: 0.25rem; display: block;">{{T "items.edit.active_receipt"}}: {{.EditingItem.ReceiptPath}}</span>
{{end}}
</div>
</div>
<h3 style="font-weight: 700; margin-bottom: 0.5rem; color: var(--color-brand-primary); border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; margin-top: 2rem;">{{T "items.edit.custom_fields"}}</h3>
<p style="font-size: 0.8rem; color: var(--color-text-muted); margin-bottom: 1rem;">{{T "items.edit.custom_fields_help"}}</p>
<div class="form-group" style="margin-bottom: 2.5rem;">
<label for="custom_fields" class="form-label">{{T "items.edit.custom_fields_editor"}}</label>
<textarea id="custom_fields" name="custom_fields" class="form-control" rows="4" placeholder="Battery: 18v&#10;MotorType: Brushless">{{.CustomFieldsRaw}}</textarea>
</div>
<button type="submit" class="btn btn-primary" style="padding: 0.75rem 2rem; font-size: 1rem;">
{{T "common.save"}}
</button>
</form>
</div>
{{else}}
<!-- ================== PREMIUM ADD ASSET WIZARD ================== -->
<div class="page-header">
<div class="page-title">
<h1>{{T "wizard.title"}}</h1>
<p>{{T "wizard.subtitle"}}</p>
</div>
<div>
<a href="/admin" class="btn btn-secondary">{{T "common.cancel"}}</a>
</div>
</div>
<!-- Progress Steps -->
<div class="wizard-progress-bar">
<div class="wizard-step active" id="progress-step-1">
<span class="step-num">1</span>
<span class="step-label">{{T "wizard.step_category"}}</span>
</div>
<div class="wizard-line" id="progress-line-1"></div>
<div class="wizard-step" id="progress-step-2">
<span class="step-num">2</span>
<span class="step-label">{{T "wizard.step_item"}}</span>
</div>
<div class="wizard-line" id="progress-line-2"></div>
<div class="wizard-step" id="progress-step-3">
<span class="step-num">3</span>
<span class="step-label">{{T "wizard.step_brand"}}</span>
</div>
</div>
<!-- Wizard Card Box -->
<div class="card" style="padding: 2.25rem;">
<!-- Hidden Form to submit the selection -->
<form id="wizard-form" action="/admin/items/new" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<input type="hidden" name="wizard_flow" value="true">
<input type="hidden" id="input-category" name="category" value="">
<input type="hidden" id="input-item" name="item" value="">
<input type="hidden" id="input-brand" name="brand" value="">
</form>
<!-- Back Button Navigation -->
<div style="margin-bottom: 2rem; display: none;" id="wizard-back-wrapper">
<button type="button" class="btn btn-secondary" id="btn-wizard-back" style="padding: 0.5rem 1rem; font-size: 0.85rem; border-radius: var(--radius-sm);">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width: 14px; height: 14px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" />
</svg>
{{T "wizard.back"}}
</button>
</div>
<!-- Step 1: Category Screen -->
<div class="wizard-screen active" id="screen-category">
<h3 class="wizard-screen-title">{{T "wizard.category_question"}}</h3>
<div class="category-grid" id="category-grid-container">
<!-- Loaded dynamically via JS -->
</div>
</div>
<!-- Step 2: Item Screen -->
<div class="wizard-screen" id="screen-item">
<h3 class="wizard-screen-title" id="item-screen-heading"></h3>
<div class="pills-grid" id="item-grid-container">
<!-- Loaded dynamically via JS -->
</div>
</div>
<!-- Step 3: Brand Screen -->
<div class="wizard-screen" id="screen-brand">
<h3 class="wizard-screen-title" id="brand-screen-heading"></h3>
<div class="pills-grid" id="brand-grid-container">
<!-- Loaded dynamically via JS -->
</div>
</div>
</div>
<!-- Styles specific to the Wizard to avoid polluting main theme -->
<style>
.wizard-progress-bar {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 2.5rem;
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.wizard-step {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
position: relative;
z-index: 10;
transition: all 0.3s ease;
}
.wizard-step .step-num {
width: 36px;
height: 36px;
border-radius: 50%;
background-color: var(--color-bg-base);
border: 2px solid var(--color-border);
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
color: var(--color-text-light);
font-size: 0.95rem;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.wizard-step .step-label {
font-size: 0.85rem;
font-weight: 600;
color: var(--color-text-light);
transition: all 0.3s ease;
}
.wizard-step.active .step-num {
background-color: var(--color-brand-primary);
border-color: var(--color-brand-primary);
color: white;
box-shadow: 0 4px 10px rgba(217, 119, 6, 0.3);
}
.wizard-step.active .step-label {
color: var(--color-brand-primary);
font-weight: 700;
}
.wizard-step.completed .step-num {
background-color: #10b981;
border-color: #10b981;
color: white;
box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}
.wizard-step.completed .step-label {
color: #10b981;
}
.wizard-line {
flex-grow: 1;
height: 3px;
background-color: var(--color-border);
margin: 0 -0.5rem;
transform: translateY(-13px);
transition: background-color 0.3s ease;
}
.wizard-line.completed {
background-color: #10b981;
}
.wizard-line.active {
background-color: var(--color-brand-primary);
}
.wizard-screen {
display: none;
animation: wizardFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.wizard-screen.active {
display: block;
}
@keyframes wizardFadeIn {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.wizard-screen-title {
font-size: 1.35rem;
font-weight: 700;
margin-bottom: 2rem;
color: var(--color-text-main);
text-align: center;
}
/* Categories Grid of big square cards */
.category-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: 1.25rem;
}
.category-card {
aspect-ratio: 1/1;
background-color: var(--color-bg-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-md);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1.5rem 1rem;
cursor: pointer;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: var(--shadow-sm);
text-align: center;
}
.category-card:hover {
transform: translateY(-4px);
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.08);
border-color: var(--cat-color);
background-color: var(--cat-color-bg);
}
.category-badge {
width: 48px;
height: 48px;
border-radius: 12px;
background-color: var(--cat-color-badge-bg);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.4rem;
font-weight: 700;
color: var(--cat-color);
margin-bottom: 1rem;
transition: transform 0.2s ease;
}
.category-card:hover .category-badge {
transform: scale(1.1);
}
.category-name {
font-size: 0.95rem;
font-weight: 600;
color: var(--color-text-main);
}
/* Sub-screen pill grid */
.pills-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
}
.pill-button {
background-color: var(--color-bg-surface);
border: 1.5px solid var(--color-border);
border-radius: var(--radius-sm);
padding: 1rem 1.25rem;
font-size: 1rem;
font-weight: 600;
color: var(--color-text-main);
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: var(--shadow-sm);
}
.pill-button:hover {
border-color: var(--color-brand-primary);
background-color: #fefaf0;
color: var(--color-brand-primary);
transform: translateX(2px);
}
.pill-button svg {
width: 16px;
height: 16px;
color: var(--color-text-light);
transition: transform 0.2s ease, color 0.2s ease;
}
.pill-button:hover svg {
transform: translateX(3px);
color: var(--color-brand-primary);
}
.pill-button.other-pill {
border-style: dashed;
border-width: 2px;
background-color: var(--color-bg-base);
color: var(--color-text-muted);
}
.pill-button.other-pill:hover {
border-color: var(--color-text-muted);
background-color: var(--color-border);
color: var(--color-text-main);
}
</style>
<script>
(function() {
// Parse catalog JSON data dynamically injected by handler
const catalog = {{safeJS .CatalogJSON}};
// i18n strings for the wizard
const __t = {
itemQuestion: "{{T "wizard.item_question"}}",
brandQuestion: "{{T "wizard.brand_question"}}",
otherUnlisted: "{{T "wizard.other_unlisted"}}",
otherItem: "{{T "wizard.other_item"}}",
otherBrand: "{{T "wizard.other_brand"}}"
};
let currentStep = 1;
let selectedCategory = null;
let selectedItem = null;
let selectedBrand = null;
// Helper to get element by ID at runtime
const getEl = (id) => document.getElementById(id);
// 1. Initial render of Categories screen
function initWizard() {
const categoryGrid = getEl('category-grid-container');
if (!categoryGrid) {
console.warn("category-grid-container not in DOM yet. Retrying...");
setTimeout(initWizard, 30);
return;
}
categoryGrid.innerHTML = '';
catalog.forEach(cat => {
// Create beautiful HSL tints using the custom category color
const color = cat.color || '#d97706';
// Simple helper to convert HEX to RGBA / transparent tint
const r = parseInt(color.slice(1, 3), 16);
const g = parseInt(color.slice(3, 5), 16);
const b = parseInt(color.slice(5, 7), 16);
const card = document.createElement('div');
card.className = 'category-card';
card.style.setProperty('--cat-color', color);
card.style.setProperty('--cat-color-bg', `rgba(${r}, ${g}, ${b}, 0.04)`);
card.style.setProperty('--cat-color-badge-bg', `rgba(${r}, ${g}, ${b}, 0.1)`);
// Pick beautiful stylized icon or stylized letter badge
const initial = cat.name.charAt(0);
card.innerHTML = `
<div class="category-badge">${initial}</div>
<div class="category-name">${cat.name}</div>
`;
card.addEventListener('click', () => {
selectCategory(cat);
});
categoryGrid.appendChild(card);
});
// Add "Other" selection Card at first layer
const otherCard = document.createElement('div');
otherCard.className = 'category-card';
otherCard.style.setProperty('--cat-color', 'var(--color-text-muted)');
otherCard.style.setProperty('--cat-color-bg', 'var(--color-bg-base)');
otherCard.style.setProperty('--cat-color-badge-bg', 'var(--color-border)');
otherCard.style.borderStyle = 'dashed';
otherCard.style.borderWidth = '2px';
otherCard.innerHTML = `
<div class="category-badge" style="font-weight: 500;">+</div>
<div class="category-name">${__t.otherUnlisted}</div>
`;
otherCard.addEventListener('click', () => {
selectCategory({ id: 'Other', name: 'Other', items: [] });
});
categoryGrid.appendChild(otherCard);
}
// 2. Category selection logic
function selectCategory(cat) {
selectedCategory = cat.id;
const inputCategory = getEl('input-category');
if (inputCategory) inputCategory.value = cat.id;
if (cat.id === 'Other') {
// Instantly submit with Other fallback
const inputItem = getEl('input-item');
const inputBrand = getEl('input-brand');
const wizardForm = getEl('wizard-form');
if (inputItem) inputItem.value = 'Other';
if (inputBrand) inputBrand.value = 'Other';
if (wizardForm) wizardForm.submit();
return;
}
renderItems(cat);
goToStep(2);
}
// 3. Render Items Screen
function renderItems(cat) {
const heading = getEl('item-screen-heading');
if (heading) heading.textContent = __t.itemQuestion.replace('%s', cat.name);
const itemGrid = getEl('item-grid-container');
if (!itemGrid) return;
itemGrid.innerHTML = '';
cat.items.forEach(item => {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'pill-button';
btn.innerHTML = `
<span>${item.name}</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
</svg>
`;
btn.addEventListener('click', () => {
selectItem(cat, item);
});
itemGrid.appendChild(btn);
});
// Add "Other" option in Layer 2
const otherBtn = document.createElement('button');
otherBtn.type = 'button';
otherBtn.className = 'pill-button other-pill';
otherBtn.innerHTML = `
<span>${__t.otherItem}</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
`;
otherBtn.addEventListener('click', () => {
selectItem(cat, { name: 'Other', brands: [] });
});
itemGrid.appendChild(otherBtn);
}
// 4. Item selection logic
function selectItem(cat, item) {
selectedItem = item.name;
const inputItem = getEl('input-item');
if (inputItem) inputItem.value = item.name;
if (item.name === 'Other') {
// Instantly submit with Other fallback
const inputBrand = getEl('input-brand');
const wizardForm = getEl('wizard-form');
if (inputBrand) inputBrand.value = 'Other';
if (wizardForm) wizardForm.submit();
return;
}
renderBrands(item);
goToStep(3);
}
// 5. Render Brands Screen
function renderBrands(item) {
const heading = getEl('brand-screen-heading');
if (heading) heading.textContent = __t.brandQuestion.replace('%s', item.name);
const brandGrid = getEl('brand-grid-container');
if (!brandGrid) return;
brandGrid.innerHTML = '';
item.brands.forEach(brand => {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'pill-button';
btn.innerHTML = `
<span>${brand}</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
`;
btn.addEventListener('click', () => {
selectBrand(brand);
});
brandGrid.appendChild(btn);
});
// Add "Other" option in Layer 3
const otherBtn = document.createElement('button');
otherBtn.type = 'button';
otherBtn.className = 'pill-button other-pill';
otherBtn.innerHTML = `
<span>${__t.otherBrand}</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
`;
otherBtn.addEventListener('click', () => {
selectBrand('Other');
});
brandGrid.appendChild(otherBtn);
}
// 6. Brand selection logic (final layer)
function selectBrand(brand) {
selectedBrand = brand;
const inputBrand = getEl('input-brand');
if (inputBrand) inputBrand.value = brand;
// Submit the form immediately to complete creation
const wizardForm = getEl('wizard-form');
if (wizardForm) wizardForm.submit();
}
// 7. Navigation Step Controller
function goToStep(step) {
currentStep = step;
const screenCategory = getEl('screen-category');
const screenItem = getEl('screen-item');
const screenBrand = getEl('screen-brand');
const step1 = getEl('progress-step-1');
const step2 = getEl('progress-step-2');
const step3 = getEl('progress-step-3');
const line1 = getEl('progress-line-1');
const line2 = getEl('progress-line-2');
const backBtnWrapper = getEl('wizard-back-wrapper');
if (!screenCategory || !screenItem || !screenBrand || !step1 || !step2 || !step3 || !line1 || !line2 || !backBtnWrapper) {
console.warn("Some wizard elements missing during goToStep. Retrying step set...");
setTimeout(() => goToStep(step), 20);
return;
}
// Hide all screens
screenCategory.classList.remove('active');
screenItem.classList.remove('active');
screenBrand.classList.remove('active');
// Update steps indicator class
step1.className = 'wizard-step';
step2.className = 'wizard-step';
step3.className = 'wizard-step';
line1.className = 'wizard-line';
line2.className = 'wizard-line';
if (step === 1) {
screenCategory.classList.add('active');
step1.classList.add('active');
backBtnWrapper.style.display = 'none';
} else if (step === 2) {
screenItem.classList.add('active');
step1.classList.add('completed');
step2.classList.add('active');
line1.classList.add('completed');
backBtnWrapper.style.display = 'block';
} else if (step === 3) {
screenBrand.classList.add('active');
step1.classList.add('completed');
step2.classList.add('completed');
step3.classList.add('active');
line1.classList.add('completed');
line2.classList.add('completed');
backBtnWrapper.style.display = 'block';
}
}
// Bind back button hook
function initBackBtn() {
const backBtn = getEl('btn-wizard-back');
if (!backBtn) {
setTimeout(initBackBtn, 30);
return;
}
backBtn.onclick = () => {
if (currentStep > 1) {
goToStep(currentStep - 1);
}
};
}
// Run initialization
initWizard();
initBackBtn();
})();
</script>
{{end}}
{{else if .ViewMode}}
<!-- ================== ASSET VIEW DETAILS MODE ================== -->
<div class="page-header">
<div class="page-title">
<span style="color: var(--color-text-light); font-size: 0.85rem; font-weight: 600; text-transform: uppercase;">{{T "items.detail.title"}}</span>
<h1 style="margin-top: 0.15rem;">{{.Item.Name}}</h1>
</div>
<div style="display: flex; gap: 0.5rem;">
{{if .IsAuthenticated}}
<a href="/admin/items/edit/{{.Item.ID}}" class="btn btn-primary">
{{T "items.detail.edit"}}
</a>
<a href="/admin" class="btn btn-secondary">
{{T "items.detail.back_list"}}
</a>
{{else}}
<a href="{{with .CurrentLocation}}/{{.Slug}}{{else}}/default-room{{end}}" class="btn btn-secondary">
{{T "items.detail.back_dir"}}
</a>
{{end}}
</div>
</div>
<div class="detail-grid" {{if not .IsAuthenticated}}style="grid-template-columns: 1fr;"{{end}}>
<!-- Detail Main Section -->
<div class="detail-main">
<!-- Basic info card -->
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem;">
<div>
<div class="status-pill {{if eq .Item.Status "In Use"}}in-use{{else if eq .Item.Status "In Storage"}}in-storage{{else if eq .Item.Status "Borrowed"}}borrowed{{else if eq .Item.Status "Lost"}}lost{{else}}disposed{{end}}">
{{.Item.Status}}
</div>
{{if .IsAuthenticated}}
<span style="margin-left: 0.5rem; font-size: 0.9rem; color: var(--color-text-muted); font-weight: 500;">
{{T "items.detail.quantity"}}: <strong>{{.Item.Quantity}}</strong>
</span>
{{end}}
</div>
{{if .IsAuthenticated}}
<div class="tag-list">
{{range .Item.Tags}}
<a href="/admin?tag={{.ID}}" style="text-decoration: none;"><span class="tag-pill" style="background-color: {{.Color}};">{{.Name}}</span></a>
{{end}}
</div>
{{end}}
</div>
<h3 style="font-weight: 700; font-size: 1.15rem; margin-bottom: 0.75rem;">{{T "items.detail.description"}}</h3>
<p style="color: var(--color-text-muted); {{if .IsAuthenticated}}margin-bottom: 1.75rem;{{else}}margin-bottom: 0.5rem;{{end}}">
{{if .Item.Description}}{{.Item.Description}}{{else}}<em>{{T "items.detail.no_description"}}</em>{{end}}
</p>
{{if .IsAuthenticated}}
<div class="form-grid form-grid--2" style="border-top: 1px solid var(--color-border); padding-top: 1.5rem;">
<div>
<span style="font-size: 0.85rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.model_number"}}</span>
<span style="font-weight: 500; font-size: 1.05rem;">{{if .Item.ModelNumber}}{{.Item.ModelNumber}}{{else}}--{{end}}</span>
</div>
<div>
<span style="font-size: 0.85rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.serial_number"}}</span>
<span style="font-weight: 500; font-size: 1.05rem; font-family: monospace;">{{if .Item.SerialNumber}}{{.Item.SerialNumber}}{{else}}--{{end}}</span>
</div>
</div>
{{end}}
</div>
{{if .IsAuthenticated}}
<!-- Image Visuals and Receipts -->
<div class="item-visuals">
<div class="card" style="padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem;">
<h4 style="font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted); border-bottom:1px solid var(--color-border); padding-bottom:0.25rem;">{{T "items.detail.photo"}}</h4>
<div class="visual-box">
{{if .Item.ImagePath}}
<img src="/uploads/{{.Item.ImagePath}}" alt="Asset Photo">
{{else}}
<div class="visual-placeholder">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width: 48px; height: 48px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V6.75zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z" />
</svg>
<span>{{T "items.detail.no_photo"}}</span>
</div>
{{end}}
</div>
</div>
<div class="card" style="padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem;">
<h4 style="font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted); border-bottom:1px solid var(--color-border); padding-bottom:0.25rem;">{{T "items.detail.receipt"}}</h4>
<div class="visual-box">
{{if .Item.ReceiptPath}}
<img src="/uploads/{{.Item.ReceiptPath}}" alt="Receipt">
<div style="position: absolute; bottom: 0.5rem; right: 0.5rem;">
<a href="/uploads/{{.Item.ReceiptPath}}" target="_blank" class="btn btn-secondary" style="padding: 0.25rem 0.5rem; font-size: 0.75rem; background: white;">
{{T "items.detail.open_doc"}}
</a>
</div>
{{else}}
<div class="visual-placeholder">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width: 48px; height: 48px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
</svg>
<span>{{T "items.detail.no_receipt"}}</span>
</div>
{{end}}
</div>
</div>
</div>
<!-- Custom fields card -->
<div class="card">
<h3 style="font-weight: 700; font-size: 1.15rem; margin-bottom: 1.25rem; color: var(--color-brand-primary); border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem;">{{T "items.detail.custom_fields"}}</h3>
{{if .CustomFieldsMap}}
<div class="data-table-wrapper">
<table class="data-table">
<tbody>
{{range $key, $value := .CustomFieldsMap}}
<tr>
<td style="font-weight: 600; width: 200px; color: var(--color-text-muted); padding: 0.75rem 0.5rem;">{{$key}}</td>
<td style="font-family: monospace; font-size: 0.95rem; padding: 0.75rem 0.5rem;">{{$value}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{else}}
<p style="color: var(--color-text-light); font-size: 0.95rem; font-style: italic;">{{T "items.detail.no_custom"}}</p>
{{end}}
</div>
{{end}}
</div>
{{if .IsAuthenticated}}
<!-- Detail Sidebar Section -->
<div class="detail-sidebar">
<!-- QR code card -->
<div class="card qr-card">
<h4 style="font-weight: 700; color: var(--color-text-muted); font-size: 1.05rem;">{{T "items.detail.qr"}}</h4>
{{if .Item.ShortSlug}}
<img class="qr-image" src="/admin/qr/{{.Item.ShortSlug}}" alt="QR Code">
<code style="font-family: monospace; background-color: var(--color-bg-base); padding: 0.35rem 0.75rem; border-radius: 4px; border: 1px solid var(--color-border); font-weight: 600; font-size: 0.95rem;">
s/{{.Item.ShortSlug}}
</code>
<a href="/admin/qr/{{.Item.ShortSlug}}" download="{{.Item.Name}}_QR.png" class="btn btn-secondary" style="width: 100%; font-size: 0.85rem;">
{{T "items.detail.download_qr"}}
</a>
{{else}}
<span style="color: var(--color-text-light); font-size: 0.85rem;">{{T "items.detail.no_short_url"}}</span>
{{end}}
</div>
<!-- Purchase particulars card -->
<div class="card" style="display: flex; flex-direction: column; gap: 1.25rem;">
<h4 style="font-weight: 700; color: var(--color-text-muted); font-size: 1.05rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; margin-bottom: 0.25rem;">{{T "items.detail.purchase_context"}}</h4>
<div>
<span style="font-size: 0.75rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.purchase_price"}}</span>
<span style="font-weight: 700; font-size: 1.35rem; color: var(--color-brand-primary);">
{{if .Item.PurchasePrice.Valid}}{{formatPrice .Item.PurchasePrice}}{{else}}--{{end}}
</span>
</div>
<div>
<span style="font-size: 0.75rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.supplier"}}</span>
<span style="font-weight: 600; font-size: 1rem;">
{{if .Item.Supplier}}{{.Item.Supplier}}{{else}}--{{end}}
</span>
</div>
<div>
<span style="font-size: 0.75rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.purchase_date"}}</span>
<span style="font-weight: 600; font-size: 1rem;">
{{if .Item.PurchaseDate.Valid}}{{formatDate .Item.PurchaseDate}}{{else}}--{{end}}
</span>
</div>
<div>
<span style="font-size: 0.75rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.warranty_period"}}</span>
<span style="font-weight: 600; font-size: 1rem;">
{{if .Item.WarrantyMonths.Valid}}{{.Item.WarrantyMonths.Int64}} {{T "items.detail.months"}}{{else}}--{{end}}
</span>
</div>
<div>
<span style="font-size: 0.75rem; color: var(--color-text-light); text-transform: uppercase; font-weight: 600; display: block;">{{T "items.detail.assigned_location"}}</span>
<span style="font-weight: 600; font-size: 1rem;">
{{if .Item.LocationName.Valid}}
<a href="/{{.Item.LocationSlug.String}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Item.LocationName.String}}</a>
{{else}}
<span style="color: var(--color-text-light); font-style: italic; font-weight: 500;">{{T "common.unassigned"}}</span>
{{end}}
</span>
</div>
</div>
</div>
{{end}}
</div>
{{else}}
<!-- ================== DEFAULT: MAIN INVENTORY LIST ================== -->
<div class="page-header">
<div class="page-title">
<h1>{{T "items.title"}}</h1>
<p>{{T "items.subtitle"}}</p>
</div>
<div>
<a href="/admin/items/new" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width: 18px; height: 18px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
{{T "items.add"}}
</a>
</div>
</div>
<!-- Search & Filters -->
<form action="/admin" method="GET" class="filter-bar">
<div class="search-input-wrapper">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.604 10.604z" />
</svg>
<input type="text" name="search" class="form-control" placeholder="{{T "items.search_placeholder"}}" value="{{.SearchQuery}}">
</div>
<select name="status" class="form-control filter-select" onchange="this.form.submit()">
<option value="">{{T "items.all_statuses"}}</option>
<option value="In Use" {{if eq .SelectedStatus "In Use"}}selected{{end}}>{{T "status.in_use"}}</option>
<option value="In Storage" {{if eq .SelectedStatus "In Storage"}}selected{{end}}>{{T "status.in_storage"}}</option>
<option value="Borrowed" {{if eq .SelectedStatus "Borrowed"}}selected{{end}}>{{T "status.borrowed"}}</option>
<option value="Lost" {{if eq .SelectedStatus "Lost"}}selected{{end}}>{{T "status.lost"}}</option>
<option value="Disposed" {{if eq .SelectedStatus "Disposed"}}selected{{end}}>{{T "status.disposed"}}</option>
</select>
<select name="location" class="form-control filter-select" onchange="this.form.submit()">
<option value="">{{T "items.all_locations"}}</option>
{{range .Locations}}
<option value="{{.ID}}" {{if eq $.SelectedLocation .ID}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<select name="tag" class="form-control filter-select" onchange="this.form.submit()">
<option value="">{{T "items.all_tags"}}</option>
{{range .Tags}}
<option value="{{.ID}}" {{if eq $.SelectedTag .ID}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap; margin: 0 0.5rem;">
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
{{T "common.show_removed"}}
</label>
<button type="submit" class="btn btn-secondary">{{T "common.filter"}}</button>
{{if or .SearchQuery (or .SelectedStatus (or .SelectedLocation (or .SelectedTag .ShowRemoved)))}}
<a href="/admin" class="btn btn-secondary" style="padding: 0.625rem;">{{T "common.reset"}}</a>
{{end}}
</form>
<!-- Assets Inventory Table -->
<div class="card" style="padding: 0;">
<div class="data-table-wrapper">
<table class="data-table data-table--responsive">
<thead>
<tr>
<th style="width: 80px;">{{T "items.col.qr"}}</th>
<th>{{T "items.col.name"}}</th>
<th>{{T "items.col.location"}}</th>
<th>{{T "items.col.status"}}</th>
<th>{{T "items.col.quantity"}}</th>
<th>{{T "items.col.tags"}}</th>
<th style="width: 140px; text-align: right;">{{T "common.actions"}}</th>
</tr>
</thead>
<tbody>
{{if .Items}}
{{range .Items}}
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
<td data-label="{{T "items.col.qr"}}" style="text-align: center; vertical-align: middle;">
{{if .ShortSlug}}
<a href="javascript:void(0)" onclick="openQRModal('{{.ShortSlug}}', '{{.Name}}')">
<img src="/admin/qr/{{.ShortSlug}}" alt="QR Label" style="width: 42px; height: 42px; border: 1px solid var(--color-border); padding: 1px; border-radius: 4px; background: white; cursor: pointer;">
</a>
{{else}}
<span style="color: var(--color-text-light); font-size: 0.75rem;">--</span>
{{end}}
</td>
<td data-label="{{T "items.col.name"}}">
<div style="display: flex; flex-direction: column;">
<a href="/admin?view={{.ID}}" style="font-weight: 700; color: var(--color-text-main); text-decoration: none; font-size: 1.05rem;">
{{.Name}}
</a>
{{if .ModelNumber}}
<span style="color: var(--color-text-muted); font-size: 0.8rem; font-family: monospace;">{{T "items.model_prefix"}}: {{.ModelNumber}}</span>
{{end}}
</div>
</td>
<td data-label="{{T "items.col.location"}}">
{{if .LocationName.Valid}}
<span style="font-weight: 500; font-size: 0.95rem;">
<a href="/{{.LocationSlug.String}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.LocationName.String}}</a>
</span>
{{else}}
<span style="color: var(--color-text-light); font-style: italic; font-size: 0.9rem;">{{T "common.unassigned"}}</span>
{{end}}
</td>
<td data-label="{{T "items.col.status"}}">
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived">{{T "common.archived"}}</span>
{{else}}
<span class="status-pill {{if eq .Status "In Use"}}in-use{{else if eq .Status "In Storage"}}in-storage{{else if eq .Status "Borrowed"}}borrowed{{else if eq .Status "Lost"}}lost{{else}}disposed{{end}}">
{{.Status}}
</span>
{{end}}
</td>
<td data-label="{{T "items.col.quantity"}}" style="font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted); text-align: center;">
{{.Quantity}}
</td>
<td data-label="{{T "items.col.tags"}}">
<div class="tag-list">
{{range .Tags}}
<a href="/admin?tag={{.ID}}" style="text-decoration: none;"><span class="tag-pill" style="background-color: {{.Color}};">{{.Name}}</span></a>
{{end}}
</div>
</td>
<td data-label="{{T "common.actions"}}" class="actions-cell" style="text-align: right;">
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
{{if eq .LifecycleState "removed"}}
<!-- Soft removed item actions -->
<form action="/admin/items/restore/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
{{T "common.restore"}}
</button>
</form>
<form action="/admin/items/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('{{T "items.confirm_delete"}}')" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
{{T "common.delete_forever"}}
</button>
</form>
{{else}}
<!-- Active or Archived item actions -->
<a href="/admin?view={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
{{T "common.details"}}
</a>
{{if ne .LifecycleState "archived"}}
<a href="/admin/items/edit/{{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
{{T "common.edit"}}
</a>
{{end}}
<div class="actions-dropdown">
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
{{T "common.delete"}} <span style="font-size: 0.65rem;">▼</span>
</button>
<div class="actions-dropdown-menu">
<form action="/admin/items/remove/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-danger">
🗑 {{T "items.remove_item"}}
</button>
</form>
{{if ne .LifecycleState "archived"}}
<form action="/admin/items/archive/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-warning">
📦 {{T "items.archive_item"}}
</button>
</form>
{{end}}
</div>
</div>
{{end}}
</div>
</td>
</tr>
{{end}}
{{else}}
<tr>
<td colspan="7" style="text-align: center; color: var(--color-text-light); padding: 5rem 1rem;">
<div style="display: flex; flex-direction: column; align-items: center; gap: 1rem;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" style="width: 64px; height: 64px; color: var(--color-text-light);">
<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z" />
</svg>
<div>
<h3 style="font-weight:600; color:var(--color-text-muted);">{{T "items.empty.title"}}</h3>
<p style="font-size:0.9rem; margin-top:0.25rem;">{{T "items.empty.subtitle"}}</p>
</div>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
{{end}}
{{end}}