diff --git a/dt-assets/js/details.js b/dt-assets/js/details.js index 748721cc7..6ca1e3cef 100644 --- a/dt-assets/js/details.js +++ b/dt-assets/js/details.js @@ -79,53 +79,6 @@ jQuery(document).ready(function ($) { }; } - /* field type: link */ - $('input.link-input').change(function () { - const link_input = $(this); - const fieldKey = $(link_input).data('field-key'); - const type = $(link_input).data('type'); - const meta_id = $(link_input).data('meta-id'); - const value = $(link_input).val(); - - if ($(link_input).prop('required') && value === '') { - return; - } - - const fieldValues = { - values: [ - { - value, - type, - meta_id, - }, - ], - }; - $(`#${fieldKey}-spinner`).addClass('active'); - rest_api - .update_post(post_type, post_id, { [fieldKey]: fieldValues }) - .then((newPost) => { - $(`#${fieldKey}-spinner`).removeClass('active'); - post = newPost; - - // Make sure a key exists for the new link field. - if (post && post[fieldKey] && post[fieldKey].length > 0) { - let updated_values = post[fieldKey].filter((option) => { - return option['type'] === type && option['value'] === value; - }); - - // This ensures any immediate updates, are assigned to correct link input and not to a new/duplicated input field. - if ( - updated_values && - updated_values[0] && - updated_values[0]['meta_id'] - ) { - $(link_input).data('meta-id', updated_values[0]['meta_id']); - } - } - }) - .catch(window.handleAjaxError); - }); - /* field type: datetime */ $('.dt_date_time_group').each(function setTimePickers() { const timestamp = this.dataset.timestamp; diff --git a/dt-assets/js/merge-post-details.js b/dt-assets/js/merge-post-details.js index c53113519..813c286c3 100644 --- a/dt-assets/js/merge-post-details.js +++ b/dt-assets/js/merge-post-details.js @@ -225,11 +225,6 @@ jQuery(function ($) { return typeahead && !window.lodash.isEmpty(typeahead.items); } - case 'link': - return !window.lodash.isEmpty( - $(td_field_input).find('input.link-input').not('[value=""]'), - ); - case 'communication_channel': case 'location_meta': return !window.lodash.isEmpty( @@ -296,48 +291,6 @@ jQuery(function ($) { .prop('disabled', read_only); break; - case 'link': { - // Disable/Display field accordingly, based on read-only flag - $(td).find('input.link-input').prop('disabled', read_only); - $(td).find('button.link-delete-button').prop('disabled', read_only); - - // Ensure add link functionality is suppressed. - $(td).find('div.add-link-dropdown').remove(); - - if (!read_only) { - $(td) - .find('input.link-input') - .each(function (idx, input) { - if (window.lodash.isEmpty($(input).val())) { - $(input).parent().hide(); - } - }); - - /** - * Remove - */ - - $(document).on('click', '.link-delete-button', (evt) => { - const delete_but = $(evt.currentTarget); - - // Keep a record of deleted meta_ids. - let meta_id = $(delete_but).data('meta-id'); - let deleted_items = $(field_meta).val() - ? JSON.parse($(field_meta).val()) - : []; - if (!window.lodash.includes(deleted_items, meta_id)) { - deleted_items.push(meta_id); - $(field_meta).val(JSON.stringify(deleted_items)); - } - - // Finally, remove from parent. - $(delete_but).parent().parent().remove(); - }); - } - - break; - } - case 'user_select': { let user_select_typeahead_field_input = '.js-typeahead-' + field_id; @@ -501,78 +454,6 @@ jQuery(function ($) { break; } - case 'link': { - // Determine selector source field link inputs to be processed. - let source_field_link_inputs = []; - let tr = $(selector).parent().parent(); - $(tr) - .find('.td-field-input input.link-input') - .each(function (idx, input) { - if ($(input).val()) { - source_field_link_inputs.push(input); - } - }); - - // Delete/Add updated post record, based on identified source field inputs. - let main_updated_fields_div = $('#main_updated_fields_div'); - let link_field_meta_input = $(main_updated_fields_div) - .find(`.link-list-${update_field_id}`) - .parent() - .parent() - .find('#field_meta'); - let deleted_items = $(link_field_meta_input).val() - ? JSON.parse($(link_field_meta_input).val()) - : []; - - // Locate by link field values. - $.each(source_field_link_inputs, function (idx, input) { - let link_list_section_div = $(main_updated_fields_div).find( - `.link-list-${update_field_id} .link-section--${$(input).data('type')}`, - ); - let matched_input = $(link_list_section_div).find( - `.input-group input[value="${$(input).val()}"].link-input`, - ); - - // Handle accordingly, based on incoming selected state. - if (is_selected) { - // Add new updated link fields. - if (matched_input.length === 0) { - $(link_list_section_div).append(` -
- -
- -
-
`); - - // Remove any previously deleted entries. - window.lodash.remove(deleted_items, function (meta_id) { - return meta_id === $(input).data('meta-id'); - }); - $(link_field_meta_input).val(JSON.stringify(deleted_items)); - } - } else { - // Remove new updated link fields. - if (matched_input.length > 0) { - $(matched_input).parent().remove(); - - // Keep a record of deleted meta_ids. - if ( - !window.lodash.includes( - deleted_items, - $(matched_input).data('meta-id'), - ) - ) { - deleted_items.push($(matched_input).data('meta-id')); - $(link_field_meta_input).val(JSON.stringify(deleted_items)); - } - } - } - }); - - break; - } - case 'communication_channel': { // Determine values to be updated const sourceValue = sourceField.val() || []; @@ -1207,61 +1088,6 @@ jQuery(function ($) { break; } - case 'link': { - // Determine values to be processed - let link_entries = []; - let link_deletions = field_meta.val() - ? JSON.parse(field_meta.val()) - : []; - - // Package values and any deletions - $(td) - .find('.input-group input.link-input') - .each(function (idx, input) { - let link_type = $(input).data('type'); - let link_meta_id = $(input).data('meta-id'); - let link_val = $(input).val(); - - let has_value = is_link_field_value_already_in_primary( - post_field_id, - link_type, - link_meta_id, - link_val, - true, - ); - let matched_meta_id = is_link_field_value_already_in_primary( - post_field_id, - link_type, - link_meta_id, - link_val, - false, - ); - - if (link_val && !has_value) { - link_entries.push({ - value: link_val, - type: link_type, - meta_id: matched_meta_id ? link_meta_id : '', - }); - } - }); - - $.each(link_deletions, function (idx, deleted_meta_id) { - link_entries.push({ - meta_id: deleted_meta_id, - delete: true, - }); - }); - - // If present, capture entries - if (link_entries) { - values[post_field_id] = { - values: link_entries, - }; - } - break; - } - case 'user_select': { let user_select_typeahead = window.Typeahead['.js-typeahead-' + field_id]; diff --git a/dt-assets/js/new-bulk-record.js b/dt-assets/js/new-bulk-record.js index 473e3b5ac..179c4c5fc 100644 --- a/dt-assets/js/new-bulk-record.js +++ b/dt-assets/js/new-bulk-record.js @@ -117,19 +117,6 @@ jQuery(function ($) { new_post[$(entry).attr('id')] = $(entry).val(); } }); - $('.link-input').each((index, entry) => { - let fieldKey = $(entry).data('field-key'); - let type = $(entry).data('type'); - if ($(entry).val()) { - if (!Object.prototype.hasOwnProperty.call(new_post, fieldKey)) { - new_post[fieldKey] = { values: [] }; - } - new_post[fieldKey].values.push({ - value: $(entry).val(), - type: type, - }); - } - }); $('.dt_textarea').each((index, entry) => { if ($(entry).val()) { new_post[$(entry).attr('id')] = $(entry).val(); diff --git a/dt-assets/js/new-record.js b/dt-assets/js/new-record.js index 15adf76d2..6210e4346 100644 --- a/dt-assets/js/new-record.js +++ b/dt-assets/js/new-record.js @@ -232,19 +232,6 @@ jQuery(function ($) { new_post[$(entry).attr('id')] = $(entry).val(); } }); - $('.link-input').each((index, entry) => { - let fieldKey = $(entry).data('field-key'); - let type = $(entry).data('type'); - if ($(entry).val()) { - if (!Object.prototype.hasOwnProperty.call(new_post, fieldKey)) { - new_post[fieldKey] = { values: [] }; - } - new_post[fieldKey].values.push({ - value: $(entry).val(), - type: type, - }); - } - }); // location_meta if (typeof window.selected_location_grid_meta !== 'undefined') { diff --git a/dt-core/global-functions.php b/dt-core/global-functions.php index 18b05e79c..ad74c374f 100755 --- a/dt-core/global-functions.php +++ b/dt-core/global-functions.php @@ -654,6 +654,9 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr case 'user_select': DT_Components::render_user_select( $field_key, $fields, $post, $params ); break; + case 'link': + DT_Components::render_link( $field_key, $fields, $post, $params ); + break; default: $is_legacy = true; break; @@ -663,60 +666,6 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr $is_empty_post = !is_array( $post ) || count( array_keys( $post ) ) <= 1; // if this is a new post, it only has a post_type key $hide_label = isset( $params['hide_label'] ) && $params['hide_label'] === true; ?> - -
> - - - - "> - - - - - - - - - -
- " min="" max="" onwheel="return false;" /> - - - -
@@ -834,34 +727,6 @@ class="text-input" value="" - -
- - - > -
- -
-
- - (string) $key, + 'label' => $value['label'] ?? $key + ]; + }, array_keys( $default_options ), $default_options); + ?> + + groups='' + value=""> + + +