diff --git a/templates/project/_requirements-list.go.html b/templates/project/_requirements-list.go.html index c4c6b1ea6483326877acb5ee85c18f656bffd0e7..d485ca1c73f82ff51a115d03f3b9990414dbeb20 100644 --- a/templates/project/_requirements-list.go.html +++ b/templates/project/_requirements-list.go.html @@ -78,7 +78,9 @@ <td> <div class="btn-group btn-group-sm"> <!-- Clone requirement button --> - <button class="btn btn-outline-secondary" title="Klonen"> + <button onclick="cloneRequirement('{{ .ID.Hex }}', '{{ .RequirementID }}')" + class="btn btn-outline-secondary" + title="Klonen"> 📋 </button> <!-- Delete requirement button --> @@ -94,4 +96,55 @@ </div> {{ end }} </div> + +<script> +function cloneRequirement(reqId, reqName) { + // Get list of available projects from the current page context + const projects = [ + {{ range $.Data.Project.Project.CreatedBy }} + // This won't work, we need to get projects differently + {{ end }} + ]; + + // Simple prompt-based solution for now + const targetProjectId = prompt(`Anforderung "${reqName}" klonen.\n\nGeben Sie die Projekt-ID des Zielprojekts ein:`); + if (!targetProjectId) return; + + const newName = prompt(`Neuer Name für die geklonte Anforderung:`, `${reqName}-kopie`); + if (!newName) return; + + // Debug: Log the request details + console.log('Making clone request:', { + url: `/requirement/${reqId}/clone`, + targetProjectId: targetProjectId, + newName: newName + }); + + // Make the clone request + fetch(`/requirement/${reqId}/clone`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `ProjectID=${encodeURIComponent(targetProjectId)}&Name=${encodeURIComponent(newName)}` + }) + .then(response => { + console.log('Response status:', response.status); + console.log('Response headers:', response.headers); + return response.text().then(text => { + console.log('Response body:', text); + if (response.ok) { + alert(`Anforderung erfolgreich nach Projekt "${targetProjectId}" geklont!`); + location.reload(); // Refresh to show changes + } else { + alert(`Fehler beim Klonen der Anforderung: ${response.status} - ${text}`); + } + }); + }) + .catch(error => { + console.error('Error:', error); + alert('Fehler beim Klonen der Anforderung: ' + error.message); + }); +} +</script> {{ end }} \ No newline at end of file