diff --git a/teamcard-admin.js b/teamcard-admin.js deleted file mode 100644 index 886c22b..0000000 --- a/teamcard-admin.js +++ /dev/null @@ -1,237 +0,0 @@ -jQuery(document).ready(function($) { - // Medienbibliothek für neues Teammitglied - var newTeamcardFrame; - - $('#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 - var teamcardFrame; - - $(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 auswählen', - 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(); - var funktion = $('#new-teamcard-funktion').val(); - var zustaendigkeit = $('#new-teamcard-zustaendigkeit').val(); - var bildId = $('#new-teamcard-bild-id').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: funktion, - zustaendigkeit: zustaendigkeit, - bild_id: bildId, - nonce: teamcard_data.nonce - }, - success: function(response) { - if (response.success) { - var bildHtml = ''; - if (response.data.bild_url) { - bildHtml = ''; - } - - var newRow = '' + - '' + - '
' + bildHtml + '
' + - '' + - '' + - '
' + name + '
' + - '
' + funktion + '
' + - '
' + zustaendigkeit + '
' + - '' + - ''; - - $('#teamcard-list').append(newRow); - - // Formular zurücksetzen - $('#new-teamcard-name').val(''); - $('#new-teamcard-funktion').val(''); - $('#new-teamcard-zustaendigkeit').val(''); - $('#new-teamcard-bild-id').val(''); - $('#new-teamcard-bild-vorschau').attr('src', '').hide(); - - showMessage('Teammitglied erfolgreich hinzugefügt', 'success'); - } else { - showMessage(response.data.message, 'error'); - } - } - }); - }); - - // Inline-Bearbeitung - $(document).on('click', '.editable', function() { - var element = $(this); - var currentText = element.text(); - - element.html(''); - element.find('input').focus().select(); - }); - - $(document).on('blur', '.inline-edit', function() { - var input = $(this); - var element = input.parent(); - var newValue = input.val(); - var field = element.data('field'); - var id = element.data('id'); - - $.ajax({ - url: teamcard_data.ajax_url, - type: 'POST', - data: { - action: 'update_teamcard', - id: id, - field: field, - value: newValue, - nonce: teamcard_data.nonce - }, - success: function(response) { - if (response.success) { - element.text(newValue); - showMessage('Erfolgreich aktualisiert', 'success'); - } - } - }); - }); - - $(document).on('keypress', '.inline-edit', function(e) { - if (e.which === 13) { - $(this).blur(); - } - }); - - // Teammitglied löschen - $(document).on('click', '.teamcard-delete', function() { - if (!confirm('Möchtest du dieses Teammitglied wirklich löschen?')) { - return; - } - - var button = $(this); - var id = button.data('id'); - - $.ajax({ - url: teamcard_data.ajax_url, - type: 'POST', - data: { - action: 'delete_teamcard', - id: id, - nonce: teamcard_data.nonce - }, - success: function(response) { - if (response.success) { - button.closest('tr').remove(); - showMessage('Teammitglied erfolgreich gelöscht', 'success'); - } else { - showMessage(response.data.message, 'error'); - } - } - }); - }); - - // Drag & Drop Sortierung - $('#teamcard-list').sortable({ - handle: 'td:first', - placeholder: 'ui-state-highlight', - update: function(event, ui) { - var order = []; - $('.teamcard-item').each(function() { - order.push($(this).data('id')); - }); - - $.ajax({ - url: teamcard_data.ajax_url, - type: 'POST', - data: { - action: 'update_teamcard_order', - order: order, - nonce: teamcard_data.nonce - }, - success: function(response) { - if (response.success) { - showMessage('Reihenfolge erfolgreich aktualisiert', 'success'); - } - } - }); - } - }); - - // Hilfsfunktion für Nachrichten - function showMessage(message, type) { - var messageElement = $('#teamcard-message'); - messageElement.removeClass('notice-success notice-error').addClass('notice-' + type); - messageElement.html('

' + message + '

').show(); - - setTimeout(function() { - messageElement.fadeOut(); - }, 3000); - } -});