Skip to content

Commit

Permalink
Edit page components integration fixing (#2510)
Browse files Browse the repository at this point in the history
* moves component services to header

* dt-tags fixes on edit detail page and code remove for duplicate check on contact and email fields related

* debug

* phpcbf and phpcs fixes

---------

Co-authored-by: Micah Mills <[email protected]>
  • Loading branch information
Ashima-Arora and micahmills authored Jun 21, 2024
1 parent f590336 commit 949d0b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 96 deletions.
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
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;
}, $post[$field_key] ?? []);
?>
<dt-tags <?php echo wp_kses_post( $shared_attributes ) ?> value="<?php echo esc_attr( json_encode( $value ) ) ?>"
Expand Down

0 comments on commit 949d0b8

Please sign in to comment.