This commit is contained in:
2026-01-06 11:52:03 +01:00
parent b74cf45c5c
commit 34f040df30
11 changed files with 1027 additions and 264 deletions

View File

@@ -168,6 +168,21 @@
flex: 1;
margin-bottom: 0;
}
.number-input-container {
display: flex;
align-items: center;
margin-bottom: 15px;
}
.number-input-container label {
width: 120px;
margin-bottom: 0;
margin-right: 10px;
font-weight: bold;
}
.number-input-container input {
width: 80px;
margin-bottom: 0;
}
</style>
</head>
<body>
@@ -184,126 +199,245 @@
<div class="table-container">
<button class="add-row-btn" id="add-row-two">Add Output</button>
<table id="table-two">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Client</th>
<th>Date</th>
<th>Warm</th>
<th>LHe Delivery</th>
<th>LHe Output</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entry in entries_table2 %}
<tr data-id="{{ entry.id }}">
<td>{{ forloop.counter }}</td>
<td>{{ entry.id }}</td>
<td>{{ entry.client.name }}</td>
<td>{{ entry.date }}</td>
<td>{{ entry.is_warm|yesno:"Yes,No" }}</td>
<td>{{ entry.lhe_delivery }}</td>
<td>{{ entry.lhe_output }}</td>
<td>{{ entry.notes }}</td>
<td class="actions">
<button class="edit-btn-two">Edit</button>
<button class="delete-btn-two">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Institute</th>
<th>Client</th>
<th>Date</th>
<th>Warm</th>
<th>LHe Delivery</th>
<th>LHe Output</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entry in entries_table2 %}
<tr data-id="{{ entry.id }}">
<td>{{ forloop.counter }}</td>
<td>{{ entry.id }}</td>
<td>{{ entry.client.institute.name }}</td>
<td>{{ entry.client.name }}</td>
<td>{{ entry.date }}</td>
<td>{{ entry.is_warm|yesno:"Yes,No" }}</td>
<td>{{ entry.lhe_delivery }}</td>
<td>{{ entry.lhe_output }}</td>
<td>{{ entry.notes }}</td>
<td class="actions">
<button class="edit-btn-two">Edit</button>
<button class="delete-btn-two">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Add Entry Popup -->
<div id="add-popup-two" class="popup">
<span class="close-btn">&times;</span>
<h3>LHe Dewar Output</h3>
<label for="add-client-id">Client:</label>
<select id="add-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<label for="add-date">Date:</label>
<input type="date" id="add-date">
<div class="checkbox-container">
<input type="checkbox" id="add-is-warm">
<label for="add-is-warm">Warm</label>
</div>
<div class="input-with-label">
<label for="add-lhe-delivery">LHe Anlieferung:</label>
<input type="text" id="add-lhe-delivery" placeholder="Enter delivery amount">
</div>
<div class="input-with-label">
<label for="add-lhe-output">LHe Ausgabe:</label>
<input type="number" id="add-lhe-output" placeholder="Enter output amount (numbers only)" step="0.01" min="0" placeholder="Enter output amount">
</div>
<label for="add-notes">Notes:</label>
<textarea id="add-notes" placeholder="Additional notes"></textarea>
<div class="popup-buttons">
<button class="save-btn" id="save-add-two">Save</button>
<button class="cancel-btn" id="cancel-add-two">Cancel</button>
<button class="help-btn">Help</button>
</div>
<span class="close-btn">&times;</span>
<h3>LHe Dewar Output</h3>
<!-- Institute Selection -->
<label for="add-institute-id">Institute:</label>
<select id="add-institute-id">
<option value="">Select Institute</option>
{% for institute in institutes %}
<option value="{{ institute.id }}">{{ institute.name }}</option>
{% endfor %}
</select>
<!-- Client Selection (will be populated based on institute) -->
<label for="add-client-id">Client:</label>
<select id="add-client-id" disabled>
<option value="">Select Institute first</option>
{% for client in clients %}
<option value="{{ client.id }}" data-institute="{{ client.institute.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<label for="add-date">Date:</label>
<input type="date" id="add-date">
<!-- Changed from checkbox to number input -->
<div class="number-input-container">
<label for="add-is-warm">Warm:</label>
<input type="number" id="add-is-warm" min="0" max="1" step="1" value="0">
</div>
<div class="input-with-label">
<label for="add-lhe-delivery">LHe Anlieferung:</label>
<input type="text" id="add-lhe-delivery" placeholder="Enter delivery amount">
</div>
<div class="input-with-label">
<label for="add-lhe-output">LHe Ausgabe:</label>
<input type="number" id="add-lhe-output" placeholder="Enter output amount (numbers only)" step="0.01" min="0">
</div>
<label for="add-notes">Notes:</label>
<textarea id="add-notes" placeholder="Additional notes"></textarea>
<div class="popup-buttons">
<button class="save-btn" id="save-add-two">Save</button>
<button class="cancel-btn" id="cancel-add-two">Cancel</button>
<button class="help-btn">Help</button>
</div>
</div>
<!-- Edit Entry Popup -->
<div id="edit-popup-two" class="popup">
<span class="close-btn">&times;</span>
<h3>LHe Dewar Output</h3>
<input type="hidden" id="edit-id">
<label for="edit-client-id">Client:</label>
<select id="edit-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<label for="edit-date">Date:</label>
<input type="date" id="edit-date">
<div class="checkbox-container">
<input type="checkbox" id="edit-is-warm">
<label for="edit-is-warm">Warm</label>
</div>
<div class="input-with-label">
<label for="edit-lhe-delivery">LHe Anlieferung:</label>
<input type="text" id="edit-lhe-delivery" placeholder="Enter delivery amount">
</div>
<div class="input-with-label">
<label for="edit-lhe-output">LHe Ausgabe:</label>
<input type="number" id="edit-lhe-output" placeholder="Enter output amount">
</div>
<label for="edit-notes">Notes:</label>
<textarea id="edit-notes" placeholder="Additional notes"></textarea>
<div class="popup-buttons">
<button class="save-btn" id="save-edit-two">Save</button>
<button class="cancel-btn" id="cancel-edit-two">Cancel</button>
<button class="help-btn">Help</button>
</div>
<span class="close-btn">&times;</span>
<h3>LHe Dewar Output</h3>
<input type="hidden" id="edit-id">
<!-- Institute Selection -->
<label for="edit-institute-id">Institute:</label>
<select id="edit-institute-id">
<option value="">Select Institute</option>
{% for institute in institutes %}
<option value="{{ institute.id }}">{{ institute.name }}</option>
{% endfor %}
</select>
<!-- Client Selection (will be populated based on institute) -->
<label for="edit-client-id">Client:</label>
<select id="edit-client-id" disabled>
<option value="">Select Institute first</option>
{% for client in clients %}
<option value="{{ client.id }}" data-institute="{{ client.institute.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<label for="edit-date">Date:</label>
<input type="date" id="edit-date">
<!-- Changed from checkbox to number input -->
<div class="number-input-container">
<label for="edit-is-warm">Warm:</label>
<input type="number" id="edit-is-warm" min="0" max="1" step="1" value="0">
</div>
<div class="input-with-label">
<label for="edit-lhe-delivery">LHe Anlieferung:</label>
<input type="text" id="edit-lhe-delivery" placeholder="Enter delivery amount">
</div>
<div class="input-with-label">
<label for="edit-lhe-output">LHe Ausgabe:</label>
<input type="number" id="edit-lhe-output" placeholder="Enter output amount">
</div>
<label for="edit-notes">Notes:</label>
<textarea id="edit-notes" placeholder="Additional notes"></textarea>
<div class="popup-buttons">
<button class="save-btn" id="save-edit-two">Save</button>
<button class="cancel-btn" id="cancel-edit-two">Cancel</button>
<button class="help-btn">Help</button>
</div>
</div>
<script>
$(document).ready(function () {
let currentTableId = null;
let currentModelName = null;
// Store all client options for both dropdowns
const allClientOptions = $('#add-client-id').html();
const allEditClientOptions = $('#edit-client-id').html();
// Function to filter clients based on institute selection
function filterClients(instituteId, targetSelect, allOptions) {
if (!instituteId) {
// Show only the default option if no institute selected
targetSelect.html('<option value="">Select Institute first</option>');
targetSelect.prop('disabled', true);
} else {
// Restore all options first
targetSelect.html(allOptions);
// Enable the dropdown
targetSelect.prop('disabled', false);
// Hide all options first
targetSelect.find('option').hide();
// Always show the "Select Client" option
targetSelect.find('option[value=""]').show().text('Select Client');
// Show only clients from selected institute
const clientsFromInstitute = targetSelect.find(`option[data-institute="${instituteId}"]`);
if (clientsFromInstitute.length > 0) {
clientsFromInstitute.show();
} else {
targetSelect.html('<option value="">No clients found for this institute</option>');
}
// Reset selection
targetSelect.val('');
}
}
// Function to handle warm field change and control LHe Anlieferung field
function handleWarmFieldChange(warmField, deliveryField) {
const warmValue = parseInt(warmField.val());
// Ensure value is only 0 or 1
if (warmValue !== 0 && warmValue !== 1) {
warmField.val(0);
}
// If warm is 1, set delivery to 0 and disable it
if (parseInt(warmField.val()) === 1) {
deliveryField.val('0');
deliveryField.prop('disabled', true);
deliveryField.prop('readonly', true);
} else {
deliveryField.prop('disabled', false);
deliveryField.prop('readonly', false);
}
}
// Initialize warm field handlers for add popup
$('#add-is-warm').on('change input', function() {
handleWarmFieldChange($(this), $('#add-lhe-delivery'));
});
// Initialize warm field handlers for edit popup
$('#edit-is-warm').on('change input', function() {
handleWarmFieldChange($(this), $('#edit-lhe-delivery'));
});
// Institute change handler for add popup
$('#add-institute-id').on('change', function() {
const instituteId = $(this).val();
filterClients(instituteId, $('#add-client-id'), allClientOptions);
});
// Institute change handler for edit popup
$('#edit-institute-id').on('change', function() {
const instituteId = $(this).val();
filterClients(instituteId, $('#edit-client-id'), allEditClientOptions);
});
// Open Add Popup for Table 2
$('#add-row-two').on('click', function () {
currentTableId = 'table-two';
currentModelName = 'SecondTableEntry';
// Reset form
$('#add-institute-id').val('');
$('#add-client-id').html('<option value="">Select Institute first</option>');
$('#add-client-id').prop('disabled', true);
$('#add-date').val('');
$('#add-is-warm').val('0');
$('#add-lhe-delivery').val('');
$('#add-lhe-delivery').prop('disabled', false);
$('#add-lhe-delivery').prop('readonly', false);
$('#add-lhe-output').val('');
$('#add-notes').val('');
// Apply initial warm field logic
handleWarmFieldChange($('#add-is-warm'), $('#add-lhe-delivery'));
$('#add-popup-two').fadeIn();
});
@@ -314,10 +448,30 @@
// Save Add Entry
$('#save-add-two').on('click', function() {
const clientId = $('#add-client-id').val();
const instituteId = $('#add-institute-id').val();
if (!instituteId) {
alert('Please select an institute');
return;
}
if (!clientId) {
alert('Please select a client');
return;
}
// Validate warm field
const warmValue = parseInt($('#add-is-warm').val());
if (warmValue !== 0 && warmValue !== 1) {
alert('Warm field must be 0 or 1');
return;
}
let formData = {
'client_id': $('#add-client-id').val(),
'date': $('#add-date').val(), // Ensure this is in YYYY-MM-DD format
'is_warm': $('#add-is-warm').is(':checked'),
'client_id': clientId,
'date': $('#add-date').val(),
'is_warm': warmValue,
'lhe_delivery': $('#add-lhe-delivery').val(),
'lhe_output': $('#add-lhe-output').val(),
'notes': $('#add-notes').val(),
@@ -331,7 +485,7 @@
}
// Validate LHe Output is a number
if (isNaN(parseFloat(formData.lhe_output))) {
if (formData.lhe_output && isNaN(parseFloat(formData.lhe_output))) {
alert('LHe Output must be a valid number');
return;
}
@@ -347,6 +501,7 @@
<tr data-id="${response.id}">
<td>${$('#table-two tbody tr').length + 1}</td>
<td>${response.id}</td>
<td>${response.institute_name || ''}</td>
<td>${response.client_name}</td>
<td>${response.date || ''}</td>
<td>${response.is_warm ? 'Yes' : 'No'}</td>
@@ -371,53 +526,81 @@
});
});
// Add this new function to load table data
function loadTableData() {
$.ajax({
url: window.location.href,
method: 'GET',
success: function(data) {
// Parse the HTML response to extract the table body
let newBody = $(data).find('#table-two tbody').html();
$('#table-two tbody').html(newBody);
},
error: function() {
alert('Failed to refresh table data');
}
});
}
// Open Edit Popup
$(document).on('click', '.edit-btn-two', function() {
let row = $(this).closest('tr');
$('#edit-id').val(row.data('id'));
const entryId = row.data('id');
const clientName = row.find('td:eq(2)').text().trim();
// Set client - find by name since we're showing names in the table
let clientName = row.find('td:eq(2)').text().trim();
$(`#edit-client-id option:contains("${clientName}")`).prop('selected', true);
// Reset edit form first
$('#edit-institute-id').val('');
$('#edit-client-id').html(allEditClientOptions);
$('#edit-client-id').prop('disabled', true);
// Set date - ensure proper format
let dateText = row.find('td:eq(3)').text().trim();
if (dateText) {
$('#edit-date').val(dateText);
// Find the client and set the institute
const clientOptions = $('#edit-client-id option');
let foundInstituteId = '';
let foundClientId = '';
clientOptions.each(function() {
if ($(this).text() === clientName) {
foundInstituteId = $(this).data('institute');
foundClientId = $(this).val();
return false; // break the loop
}
});
if (foundInstituteId) {
$('#edit-institute-id').val(foundInstituteId);
filterClients(foundInstituteId, $('#edit-client-id'), allEditClientOptions);
$('#edit-client-id').val(foundClientId);
}
// Set other fields
$('#edit-is-warm').prop('checked', row.find('td:eq(4)').text().trim() === 'Yes');
$('#edit-id').val(entryId);
$('#edit-date').val(row.find('td:eq(3)').text().trim());
// Set warm value (convert from "Yes"/"No" to 1/0)
const warmValue = row.find('td:eq(4)').text().trim() === 'Yes' ? 1 : 0;
$('#edit-is-warm').val(warmValue);
$('#edit-lhe-delivery').val(row.find('td:eq(5)').text().trim());
$('#edit-lhe-output').val(row.find('td:eq(6)').text().trim());
$('#edit-notes').val(row.find('td:eq(7)').text().trim());
// Apply warm field logic
handleWarmFieldChange($('#edit-is-warm'), $('#edit-lhe-delivery'));
$('#edit-popup-two').fadeIn();
});
// Save Edit Entry
$('#save-edit-two').on('click', function() {
const clientId = $('#edit-client-id').val();
const instituteId = $('#edit-institute-id').val();
if (!instituteId) {
alert('Please select an institute');
return;
}
if (!clientId) {
alert('Please select a client');
return;
}
// Validate warm field
const warmValue = parseInt($('#edit-is-warm').val());
if (warmValue !== 0 && warmValue !== 1) {
alert('Warm field must be 0 or 1');
return;
}
let formData = {
'id': $('#edit-id').val(),
'client_id': $('#edit-client-id').val(),
'date': $('#edit-date').val(), // Already in YYYY-MM-DD format
'is_warm': $('#edit-is-warm').is(':checked'),
'client_id': clientId,
'date': $('#edit-date').val(),
'is_warm': warmValue,
'lhe_delivery': $('#edit-lhe-delivery').val(),
'lhe_output': $('#edit-lhe-output').val(),
'notes': $('#edit-notes').val(),
@@ -429,7 +612,7 @@
alert('Please select a date');
return;
}
if (isNaN(parseFloat(formData.lhe_output))) {
if (formData.lhe_output && isNaN(parseFloat(formData.lhe_output))) {
alert('Please enter a valid LHe Output value');
return;
}
@@ -462,13 +645,11 @@
$(document).on('click', '.delete-btn-two', function () {
let row = $(this).closest('tr');
let id = row.data('id');
currentTableId = row.closest('table').attr('id');
currentModelName = 'SecondTableEntry';
if (!confirm('Are you sure you want to delete this entry?')) return;
$.ajax({
url: `/delete-entry/${currentModelName}/`,
url: '/delete-entry/SecondTableEntry/',
method: 'POST',
data: {
'id': id,