diff --git a/assets/js/teamcard-admin.js b/assets/js/teamcard-admin.js
new file mode 100644
index 0000000..a2c7553
--- /dev/null
+++ b/assets/js/teamcard-admin.js
@@ -0,0 +1,171 @@
+jQuery(document).ready(function($) {
+ var newTeamcardFrame;
+ var teamcardFrame;
+
+ // Medienbibliothek für neues Teammitglied
+ $('#new-teamcard-bild-button').on('click', function(e) {
+ e.preventDefault();
+ if (newTeamcardFrame) { newTeamcardFrame.open(); return; }
+
+ newTeamcardFrame = wp.media({ title: 'Bild auswählen', button: { text: 'Verwenden' }, multiple: false });
+ newTeamcardFrame.on('select', function() {
+ var attachment = newTeamcardFrame.state().get('selection').first().toJSON();
+ $('#new-teamcard-bild-id').val(attachment.id);
+ $('#new-teamcard-bild-vorschau').attr('src', attachment.url).show();
+ });
+ newTeamcardFrame.open();
+ });
+
+ // Medienbibliothek für vorhandene Teammitglieder
+ $(document).on('click', '.teamcard-bild-button', function(e) {
+ e.preventDefault();
+ var button = $(this);
+ var teamcardId = button.data('id');
+
+ if (teamcardFrame) { teamcardFrame.open(); return; }
+
+ teamcardFrame = wp.media({ title: 'Bild ändern', button: { text: 'Verwenden' }, multiple: false });
+ teamcardFrame.on('select', function() {
+ var attachment = teamcardFrame.state().get('selection').first().toJSON();
+ $.ajax({
+ url: teamcard_data.ajax_url,
+ type: 'POST',
+ data: { action: 'update_teamcard_image', id: teamcardId, bild_id: attachment.id, nonce: teamcard_data.nonce },
+ success: function(response) {
+ if (response.success) {
+ var container = button.siblings('.image-preview-container');
+ container.html('');
+ showMessage('Bild erfolgreich aktualisiert.', 'success');
+ }
+ }
+ });
+ });
+ teamcardFrame.open();
+ });
+
+ // Neues Teammitglied hinzufügen
+ $('#add-teamcard-button').on('click', function() {
+ var name = $('#new-teamcard-name').val();
+ if (!name) { showMessage('Bitte gib einen Namen ein.', 'error'); return; }
+
+ $.ajax({
+ url: teamcard_data.ajax_url,
+ type: 'POST',
+ data: {
+ action: 'add_teamcard',
+ name: name,
+ funktion: $('#new-teamcard-funktion').val(),
+ zustaendigkeit: $('#new-teamcard-zustaendigkeit').val(),
+ card_type: $('#new-teamcard-card-type').val(),
+ bild_id: $('#new-teamcard-bild-id').val(),
+ nonce: teamcard_data.nonce
+ },
+ success: function(response) {
+ if (response.success) {
+ var bildHtml = response.data.bild_url ? '
' : '';
+ var newRow = `
+
' + message + '
').show().delay(3000).fadeOut(); + } +}); \ No newline at end of file