});
$('.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}
{if $customValueCount}
{literal}
<script type="text/javascript">
- var customValueCount = {/literal}"{$customValueCount}"{literal};
- var groupID = {/literal}"{$groupID}"{literal};
- var contact_type = {/literal}"{$contact_type}"{literal};
- var contact_subtype = {/literal}"{$contact_subtype}"{literal};
- CRM.buildCustomData( contact_type, contact_subtype );
- for ( var i = 1; i < customValueCount; i++ ) {
- CRM.buildCustomData( contact_type, contact_subtype, null, i, groupID, true );
- }
+ CRM.$(function() {
+ {/literal}
+ var customValueCount = "{$customValueCount}",
+ groupID = "{$groupID}",
+ contact_type = "{$contact_type}",
+ contact_subtype = "{$contact_subtype}",
+ i = 1;
+ {literal}
+ // FIXME: This is pretty terrible. Loading each item at a time via ajax.
+ // Building the complete form in php with no ajax would be way more efficient.
+ function loadNextRecord() {
+ if (i < customValueCount) {
+ CRM.buildCustomData(contact_type, contact_subtype, null, i++, groupID, true).one('crmLoad', loadNextRecord);
+ }
+ }
+ CRM.buildCustomData(contact_type, contact_subtype).one('crmLoad', loadNextRecord);
+ });
</script>
{/literal}
{/if}