Skip to content

Commit

Permalink
Consolidate CustomData code into shared tpl
Browse files Browse the repository at this point in the history
 The only change that I found in function was that the delete icon was originally in a
 table on contact edit but afterwards it was not. However the UI looked the same
  • Loading branch information
eileenmcnaughton committed Mar 22, 2018
1 parent f3e2844 commit 1145f96
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 94 deletions.
12 changes: 1 addition & 11 deletions templates/CRM/Contact/Form/Edit/Address/CustomData.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@
{$cd_edit.title}
</div>
<div>
{if $cd_edit.help_pre}
<div class="messages help">{$cd_edit.help_pre}</div>
{/if}
<table class="form-layout-compressed">
{foreach from=$cd_edit.fields item=element key=field_id}
{assign var="element_name" value=$element.element_custom_name}
{include file="CRM/Custom/Form/Edit/CustomField.tpl" formElement=$form.address.$blockId.$element_name}
{/foreach}
</table>
<div class="spacer"></div>
{if $cd_edit.help_post}<div class="messages help">{$cd_edit.help_post}</div>{/if}
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='address'}
</div>
</div>

Expand Down
14 changes: 0 additions & 14 deletions templates/CRM/Contact/Form/Edit/CustomData.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@
<div class="crm-accordion-header">
{$cd_edit.title}
</div>

<div id="customData{$group_id}" class="crm-accordion-body">
{if $cd_edit.is_multiple eq 1}
{if $cd_edit.table_id}
<table class="no-border">
<tr>
<a href="#" class="crm-hover-button crm-custom-value-del" title="{ts 1=$cd_edit.title}Delete %1{/ts}"
data-post='{ldelim}"valueID": "{$tableID}", "groupID": "{$group_id}", "contactId": "{$contactId}", "key": "{crmKey name='civicrm/ajax/customvalue'}"{rdelim}'>
<span class="icon delete-icon"></span> {ts}Delete{/ts}
</a>
<!-- crm-submit-buttons -->
</tr>
</table>
{/if}
{/if}
{include file="CRM/Custom/Form/CustomData.tpl" formEdit=true}
</div>
<!-- crm-accordion-body-->
Expand Down
78 changes: 9 additions & 69 deletions templates/CRM/Custom/Form/CustomData.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,18 @@
*}
{* Custom Data form*}
{if $formEdit}
{if $cd_edit.help_pre}
<div class="messages help">{$cd_edit.help_pre}</div>
{/if}
<table class="form-layout-compressed">
{foreach from=$cd_edit.fields item=element key=field_id}
{assign var="element_name" value=$element.element_name}
{include file="CRM/Custom/Form/Edit/CustomField.tpl" formElement=$form.$element_name}
{/foreach}
</table>
<div class="spacer"></div>
{if $cd_edit.help_post}
<div class="messages help">{$cd_edit.help_post}</div>
{/if}
{if $cd_edit.is_multiple and ( ( $cd_edit.max_multiple eq '' ) or ( $cd_edit.max_multiple > 0 and $cd_edit.max_multiple > $cgCount ) ) }
<div id="add-more-link-{$cgCount}" class="add-more-link-{$group_id} add-more-link-{$group_id}-{$cgCount}">
<a href="#" class="crm-hover-button" onclick="CRM.buildCustomData('{$cd_edit.extends}',{if $cd_edit.subtype}'{$cd_edit.subtype}'{else}'{$cd_edit.extends_entity_column_id}'{/if}, '', {$cgCount}, {$group_id}, true ); return false;">
<i class="crm-i fa-plus-circle"></i>
{ts 1=$cd_edit.title}Another %1 record{/ts}
</a>
</div>
{/if}
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity=''}
{else}
{foreach from=$groupTree item=cd_edit key=group_id name=custom_sets}
{if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'}
{assign var="isSingleRecordEdit" value=TRUE}
{else}
{* always assign to prevent leakage*}
{assign var="isSingleRecordEdit" value=''}
{/if}
{if $isSingleRecordEdit}
<div class="custom-group custom-group-{$cd_edit.name}">
{if $cd_edit.help_pre}
<div class="messages help">{$cd_edit.help_pre}</div>
{/if}
<table>
{foreach from=$cd_edit.fields item=element key=field_id}
{assign var="element_name" value=$element.element_name}
{include file="CRM/Custom/Form/Edit/CustomField.tpl" formElement=$form.$element_name}
{/foreach}
</table>
<div class="spacer"></div>
{if $cd_edit.help_post}
<div class="messages help">{$cd_edit.help_post}</div>
{/if}
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity=''}
</div>
{else}
<div class="custom-group custom-group-{$cd_edit.name} crm-accordion-wrapper crm-custom-accordion {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
Expand All @@ -72,43 +46,9 @@
</div><!-- /.crm-accordion-header -->
{/if}
<div class="crm-accordion-body">
{if $cd_edit.is_multiple eq 1 and $cd_edit.table_id and $contactId and !$skipTitle and $cd_edit.style eq 'Inline'}
{assign var=tableID value=$cd_edit.table_id}
<a href="#" class="crm-hover-button crm-custom-value-del" title="{ts 1=$cd_edit.title}Delete %1{/ts}"
data-post='{ldelim}"valueID": "{$tableID}", "groupID": "{$group_id}", "contactId": "{$contactId}", "key": "{crmKey name='civicrm/ajax/customvalue'}"{rdelim}'>
<span class="icon delete-icon"></span> {ts}Delete{/ts}
</a>
{/if}
{if $cd_edit.help_pre}
<div class="messages help">{$cd_edit.help_pre}</div>
{/if}
<table class="form-layout-compressed">
{foreach from=$cd_edit.fields item=element key=field_id}
{assign var="element_name" value=$element.element_name}
{include file="CRM/Custom/Form/Edit/CustomField.tpl" formElement=$form.$element_name}
{/foreach}
</table>
<div class="spacer"></div>
{if $cd_edit.help_post}
<div class="messages help">{$cd_edit.help_post}</div>
{/if}
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity=''}
</div>
</div>
{if $cd_edit.is_multiple and ( ( $cd_edit.max_multiple eq '' ) or ( $cd_edit.max_multiple > 0 and $cd_edit.max_multiple > $cgCount ) ) }
{if $skipTitle}
{* We don't yet support adding new records in inline-edit forms *}
<div class="messages help">
<em>{ts 1=$cd_edit.title}Click "Edit Contact" to add more %1 records{/ts}</em>
</div>
{else}
<div id="add-more-link-{$cgCount}" class="add-more-link-{$group_id} add-more-link-{$group_id}-{$cgCount}">
<a href="#" class="crm-hover-button" onclick="CRM.buildCustomData('{$cd_edit.extends}',{if $cd_edit.subtype}'{$cd_edit.subtype}'{else}'{$cd_edit.extends_entity_column_id}'{/if}, '', {$cgCount}, {$group_id}, true ); return false;">
<i class="crm-i fa-plus-circle"></i>
{ts 1=$cd_edit.title}Another %1 record{/ts}
</a>
</div>
{/if}
{/if}
{/if}
<div id="custom_group_{$group_id}_{$cgCount}"></div>
{/foreach}
Expand Down
45 changes: 45 additions & 0 deletions templates/CRM/Custom/Form/Edit/CustomData.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{if !$isSingleRecordEdit && $cd_edit.is_multiple eq 1 and $cd_edit.table_id and $contactId and !$skipTitle and $cd_edit.style eq 'Inline'}
{assign var=tableID value=$cd_edit.table_id}
<a href="#" class="crm-hover-button crm-custom-value-del" title="{ts 1=$cd_edit.title}Delete %1{/ts}"
data-post='{ldelim}"valueID": "{$tableID}", "groupID": "{$group_id}", "contactId": "{$contactId}", "key": "{crmKey name='civicrm/ajax/customvalue'}"{rdelim}'>
<span class="icon delete-icon"></span> {ts}Delete{/ts}
</a>
{/if}

{if $cd_edit.help_pre}
<div class="messages help">{$cd_edit.help_pre}</div>
{/if}
<table {if !$isSingleRecordEdit}class="form-layout-compressed"{/if}>
{foreach from=$cd_edit.fields item=element key=field_id}
{if $customDataEntity && $blockId}
{* custom data entity combined with blockId tells us we have an entity with mutliple blocks
such as address. Some risk of leakage on blockId so only set customDataEntity when using blocks*}
{assign var="element_name" value=$element.element_custom_name}
{assign var="formElement" value=$form.$customDataEntity.$blockId.$element_name}
{else}
{assign var="element_name" value=$element.element_name}
{assign var="formElement" value=$form.$element_name}
{/if}
{include file="CRM/Custom/Form/Edit/CustomField.tpl"}
{/foreach}
</table>
<div class="spacer"></div>
{if $cd_edit.help_post}<div class="messages help">{$cd_edit.help_post}</div>{/if}
{if !$isSingleRecordEdit && $cd_edit.is_multiple and ( ( $cd_edit.max_multiple eq '' ) or ( $cd_edit.max_multiple > 0 and $cd_edit.max_multiple > $cgCount ) ) }
{if $skipTitle}
{* We don't yet support adding new records in inline-edit forms *}
<div class="messages help">
<em>{ts 1=$cd_edit.title}Click "Edit Contact" to add more %1 records{/ts}</em>
</div>
{else}
<div id="add-more-link-{$cgCount}" class="add-more-link-{$group_id} add-more-link-{$group_id}-{$cgCount}">
<a href="#" class="crm-hover-button" onclick="CRM.buildCustomData('{$cd_edit.extends}',{if $cd_edit.subtype}'{$cd_edit.subtype}'{else}'{$cd_edit.extends_entity_column_id}'{/if}, '', {$cgCount}, {$group_id}, true ); return false;">
<i class="crm-i fa-plus-circle"></i>
{ts 1=$cd_edit.title}Another %1 record{/ts}
</a>
</div>
{/if}
{/if}

{*set customDataEntity to null to prevent leakage if this is called more than once*}
{assign var='customDataEntity' value=''}

0 comments on commit 1145f96

Please sign in to comment.