Merge lavoro/daitarn-trafilo-duplica
This commit is contained in:
@@ -526,7 +526,8 @@ function recipeEditor() {
|
||||
currentVersion: {{ (recipe.current_version.version_number if recipe and recipe.current_version else 0)|tojson }},
|
||||
|
||||
// ---- Measurement interval ----
|
||||
measurementIntervalMinutes: {{ (recipe.measurement_interval_minutes if recipe and recipe.measurement_interval_minutes else 'null')|tojson }},
|
||||
// #49: a new recipe starts from the system default duration (default_interval), an existing one never does
|
||||
measurementIntervalMinutes: {{ (recipe.measurement_interval_minutes if recipe and recipe.measurement_interval_minutes else (default_interval if not recipe and default_interval else 'null'))|tojson }},
|
||||
|
||||
// ---- Rules of measurement (points 8 and 9) ----
|
||||
// A new recipe forbids typing: the caliper is the instrument, and permission
|
||||
|
||||
@@ -10,6 +10,51 @@
|
||||
filter: 'all',
|
||||
deleteModal: false,
|
||||
deleteTarget: null,
|
||||
// #52: duplicate modal state
|
||||
dupModal: false,
|
||||
dupSource: null,
|
||||
dupCode: '',
|
||||
dupName: '',
|
||||
dupError: '',
|
||||
dupBusy: false,
|
||||
|
||||
openDupModal(recipe) {
|
||||
this.dupSource = recipe;
|
||||
this.dupCode = recipe.code + '-COPIA';
|
||||
this.dupName = recipe.name + ' ' + {{ _('(copia)')|tojson_attr }};
|
||||
this.dupError = '';
|
||||
this.dupModal = true;
|
||||
},
|
||||
|
||||
async duplicateRecipe() {
|
||||
const csrfToken = document.querySelector('meta[name=csrf-token]')?.content;
|
||||
this.dupBusy = true;
|
||||
this.dupError = '';
|
||||
try {
|
||||
const resp = await fetch(`/maker/api/recipes/${this.dupSource.id}/duplicate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken || '' },
|
||||
body: JSON.stringify({ code: this.dupCode.trim(), name: this.dupName.trim() })
|
||||
});
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
if (resp.ok) {
|
||||
// open the new recipe in the editor
|
||||
window.location.href = '/maker/recipes/' + data.id + '/edit';
|
||||
return;
|
||||
}
|
||||
if (resp.status === 409) {
|
||||
this.dupError = {{ _('Esiste già una ricetta con questo codice')|tojson_attr }};
|
||||
} else if (resp.status === 422) {
|
||||
this.dupError = {{ _('Codice o nome non validi')|tojson_attr }};
|
||||
} else {
|
||||
this.dupError = data.detail || data.error || {{ _('Errore durante la duplicazione')|tojson_attr }};
|
||||
}
|
||||
} catch (err) {
|
||||
this.dupError = {{ _('Errore di connessione')|tojson_attr }};
|
||||
} finally {
|
||||
this.dupBusy = false;
|
||||
}
|
||||
},
|
||||
|
||||
get filteredRecipes() {
|
||||
let filtered = this.recipes;
|
||||
@@ -265,6 +310,15 @@
|
||||
{{ _('Versioni') }}
|
||||
</a>
|
||||
|
||||
<!-- Duplica (#52) -->
|
||||
<button @click="openDupModal(recipe)"
|
||||
class="btn btn-secondary gap-1.5 text-xs">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
{{ _('Duplica') }}
|
||||
</button>
|
||||
|
||||
<!-- Spacer -->
|
||||
<div class="flex-1"></div>
|
||||
|
||||
@@ -318,6 +372,42 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Duplicate Modal (#52) -->
|
||||
<div x-show="dupModal"
|
||||
x-cloak
|
||||
@keydown.escape.window="dupModal = false"
|
||||
class="fixed inset-0 z-50 overflow-y-auto"
|
||||
role="dialog"
|
||||
aria-modal="true">
|
||||
<div @click="dupModal = false" class="fixed inset-0 bg-black/50 backdrop-blur-sm"></div>
|
||||
<div class="flex min-h-full items-center justify-center p-4">
|
||||
<div class="tmf-card max-w-lg w-full relative p-6">
|
||||
<h3 class="text-lg font-semibold text-[var(--text-primary)] mb-4">
|
||||
{{ _('Duplica ricetta') }}
|
||||
</h3>
|
||||
<div class="mb-3">
|
||||
<label class="tmf-label" for="dup-code">{{ _('Codice') }}</label>
|
||||
<input id="dup-code" type="text" x-model="dupCode" maxlength="100" class="tmf-input">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="tmf-label" for="dup-name">{{ _('Nome') }}</label>
|
||||
<input id="dup-name" type="text" x-model="dupName" maxlength="255" class="tmf-input">
|
||||
</div>
|
||||
<p x-show="dupError" x-text="dupError" class="text-sm text-red-600 mb-3"></p>
|
||||
<div class="flex flex-col sm:flex-row gap-3">
|
||||
<button @click="dupModal = false" class="btn btn-secondary flex-1 justify-center">
|
||||
{{ _('Annulla') }}
|
||||
</button>
|
||||
<button @click="duplicateRecipe()"
|
||||
:disabled="dupBusy || !dupCode.trim() || !dupName.trim()"
|
||||
class="btn btn-primary flex-1 justify-center">
|
||||
{{ _('Duplica') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div x-show="deleteModal"
|
||||
x-cloak
|
||||
|
||||
Reference in New Issue
Block a user