Конкретно пересмотрел логику работы. Легаси вынесена в архив
All checks were successful
Deploy MES Core / deploy (push) Successful in 13s
All checks were successful
Deploy MES Core / deploy (push) Successful in 13s
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card shadow border-secondary mb-3">
|
||||
<div class="card-header border-secondary py-3 d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<h3 class="text-accent mb-0"><i class="bi bi-activity me-2"></i>Марки стали</h3>
|
||||
|
||||
<div class="d-flex flex-wrap gap-2 align-items-center">
|
||||
<form method="get" class="d-flex gap-2 align-items-center">
|
||||
<input class="form-control form-control-sm bg-body text-body border-secondary" name="q" value="{{ q }}" placeholder="Поиск...">
|
||||
<button class="btn btn-outline-secondary btn-sm" type="submit"><i class="bi bi-search me-1"></i>Найти</button>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="{% url 'steel_grades_catalog' %}"><i class="bi bi-arrow-counterclockwise me-1"></i>Сброс</a>
|
||||
</form>
|
||||
|
||||
{% if can_edit %}
|
||||
<button class="btn btn-outline-accent btn-sm" type="button" data-bs-toggle="modal" data-bs-target="#gradeModal" onclick="openGradeCreate()">
|
||||
<i class="bi bi-plus-lg me-1"></i>Создать
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0 align-middle">
|
||||
<thead>
|
||||
<tr class="table-custom-header">
|
||||
<th>Название</th>
|
||||
<th>ГОСТ</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for g in grades %}
|
||||
<tr role="button" {% if can_edit %}onclick="openGradeEdit(this)"{% endif %}
|
||||
data-id="{{ g.id }}" data-name="{{ g.name }}" data-gost="{{ g.gost_standard }}">
|
||||
<td class="fw-bold">{{ g.name }}</td>
|
||||
<td>{{ g.gost_standard|default:"—" }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="2" class="text-center text-muted py-4">Нет данных</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<a class="btn btn-outline-secondary btn-sm" href="{% url 'directories' %}">Назад</a>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="gradeModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<form class="modal-content border-secondary" onsubmit="event.preventDefault(); saveGrade();">
|
||||
<div class="modal-header border-secondary">
|
||||
<h5 class="modal-title" id="gradeModalTitle">Марка</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" id="gradeId">
|
||||
|
||||
<div class="row g-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Название</label>
|
||||
<input class="form-control bg-body text-body border-secondary" id="gradeName" required {% if not can_edit %}disabled{% endif %}>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">ГОСТ</label>
|
||||
<input class="form-control bg-body text-body border-secondary" id="gradeGost" {% if not can_edit %}disabled{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer border-secondary">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||
{% if can_edit %}
|
||||
<button type="submit" class="btn btn-outline-accent">Сохранить</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function getCookie(name) {
|
||||
const value = `; ${document.cookie}`;
|
||||
const parts = value.split(`; ${name}=`);
|
||||
if (parts.length === 2) return parts.pop().split(';').shift();
|
||||
return '';
|
||||
}
|
||||
|
||||
function openGradeCreate() {
|
||||
document.getElementById('gradeModalTitle').textContent = 'Марка стали (создание)';
|
||||
document.getElementById('gradeId').value = '';
|
||||
document.getElementById('gradeName').value = '';
|
||||
document.getElementById('gradeGost').value = '';
|
||||
new bootstrap.Modal(document.getElementById('gradeModal')).show();
|
||||
}
|
||||
|
||||
function openGradeEdit(tr) {
|
||||
document.getElementById('gradeModalTitle').textContent = 'Марка стали (правка)';
|
||||
document.getElementById('gradeId').value = tr.getAttribute('data-id') || '';
|
||||
document.getElementById('gradeName').value = tr.getAttribute('data-name') || '';
|
||||
document.getElementById('gradeGost').value = tr.getAttribute('data-gost') || '';
|
||||
new bootstrap.Modal(document.getElementById('gradeModal')).show();
|
||||
}
|
||||
|
||||
async function saveGrade() {
|
||||
const fd = new FormData();
|
||||
fd.append('id', document.getElementById('gradeId').value);
|
||||
fd.append('name', document.getElementById('gradeName').value);
|
||||
fd.append('gost_standard', document.getElementById('gradeGost').value);
|
||||
|
||||
const res = await fetch("{% url 'steel_grade_upsert' %}", {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'X-CSRFToken': getCookie('csrftoken') },
|
||||
body: fd,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
alert('Не удалось сохранить марку стали');
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user