new update
This commit is contained in:
@@ -1,290 +1,124 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Clients Table</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;
|
||||
}
|
||||
.add-row-btn, .btn-go-back {
|
||||
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,
|
||||
.btn-go-back:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.container {
|
||||
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%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
th {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
tr:hover {
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
.actions button {
|
||||
margin: 2px;
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
.edit-btn {
|
||||
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
.delete-btn {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<!-- Year Filter -->
|
||||
<div class="year-filter">
|
||||
<label for="year-select">Year:</label>
|
||||
<select id="year-select" onchange="window.location.href='?year='+this.value">
|
||||
{% for year in available_years %}
|
||||
<option value="{{ year }}" {% if year == current_year %}selected{% endif %}>
|
||||
{{ year }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<h2>Clients Table</h2>
|
||||
<button class="add-row-btn" id="add-client">Add Client</button>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th> <!-- This is your new sequential number column -->
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for client in clients %}
|
||||
<tr data-id="{{ client.id }}">
|
||||
<td>{{ forloop.counter }}</td> <!-- ← this gives you 1, 2, 3... -->
|
||||
<td>{{ client.id }}</td>
|
||||
<td>{{ client.name }}</td>
|
||||
<td>{{ client.address }}</td>
|
||||
<td class="actions">
|
||||
<button class="edit-btn">Edit</button>
|
||||
<button class="delete-btn">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Annual Summary Table -->
|
||||
<table class="summary-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Client</th>
|
||||
{% for month in months %}
|
||||
<th>{{ month }}</th>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for data in monthly_data %}
|
||||
<tr>
|
||||
<td>{{ data.client.name }}</td>
|
||||
{% for total in data.monthly_totals %}
|
||||
<td>{{ total|floatformat:2 }}</td>
|
||||
{% endfor %}
|
||||
<td class="total">{{ data.year_total|floatformat:2 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- Add Client Popup -->
|
||||
<div id="add-popup" class="popup">
|
||||
<span class="close-btn">×</span>
|
||||
<h3>Add Client</h3>
|
||||
<input type="text" id="add-name" placeholder="Name">
|
||||
<input type="text" id="add-address" placeholder="Address">
|
||||
<button id="save-add">Add</button>
|
||||
</div>
|
||||
|
||||
<!-- Edit Client Popup -->
|
||||
<div id="edit-popup" class="popup">
|
||||
<span class="close-btn">×</span>
|
||||
<h3>Edit Client</h3>
|
||||
<input type="hidden" id="edit-id">
|
||||
<input type="text" id="edit-name" placeholder="Name">
|
||||
<input type="text" id="edit-address" placeholder="Address">
|
||||
<button id="save-edit">Save</button>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 30px; text-align: center;">
|
||||
<a href="{% url 'table_one' %}">
|
||||
<button class="add-row-btn">Go to Helium input</button>
|
||||
<!-- Navigation Buttons -->
|
||||
<div class="navigation-buttons">
|
||||
<a href="{% url 'table_one' %}" class="nav-button">
|
||||
Go to Helium Input
|
||||
</a>
|
||||
<a href="{% url 'table_two' %}">
|
||||
<button class="add-row-btn">Go to Table output</button>
|
||||
<a href="{% url 'table_two' %}" class="nav-button">
|
||||
Go to Helium Output
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.year-filter {
|
||||
margin: 20px 0;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.year-filter label {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.year-filter select {
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
<script>
|
||||
let currentModelName = "Client";
|
||||
.summary-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.summary-table th, .summary-table td {
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.summary-table th {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.summary-table tr:nth-child(even) {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.summary-table tr:hover {
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.total {
|
||||
font-weight: bold;
|
||||
background-color: #e6f2ff;
|
||||
}
|
||||
|
||||
// Open Add Popup
|
||||
$('#add-client').on('click', function () {
|
||||
$('#add-popup').fadeIn();
|
||||
});
|
||||
|
||||
// Close Popups
|
||||
$('.close-btn').on('click', function () {
|
||||
$('.popup').fadeOut();
|
||||
});
|
||||
|
||||
// Save Add Client
|
||||
$('#save-add').on('click', function () {
|
||||
let name = $('#add-name').val();
|
||||
let address = $('#add-address').val();
|
||||
|
||||
$.ajax({
|
||||
url: `/add-entry/Client/`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
'name': name,
|
||||
'address': address,
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
},
|
||||
success: function (response) {
|
||||
let rowCount = $('tbody tr').length + 1;
|
||||
let newRow = `
|
||||
<tr data-id="${response.id}">
|
||||
<td>${rowCount}</td>
|
||||
<td>${response.id}</td>
|
||||
<td>${response.name}</td>
|
||||
<td>${response.address}</td>
|
||||
<td class="actions">
|
||||
<button class="edit-btn">Edit</button>
|
||||
<button class="delete-btn">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
$('tbody').append(newRow);
|
||||
$('#add-popup').fadeOut();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert('Failed to add client: ' + xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Open Edit Popup
|
||||
$(document).on('click', '.edit-btn', function () {
|
||||
let row = $(this).closest('tr');
|
||||
$('#edit-id').val(row.data('id'));
|
||||
$('#edit-name').val(row.find('td:eq(2)').text()); // Name
|
||||
$('#edit-address').val(row.find('td:eq(3)').text()); // Address
|
||||
$('#edit-popup').fadeIn();
|
||||
});
|
||||
|
||||
// Save Edit Client
|
||||
$('#save-edit').on('click', function () {
|
||||
let id = $('#edit-id').val();
|
||||
let name = $('#edit-name').val();
|
||||
let address = $('#edit-address').val();
|
||||
|
||||
$.ajax({
|
||||
url: `/update-entry/${currentModelName}/`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'address': address,
|
||||
'age': 0,
|
||||
'email': 'none@example.com',
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.status === 'success') {
|
||||
let row = $(`tr[data-id="${id}"]`);
|
||||
row.find('td:eq(2)').text(name); // Correct column for Name
|
||||
row.find('td:eq(3)').text(address); // Correct column for Address
|
||||
$('#edit-popup').fadeOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Delete Client
|
||||
$(document).on('click', '.delete-btn', function () {
|
||||
let row = $(this).closest('tr');
|
||||
let id = row.data('id');
|
||||
|
||||
if (!confirm('Are you sure you want to delete this client?')) 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('Delete failed: ' + response.message);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert('Delete request failed:\n' + xhr.responseText);
|
||||
console.log('Error:', error);
|
||||
console.log('Status:', status);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
.navigation-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.nav-button {
|
||||
padding: 12px 24px;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.nav-button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -27,18 +27,32 @@
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
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;
|
||||
@@ -106,6 +120,7 @@
|
||||
.add-row-btn:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -118,14 +133,25 @@
|
||||
<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>Entry 1</th>
|
||||
<th>Entry 2</th>
|
||||
<th>Druck</th>
|
||||
<th>Reinheit</th>
|
||||
<th>Date Joined</th>
|
||||
<th>Notes</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -135,9 +161,10 @@
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>{{ entry.id }}</td>
|
||||
<td>{{ entry.client.name }}</td>
|
||||
<td>{{ entry.age }}</td>
|
||||
<td>{{ entry.email }}</td>
|
||||
<td>{{ entry.date_joined }}</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>
|
||||
@@ -152,30 +179,72 @@
|
||||
<!-- Add Popup -->
|
||||
<div id="add-popup-one" class="popup">
|
||||
<span class="close-btn">×</span>
|
||||
<h3>Add Entry</h3>
|
||||
<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>
|
||||
<input type="number" id="add-age" placeholder="Age">
|
||||
<input type="email" id="add-email" placeholder="Email">
|
||||
<button id="save-add-one">Add</button>
|
||||
|
||||
<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>Edit Entry</h3>
|
||||
<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>
|
||||
<input type="number" id="edit-age" placeholder="Age">
|
||||
<input type="email" id="edit-email" placeholder="Email">
|
||||
<button id="save-edit-one">Save</button>
|
||||
|
||||
<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>
|
||||
@@ -192,81 +261,135 @@
|
||||
});
|
||||
|
||||
// Add
|
||||
$('#save-add-one').on('click', function () {
|
||||
let client_id = $('#add-client-id').val();
|
||||
let age = $('#add-age').val();
|
||||
let email = $('#add-email').val();
|
||||
$('#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/${currentModelName}/`,
|
||||
url: '/add-entry/ExcelEntry/',
|
||||
method: 'POST',
|
||||
data: {
|
||||
'client_id': client_id,
|
||||
'age': age,
|
||||
'email': email,
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
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'));
|
||||
}
|
||||
},
|
||||
success: function (response) {
|
||||
let rowCount = $(`#${currentTableId} tbody tr`).length + 1;
|
||||
let newRow = `
|
||||
<tr data-id="${response.id}">
|
||||
<td>${rowCount}</td>
|
||||
<td>${response.id}</td>
|
||||
<td>${response.client_name}</td>
|
||||
<td>${response.age}</td>
|
||||
<td>${response.email}</td>
|
||||
<td>${response.date_joined}</td>
|
||||
<td class="actions">
|
||||
<button class="edit-btn-one">Edit</button>
|
||||
<button class="delete-btn-one">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
$(`#${currentTableId} tbody`).append(newRow);
|
||||
$('#add-popup-one').fadeOut();
|
||||
error: function(xhr) {
|
||||
alert('Error: ' + (xhr.responseJSON?.message || 'Server error'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Edit
|
||||
$(document).on('click', '.edit-btn-one', function () {
|
||||
$(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());
|
||||
$('#edit-age').val(row.find('td:eq(3)').text());
|
||||
$('#edit-email').val(row.find('td:eq(4)').text());
|
||||
$('#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();
|
||||
});
|
||||
|
||||
$('#save-edit-one').on('click', function () {
|
||||
let id = $('#edit-id').val();
|
||||
let client_id = $('#edit-client-id').val();
|
||||
let age = $('#edit-age').val();
|
||||
let email = $('#edit-email').val();
|
||||
// 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/${currentModelName}/`,
|
||||
url: '/update-entry/ExcelEntry/',
|
||||
method: 'POST',
|
||||
data: {
|
||||
'id': id,
|
||||
'client_id': client_id,
|
||||
'age': age,
|
||||
'email': email,
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
},
|
||||
success: function (response) {
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
let row = $(`tr[data-id="${response.id}"]`);
|
||||
row.find('td:eq(2)').text(response.name);
|
||||
row.find('td:eq(3)').text(response.age);
|
||||
row.find('td:eq(4)').text(response.email);
|
||||
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('Failed to update entry: ' + response.message);
|
||||
alert('Error: ' + (response.message || 'Failed to update entry'));
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Failed to update entry. Please try again.');
|
||||
error: function(xhr) {
|
||||
alert('Error: ' + (xhr.responseJSON?.message || 'Server error'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>Helium Output</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 href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" rel="stylesheet"/>
|
||||
<style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Helium Output</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;
|
||||
@@ -76,23 +75,56 @@
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
||||
z-index: 1000;
|
||||
width: 400px;
|
||||
}
|
||||
.popup input {
|
||||
.popup h3 {
|
||||
margin-top: 0;
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.popup label {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.popup input, .popup select, .popup textarea {
|
||||
display: block;
|
||||
margin-bottom: 15px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.popup textarea {
|
||||
height: 100px;
|
||||
resize: vertical;
|
||||
}
|
||||
.popup-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.popup button {
|
||||
margin-top: 10px;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
.save-btn {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
.cancel-btn {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
.help-btn {
|
||||
background-color: #17a2b8;
|
||||
color: white;
|
||||
}
|
||||
.close-btn {
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
@@ -112,174 +144,244 @@
|
||||
.add-row-btn:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.popup select {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-family: Arial, sans-serif;
|
||||
.checkbox-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.checkbox-container input[type="checkbox"] {
|
||||
width: auto;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.input-with-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.input-with-label label {
|
||||
width: 120px;
|
||||
margin-bottom: 0;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.input-with-label input {
|
||||
flex: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="d-flex justify-content-start mb-2">
|
||||
<!-- "Go to Clients" button at top-left -->
|
||||
<a class="btn btn-outline-primary" href="{% url 'clients_list' %}">
|
||||
⇦ Go to Clients
|
||||
|
||||
<div class="d-flex justify-content-start mb-2">
|
||||
<!-- "Go to Clients" button at top-left -->
|
||||
<a href="{% url 'clients_list' %}" class="btn btn-outline-primary">
|
||||
⇦ Go to Clients
|
||||
</a>
|
||||
</div>
|
||||
<h2>Helium Output</h2>
|
||||
<!-- Second Table -->
|
||||
<div class="table-container">
|
||||
<button class="add-row-btn" id="add-row-two">Add Row</button>
|
||||
<table id="table-two">
|
||||
<thead><tr><th>#</th><th>ID</th><th>Client</th><th>Date</th><th>Warm</th><th>LHe Anlieferung</th><th>LHe Ausgabe</th><th>Comments</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.age }}</td>
|
||||
<td>{{ entry.email }}</td>
|
||||
<td>{{ entry.date_joined }}</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" style="display:none;">
|
||||
<span class="close-btn">×</span>
|
||||
<h3>Add Entry</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">Datum:</label>
|
||||
<input type="date" id="add-date">
|
||||
|
||||
<label><input type="checkbox" id="add-warm"> warm</label>
|
||||
|
||||
<label for="add-lhe-anlieferung">LHe Anlieferung:</label>
|
||||
<input type="text" id="add-lhe-anlieferung" placeholder="LHe Anlieferung">
|
||||
|
||||
<label for="add-lhe-ausgabe">LHe Ausgabe:</label>
|
||||
<input type="text" id="add-lhe-ausgabe" placeholder="LHe Ausgabe">
|
||||
|
||||
<label for="add-comment">Kommentar:</label>
|
||||
<textarea id="add-comment" rows="4"></textarea>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="save-add-two">💾 Save</button>
|
||||
<button class="close-btn">❌ Cancel</button>
|
||||
<button id="help-btn">❓ Help</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- Edit Entry Popup -->
|
||||
<div class="popup" id="edit-popup-two">
|
||||
<span class="close-btn">×</span>
|
||||
<h3>Edit Entry</h3>
|
||||
<input id="edit-id" type="hidden"/>
|
||||
<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><input id="edit-warm" type="checkbox"/> warm</label>
|
||||
<input id="edit-anlieferung" placeholder="LHe Anlieferung" type="text"/>
|
||||
<input id="edit-ausgabe" placeholder="LHe Ausgabe" type="text"/>
|
||||
<textarea id="edit-comments" placeholder="Comments" rows="4"></textarea>
|
||||
<button id="save-edit-two">Save</button>
|
||||
<button class="close-btn">Cancel</button>
|
||||
<button id="help-btn-edit-two">Help</button>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
let currentTableId = null; // To track which table is being edited
|
||||
let currentModelName = null; // To track which model is being used
|
||||
<h2>LHe Dewar Output</h2>
|
||||
|
||||
// Open Add Popup for Table 2
|
||||
$('#add-row-two').on('click', function () {
|
||||
currentTableId = 'table-two';
|
||||
currentModelName = 'SecondTableEntry'; // Model name for Table 2
|
||||
$('#add-popup-two').fadeIn();
|
||||
});
|
||||
|
||||
// Close Popups
|
||||
$('.close-btn').on('click', function () {
|
||||
$('.popup').fadeOut();
|
||||
});
|
||||
|
||||
// Save Add Entry
|
||||
$('#save-add-two').on('click', function () {
|
||||
let client_id = $('#add-client-id').val();
|
||||
let date = $('#add-date').val();
|
||||
let warm = $('#add-warm').is(':checked') ? 1 : 0;
|
||||
let lhe_anlieferung = $('#add-lhe-anlieferung').val();
|
||||
let lhe_ausgabe = $('#add-lhe-ausgabe').val();
|
||||
let comment = $('#add-comment').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/add-entry/SecondTableEntry/',
|
||||
method: 'POST',
|
||||
data: {
|
||||
'client_id': client_id,
|
||||
'date': date,
|
||||
'warm': warm,
|
||||
'lhe_anlieferung': lhe_anlieferung,
|
||||
'lhe_ausgabe': lhe_ausgabe,
|
||||
'comment': comment,
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
},
|
||||
success: function (response) {
|
||||
let rowCount = $('tbody tr').length + 1;
|
||||
let newRow = `
|
||||
<tr data-id="${response.id}">
|
||||
<td>${rowCount}</td>
|
||||
<td>${response.id}</td>
|
||||
<td>${response.name}</td>
|
||||
<td>${response.warm}</td>
|
||||
<td>${response.lhe_anlieferung}</td>
|
||||
<td>${response.lhe_ausgabe}</td>
|
||||
<td>${response.date}</td>
|
||||
<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>`;
|
||||
$('tbody').append(newRow);
|
||||
$('#add-popup-two').fadeOut();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert('Failed to add entry: ' + xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Add Entry Popup -->
|
||||
<div id="add-popup-two" class="popup">
|
||||
<span class="close-btn">×</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>
|
||||
</div>
|
||||
|
||||
<!-- Edit Entry Popup -->
|
||||
<div id="edit-popup-two" class="popup">
|
||||
<span class="close-btn">×</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>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
let currentTableId = null;
|
||||
let currentModelName = null;
|
||||
|
||||
// Open Add Popup for Table 2
|
||||
$('#add-row-two').on('click', function () {
|
||||
currentTableId = 'table-two';
|
||||
currentModelName = 'SecondTableEntry';
|
||||
$('#add-popup-two').fadeIn();
|
||||
});
|
||||
|
||||
// Close Popups
|
||||
$('.close-btn, .cancel-btn').on('click', function () {
|
||||
$('.popup').fadeOut();
|
||||
});
|
||||
|
||||
// Save Add Entry
|
||||
$('#save-add-two').on('click', function() {
|
||||
let formData = {
|
||||
'client_id': $('#add-client-id').val(),
|
||||
'date': $('#add-date').val(),
|
||||
'is_warm': $('#add-is-warm').is(':checked'),
|
||||
'lhe_delivery': $('#add-lhe-delivery').val(),
|
||||
'lhe_output': $('#add-lhe-output').val(),
|
||||
'notes': $('#add-notes').val(),
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
};
|
||||
|
||||
// Validate LHe Output is a number
|
||||
if (isNaN(parseFloat(formData.lhe_output))) {
|
||||
alert('LHe Output must be a valid number');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/add-entry/SecondTableEntry/',
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
// Clear the form
|
||||
$('#add-popup-two').find('input, textarea, select').val('');
|
||||
$('#add-is-warm').prop('checked', false);
|
||||
$('#add-popup-two').fadeOut();
|
||||
|
||||
// Reload the table data
|
||||
loadTableData();
|
||||
},
|
||||
error: function(xhr) {
|
||||
alert('Error: ' + xhr.responseJSON?.message || 'Failed to add entry');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 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');
|
||||
currentTableId = row.closest('table').attr('id'); // Set current table ID
|
||||
currentModelName = 'SecondTableEntry'; // Set model name
|
||||
currentTableId = row.closest('table').attr('id');
|
||||
currentModelName = 'SecondTableEntry';
|
||||
|
||||
// Get data from the row
|
||||
let is_warm = row.find('td:eq(4)').text().trim() === 'Yes';
|
||||
|
||||
$('#edit-id').val(row.data('id'));
|
||||
$('#edit-client-id').val(row.find('td:eq(2)').text()); // Name is now in column 2
|
||||
$('#edit-age').val(row.find('td:eq(3)').text()); // Age is now in column 3
|
||||
$('#edit-email').val(row.find('td:eq(4)').text()); // Email is now in column 4
|
||||
$('#edit-client-id').val(row.find('td:eq(2)').text().trim());
|
||||
$('#edit-date').val(row.find('td:eq(3)').text().trim());
|
||||
$('#edit-is-warm').prop('checked', is_warm);
|
||||
$('#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());
|
||||
|
||||
$('#edit-popup-two').fadeIn();
|
||||
});
|
||||
|
||||
@@ -287,8 +389,11 @@ $('#save-add-two').on('click', function () {
|
||||
$('#save-edit-two').on('click', function () {
|
||||
let id = $('#edit-id').val();
|
||||
let client_id = $('#edit-client-id').val();
|
||||
let age = $('#edit-age').val();
|
||||
let email = $('#edit-email').val();
|
||||
let date = $('#edit-date').val();
|
||||
let is_warm = $('#edit-is-warm').is(':checked');
|
||||
let lhe_delivery = $('#edit-lhe-delivery').val();
|
||||
let lhe_output = $('#edit-lhe-output').val();
|
||||
let notes = $('#edit-notes').val();
|
||||
|
||||
$.ajax({
|
||||
url: `/update-entry/${currentModelName}/`,
|
||||
@@ -296,23 +401,30 @@ $('#save-add-two').on('click', function () {
|
||||
data: {
|
||||
'id': id,
|
||||
'client_id': client_id,
|
||||
'age': age,
|
||||
'email': email,
|
||||
'date': date,
|
||||
'is_warm': is_warm,
|
||||
'lhe_delivery': lhe_delivery,
|
||||
'lhe_output': lhe_output,
|
||||
'notes': notes,
|
||||
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.status === 'success') {
|
||||
let row = $(`tr[data-id="${response.id}"]`);
|
||||
row.find('td:eq(2)').text(response.name);
|
||||
row.find('td:eq(3)').text(response.age);
|
||||
row.find('td:eq(4)').text(response.email);
|
||||
row.find('td:eq(2)').text(response.client_name);
|
||||
row.find('td:eq(3)').text(response.date);
|
||||
row.find('td:eq(4)').text(response.is_warm ? 'Yes' : 'No');
|
||||
row.find('td:eq(5)').text(response.lhe_delivery);
|
||||
row.find('td:eq(6)').text(response.lhe_output);
|
||||
row.find('td:eq(7)').text(response.notes);
|
||||
$('#edit-popup-two').fadeOut();
|
||||
} else {
|
||||
alert('Failed to update entry: ' + response.message);
|
||||
alert('Update failed: ' + (response.message || 'Please try again later'));
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Failed to update entry. Please try again.');
|
||||
error: function (xhr, status, error) {
|
||||
alert('Update failed: ' + (xhr.responseJSON?.message || 'Please try again later'));
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -321,8 +433,8 @@ $('#save-add-two').on('click', function () {
|
||||
$(document).on('click', '.delete-btn-two', function () {
|
||||
let row = $(this).closest('tr');
|
||||
let id = row.data('id');
|
||||
currentTableId = row.closest('table').attr('id'); // Set current table ID
|
||||
currentModelName = 'SecondTableEntry'; // Set model name
|
||||
currentTableId = row.closest('table').attr('id');
|
||||
currentModelName = 'SecondTableEntry';
|
||||
|
||||
if (!confirm('Are you sure you want to delete this entry?')) return;
|
||||
|
||||
@@ -337,11 +449,12 @@ $('#save-add-two').on('click', function () {
|
||||
if (response.status === 'success') {
|
||||
row.fadeOut(300, function () { $(this).remove(); });
|
||||
} else {
|
||||
alert('Failed to delete entry: ' + response.message);
|
||||
alert('Delete failed: ' + response.message);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Failed to delete entry. Please try again.');
|
||||
error: function (xhr, status, error) {
|
||||
alert('Delete failed: ' + (xhr.responseJSON?.message || 'Please try again later'));
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user