diff --git a/assets/js/admin.js b/assets/js/admin.js index 2d252ae..6cf0a97 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -68,47 +68,48 @@ $(document).on('click', '.next-page', function(e) { if (activeTab === '#tab-5') { loadContacts(currentPage); } - - // Existing search by identifier - $('#search-contacts').click(function() { - var identifier = $('#contact-id').val(); - - $.ajax({ - url: rrzeFaudirAjax.ajax_url, - method: 'POST', - data: { - action: 'rrze_faudir_search_contacts', - security: rrzeFaudirAjax.api_nonce, - identifier: identifier - }, - success: function(response) { + + // Clear cache button handler + $('#clear-cache-button').on('click', function() { + if (confirm(rrzeFaudirAjax.confirm_clear_cache)) { + $.post(rrzeFaudirAjax.ajax_url, { + action: 'rrze_faudir_clear_cache', + security: rrzeFaudirAjax.api_nonce + }, function(response) { if (response.success) { - $('#contacts-list').html(response.data); + alert(response.data); } else { - $('#contacts-list').html('
' + response.data + '
'); + alert('Error clearing cache.'); } - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - $('#contacts-list').html('An error occurred during the request.
'); - } - }); + }); + } }); +}); +jQuery(document).ready(function($) { - // Search by ID + // Search by name or ID $('#search-person-by-id').click(function() { var personId = $('#person-id').val().trim(); - - if (personId.length > 0) { + var givenName = $('#given-name').val().trim(); + var familyName = $('#family-name').val().trim(); + + console.log('Person ID:', personId); + console.log('Given Name:', givenName); + console.log('Family Name:', familyName); + + if (personId.length > 0 || givenName.length > 0 || familyName.length > 0) { $.ajax({ url: rrzeFaudirAjax.ajax_url, method: 'POST', data: { action: 'search_person_by_id', security: rrzeFaudirAjax.api_nonce, - personId: personId + personId: personId, + givenName: givenName, + familyName: familyName }, success: function(response) { + console.log('Response:', response); // Log the response if (response.success) { $('#contacts-list').html(response.data); } else { @@ -121,23 +122,8 @@ $(document).on('click', '.next-page', function(e) { } }); } else { - $('#contacts-list').html('Please enter a valid ID.
'); - } - }); - - // Clear cache button handler - $('#clear-cache-button').on('click', function() { - if (confirm(rrzeFaudirAjax.confirm_clear_cache)) { - $.post(rrzeFaudirAjax.ajax_url, { - action: 'rrze_faudir_clear_cache', - security: rrzeFaudirAjax.api_nonce - }, function(response) { - if (response.success) { - alert(response.data); - } else { - alert('Error clearing cache.'); - } - }); + $('#contacts-list').html('Please enter a valid search term.
'); } }); + }); diff --git a/assets/js/rrze-faudir.js b/assets/js/rrze-faudir.js index fa2f887..9c65454 100644 --- a/assets/js/rrze-faudir.js +++ b/assets/js/rrze-faudir.js @@ -1,3 +1,90 @@ +wp.blocks.registerBlockType('rrze/faudir-block', { + title: 'FAUDIR Block', + icon: 'admin-users', + category: 'common', + attributes: { + category: { type: 'string', default: '' }, + identifier: { type: 'string', default: '' }, + format: { type: 'string', default: 'list' }, + show: { type: 'string', default: 'name, email, phone, organization, function' }, + hide: { type: 'string', default: '' }, + }, + edit: function(props) { + return wp.element.createElement( + 'div', + null, + wp.element.createElement( + 'label', + null, + 'Category', + wp.element.createElement('input', { + type: 'text', + value: props.attributes.category, + onChange: function(event) { + props.setAttributes({ category: event.target.value }); + } + }) + ), + wp.element.createElement( + 'label', + null, + 'Identifier', + wp.element.createElement('input', { + type: 'text', + value: props.attributes.identifier, + onChange: function(event) { + props.setAttributes({ identifier: event.target.value }); + } + }) + ), + wp.element.createElement( + 'label', + null, + 'Format', + wp.element.createElement('select', { + value: props.attributes.format, + onChange: function(event) { + props.setAttributes({ format: event.target.value }); + } + }, + wp.element.createElement('option', { value: 'list' }, 'List'), + wp.element.createElement('option', { value: 'table' }, 'Table'), + wp.element.createElement('option', { value: 'card' }, 'Card'), + wp.element.createElement('option', { value: 'page' }, 'Page') + ) + ), + wp.element.createElement( + 'label', + null, + 'Show Fields', + wp.element.createElement('input', { + type: 'text', + value: props.attributes.show, + onChange: function(event) { + props.setAttributes({ show: event.target.value }); + } + }) + ), + wp.element.createElement( + 'label', + null, + 'Hide Fields', + wp.element.createElement('input', { + type: 'text', + value: props.attributes.hide, + onChange: function(event) { + props.setAttributes({ hide: event.target.value }); + } + }) + ) + ); + }, + save: function() { + // This block will be rendered dynamically on the server-side, so no need to save anything here + return null; + }, +}); + jQuery(document).ready(function ($) { console.log('RRZE FAUDIR JS from src directory'); }); diff --git a/includes/admin/settings-page.php b/includes/admin/settings-page.php index 12016a4..3993924 100644 --- a/includes/admin/settings-page.php +++ b/includes/admin/settings-page.php @@ -5,22 +5,30 @@ } // Add admin menu -function rrze_faudir_add_admin_menu() { +function rrze_faudir_add_admin_menu() +{ add_menu_page( - __('FAU Directory Settings', 'rrze-faudir'), // Page title - __('FAU Directory', 'rrze-faudir'), // Menu title - 'manage_options', // Capability - 'rrze-faudir', // Menu slug - 'rrze_faudir_settings_page', // Callback function - 'dashicons-admin-generic', // Icon - 81 // Position + __('FAU Directory Settings', 'rrze-faudir'), + // Page title + __('FAU Directory', 'rrze-faudir'), + // Menu title + 'manage_options', + // Capability + 'rrze-faudir', + // Menu slug + 'rrze_faudir_settings_page', + // Callback function + 'dashicons-admin-generic', + // Icon + 81 // Position ); } add_action('admin_menu', 'rrze_faudir_add_admin_menu'); // Register settings // Register settings -function rrze_faudir_settings_init() { +function rrze_faudir_settings_init() +{ register_setting('rrze_faudir_settings', 'rrze_faudir_options'); // API Settings Section @@ -126,24 +134,29 @@ function rrze_faudir_settings_init() { // Callback functions -function rrze_faudir_api_section_callback() { +function rrze_faudir_api_section_callback() +{ echo '' . __('Configure the API settings for accessing the FAU person and institution directory.', 'rrze-faudir') . '
'; } -function rrze_faudir_cache_section_callback() { +function rrze_faudir_cache_section_callback() +{ echo '' . __('Configure caching settings for the plugin.', 'rrze-faudir') . '
'; } -function rrze_faudir_error_section_callback() { +function rrze_faudir_error_section_callback() +{ echo '' . __('Handle error messages for invalid contact entries.', 'rrze-faudir') . '
'; } -function rrze_faudir_business_card_section_callback() { +function rrze_faudir_business_card_section_callback() +{ echo '' . __('Configure the business card link settings.', 'rrze-faudir') . '
'; } // Render functions -function rrze_faudir_api_key_render() { +function rrze_faudir_api_key_render() +{ if (FaudirUtils::isUsingNetworkKey()) { echo '' . __('The API key is being used from the network installation.', 'rrze-faudir') . '
'; } else { @@ -154,40 +167,46 @@ function rrze_faudir_api_key_render() { } } -function rrze_faudir_no_cache_logged_in_render() { +function rrze_faudir_no_cache_logged_in_render() +{ $options = get_option('rrze_faudir_options'); $checked = isset($options['no_cache_logged_in']) ? 'checked' : ''; echo ''; echo '' . __('Disable caching for logged-in editors.', 'rrze-faudir') . '
'; } -function rrze_faudir_cache_timeout_render() { +function rrze_faudir_cache_timeout_render() +{ $options = get_option('rrze_faudir_options'); $value = isset($options['cache_timeout']) ? intval($options['cache_timeout']) : 15; echo ''; echo '' . __('Set the cache timeout in minutes (minimum 15 minutes).', 'rrze-faudir') . '
'; } -function rrze_faudir_cache_org_timeout_render() { +function rrze_faudir_cache_org_timeout_render() +{ $options = get_option('rrze_faudir_options'); $value = isset($options['cache_org_timeout']) ? intval($options['cache_org_timeout']) : 1; echo ''; echo '' . __('Set the cache timeout in days for organization identifiers.', 'rrze-faudir') . '
'; } -function rrze_faudir_clear_cache_render() { +function rrze_faudir_clear_cache_render() +{ echo ''; echo '' . __('Click the button to clear all cached data.', 'rrze-faudir') . '
'; } -function rrze_faudir_error_message_render() { +function rrze_faudir_error_message_render() +{ $options = get_option('rrze_faudir_options'); $checked = isset($options['show_error_message']) ? 'checked' : ''; echo ''; echo '' . __('Show error messages for incorrect contact entries.', 'rrze-faudir') . '
'; } -function rrze_faudir_business_card_title_render() { +function rrze_faudir_business_card_title_render() +{ $options = get_option('rrze_faudir_options'); $value = isset($options['business_card_title']) ? sanitize_text_field($options['business_card_title']) : __('Call up business card', 'rrze-faudir'); echo ''; @@ -195,185 +214,159 @@ function rrze_faudir_business_card_title_render() { } // Settings page display - function rrze_faudir_settings_page() { - ?> -