Add required battery_size to devices, filter install panels by size
This commit is contained in:
@@ -39,6 +39,12 @@
|
||||
<td style="border:none;">{{ device.device_type }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.battery_size %}
|
||||
<tr>
|
||||
<td style="padding:0.3rem 1rem 0.3rem 0;font-weight:600;color:#64748b;border:none;">Battery Size</td>
|
||||
<td style="border:none;">{{ device.battery_size }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.has_mixed_brands() %}
|
||||
<tr>
|
||||
<td style="padding:0.3rem 1rem 0.3rem 0;font-weight:600;color:#64748b;border:none;">Warning</td>
|
||||
@@ -79,7 +85,7 @@
|
||||
<div class="card">
|
||||
<h2>Install Batteries</h2>
|
||||
{% set free_slots = device.battery_slots - device.installed_count() %}
|
||||
<p class="text-muted" style="margin-bottom:0.75rem;">{{ free_slots }} slot(s) free</p>
|
||||
<p class="text-muted" style="margin-bottom:0.75rem;">{{ free_slots }} slot(s) free{% if device.battery_size %} — showing {{ device.battery_size }} batteries only{% endif %}</p>
|
||||
<form method="post" action="{{ url_for('device_install', device_id=device.id) }}">
|
||||
<div id="install-grid" style="display:grid;grid-template-columns:1fr auto;gap:0.4rem;max-width:400px;align-items:start;margin-bottom:0.5rem;">
|
||||
<span style="font-weight:600;font-size:0.85rem;color:#64748b;">Brand</span>
|
||||
@@ -115,6 +121,14 @@ function editTypeSelectChanged(sel) {
|
||||
input.style.display = 'none'; input.value = sel.value;
|
||||
}
|
||||
}
|
||||
function editSizeSelectChanged(sel) {
|
||||
var input = document.getElementById('edit-battery-size');
|
||||
if (sel.value === '__new__') {
|
||||
input.style.display = ''; input.value = ''; input.focus();
|
||||
} else {
|
||||
input.style.display = 'none'; input.value = sel.value;
|
||||
}
|
||||
}
|
||||
function editLocationSelectChanged(sel) {
|
||||
var input = document.getElementById('edit-location');
|
||||
if (sel.value === '__new__') {
|
||||
@@ -186,7 +200,7 @@ function addInstallRow() {
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Install Specific Battery</h2>
|
||||
<h2>Install Specific Battery{% if device.battery_size %} <small class="text-muted" style="font-weight:normal;font-size:0.8rem;">({{ device.battery_size }} only)</small>{% endif %}</h2>
|
||||
{% if available_batteries %}
|
||||
<form method="post" action="{{ url_for('device_install_one', device_id=device.id) }}">
|
||||
<div class="form-group">
|
||||
@@ -238,6 +252,29 @@ function addInstallRow() {
|
||||
placeholder="Enter device type"
|
||||
style="display:{% if device.device_type and device.device_type not in _preset_types %}''{% else %}none{% endif %};margin-top:0.4rem;">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Battery Size</label>
|
||||
{% set _preset_sizes = ['AA','AAA','C','D','9V','CR2032','CR2025','CR2016','18650','14500','16340','26650','LR44/AG13'] %}
|
||||
<select id="edit-battery-size-select" onchange="editSizeSelectChanged(this)">
|
||||
<option value="">— none —</option>
|
||||
{% for s in _preset_sizes %}
|
||||
<option value="{{ s }}" {% if device.battery_size == s %}selected{% endif %}>{{ s }}</option>
|
||||
{% endfor %}
|
||||
{% for s in device_battery_sizes|default([]) %}
|
||||
{% if s not in _preset_sizes %}
|
||||
<option value="{{ s }}" {% if device.battery_size == s %}selected{% endif %}>{{ s }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if device.battery_size and device.battery_size not in _preset_sizes and device.battery_size not in device_battery_sizes|default([]) %}
|
||||
<option value="{{ device.battery_size }}" selected>{{ device.battery_size }}</option>
|
||||
{% endif %}
|
||||
<option value="__new__">Other…</option>
|
||||
</select>
|
||||
<input type="text" id="edit-battery-size" name="battery_size"
|
||||
value="{{ device.battery_size or '' }}"
|
||||
placeholder="e.g. CR123A"
|
||||
style="display:{% if device.battery_size and device.battery_size not in _preset_sizes %}''{% else %}none{% endif %};margin-top:0.4rem;">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Location</label>
|
||||
<select id="edit-location-select" onchange="editLocationSelectChanged(this)">
|
||||
|
||||
Reference in New Issue
Block a user