428 lines
16 KiB
HTML
428 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Helium Input</title>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 20px;
|
|
background-color: #f4f4f9;
|
|
}
|
|
.table-container {
|
|
width: 48%;
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
h2 {
|
|
text-align: center;
|
|
color: #333;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
table-layout: fixed;
|
|
border-collapse: collapse;
|
|
}
|
|
th, td {
|
|
padding: 12px;
|
|
text-align: center;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
th:nth-child(1), td:nth-child(1) { width: 5%; } /* # column */
|
|
th:nth-child(2), td:nth-child(2) { width: 5%; } /* ID column */
|
|
th:nth-child(3), td:nth-child(3) { width: 15%; } /* Client column */
|
|
th:nth-child(4), td:nth-child(4) { width: 10%; } /* Entry 1 (Pressure) */
|
|
th:nth-child(5), td:nth-child(5) { width: 10%; } /* Entry 2 (Purity) */
|
|
th:nth-child(6), td:nth-child(6) { width: 15%; } /* Date Joined */
|
|
th:nth-child(7), td:nth-child(7) { width: 25%; } /* Notes */
|
|
th:nth-child(7), td:nth-child(7) { width: 30%; } /* Actions */
|
|
|
|
.actions {
|
|
white-space: nowrap; /* Prevent buttons from wrapping */
|
|
}
|
|
th {
|
|
background-color: #007bff;
|
|
color: white;
|
|
font-weight: bold;
|
|
position: sticky;
|
|
top: 0;
|
|
}
|
|
tr:hover {
|
|
background-color: #f1f1f1;
|
|
}
|
|
.actions button {
|
|
margin: 2px;
|
|
padding: 5px 10px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
}
|
|
.edit-btn-one {
|
|
background-color: #28a745;
|
|
color: white;
|
|
}
|
|
.delete-btn-one {
|
|
background-color: #dc3545;
|
|
color: white;
|
|
}
|
|
.popup {
|
|
display: none;
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
|
z-index: 1000;
|
|
}
|
|
.popup input, .popup select {
|
|
display: block;
|
|
margin-bottom: 10px;
|
|
width: 100%;
|
|
padding: 8px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
.popup button {
|
|
margin-top: 10px;
|
|
padding: 8px 16px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
}
|
|
.close-btn {
|
|
cursor: pointer;
|
|
float: right;
|
|
font-size: 18px;
|
|
color: #333;
|
|
}
|
|
.add-row-btn {
|
|
padding: 10px 20px;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.add-row-btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<a href="{% url 'clients_list' %}" class="btn btn-outline-primary">
|
|
⇦ Go to Clients
|
|
</a>
|
|
|
|
<h2>Helium Input</h2>
|
|
<div class="table-container">
|
|
<button class="add-row-btn" id="add-row-one">Add Row</button>
|
|
<table id="table-one">
|
|
<colgroup>
|
|
<col style="width: 5%"> <!-- # -->
|
|
<col style="width: 5%"> <!-- ID -->
|
|
<col style="width: 15%"> <!-- Client -->
|
|
<col style="width: 10%"> <!-- Druck -->
|
|
<col style="width: 10%"> <!-- Reinheit -->
|
|
<col style="width: 15%"> <!-- Date Joined -->
|
|
<col style="width: 25%"> <!-- Notes -->
|
|
<col style="width: 15%"> <!-- Actions -->
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>ID</th>
|
|
<th>Client</th>
|
|
<th>Druck</th>
|
|
<th>Reinheit</th>
|
|
<th>Date Joined</th>
|
|
<th>Notes</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for entry in entries_table1 %}
|
|
<tr data-id="{{ entry.id }}">
|
|
<td>{{ forloop.counter }}</td>
|
|
<td>{{ entry.id }}</td>
|
|
<td>{{ entry.client.name }}</td>
|
|
<td>{{ entry.pressure|floatformat:2 }}</td>
|
|
<td>{{ entry.purity|floatformat:2 }}</td>
|
|
<td>{{ entry.date_joined|date:"Y-m-d" }}</td>
|
|
<td>{{ entry.notes|default:"" }}</td>
|
|
<td class="actions">
|
|
<button class="edit-btn-one">Edit</button>
|
|
<button class="delete-btn-one">Delete</button>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
<!-- Add Popup -->
|
|
<div id="add-popup-one" class="popup">
|
|
<span class="close-btn">×</span>
|
|
<h3>He Gas Bundle</h3>
|
|
|
|
<label for="add-client-id">Kunde:</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="input-with-label">
|
|
<label for="add-pressure">Druck:</label>
|
|
<input type="number" id="add-pressure" placeholder="Enter pressure" step="0.01" min="0">
|
|
</div>
|
|
|
|
<div class="input-with-label">
|
|
<label for="add-purity">Reinheit:</label>
|
|
<input type="number" id="add-purity" placeholder="Enter purity" step="0.01" min="0" max="100">
|
|
</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-one">Save</button>
|
|
<button class="cancel-btn">Cancel</button>
|
|
<button class="help-btn">Help</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Edit Popup -->
|
|
<div id="edit-popup-one" class="popup">
|
|
<span class="close-btn">×</span>
|
|
<h3>He Gas Bundle</h3>
|
|
<input type="hidden" id="edit-id">
|
|
|
|
<label for="edit-client-id">Kunde:</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="input-with-label">
|
|
<label for="edit-pressure">Druck:</label>
|
|
<input type="number" id="edit-pressure" placeholder="Enter pressure" step="0.01" min="0">
|
|
</div>
|
|
|
|
<div class="input-with-label">
|
|
<label for="edit-purity">Reinheit:</label>
|
|
<input type="number" id="edit-purity" placeholder="Enter purity" step="0.01" min="0" max="100">
|
|
</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-one">Save</button>
|
|
<button class="cancel-btn">Cancel</button>
|
|
<button class="help-btn">Help</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
let currentTableId = 'table-one';
|
|
let currentModelName = 'ExcelEntry';
|
|
|
|
$('#add-row-one').on('click', function () {
|
|
$('#add-popup-one').fadeIn();
|
|
});
|
|
|
|
$('.close-btn').on('click', function () {
|
|
$('.popup').fadeOut();
|
|
});
|
|
|
|
// Add
|
|
$('#save-add-one').on('click', function() {
|
|
// Validate date first
|
|
let dateInput = $('#add-date').val();
|
|
if (!dateInput) {
|
|
alert('Please select a date');
|
|
return;
|
|
}
|
|
|
|
// Validate numbers
|
|
let pressure = parseFloat($('#add-pressure').val());
|
|
let purity = parseFloat($('#add-purity').val());
|
|
|
|
if (isNaN(pressure) || pressure < 0) {
|
|
alert('Please enter a valid pressure value');
|
|
return;
|
|
}
|
|
|
|
if (isNaN(purity) || purity < 0 || purity > 100) {
|
|
alert('Please enter a valid purity value (0-100)');
|
|
return;
|
|
}
|
|
|
|
// Prepare the form data
|
|
let formData = {
|
|
'client_id': $('#add-client-id').val(),
|
|
'date': dateInput,
|
|
'pressure': pressure,
|
|
'purity': purity,
|
|
'notes': $('#add-notes').val(),
|
|
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
|
};
|
|
|
|
$.ajax({
|
|
url: '/add-entry/ExcelEntry/',
|
|
method: 'POST',
|
|
data: formData,
|
|
success: function(response) {
|
|
if (response.status === 'success') {
|
|
// Add the new row to the table
|
|
let newRow = `
|
|
<tr data-id="${response.id}">
|
|
<td>${$('#table-one tbody tr').length + 1}</td>
|
|
<td>${response.id}</td>
|
|
<td>${response.client_name}</td>
|
|
<td>${response.pressure}</td>
|
|
<td>${response.purity}</td>
|
|
<td>${response.date || ''}</td>
|
|
<td>${response.notes || ''}</td>
|
|
<td class="actions">
|
|
<button class="edit-btn-one">Edit</button>
|
|
<button class="delete-btn-one">Delete</button>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
$('#table-one tbody').append(newRow);
|
|
$('#add-popup-one').fadeOut();
|
|
} else {
|
|
alert('Error: ' + (response.message || 'Failed to add entry'));
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
alert('Error: ' + (xhr.responseJSON?.message || 'Server error'));
|
|
}
|
|
});
|
|
});
|
|
|
|
// Edit
|
|
$(document).on('click', '.edit-btn-one', function() {
|
|
let row = $(this).closest('tr');
|
|
$('#edit-id').val(row.data('id'));
|
|
$('#edit-client-id').val(row.find('td:eq(2)').text().trim());
|
|
|
|
// Handle date - ensure it's in correct format
|
|
let dateText = row.find('td:eq(5)').text().trim();
|
|
if (dateText) {
|
|
$('#edit-date').val(dateText);
|
|
}
|
|
|
|
$('#edit-pressure').val(row.find('td:eq(3)').text().trim());
|
|
$('#edit-purity').val(row.find('td:eq(4)').text().trim());
|
|
$('#edit-notes').val(row.find('td:eq(6)').text().trim());
|
|
$('#edit-popup-one').fadeIn();
|
|
});
|
|
|
|
// Update the save-edit-one handler
|
|
$('#save-edit-one').on('click', function() {
|
|
let formData = {
|
|
'id': $('#edit-id').val(),
|
|
'client_id': $('#edit-client-id').val(),
|
|
'date': $('#edit-date').val(), // Already in YYYY-MM-DD format
|
|
'pressure': $('#edit-pressure').val(),
|
|
'purity': $('#edit-purity').val(),
|
|
'notes': $('#edit-notes').val(),
|
|
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
|
};
|
|
|
|
// Validate inputs
|
|
if (!formData.date) {
|
|
alert('Please select a date');
|
|
return;
|
|
}
|
|
if (isNaN(formData.pressure) || formData.pressure < 0) {
|
|
alert('Please enter a valid pressure value');
|
|
return;
|
|
}
|
|
if (isNaN(formData.purity) || formData.purity < 0 || formData.purity > 100) {
|
|
alert('Please enter a valid purity value (0-100)');
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: '/update-entry/ExcelEntry/',
|
|
method: 'POST',
|
|
data: formData,
|
|
success: function(response) {
|
|
if (response.status === 'success') {
|
|
let row = $(`tr[data-id="${response.id}"]`);
|
|
row.find('td:eq(2)').text(response.client_name);
|
|
row.find('td:eq(3)').text(response.pressure);
|
|
row.find('td:eq(4)').text(response.purity);
|
|
row.find('td:eq(5)').text(response.date || '');
|
|
row.find('td:eq(6)').text(response.notes || '');
|
|
$('#edit-popup-one').fadeOut();
|
|
} else {
|
|
alert('Error: ' + (response.message || 'Failed to update entry'));
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
alert('Error: ' + (xhr.responseJSON?.message || 'Server error'));
|
|
}
|
|
});
|
|
});
|
|
|
|
// Delete
|
|
$(document).on('click', '.delete-btn-one', function () {
|
|
let row = $(this).closest('tr');
|
|
let id = row.data('id');
|
|
|
|
if (!confirm('Are you sure you want to delete this entry?')) return;
|
|
|
|
$.ajax({
|
|
url: `/delete-entry/${currentModelName}/`,
|
|
method: 'POST',
|
|
data: {
|
|
'id': id,
|
|
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
|
},
|
|
success: function (response) {
|
|
if (response.status === 'success') {
|
|
row.fadeOut(300, function () { $(this).remove(); });
|
|
} else {
|
|
alert('Failed to delete entry: ' + response.message);
|
|
}
|
|
},
|
|
error: function () {
|
|
alert('Failed to delete entry. Please try again.');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|