Skip to content

Commit

Permalink
#32 init block fau dir #26 search by name/surbame
Browse files Browse the repository at this point in the history
  • Loading branch information
FitoreGashi committed Sep 11, 2024
1 parent d2f5ea7 commit dadfd76
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 297 deletions.
72 changes: 29 additions & 43 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>' + response.data + '</p>');
alert('Error clearing cache.');
}
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
$('#contacts-list').html('<p>An error occurred during the request.</p>');
}
});
});
}
});
});
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 {
Expand All @@ -121,23 +122,8 @@ $(document).on('click', '.next-page', function(e) {
}
});
} else {
$('#contacts-list').html('<p>Please enter a valid ID.</p>');
}
});

// 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('<p>Please enter a valid search term.</p>');
}
});

});
87 changes: 87 additions & 0 deletions assets/js/rrze-faudir.js
Original file line number Diff line number Diff line change
@@ -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');
});
Loading

0 comments on commit dadfd76

Please sign in to comment.