From 594cfdadef74c8c11693248dcf7c04a8111a84ee Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 21 May 2016 10:53:07 -0400 Subject: [PATCH] CRM-18586 - Fix race condition when loading custom data forms --- templates/CRM/Contact/Form/Contact.tpl | 27 +++++++++++++---------- templates/CRM/Contact/Form/CustomData.tpl | 25 ++++++++++++++------- templates/CRM/common/customData.tpl | 2 +- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/templates/CRM/Contact/Form/Contact.tpl b/templates/CRM/Contact/Form/Contact.tpl index 5d1af722cb..776d541932 100644 --- a/templates/CRM/Contact/Form/Contact.tpl +++ b/templates/CRM/Contact/Form/Contact.tpl @@ -191,29 +191,32 @@ }); $('.customDataPresent').change(function() { - //$('.crm-custom-accordion').remove(); var values = $("#contact_sub_type").val(); - var contactType = {/literal}"{$contactType}"{literal}; - CRM.buildCustomData(contactType, values); - loadMultiRecordFields(values); - $('.crm-custom-accordion').each(function() { + CRM.buildCustomData({/literal}"{$contactType}"{literal}, values).one('crmLoad', function() { highlightTabs(this); + loadMultiRecordFields(values); }); }); function loadMultiRecordFields(subTypeValues) { - if (subTypeValues == false) { - var subTypeValues = null; + if (subTypeValues === false) { + subTypeValues = null; } - else if (!subTypeValues) { - var subTypeValues = {/literal}"{$paramSubType}"{literal}; + else if (!subTypeValues) { + subTypeValues = {/literal}"{$paramSubType}"{literal}; + } + function loadNextRecord(i, groupValue, groupCount) { + if (i < groupCount) { + CRM.buildCustomData({/literal}"{$contactType}"{literal}, subTypeValues, null, i, groupValue, true).one('crmLoad', function() { + highlightTabs(this); + loadNextRecord(i+1, groupValue, groupCount); + }); + } } {/literal} {foreach from=$customValueCount item="groupCount" key="groupValue"} {if $groupValue}{literal} - for ( var i = 1; i < {/literal}{$groupCount}{literal}; i++ ) { - CRM.buildCustomData( {/literal}"{$contactType}"{literal}, subTypeValues, null, i, {/literal}{$groupValue}{literal}, true ); - } + loadNextRecord(1, {/literal}{$groupValue}{literal}, {/literal}{$groupCount}{literal}); {/literal} {/if} {/foreach} diff --git a/templates/CRM/Contact/Form/CustomData.tpl b/templates/CRM/Contact/Form/CustomData.tpl index fdbc285055..01775c8b16 100644 --- a/templates/CRM/Contact/Form/CustomData.tpl +++ b/templates/CRM/Contact/Form/CustomData.tpl @@ -39,14 +39,23 @@ {if $customValueCount} {literal} {/literal} {/if} diff --git a/templates/CRM/common/customData.tpl b/templates/CRM/common/customData.tpl index 71a737553f..129e0555b5 100644 --- a/templates/CRM/common/customData.tpl +++ b/templates/CRM/common/customData.tpl @@ -80,7 +80,7 @@ fname += subName; } - CRM.loadPage(dataUrl, {target: fname}); + return CRM.loadPage(dataUrl, {target: fname}); }; })(CRM.$); -- 2.25.1