CRM-15153 - Give forms a unique css class based on full class name
[civicrm-core.git] / templates / CRM / Contact / Form / Contact.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 *}
26 {* This form is for Contact Add/Edit interface *}
27 {if $addBlock}
28 {include file="CRM/Contact/Form/Edit/$blockName.tpl"}
29 {else}
30 {if $contactId}
31 {include file="CRM/Contact/Form/Edit/Lock.tpl"}
32 {/if}
33 <div class="crm-form-block crm-search-form-block">
34 {if call_user_func(array('CRM_Core_Permission','check'), 'administer CiviCRM') }
35 <a href='{crmURL p="civicrm/admin/setting/preferences/display" q="reset=1"}' title="{ts}Click here to configure the panes.{/ts}"><span class="icon settings-icon"></span></a>
36 {/if}
37 <span style="float:right;"><a href="#expand" id="expand">{ts}Expand all tabs{/ts}</a></span>
38 <div class="crm-submit-buttons">
39 {include file="CRM/common/formButtons.tpl" location="top"}
40 </div>
41
42 <div class="crm-accordion-wrapper crm-contactDetails-accordion">
43 <div class="crm-accordion-header">
44 {ts}Contact Details{/ts}
45 </div><!-- /.crm-accordion-header -->
46 <div class="crm-accordion-body" id="contactDetails">
47 <div id="contactDetails">
48 <div class="crm-section contact_basic_information-section">
49 {include file="CRM/Contact/Form/Edit/$contactType.tpl"}
50 </div>
51 <table class="crm-section contact_information-section form-layout-compressed">
52 {foreach from=$blocks item="label" key="block"}
53 {include file="CRM/Contact/Form/Edit/$block.tpl"}
54 {/foreach}
55 </table>
56 <table class="crm-section contact_source-section form-layout-compressed">
57 <tr class="last-row">
58 <td>{$form.contact_source.label} {help id="id-source"}<br />
59 {$form.contact_source.html|crmAddClass:twenty}
60 </td>
61 <td>{$form.external_identifier.label}&nbsp;{help id="id-external-id"}<br />
62 {$form.external_identifier.html}
63 </td>
64 {if $contactId}
65 <td><label for="internal_identifier_display">{ts}CiviCRM ID{/ts}{help id="id-internal-id"}</label><br /><input id="internal_identifier_display" type="text" class="form-text eight" size="8" disabled="disabled" value="{$contactId}"></td>
66 {/if}
67 </tr>
68 </table>
69 <table class="image_URL-section form-layout-compressed">
70 <tr>
71 <td>
72 {$form.image_URL.label}&nbsp;&nbsp;{help id="id-upload-image" file="CRM/Contact/Form/Contact.hlp"}<br />
73 {$form.image_URL.html|crmAddClass:twenty}
74 {if !empty($imageURL)}
75 {include file="CRM/Contact/Page/ContactImage.tpl"}
76 {/if}
77 </td>
78 </tr>
79 </table>
80
81 {*add dupe buttons *}
82 <span class="crm-button crm-button_qf_Contact_refresh_dedupe">
83 {$form._qf_Contact_refresh_dedupe.html}
84 </span>
85 {if $isDuplicate}
86 &nbsp;&nbsp;
87 <span class="crm-button crm-button_qf_Contact_upload_duplicate">
88 {$form._qf_Contact_upload_duplicate.html}
89 </span>
90 {/if}
91 <div class="spacer"></div>
92 </div>
93 </div><!-- /.crm-accordion-body -->
94 </div><!-- /.crm-accordion-wrapper -->
95
96 {foreach from = $editOptions item = "title" key="name"}
97 {if $name eq 'CustomData' }
98 <div id='customData'>{include file="CRM/Contact/Form/Edit/CustomData.tpl"}</div>
99 {else}
100 {include file="CRM/Contact/Form/Edit/$name.tpl"}
101 {/if}
102 {/foreach}
103 <div class="crm-submit-buttons">
104 {include file="CRM/common/formButtons.tpl" location="bottom"}
105 </div>
106 </div>
107 {literal}
108
109 <script type="text/javascript" >
110 CRM.$(function($) {
111 var $form = $("form.{/literal}{$form.formClass}{literal}");
112 var action = "{/literal}{$action}{literal}";
113
114 $('.crm-accordion-body').each( function() {
115 //remove tab which doesn't have any element
116 if ( ! $.trim( $(this).text() ) ) {
117 ele = $(this);
118 prevEle = $(this).prev();
119 $(ele).remove();
120 $(prevEle).remove();
121 }
122 //open tab if form rule throws error
123 if ( $(this).children().find('span.crm-error').text().length > 0 ) {
124 $(this).parents('.collapsed').crmAccordionToggle();
125 }
126 });
127 if (action == '2') {
128 $('.crm-accordion-wrapper').not('.crm-accordion-wrapper .crm-accordion-wrapper').each(function() {
129 highlightTabs(this);
130 });
131 $('#crm-container').on('change click', '.crm-accordion-body :input, .crm-accordion-body a', function() {
132 highlightTabs($(this).parents('.crm-accordion-wrapper'));
133 });
134 }
135 function highlightTabs(tab) {
136 //highlight the tab having data inside.
137 $('.crm-accordion-body :input', tab).each( function() {
138 var active = false;
139 switch($(this).prop('type')) {
140 case 'checkbox':
141 case 'radio':
142 if($(this).is(':checked') && !$(this).is('[id$=IsPrimary],[id$=IsBilling]')) {
143 $('.crm-accordion-header:first', tab).addClass('active');
144 return false;
145 }
146 break;
147
148 case 'text':
149 case 'textarea':
150 if($(this).val()) {
151 $('.crm-accordion-header:first', tab).addClass('active');
152 return false;
153 }
154 break;
155
156 case 'select-one':
157 case 'select-multiple':
158 if($(this).val() && $('option[value=""]', this).length > 0) {
159 $('.crm-accordion-header:first', tab).addClass('active');
160 return false;
161 }
162 break;
163
164 case 'file':
165 if($(this).next().html()) {
166 $('.crm-accordion-header:first', tab).addClass('active');
167 return false;
168 }
169 break;
170 }
171 $('.crm-accordion-header:first', tab).removeClass('active');
172 });
173 }
174
175 $('a#expand').click( function() {
176 if( $(this).attr('href') == '#expand') {
177 var message = {/literal}"{ts escape='js'}Collapse all tabs{/ts}"{literal};
178 $(this).attr('href', '#collapse');
179 $('.crm-accordion-wrapper.collapsed').crmAccordionToggle();
180 }
181 else {
182 var message = {/literal}"{ts escape='js'}Expand all tabs{/ts}"{literal};
183 $('.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
184 $(this).attr('href', '#expand');
185 }
186 $(this).html(message);
187 return false;
188 });
189
190 $('.customDataPresent').change(function() {
191 //$('.crm-custom-accordion').remove();
192 var values = $("#contact_sub_type").val();
193 var contactType = {/literal}"{$contactType}"{literal};
194 CRM.buildCustomData(contactType, values);
195 loadMultiRecordFields(values);
196 $('.crm-custom-accordion').each(function() {
197 highlightTabs(this);
198 });
199 });
200
201 function loadMultiRecordFields(subTypeValues) {
202 if (subTypeValues == false) {
203 var subTypeValues = null;
204 }
205 else if (!subTypeValues) {
206 var subTypeValues = {/literal}"{$paramSubType}"{literal};
207 }
208 {/literal}
209 {foreach from=$customValueCount item="groupCount" key="groupValue"}
210 {if $groupValue}{literal}
211 for ( var i = 1; i < {/literal}{$groupCount}{literal}; i++ ) {
212 CRM.buildCustomData( {/literal}"{$contactType}"{literal}, subTypeValues, null, i, {/literal}{$groupValue}{literal}, true );
213 }
214 {/literal}
215 {/if}
216 {/foreach}
217 {literal}
218 }
219
220 loadMultiRecordFields();
221
222 {/literal}{if $oldSubtypes}{literal}
223 $('input[name=_qf_Contact_upload_view], input[name=_qf_Contact_upload_new]').click(function() {
224 var submittedSubtypes = $('#contact_sub_type').val();
225 var oldSubtypes = {/literal}{$oldSubtypes}{literal};
226
227 var warning = false;
228 $.each(oldSubtypes, function(index, subtype) {
229 if ( $.inArray(subtype, submittedSubtypes) < 0 ) {
230 warning = true;
231 }
232 });
233 if ( warning ) {
234 return confirm({/literal}'{ts escape="js"}One or more contact subtypes have been de-selected from the list for this contact. Any custom data associated with de-selected subtype will be removed. Click OK to proceed, or Cancel to review your changes before saving.{/ts}'{literal});
235 }
236 return true;
237 });
238 {/literal}{/if}{literal}
239
240 // Handle delete of multi-record custom data
241 $form.on('click', '.crm-custom-value-del', function(e) {
242 e.preventDefault();
243 var $el = $(this),
244 msg = '{/literal}{ts escape="js"}The record will be deleted immediately. This action cannot be undone.{/ts}{literal}';
245 CRM.confirm({title: $el.attr('title'), message: msg})
246 .on('crmConfirm:yes', function() {
247 var url = CRM.url('civicrm/ajax/customvalue');
248 var request = $.post(url, $el.data('post'));
249 CRM.status({success: '{/literal}{ts escape="js"}Record Deleted{/ts}{literal}'}, request);
250 var addClass = '.add-more-link-' + $el.data('post').groupID;
251 $el.closest('div.crm-custom-accordion').remove();
252 $('div' + addClass).last().show();
253 });
254 });
255 });
256
257 </script>
258 {/literal}
259
260 {* jQuery validate *}
261 {include file="CRM/Form/validate.tpl"}
262
263 {* include common additional blocks tpl *}
264 {include file="CRM/common/additionalBlocks.tpl"}
265
266 {/if}