diff --git a/app.py b/app.py
index f89e243..7db066c 100644
--- a/app.py
+++ b/app.py
@@ -28,7 +28,13 @@ def create_app(config_object="config"):
@app.route("/")
def dashboard():
batteries = db.query(Battery).order_by(Battery.label).all()
- return render_template("dashboard.html", batteries=batteries)
+ storage_locations = [
+ r[0] for r in db.query(Battery.storage_location)
+ .filter(Battery.storage_location.isnot(None))
+ .distinct().order_by(Battery.storage_location).all()
+ ]
+ return render_template("dashboard.html", batteries=batteries,
+ storage_locations=storage_locations)
# ------------------------------------------------------------------ #
# Battery — add
@@ -278,6 +284,21 @@ def create_app(config_object="config"):
b.brand = new_brand
db.commit()
flash(f"Updated brand to '{new_brand}' for {n} batter{'y' if n == 1 else 'ies'}.", "success")
+ elif action == "set_field":
+ field_name = request.form.get("field_name", "").strip()
+ field_value = request.form.get("field_value", "").strip() or None
+ allowed = {"brand", "storage_location"}
+ if field_name not in allowed:
+ flash("Invalid field.", "error")
+ return redirect(url_for("dashboard"))
+ if field_name == "brand" and not field_value:
+ flash("Brand name is required.", "error")
+ return redirect(url_for("dashboard"))
+ for b in batteries:
+ setattr(b, field_name, field_value)
+ db.commit()
+ label = field_name.replace("_", " ").title()
+ flash(f"Set {label} on {n} batter{'y' if n == 1 else 'ies'}.", "success")
else:
flash("Unknown action.", "error")
diff --git a/templates/dashboard.html b/templates/dashboard.html
index 89b29c0..beb10de 100644
--- a/templates/dashboard.html
+++ b/templates/dashboard.html
@@ -37,10 +37,36 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -127,5 +153,31 @@
updateToolbar();
});
}());
+
+function updateBulkField(sel) {
+ var field = sel.value;
+ document.getElementById('bulk-field-name').value = field;
+ document.getElementById('bulk-val-storage_location').style.display = field === 'storage_location' ? 'flex' : 'none';
+ document.getElementById('bulk-val-brand').style.display = field === 'brand' ? 'flex' : 'none';
+ document.getElementById('bulk-field-value-storage').disabled = (field !== 'storage_location');
+ document.getElementById('bulk-field-value-brand').disabled = (field !== 'brand');
+}
+// initialise disabled state on page load
+document.getElementById('bulk-field-value-brand').disabled = true;
+
+function bulkStorageChanged(sel) {
+ var text = document.getElementById('bulk-storage-text');
+ var hidden = document.getElementById('bulk-field-value-storage');
+ if (sel.value === '__new__') {
+ text.style.display = '';
+ text.value = '';
+ text.oninput = function() { hidden.value = text.value; };
+ text.focus();
+ hidden.value = '';
+ } else {
+ text.style.display = 'none';
+ hidden.value = sel.value;
+ }
+}
{% endblock %}