Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit page components integration fixing #2510

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions dt-assets/js/new-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -1860,97 +1860,6 @@ jQuery(function ($) {
}
}

// Check for phone and email duplication
let non_duplicable_fields = ['contact_phone', 'contact_email'];
$.each(non_duplicable_fields, function (field_key, field_type) {
if (window.new_record_localized.post_type_settings.fields[field_type]) {
var field_name =
window.new_record_localized.post_type_settings.fields[field_type].name;
$(`input[data-field="${field_type}"]`).attr(
`data-${field_type}-index`,
'0',
);
$(`input[data-field="${field_type}"]`).after(
`<span class="loading-spinner" data-${field_type}-index="0" style="margin: 0.5rem;"></span>`,
);
$(`input[data-field="${field_type}"]`).parent().after(`
<div class="communication-channel-error" data-${field_type}-index="0" style="display: none;">
${window.new_record_localized.translations.value_already_exists.replace(
'%s',
field_name,
)}:
<span class="duplicate-ids" data-${field_type}-index="0" style="color: #3f729b;"></span>
</div>`);
}
});

function check_field_value_exists(field_type, element_index) {
var email = $(`input[data-${field_type}-index="${element_index}"]`).val();
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner active',
);
if (!email) {
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).hide();
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner',
);
return;
}
var post_type = window.wpApiShare.post_type;
var data = { communication_channel: `${field_type}`, field_value: email };
jQuery
.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url:
window.wpApiShare.root +
`dt-posts/v2/${post_type}/check_field_value_exists`,
beforeSend: (xhr) => {
xhr.setRequestHeader('X-WP-Nonce', window.wpApiShare.nonce);
},
})
.then((result) => {
if (!$.isEmptyObject(result)) {
var duplicate_ids_html = '';
$.each(result, function (k, v) {
if (k > 0) {
duplicate_ids_html += ', ';
}
duplicate_ids_html += `<a href="/${post_type}/${v.post_id}" target="_blank">${window.new_record_localized.translations.contact} #${v.post_id}</a>`;
});
$(`.duplicate-ids[data-${field_type}-index="${element_index}"]`).html(
duplicate_ids_html,
);
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).show();
} else {
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).hide();
$(`.duplicate-ids[data-${field_type}-index="${element_index}"]`).html(
'',
);
}
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner',
);
});
}

$('.form-fields').on('change', 'input[data-field^="contact_"]', function () {
var post_type = $(this).data('field');
var element_index = $(this).data(`${post_type}-index`);
check_field_value_exists(post_type, element_index);
});

/**
* ============== [ BULK RECORD ADDING FUNCTIONALITY ] ==============
*/
Expand Down
2 changes: 1 addition & 1 deletion dt-core/admin/menu/tabs/tab-custom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Disciple.Tools
*/

/**/


if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand Down
8 changes: 3 additions & 5 deletions dt-core/global-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function dt_email_template_wrapper( $message, $subject ) {
}

// Convert URLs to links.

if ( apply_filters( 'dt_email_template_convert_urls', true ) ) {
$message = make_clickable( $message );
}
Expand Down Expand Up @@ -653,7 +654,7 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr
onchange="">
</dt-comm-channel>
<?php endif; ?>
<?php if ( $field_type === 'location' ): ?>
<?php if ( $field_type === 'location_meta' ): ?>
<dt-location <?php echo wp_kses_post( $shared_attributes ) ?> <?php dt_render_icon_slot( $fields[$field_key] ) ?>
value="<?php echo esc_html( $post[$field_key] ?? '' ) ?>" requiredmessage=""
icon="https://cdn-icons-png.flaticon.com/512/1077/1077114.png" iconalttext="Icon Alt Text" privatelabel="" error=""
Expand Down Expand Up @@ -694,10 +695,7 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr
</dt-single-select>
<?php elseif ( $field_type === 'tags' ): ?>
<?php $value = array_map(function ( $value ) {
return [
'id' => $value,
'label' => $value,
];
return $value;
micahmills marked this conversation as resolved.
Show resolved Hide resolved
}, $post[$field_key] ?? []);
?>
<dt-tags <?php echo wp_kses_post( $shared_attributes ) ?> value="<?php echo esc_attr( json_encode( $value ) ) ?>"
Expand Down
Loading