Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a3865ef24 | |||
| 96d45710ac | |||
| dd3d8649a7 | |||
| 1af2a2be06 | |||
| 8e5e434116 | |||
| 2f9a93ee65 | |||
| 91467a1e76 | |||
| 3840348a2d | |||
| cdb7319c56 | |||
| 08bea97f0f | |||
| 9164cd030d | |||
| 9227392787 | |||
| 4917c22ae3 | |||
| a2f2dd5a9e | |||
| faf270ff93 | |||
| beeb562ac4 | |||
| 0199957545 |
+139
-93
@@ -3313,8 +3313,8 @@ def api_library_items():
|
|||||||
ausleihungen_db = db['ausleihungen']
|
ausleihungen_db = db['ausleihungen']
|
||||||
|
|
||||||
query = {
|
query = {
|
||||||
'ItemType': {'$in': ['book', 'cd', 'dvd', 'schoolbook', 'schulbuch', 'Buch', 'Schulbuch']},
|
'ItemType': {'$in': ['book', 'cd', 'CD', 'DVD', 'dvd', 'schoolbook', 'schulbuch', 'Buch', 'Schulbuch']},
|
||||||
#'IsGroupedSubItem': {'$ne': True},
|
'IsGroupedSubItem': {'$ne': True},
|
||||||
'Deleted': {'$ne': True}
|
'Deleted': {'$ne': True}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6366,13 +6366,26 @@ def edit_item(id):
|
|||||||
|
|
||||||
return redirect(url_for('home_admin'))
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
|
def is_library_item(item):
|
||||||
|
"""
|
||||||
|
Prüft, ob ein Artikel ein Bibliotheks-Item ist.
|
||||||
|
- 'other', None oder Leerstring -> Inventarsystem (False)
|
||||||
|
- Jeder andere Medientyp ('Buch', 'CD', etc.) -> Bibliothek (True)
|
||||||
|
"""
|
||||||
|
if not item:
|
||||||
|
return False
|
||||||
|
item_type = item.get('ItemType', 'other')
|
||||||
|
if not item_type:
|
||||||
|
return False
|
||||||
|
return item_type.strip().lower() != 'other'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
|
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
|
||||||
def item_edit(id):
|
def item_edit(id):
|
||||||
"""
|
"""
|
||||||
Endpoint zum Laden und Aktualisieren eines Eintrags (item_edit).
|
Complete endpoint for editing items. Automatically detects whether the item
|
||||||
|
is a Library item (ItemType != 'other') or an Inventory item (ItemType == 'other').
|
||||||
"""
|
"""
|
||||||
# 1. Rechte- & Auth-Check
|
|
||||||
if 'username' not in session:
|
if 'username' not in session:
|
||||||
if request.method == 'POST' and request.is_json:
|
if request.method == 'POST' and request.is_json:
|
||||||
return jsonify({'success': False, 'message': 'Nicht angemeldet.'}), 401
|
return jsonify({'success': False, 'message': 'Nicht angemeldet.'}), 401
|
||||||
@@ -6392,69 +6405,116 @@ def item_edit(id):
|
|||||||
flash('Ungültige Element-ID.', 'error')
|
flash('Ungültige Element-ID.', 'error')
|
||||||
return redirect(url_for('home_admin'))
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
db = it.db
|
current_item = it.get_item(obj_id)
|
||||||
items_col = db['items']
|
|
||||||
|
|
||||||
# --- GET: Template anzeigen ---
|
|
||||||
if request.method == 'GET':
|
|
||||||
item = items_col.find_one({'_id': obj_id})
|
|
||||||
if not item:
|
|
||||||
flash('Element nicht gefunden.', 'error')
|
|
||||||
return redirect(url_for('home_admin'))
|
|
||||||
|
|
||||||
item['_id'] = str(item['_id'])
|
|
||||||
show_library = cfg.MODULES.is_enabled('library')
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'item_edit.html',
|
|
||||||
username=session['username'],
|
|
||||||
item=item,
|
|
||||||
library_module_enabled=show_library,
|
|
||||||
show_library_features=show_library,
|
|
||||||
page_title=f"Bearbeiten: {item.get('Name', '')}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# --- POST: Speichern ---
|
|
||||||
redirect_target = request.referrer or url_for('home_admin')
|
|
||||||
current_item = items_col.find_one({'_id': obj_id})
|
|
||||||
|
|
||||||
if not current_item:
|
if not current_item:
|
||||||
flash('Element in der Datenbank nicht gefunden.', 'error')
|
flash('Element in der Datenbank nicht gefunden.', 'error')
|
||||||
return redirect(redirect_target)
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
# Formulardaten
|
# Determine item type classification
|
||||||
|
library_module_active = cfg.MODULES.is_enabled('library')
|
||||||
|
is_lib_item = it.is_library_item(current_item)
|
||||||
|
show_library_features = library_module_active and is_lib_item
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# GET METHOD: Render Form
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
if request.method == 'GET':
|
||||||
|
current_item['_id'] = str(current_item['_id'])
|
||||||
|
|
||||||
|
# Format individual group codes for the textarea
|
||||||
|
base_code = current_item.get('Code_4', '')
|
||||||
|
individual_codes = []
|
||||||
|
if current_item.get('SeriesGroupId'):
|
||||||
|
group_ids = it.get_group_item_ids(str(current_item['_id']))
|
||||||
|
if group_ids:
|
||||||
|
for gid in group_ids:
|
||||||
|
g_item = it.get_item(gid)
|
||||||
|
c4 = g_item.get('Code_4')
|
||||||
|
if c4 and c4 != base_code:
|
||||||
|
individual_codes.append(c4)
|
||||||
|
|
||||||
|
current_item['IndividualCodes'] = '\n'.join(individual_codes)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'edit_library.html',
|
||||||
|
username=session['username'],
|
||||||
|
item=current_item,
|
||||||
|
show_library_features=show_library_features,
|
||||||
|
library_module_enabled=library_module_active,
|
||||||
|
page_title=f"Bearbeiten: {current_item.get('Name', '')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# POST METHOD: Save Changes
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
redirect_target = request.referrer or url_for('home_admin')
|
||||||
|
|
||||||
|
# Common fields
|
||||||
name = sanitize_form_value(request.form.get('name'))
|
name = sanitize_form_value(request.form.get('name'))
|
||||||
ort = sanitize_form_value(request.form.get('ort'))
|
ort = sanitize_form_value(request.form.get('ort'))
|
||||||
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
|
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
|
||||||
code_4 = sanitize_form_value(request.form.get('code_4'))
|
|
||||||
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
|
|
||||||
|
|
||||||
anschaffungs_jahr = sanitize_form_value(request.form.get('anschaffungsjahr'))
|
anschaffungs_jahr = sanitize_form_value(request.form.get('anschaffungsjahr'))
|
||||||
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
|
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
|
||||||
reservierbar = 'reservierbar' in request.form
|
reservierbar = 'reservierbar' in request.form
|
||||||
|
|
||||||
item_type_input = sanitize_form_value(request.form.get('item_type_input'))
|
# Barcodes
|
||||||
library_category = sanitize_form_value(request.form.get('library_category'))
|
code_4 = sanitize_form_value(request.form.get('code_4'))
|
||||||
|
individual_codes_raw = request.form.get('individual_codes', '')
|
||||||
|
|
||||||
|
individual_codes = []
|
||||||
|
for c in individual_codes_raw.replace('\r', '').split('\n'):
|
||||||
|
clean_c = sanitize_form_value(c)
|
||||||
|
if clean_c and clean_c != code_4 and clean_c not in individual_codes:
|
||||||
|
individual_codes.append(clean_c)
|
||||||
|
|
||||||
|
all_codes_to_check = [code_4] + individual_codes
|
||||||
|
|
||||||
|
# Barcode uniqueness check
|
||||||
|
current_group_id = current_item.get('SeriesGroupId')
|
||||||
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
|
db_instance = client[cfg.MONGODB_DB]
|
||||||
|
items_col = db_instance['items']
|
||||||
|
|
||||||
|
has_code_error = False
|
||||||
|
for code in all_codes_to_check:
|
||||||
|
if not code:
|
||||||
|
continue
|
||||||
|
existing = items_col.find_one({'Code_4': code, 'Deleted': {'$ne': True}})
|
||||||
|
if existing:
|
||||||
|
is_same_item = str(existing['_id']) == str(id)
|
||||||
|
is_in_same_group = current_group_id and existing.get('SeriesGroupId') == current_group_id
|
||||||
|
if not is_same_item and not is_in_same_group:
|
||||||
|
flash(f'Der Code "{code}" wird bereits von einem anderen Artikel verwendet.', 'error')
|
||||||
|
has_code_error = True
|
||||||
|
break
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
if has_code_error:
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
# Type-specific processing
|
||||||
|
if show_library_features:
|
||||||
|
# --- LIBRARY ITEM ---
|
||||||
|
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
|
||||||
|
item_isbn = normalize_and_validate_isbn(isbn_raw) if isbn_raw else ''
|
||||||
|
item_type = sanitize_form_value(request.form.get('item_type_input', 'Buch'))
|
||||||
|
library_category = sanitize_form_value(request.form.get('library_category', ''))
|
||||||
|
|
||||||
|
filter1 = current_item.get('Filter', [])
|
||||||
|
filter2 = current_item.get('Filter2', [])
|
||||||
|
filter3 = current_item.get('Filter3', [])
|
||||||
|
images = current_item.get('Images', [])
|
||||||
|
else:
|
||||||
|
# --- INVENTORY ITEM ---
|
||||||
|
item_isbn = current_item.get('ISBN', '')
|
||||||
|
item_type = 'other' # Standard type for inventory items
|
||||||
|
library_category = current_item.get('library_category', '')
|
||||||
|
|
||||||
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
|
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
|
||||||
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
|
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
|
||||||
filter3 = sanitize_form_value(request.form.getlist('filter3'))
|
filter3 = sanitize_form_value(request.form.getlist('filter3'))
|
||||||
|
|
||||||
# Barcode Prüfen
|
# Manage images for Inventory Mode
|
||||||
if code_4 and not it.is_code_unique(code_4, exclude_id=str(id)):
|
|
||||||
flash(f'Der Code "{code_4}" wird bereits verwendet.', 'error')
|
|
||||||
return redirect(redirect_target)
|
|
||||||
|
|
||||||
# ISBN
|
|
||||||
item_isbn = ''
|
|
||||||
item_type = item_type_input or current_item.get('ItemType', 'general')
|
|
||||||
if cfg.MODULES.is_enabled('library') and isbn_raw:
|
|
||||||
item_isbn = normalize_and_validate_isbn(isbn_raw)
|
|
||||||
if not item_isbn:
|
|
||||||
flash('Ungültiges ISBN-Format.', 'error')
|
|
||||||
return redirect(redirect_target)
|
|
||||||
|
|
||||||
# Bilder verarbeiten
|
|
||||||
images_to_keep = request.form.getlist('existing_images')
|
images_to_keep = request.form.getlist('existing_images')
|
||||||
original_images = current_item.get('Images', [])
|
original_images = current_item.get('Images', [])
|
||||||
images = [img for img in original_images if img in images_to_keep]
|
images = [img for img in original_images if img in images_to_keep]
|
||||||
@@ -6468,30 +6528,23 @@ def item_edit(id):
|
|||||||
if not is_allowed:
|
if not is_allowed:
|
||||||
flash(error_msg, 'error')
|
flash(error_msg, 'error')
|
||||||
return redirect(redirect_target)
|
return redirect(redirect_target)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
secure_name = secure_filename(file.filename)
|
secure_name = secure_filename(file.filename)
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
image_bytes = file.read()
|
image_bytes = file.read()
|
||||||
|
|
||||||
if not image_bytes:
|
if not image_bytes:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
optimized_io = io.BytesIO()
|
optimized_io = io.BytesIO()
|
||||||
with Image.open(io.BytesIO(image_bytes)) as img:
|
with Image.open(io.BytesIO(image_bytes)) as img:
|
||||||
if img.mode not in ('RGB', 'RGBA'):
|
if img.mode not in ('RGB', 'RGBA'):
|
||||||
img = img.convert('RGBA')
|
img = img.convert('RGBA')
|
||||||
|
|
||||||
max_width = 800
|
max_width = 800
|
||||||
if img.width > max_width:
|
if img.width > max_width:
|
||||||
ratio = max_width / img.width
|
ratio = max_width / img.width
|
||||||
img = img.resize((max_width, int(img.height * ratio)), Image.Resampling.LANCZOS)
|
img = img.resize((max_width, int(img.height * ratio)), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
img.save(optimized_io, format='WEBP', quality=85, optimize=True)
|
img.save(optimized_io, format='WEBP', quality=85, optimize=True)
|
||||||
|
|
||||||
optimized_io.seek(0)
|
optimized_io.seek(0)
|
||||||
new_filename = f"{uuid.uuid4().hex}_{int(time.time())}.webp"
|
new_filename = f"{uuid.uuid4().hex}_{int(time.time())}.webp"
|
||||||
|
|
||||||
fs.put(
|
fs.put(
|
||||||
optimized_io,
|
optimized_io,
|
||||||
filename=new_filename,
|
filename=new_filename,
|
||||||
@@ -6500,48 +6553,41 @@ def item_edit(id):
|
|||||||
)
|
)
|
||||||
images.append(new_filename)
|
images.append(new_filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Bild-Fehler bei Item {id}: {e}")
|
app.logger.error(f"Image error for item {id}: {e}")
|
||||||
|
|
||||||
|
# Auto-add new location to predefined locations list if applicable
|
||||||
if ort and ort not in it.get_predefined_locations():
|
if ort and ort not in it.get_predefined_locations():
|
||||||
it.add_predefined_location(ort)
|
it.add_predefined_location(ort)
|
||||||
|
|
||||||
# Datenstruktur für Update
|
# Sync series/group barcode IDs
|
||||||
shared_fields = {
|
it.sync_group_codes(str(id), code_4, individual_codes)
|
||||||
'Name': name,
|
|
||||||
'Ort': ort,
|
|
||||||
'Beschreibung': beschreibung,
|
|
||||||
'Anschaffungsjahr': anschaffungs_jahr,
|
|
||||||
'Anschaffungskosten': anschaffungs_kosten,
|
|
||||||
'Reservierbar': reservierbar,
|
|
||||||
'ISBN': item_isbn,
|
|
||||||
'ItemType': item_type,
|
|
||||||
'Kategorie': library_category,
|
|
||||||
'LastUpdated': datetime.datetime.now()
|
|
||||||
}
|
|
||||||
|
|
||||||
# Gruppen-Update
|
# Update item in database
|
||||||
group_item_ids = it.get_group_item_ids(str(id))
|
success = it.update_item(
|
||||||
|
id=str(id),
|
||||||
if group_item_ids:
|
name=name,
|
||||||
group_object_ids = [ObjectId(g_id) for g_id in group_item_ids]
|
ort=ort,
|
||||||
items_col.update_many({'_id': {'$in': group_object_ids}}, {'$set': shared_fields})
|
beschreibung=beschreibung,
|
||||||
|
images=images,
|
||||||
# Individual-Update
|
verfuegbar=current_item.get('Verfuegbar', True),
|
||||||
individual_update = {
|
filter1=filter1,
|
||||||
**shared_fields,
|
filter2=filter2,
|
||||||
'Code_4': code_4,
|
filter3=filter3,
|
||||||
'Images': images,
|
ansch_jahr=anschaffungs_jahr,
|
||||||
'Filter1': filter1,
|
ansch_kost=anschaffungs_kosten,
|
||||||
'Filter2': filter2,
|
code_4=code_4,
|
||||||
'Filter3': filter3
|
reservierbar=reservierbar,
|
||||||
}
|
isbn=item_isbn,
|
||||||
|
item_type=item_type,
|
||||||
items_col.update_one({'_id': obj_id}, {'$set': individual_update})
|
library_category=library_category
|
||||||
|
)
|
||||||
|
|
||||||
|
if success:
|
||||||
flash('Artikel erfolgreich aktualisiert.', 'success')
|
flash('Artikel erfolgreich aktualisiert.', 'success')
|
||||||
|
else:
|
||||||
|
flash('Fehler beim Aktualisieren des Artikels.', 'error')
|
||||||
|
|
||||||
return redirect(redirect_target)
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/update_group', methods=['POST'])
|
@app.route('/update_group', methods=['POST'])
|
||||||
def update_group():
|
def update_group():
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,26 @@ Collection Structure:
|
|||||||
"""
|
"""
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
from bson.errors import InvalidId
|
from bson.errors import InvalidId
|
||||||
|
import uuid
|
||||||
import datetime
|
import datetime
|
||||||
import Web.modules.database.settings as cfg
|
import Web.modules.database.settings as cfg
|
||||||
from Web.modules.database.settings import MongoClient
|
from Web.modules.database.settings import MongoClient
|
||||||
import Web.modules.inventarsystem.data_protection as dp
|
import Web.modules.inventarsystem.data_protection as dp
|
||||||
|
|
||||||
|
|
||||||
|
def is_library_item(item):
|
||||||
|
"""
|
||||||
|
Determines if an item belongs to the library system.
|
||||||
|
Returns False for 'other', None, or empty ItemType (Inventory item).
|
||||||
|
Returns True for any specific library type ('Buch', 'CD', 'DVD', etc.).
|
||||||
|
"""
|
||||||
|
if not item:
|
||||||
|
return False
|
||||||
|
item_type = item.get('ItemType', 'other')
|
||||||
|
if not item_type:
|
||||||
|
return False
|
||||||
|
return str(item_type).strip().lower() != 'other'
|
||||||
|
|
||||||
def safe_decrypt_user(encrypted_user):
|
def safe_decrypt_user(encrypted_user):
|
||||||
"""
|
"""
|
||||||
Safely decrypt an encrypted username string.
|
Safely decrypt an encrypted username string.
|
||||||
@@ -1148,3 +1162,121 @@ def get_current_status(item_id, decrypt=True):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error retrieving current status for item {item_id}: {e}")
|
print(f"Error retrieving current status for item {item_id}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def sync_group_codes(primary_obj_id, base_code, individual_codes_list):
|
||||||
|
"""
|
||||||
|
Synchronisiert die Barcodes einer Gruppe im korrekten Schema
|
||||||
|
(angelehnt an das 'Augenmodell groß'-Vorbild).
|
||||||
|
"""
|
||||||
|
if not base_code:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Alle Ziel-Codes zusammenführen (Basis-Code an erster Stelle)
|
||||||
|
all_target_codes = [base_code]
|
||||||
|
for c in individual_codes_list:
|
||||||
|
if c and c not in all_target_codes:
|
||||||
|
all_target_codes.append(c)
|
||||||
|
|
||||||
|
item_count = len(all_target_codes)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
|
db = client[cfg.MONGODB_DB]
|
||||||
|
items = db['items']
|
||||||
|
|
||||||
|
primary_item = items.find_one({'_id': ObjectId(primary_obj_id)})
|
||||||
|
if not primary_item:
|
||||||
|
client.close()
|
||||||
|
return False
|
||||||
|
|
||||||
|
group_id = primary_item.get('SeriesGroupId')
|
||||||
|
|
||||||
|
# Wenn es mehr als 1 Item gibt und noch keine Gruppe existiert -> Neue GroupID erzeugen
|
||||||
|
if not group_id and item_count > 1:
|
||||||
|
group_id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
# Wenn es nun eine Gruppe gibt (item_count > 1)
|
||||||
|
if item_count > 1:
|
||||||
|
# 1. Haupt-Item (Parent) aktualisieren
|
||||||
|
items.update_one(
|
||||||
|
{'_id': primary_item['_id']},
|
||||||
|
{'$set': {
|
||||||
|
'Code_4': base_code,
|
||||||
|
'SeriesGroupId': group_id,
|
||||||
|
'SeriesCount': item_count,
|
||||||
|
'SeriesPosition': 1,
|
||||||
|
'IsGroupedSubItem': False,
|
||||||
|
'ParentItemId': None
|
||||||
|
}}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Bestehende Gruppenmitglieder laden
|
||||||
|
existing_items = list(items.find({'SeriesGroupId': group_id}))
|
||||||
|
existing_map = {it.get('Code_4'): it for it in existing_items if
|
||||||
|
it.get('Code_4') and str(it['_id']) != str(primary_item['_id'])}
|
||||||
|
|
||||||
|
# Alle verbleibenden Sub-Codes ab Position 2 abarbeiten
|
||||||
|
processed_sub_ids = []
|
||||||
|
for idx, code in enumerate(all_target_codes[1:], start=2):
|
||||||
|
if code in existing_map:
|
||||||
|
# Existiert bereits in der Gruppe -> Nur Position und Count aktualisieren
|
||||||
|
sub_item = existing_map[code]
|
||||||
|
processed_sub_ids.append(sub_item['_id'])
|
||||||
|
items.update_one(
|
||||||
|
{'_id': sub_item['_id']},
|
||||||
|
{'$set': {
|
||||||
|
'SeriesCount': item_count,
|
||||||
|
'SeriesPosition': idx,
|
||||||
|
'IsGroupedSubItem': True,
|
||||||
|
'ParentItemId': str(primary_item['_id'])
|
||||||
|
}}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Neu hinzukommender Code -> Als Klon (Sub-Item) erstellen
|
||||||
|
new_sub = primary_item.copy()
|
||||||
|
if '_id' in new_sub:
|
||||||
|
del new_sub['_id']
|
||||||
|
|
||||||
|
new_sub.update({
|
||||||
|
'Code_4': code,
|
||||||
|
'SeriesGroupId': group_id,
|
||||||
|
'SeriesCount': item_count,
|
||||||
|
'SeriesPosition': idx,
|
||||||
|
'IsGroupedSubItem': True,
|
||||||
|
'ParentItemId': str(primary_item['_id']),
|
||||||
|
'LastUpdated': primary_item.get('LastUpdated')
|
||||||
|
})
|
||||||
|
inserted_res = items.insert_one(new_sub)
|
||||||
|
processed_sub_ids.append(inserted_res.inserted_id)
|
||||||
|
|
||||||
|
# Nicht mehr benötigte Sub-Items aus dieser Gruppe entfernen
|
||||||
|
for code, sub_item in existing_map.items():
|
||||||
|
if sub_item['_id'] not in processed_sub_ids:
|
||||||
|
items.delete_one({'_id': sub_item['_id']})
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Fall: Nur 1 einziges Item (keine Gruppe / Gruppe aufgelöst)
|
||||||
|
# Eventuelle alte Sub-Items dieser Gruppe löschen
|
||||||
|
if group_id:
|
||||||
|
items.delete_many({
|
||||||
|
'SeriesGroupId': group_id,
|
||||||
|
'_id': {'$ne': primary_item['_id']}
|
||||||
|
})
|
||||||
|
|
||||||
|
items.update_one(
|
||||||
|
{'_id': primary_item['_id']},
|
||||||
|
{'$set': {
|
||||||
|
'Code_4': base_code,
|
||||||
|
'SeriesGroupId': None,
|
||||||
|
'SeriesCount': 1,
|
||||||
|
'SeriesPosition': 1,
|
||||||
|
'IsGroupedSubItem': False,
|
||||||
|
'ParentItemId': None
|
||||||
|
}}
|
||||||
|
)
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error syncing group codes: {e}")
|
||||||
|
return False
|
||||||
@@ -48,7 +48,6 @@
|
|||||||
console.log("Server-provided duplicate data:", serverDuplicateData);
|
console.log("Server-provided duplicate data:", serverDuplicateData);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Book information display styles */
|
/* Book information display styles */
|
||||||
@@ -764,17 +763,24 @@
|
|||||||
<textarea id="beschreibung" name="beschreibung" rows="4" class="form-control" required>{{ item.Beschreibung if item.Beschreibung else '' }}</textarea>
|
<textarea id="beschreibung" name="beschreibung" rows="4" class="form-control" required>{{ item.Beschreibung if item.Beschreibung else '' }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Barcode / Code_4 -->
|
<!-- Barcode / Basis-Code -->
|
||||||
<div class="form-group" id="primary_code_group">
|
<div class="form-group" id="primary_code_group">
|
||||||
<label for="code_4">Barcode / Artikel-Code:</label>
|
<label for="code_4">Basis-Code (Haupt-Barcode)</label>
|
||||||
<div style="display: flex; gap: 10px;">
|
<div style="display: flex; gap: 10px;">
|
||||||
<input type="text" id="code_4" name="code_4" class="form-control" value="{{ item.Code_4 if item.Code_4 else '' }}" required>
|
<input type="text" id="code_4" name="code_4" class="form-control" value="{{ item.Code_4 if item.Code_4 else '' }}" required>
|
||||||
<button type="button" id="scan-code4-btn" class="btn btn-primary">Barcode scannen</button>
|
<button type="button" id="scan-code4-btn" class="btn btn-primary" style="white-space: nowrap;">Barcode scannen</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="code4-scanner" style="display:none; margin-top: 10px;"></div>
|
<div id="code4-scanner" style="display:none; margin-top: 10px;"></div>
|
||||||
<small id="code4-scan-status" class="form-text text-muted"></small>
|
<small id="code4-scan-status" class="form-text text-muted"></small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Weitere Einzelcodes -->
|
||||||
|
<div class="form-group" id="individual_codes_group">
|
||||||
|
<label for="individual_codes">Weitere Einzelcodes (je Zeile ein Code)</label>
|
||||||
|
<textarea id="individual_codes" name="individual_codes" rows="4" class="form-control">{{ item.IndividualCodes if item.IndividualCodes else '' }}</textarea>
|
||||||
|
<small style="display:block; color:#666; margin-top: 5px;">Der Scanner füllt zuerst den Basis-Code; weitere gescannte Codes werden hier automatisch zeilenweise angehängt.</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if show_library_features %}
|
{% if show_library_features %}
|
||||||
<!-- Bibliotheks-Klassifizierung -->
|
<!-- Bibliotheks-Klassifizierung -->
|
||||||
<div class="filter-inputs">
|
<div class="filter-inputs">
|
||||||
@@ -918,8 +924,10 @@
|
|||||||
function startCode4Scanner() {
|
function startCode4Scanner() {
|
||||||
const scannerBox = document.getElementById('code4-scanner');
|
const scannerBox = document.getElementById('code4-scanner');
|
||||||
const scanButton = document.getElementById('scan-code4-btn');
|
const scanButton = document.getElementById('scan-code4-btn');
|
||||||
const codeField = document.getElementById('code_4');
|
const baseCodeField = document.getElementById('code_4');
|
||||||
if (!scannerBox || !scanButton || !codeField) return;
|
const individualCodesField = document.getElementById('individual_codes');
|
||||||
|
|
||||||
|
if (!scannerBox || !scanButton || !baseCodeField) return;
|
||||||
|
|
||||||
if (scannerBox.style.display !== 'none') {
|
if (scannerBox.style.display !== 'none') {
|
||||||
killScannerHardware(); scannerBox.style.display = 'none'; scanButton.textContent = 'Barcode scannen'; return;
|
killScannerHardware(); scannerBox.style.display = 'none'; scanButton.textContent = 'Barcode scannen'; return;
|
||||||
@@ -932,11 +940,25 @@
|
|||||||
code4LastScanned = decodedText; code4LastScannedAt = now;
|
code4LastScanned = decodedText; code4LastScannedAt = now;
|
||||||
|
|
||||||
killScannerHardware(); scannerBox.style.display = 'none'; scanButton.textContent = 'Barcode scannen';
|
killScannerHardware(); scannerBox.style.display = 'none'; scanButton.textContent = 'Barcode scannen';
|
||||||
codeField.value = decodedText;
|
|
||||||
validateCodeField(codeField, getItemId());
|
// Intelligentes Eintragen: Entweder Basis-Code oder Textarea
|
||||||
|
if (!baseCodeField.value.trim()) {
|
||||||
|
baseCodeField.value = decodedText;
|
||||||
|
} else {
|
||||||
|
let currentCodes = individualCodesField.value.split('\n').map(c => c.trim()).filter(c => c);
|
||||||
|
if (!currentCodes.includes(decodedText) && baseCodeField.value.trim() !== decodedText) {
|
||||||
|
currentCodes.push(decodedText);
|
||||||
|
individualCodesField.value = currentCodes.join('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 'Scanner läuft...', (msg) => { document.getElementById('code4-scan-status').textContent = msg; });
|
}, 'Scanner läuft...', (msg) => { document.getElementById('code4-scan-status').textContent = msg; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const scanCodeBtn = document.getElementById('scan-code4-btn');
|
||||||
|
if (scanCodeBtn) scanCodeBtn.addEventListener('click', startCode4Scanner);
|
||||||
|
});
|
||||||
|
|
||||||
function validateCodeField(input, excludeId) {
|
function validateCodeField(input, excludeId) {
|
||||||
const code = input.value.trim();
|
const code = input.value.trim();
|
||||||
if (!code) return;
|
if (!code) return;
|
||||||
@@ -1003,3 +1025,5 @@
|
|||||||
if (codeField) codeField.addEventListener('blur', function() { validateCodeField(this, getItemId()); });
|
if (codeField) codeField.addEventListener('blur', function() { validateCodeField(this, getItemId()); });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,515 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 2025-2026 AIIrondev
|
||||||
|
Licensed under the Inventarsystem EULA.
|
||||||
|
-->
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ page_title|default('Artikel bearbeiten') }} - Inventarsystem{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<style>
|
||||||
|
.edit-container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: var(--ui-surface);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-form h1 {
|
||||||
|
color: var(--ui-text);
|
||||||
|
margin-bottom: 30px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: var(--ui-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input,
|
||||||
|
.form-group select,
|
||||||
|
.form-group textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group textarea {
|
||||||
|
height: 100px;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-inputs {
|
||||||
|
background-color: var(--ui-surface-soft);
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-inputs h3 {
|
||||||
|
color: var(--ui-text);
|
||||||
|
margin-bottom: 15px;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.multi-filter {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-dropdown-select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.isbn-input-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.isbn-input-group input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fetch-isbn-button {
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
transition: background-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fetch-isbn-button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scanner Video Canvas */
|
||||||
|
#code4-scanner video, #code4-scanner canvas,
|
||||||
|
#isbn-scanner video, #isbn-scanner canvas {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 640px;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#code4-scanner canvas, #isbn-scanner canvas {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#code4-scanner, #isbn-scanner {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Image Management */
|
||||||
|
.existing-images-grid {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 15px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.existing-image-card {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 8px;
|
||||||
|
text-align: center;
|
||||||
|
background: #fff;
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.existing-image-card img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.existing-image-card label {
|
||||||
|
font-size: 0.8em;
|
||||||
|
margin-top: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-new-btn {
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-button {
|
||||||
|
background-color: #28a745;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 15px 30px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 20px;
|
||||||
|
transition: background-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-button:hover {
|
||||||
|
background-color: #218838;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-new-location-container {
|
||||||
|
display: none;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="edit-container">
|
||||||
|
<div class="edit-form">
|
||||||
|
<h1>{{ page_title|default('Artikel bearbeiten') }}</h1>
|
||||||
|
<form method="POST" action="{{ url_for('item_edit', id=item._id) }}" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="item_id" value="{{ item._id }}">
|
||||||
|
|
||||||
|
{% if show_library_features %}
|
||||||
|
<!-- ================= LIBRARY MODE FIELDS ================= -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="isbn">ISBN / Barcode:</label>
|
||||||
|
<div class="isbn-input-group">
|
||||||
|
<input type="text" id="isbn" name="isbn" value="{{ item.ISBN|default('') }}" placeholder="ISBN oder Barcode eingeben...">
|
||||||
|
<button type="button" id="scan-isbn-btn" class="fetch-isbn-button">Barcode scannen</button>
|
||||||
|
<button type="button" class="fetch-isbn-button" onclick="fetchBookInfo('edit')">Informationen abrufen</button>
|
||||||
|
</div>
|
||||||
|
<div id="isbn-scanner" style="width:100%; max-width:520px; display:none; margin-top:10px;"></div>
|
||||||
|
<small id="isbn-scan-status" style="display:block; color:#666; margin-top:6px;"></small>
|
||||||
|
<div id="book-info-container"></div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ================= COMMON FIELDS ================= -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Name / Titel:</label>
|
||||||
|
<input type="text" id="name" name="name" value="{{ item.Name|default('') }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="ort">Ort / Standort:</label>
|
||||||
|
<select id="ort" name="ort" data-selected="{{ item.Ort|default('') }}" required>
|
||||||
|
<option value="">-- Bitte Ort auswählen --</option>
|
||||||
|
{% if item.Ort %}
|
||||||
|
<option value="{{ item.Ort }}" selected>{{ item.Ort }}</option>
|
||||||
|
{% endif %}
|
||||||
|
</select>
|
||||||
|
<button type="button" class="add-new-btn" id="add-new-location-btn">Neuen Ort hinzufügen</button>
|
||||||
|
<div id="new-location-container" class="edit-new-location-container">
|
||||||
|
<input type="text" id="new-location-input" placeholder="Neuen Ort eingeben">
|
||||||
|
<button type="button" onclick="addNewLocation()">Hinzufügen</button>
|
||||||
|
<button type="button" onclick="cancelAddLocation()">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="beschreibung">Beschreibung:</label>
|
||||||
|
<textarea id="beschreibung" name="beschreibung" required>{{ item.Beschreibung|default('') }}</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="primary_code_group">
|
||||||
|
<label for="code_4">Basis-Code (Haupt-Barcode)</label>
|
||||||
|
<div style="display: flex; gap: 10px;">
|
||||||
|
<input type="text" id="code_4" name="code_4" class="form-control" value="{{ item.Code_4|default('') }}" required>
|
||||||
|
<button type="button" id="scan-code4-btn" class="fetch-isbn-button">Barcode scannen</button>
|
||||||
|
</div>
|
||||||
|
<div id="code4-scanner" style="display:none; margin-top: 10px;"></div>
|
||||||
|
<small id="code4-scan-status" class="form-text text-muted"></small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="individual_codes_group">
|
||||||
|
<label for="individual_codes">Weitere Einzelcodes der Gruppe (je Zeile ein Code)</label>
|
||||||
|
<textarea id="individual_codes" name="individual_codes" rows="4" class="form-control" placeholder="z.B. ABC-001 ABC-002">{{ item.IndividualCodes|default('') }}</textarea>
|
||||||
|
<small style="display:block; color:#666; margin-top: 5px;">Der Basis-Code steht oben. Alle weiteren Gruppenmitglieder werden hier untereinander aufgeführt.</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if show_library_features %}
|
||||||
|
<!-- ================= LIBRARY CATEGORIZATION ================= -->
|
||||||
|
<div class="filter-inputs">
|
||||||
|
<h3>Medientyp</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<select name="item_type_input" id="item_type_input">
|
||||||
|
<option value="Buch" {% if item.ItemType == 'Buch' %}selected{% endif %}>Buch</option>
|
||||||
|
<option value="Schulbuch" {% if item.ItemType == 'Schulbuch' %}selected{% endif %}>Schulbuch</option>
|
||||||
|
<option value="CD" {% if item.ItemType == 'CD' %}selected{% endif %}>CD</option>
|
||||||
|
<option value="DVD" {% if item.ItemType == 'DVD' %}selected{% endif %}>DVD</option>
|
||||||
|
<option value="Sonstiges" {% if item.ItemType == 'Sonstiges' %}selected{% endif %}>Sonstiges</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<h3>Kategorie / Fach:</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" name="library_category" id="library_category" value="{{ item.library_category|default('') }}" placeholder="z.B. Belletristik, Sachbücher, etc.">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<!-- ================= INVENTORY FILTERS (1-3) ================= -->
|
||||||
|
<div class="filter-inputs">
|
||||||
|
<h3>Unterrichtsfach (Filter 1):</h3>
|
||||||
|
<div class="multi-filter">
|
||||||
|
{% for idx in range(4) %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="filter1-{{ idx + 1 }}">Wert {{ idx + 1 }}:</label>
|
||||||
|
<select id="filter1-{{ idx + 1 }}" name="filter" class="filter-dropdown-select" data-selected="{{ item.Filter[idx] if item.Filter and item.Filter|length > idx else '' }}">
|
||||||
|
<option value="">-- Optional --</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Jahrgangsstufe (Filter 2):</h3>
|
||||||
|
<div class="multi-filter">
|
||||||
|
{% for idx in range(4) %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="filter2-{{ idx + 1 }}">Wert {{ idx + 1 }}:</label>
|
||||||
|
<select id="filter2-{{ idx + 1 }}" name="filter2" class="filter-dropdown-select" data-selected="{{ item.Filter2[idx] if item.Filter2 and item.Filter2|length > idx else '' }}">
|
||||||
|
<option value="">-- Optional --</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Schlagwort (Filter 3):</h3>
|
||||||
|
<div class="multi-filter">
|
||||||
|
{% for idx in range(4) %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="filter3-{{ idx + 1 }}">Wert {{ idx + 1 }}:</label>
|
||||||
|
<input type="text" id="filter3-{{ idx + 1 }}" name="filter3" value="{{ item.Filter3[idx] if item.Filter3 and item.Filter3|length > idx else '' }}">
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ================= DATES & FINANCIALS ================= -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="anschaffungsjahr">Anschaffungsjahr:</label>
|
||||||
|
<input type="date" id="anschaffungsjahr" name="anschaffungsjahr" value="{{ item.Anschaffungsjahr|default('') }}">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="anschaffungskosten">Anschaffungskosten (€):</label>
|
||||||
|
<input type="text" id="anschaffungskosten" name="anschaffungskosten" value="{{ item.Anschaffungskosten|default('') }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if not show_library_features %}
|
||||||
|
<!-- ================= INVENTORY IMAGE MANAGEMENT ================= -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Bestehende Bilder behalten:</label>
|
||||||
|
{% if item.Images and item.Images|length > 0 %}
|
||||||
|
<div class="existing-images-grid">
|
||||||
|
{% for img in item.Images %}
|
||||||
|
<div class="existing-image-card">
|
||||||
|
<img src="{{ url_for('uploaded_file', filename=img) }}" alt="Bild">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="existing_images" value="{{ img }}" checked>
|
||||||
|
Behalten
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p style="color:#777; font-size:0.9em;">Keine Bilder vorhanden.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<label for="images" style="margin-top:15px;">Neue Bilder/Videos hinzufügen:</label>
|
||||||
|
<input type="file" id="images" name="images" accept=".jpg, .jpeg, .png, .gif, .mp4, .mov, .avi, .mkv, .webm" multiple>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reservierbar" style="display:inline-block; width:auto; margin-right:10px;">Reservierbar:</label>
|
||||||
|
<input type="checkbox" id="reservierbar" name="reservierbar" style="width:auto;" {% if item.Reservierbar %}checked{% endif %}>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="submit-button">Änderungen speichern</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2/dist/quagga.js"></script>
|
||||||
|
<script>
|
||||||
|
const libraryModuleEnabled = {{ 'true' if show_library_features else 'false' }};
|
||||||
|
let scannerRunning = false;
|
||||||
|
let activeScannerCallback = null;
|
||||||
|
let code4LastScanned = '';
|
||||||
|
let code4LastScannedAt = 0;
|
||||||
|
|
||||||
|
// Load filter dropdown options and pre-select current item values
|
||||||
|
function loadAndSelectFilterValues(filterNumber) {
|
||||||
|
fetch(`/get_predefined_filter_values/${filterNumber}`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
for (let i = 1; i <= 4; i++) {
|
||||||
|
const select = document.getElementById(`filter${filterNumber}-${i}`);
|
||||||
|
if (!select) continue;
|
||||||
|
|
||||||
|
const selectedValue = select.getAttribute('data-selected') || '';
|
||||||
|
|
||||||
|
data.values.forEach(val => {
|
||||||
|
if (!val || String(val).trim() === '') return;
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = val;
|
||||||
|
opt.textContent = val;
|
||||||
|
select.appendChild(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add custom option if the item has a value not in predefined list
|
||||||
|
if (selectedValue && !Array.from(select.options).some(o => o.value === selectedValue)) {
|
||||||
|
const customOpt = document.createElement('option');
|
||||||
|
customOpt.value = selectedValue;
|
||||||
|
customOpt.textContent = selectedValue;
|
||||||
|
select.appendChild(customOpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
select.value = selectedValue;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => console.error(`Error loading Filter ${filterNumber}:`, err));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load locations
|
||||||
|
function loadLocationOptions() {
|
||||||
|
fetch('/get_predefined_locations')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
const select = document.getElementById('ort');
|
||||||
|
if (!select) return;
|
||||||
|
const currentVal = select.getAttribute('data-selected') || select.value;
|
||||||
|
|
||||||
|
data.locations.forEach(loc => {
|
||||||
|
if (!Array.from(select.options).some(o => o.value === loc)) {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = loc;
|
||||||
|
opt.textContent = loc;
|
||||||
|
select.appendChild(opt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
select.value = currentVal;
|
||||||
|
})
|
||||||
|
.catch(err => console.error('Error loading locations:', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
// New location handler
|
||||||
|
function addNewLocation() {
|
||||||
|
const input = document.getElementById('new-location-input');
|
||||||
|
const val = input.value.trim();
|
||||||
|
if (!val) return;
|
||||||
|
const select = document.getElementById('ort');
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = val;
|
||||||
|
opt.textContent = val;
|
||||||
|
opt.selected = true;
|
||||||
|
select.appendChild(opt);
|
||||||
|
document.getElementById('new-location-container').style.display = 'none';
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelAddLocation() {
|
||||||
|
document.getElementById('new-location-container').style.display = 'none';
|
||||||
|
document.getElementById('new-location-input').value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quagga Barcode Scanner Engine
|
||||||
|
function runEngineInitialization(targetSelector, activeCallback, completionMsg, errorStatusSetter) {
|
||||||
|
if (scannerRunning) { Quagga.stop(); scannerRunning = false; }
|
||||||
|
activeScannerCallback = activeCallback;
|
||||||
|
|
||||||
|
Quagga.init({
|
||||||
|
inputStream: { name: "Live", type: "LiveStream", target: document.querySelector(targetSelector), constraints: { width: 640, height: 480, facingMode: "environment" } },
|
||||||
|
decoder: { readers: ["code_128_reader", "ean_reader", "code_39_reader", "upc_reader"] }
|
||||||
|
}, function(err) {
|
||||||
|
if (err) { errorStatusSetter("Kamera-Fehler.", true); return; }
|
||||||
|
Quagga.start(); scannerRunning = true; errorStatusSetter(completionMsg, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function killScannerHardware() {
|
||||||
|
if (!scannerRunning) return;
|
||||||
|
Quagga.stop(); scannerRunning = false; activeScannerCallback = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quagga.onDetected(function(data) {
|
||||||
|
if (!data || !data.codeResult || !data.codeResult.code) return;
|
||||||
|
if (typeof activeScannerCallback === "function") activeScannerCallback(String(data.codeResult.code).trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
function startCode4Scanner() {
|
||||||
|
const scannerBox = document.getElementById('code4-scanner');
|
||||||
|
const scanBtn = document.getElementById('scan-code4-btn');
|
||||||
|
const baseField = document.getElementById('code_4');
|
||||||
|
const indArea = document.getElementById('individual_codes');
|
||||||
|
|
||||||
|
if (scannerBox.style.display !== 'none') {
|
||||||
|
killScannerHardware(); scannerBox.style.display = 'none'; scanBtn.textContent = 'Barcode scannen'; return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scannerBox.style.display = 'block'; scanBtn.textContent = 'Scanner stoppen';
|
||||||
|
runEngineInitialization('#code4-scanner', function(decodedText) {
|
||||||
|
const now = Date.now();
|
||||||
|
if (decodedText === code4LastScanned && (now - code4LastScannedAt) < 1500) return;
|
||||||
|
code4LastScanned = decodedText; code4LastScannedAt = now;
|
||||||
|
|
||||||
|
killScannerHardware(); scannerBox.style.display = 'none'; scanBtn.textContent = 'Barcode scannen';
|
||||||
|
|
||||||
|
if (!baseField.value.trim()) {
|
||||||
|
baseField.value = decodedText;
|
||||||
|
} else {
|
||||||
|
let codes = indArea.value.split('\n').map(c => c.trim()).filter(c => c);
|
||||||
|
if (!codes.includes(decodedText) && baseField.value.trim() !== decodedText) {
|
||||||
|
codes.push(decodedText);
|
||||||
|
indArea.value = codes.join('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 'Scanner läuft...', msg => { document.getElementById('code4-scan-status').textContent = msg; });
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
loadLocationOptions();
|
||||||
|
|
||||||
|
if (!libraryModuleEnabled) {
|
||||||
|
loadAndSelectFilterValues(1);
|
||||||
|
loadAndSelectFilterValues(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scanCodeBtn = document.getElementById('scan-code4-btn');
|
||||||
|
if (scanCodeBtn) scanCodeBtn.addEventListener('click', startCode4Scanner);
|
||||||
|
|
||||||
|
const addLocBtn = document.getElementById('add-new-location-btn');
|
||||||
|
if (addLocBtn) addLocBtn.addEventListener('click', () => {
|
||||||
|
const c = document.getElementById('new-location-container');
|
||||||
|
c.style.display = c.style.display === 'none' ? 'block' : 'none';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -800,7 +800,7 @@
|
|||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td class="table-title">${escapeHtml(item.Name || 'Untitled')}</td>
|
<td class="table-title">${escapeHtml(item.Name || 'Untitled')}</td>
|
||||||
<td>${escapeHtml(Item.ISBN || '-')}</td>
|
<td>${escapeHtml(item.ISBN || '-')}</td>
|
||||||
<td>${getItemTypeLabel(item.ItemType || 'book')}</td>
|
<td>${getItemTypeLabel(item.ItemType || 'book')}</td>
|
||||||
<td style="font-weight:600; text-align:center;">${item.Quantity || item.GroupedDisplayCount || 1}</td>
|
<td style="font-weight:600; text-align:center;">${item.Quantity || item.GroupedDisplayCount || 1}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user