| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.7 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 ui-icon-wrench"></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} {help id="id-external-id"}<br /> |
| 62 | {$form.external_identifier.html} |
| 63 | </td> |
| 64 | {if $contactId} |
| 65 | <td> |
| 66 | <label for="internal_identifier_display">{ts}Contact ID{/ts} {help id="id-internal-id"}</label><br /> |
| 67 | <input id="internal_identifier_display" type="text" class="crm-form-text six" size="6" readonly="readonly" value="{$contactId}"> |
| 68 | </td> |
| 69 | {/if} |
| 70 | </tr> |
| 71 | </table> |
| 72 | <table class="image_URL-section form-layout-compressed"> |
| 73 | <tr> |
| 74 | <td> |
| 75 | {$form.image_URL.label} {help id="id-upload-image" file="CRM/Contact/Form/Contact.hlp"}<br /> |
| 76 | {$form.image_URL.html|crmAddClass:twenty} |
| 77 | {if !empty($imageURL)} |
| 78 | {include file="CRM/Contact/Page/ContactImage.tpl"} |
| 79 | {/if} |
| 80 | </td> |
| 81 | </tr> |
| 82 | </table> |
| 83 | |
| 84 | {*add dupe buttons *} |
| 85 | <span class="crm-button crm-button_qf_Contact_refresh_dedupe"> |
| 86 | {$form._qf_Contact_refresh_dedupe.html} |
| 87 | </span> |
| 88 | {if $isDuplicate} |
| 89 | |
| 90 | <span class="crm-button crm-button_qf_Contact_upload_duplicate"> |
| 91 | {$form._qf_Contact_upload_duplicate.html} |
| 92 | </span> |
| 93 | {/if} |
| 94 | <div class="spacer"></div> |
| 95 | </div> |
| 96 | </div><!-- /.crm-accordion-body --> |
| 97 | </div><!-- /.crm-accordion-wrapper --> |
| 98 | |
| 99 | {foreach from = $editOptions item = "title" key="name"} |
| 100 | {if $name eq 'CustomData' } |
| 101 | <div id='customData'>{include file="CRM/Contact/Form/Edit/CustomData.tpl"}</div> |
| 102 | {else} |
| 103 | {include file="CRM/Contact/Form/Edit/$name.tpl"} |
| 104 | {/if} |
| 105 | {/foreach} |
| 106 | <div class="crm-submit-buttons"> |
| 107 | {include file="CRM/common/formButtons.tpl" location="bottom"} |
| 108 | </div> |
| 109 | </div> |
| 110 | {literal} |
| 111 | |
| 112 | <script type="text/javascript" > |
| 113 | CRM.$(function($) { |
| 114 | var $form = $("form.{/literal}{$form.formClass}{literal}"); |
| 115 | var action = "{/literal}{$action}{literal}"; |
| 116 | |
| 117 | $('.crm-accordion-body').each( function() { |
| 118 | //remove tab which doesn't have any element |
| 119 | if ( ! $.trim( $(this).text() ) ) { |
| 120 | ele = $(this); |
| 121 | prevEle = $(this).prev(); |
| 122 | $(ele).remove(); |
| 123 | $(prevEle).remove(); |
| 124 | } |
| 125 | //open tab if form rule throws error |
| 126 | if ( $(this).children().find('span.crm-error').text().length > 0 ) { |
| 127 | $(this).parents('.collapsed').crmAccordionToggle(); |
| 128 | } |
| 129 | }); |
| 130 | if (action == '2') { |
| 131 | $('.crm-accordion-wrapper').not('.crm-accordion-wrapper .crm-accordion-wrapper').each(function() { |
| 132 | highlightTabs(this); |
| 133 | }); |
| 134 | $('#crm-container').on('change click', '.crm-accordion-body :input, .crm-accordion-body a', function() { |
| 135 | highlightTabs($(this).parents('.crm-accordion-wrapper')); |
| 136 | }); |
| 137 | } |
| 138 | function highlightTabs(tab) { |
| 139 | //highlight the tab having data inside. |
| 140 | $('.crm-accordion-body :input', tab).each( function() { |
| 141 | var active = false; |
| 142 | switch($(this).prop('type')) { |
| 143 | case 'checkbox': |
| 144 | case 'radio': |
| 145 | if($(this).is(':checked') && !$(this).is('[id$=IsPrimary],[id$=IsBilling]')) { |
| 146 | $('.crm-accordion-header:first', tab).addClass('active'); |
| 147 | return false; |
| 148 | } |
| 149 | break; |
| 150 | |
| 151 | case 'text': |
| 152 | case 'textarea': |
| 153 | if($(this).val()) { |
| 154 | $('.crm-accordion-header:first', tab).addClass('active'); |
| 155 | return false; |
| 156 | } |
| 157 | break; |
| 158 | |
| 159 | case 'select-one': |
| 160 | case 'select-multiple': |
| 161 | if($(this).val() && $('option[value=""]', this).length > 0) { |
| 162 | $('.crm-accordion-header:first', tab).addClass('active'); |
| 163 | return false; |
| 164 | } |
| 165 | break; |
| 166 | |
| 167 | case 'file': |
| 168 | if($(this).next().html()) { |
| 169 | $('.crm-accordion-header:first', tab).addClass('active'); |
| 170 | return false; |
| 171 | } |
| 172 | break; |
| 173 | } |
| 174 | $('.crm-accordion-header:first', tab).removeClass('active'); |
| 175 | }); |
| 176 | } |
| 177 | |
| 178 | $('a#expand').click( function() { |
| 179 | if( $(this).attr('href') == '#expand') { |
| 180 | var message = {/literal}"{ts escape='js'}Collapse all tabs{/ts}"{literal}; |
| 181 | $(this).attr('href', '#collapse'); |
| 182 | $('.crm-accordion-wrapper.collapsed').crmAccordionToggle(); |
| 183 | } |
| 184 | else { |
| 185 | var message = {/literal}"{ts escape='js'}Expand all tabs{/ts}"{literal}; |
| 186 | $('.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle(); |
| 187 | $(this).attr('href', '#expand'); |
| 188 | } |
| 189 | $(this).html(message); |
| 190 | return false; |
| 191 | }); |
| 192 | |
| 193 | $('.customDataPresent').change(function() { |
| 194 | //$('.crm-custom-accordion').remove(); |
| 195 | var values = $("#contact_sub_type").val(); |
| 196 | var contactType = {/literal}"{$contactType}"{literal}; |
| 197 | CRM.buildCustomData(contactType, values); |
| 198 | loadMultiRecordFields(values); |
| 199 | $('.crm-custom-accordion').each(function() { |
| 200 | highlightTabs(this); |
| 201 | }); |
| 202 | }); |
| 203 | |
| 204 | function loadMultiRecordFields(subTypeValues) { |
| 205 | if (subTypeValues == false) { |
| 206 | var subTypeValues = null; |
| 207 | } |
| 208 | else if (!subTypeValues) { |
| 209 | var subTypeValues = {/literal}"{$paramSubType}"{literal}; |
| 210 | } |
| 211 | {/literal} |
| 212 | {foreach from=$customValueCount item="groupCount" key="groupValue"} |
| 213 | {if $groupValue}{literal} |
| 214 | for ( var i = 1; i < {/literal}{$groupCount}{literal}; i++ ) { |
| 215 | CRM.buildCustomData( {/literal}"{$contactType}"{literal}, subTypeValues, null, i, {/literal}{$groupValue}{literal}, true ); |
| 216 | } |
| 217 | {/literal} |
| 218 | {/if} |
| 219 | {/foreach} |
| 220 | {literal} |
| 221 | } |
| 222 | |
| 223 | loadMultiRecordFields(); |
| 224 | |
| 225 | {/literal}{if $oldSubtypes}{literal} |
| 226 | $('input[name=_qf_Contact_upload_view], input[name=_qf_Contact_upload_new]').click(function() { |
| 227 | var submittedSubtypes = $('#contact_sub_type').val(); |
| 228 | var oldSubtypes = {/literal}{$oldSubtypes}{literal}; |
| 229 | |
| 230 | var warning = false; |
| 231 | $.each(oldSubtypes, function(index, subtype) { |
| 232 | if ( $.inArray(subtype, submittedSubtypes) < 0 ) { |
| 233 | warning = true; |
| 234 | } |
| 235 | }); |
| 236 | if ( warning ) { |
| 237 | 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}); |
| 238 | } |
| 239 | return true; |
| 240 | }); |
| 241 | {/literal}{/if}{literal} |
| 242 | |
| 243 | // Handle delete of multi-record custom data |
| 244 | $form.on('click', '.crm-custom-value-del', function(e) { |
| 245 | e.preventDefault(); |
| 246 | var $el = $(this), |
| 247 | msg = '{/literal}{ts escape="js"}The record will be deleted immediately. This action cannot be undone.{/ts}{literal}'; |
| 248 | CRM.confirm({title: $el.attr('title'), message: msg}) |
| 249 | .on('crmConfirm:yes', function() { |
| 250 | var url = CRM.url('civicrm/ajax/customvalue'); |
| 251 | var request = $.post(url, $el.data('post')); |
| 252 | CRM.status({success: '{/literal}{ts escape="js"}Record Deleted{/ts}{literal}'}, request); |
| 253 | var addClass = '.add-more-link-' + $el.data('post').groupID; |
| 254 | $el.closest('div.crm-custom-accordion').remove(); |
| 255 | $('div' + addClass).last().show(); |
| 256 | }); |
| 257 | }); |
| 258 | }); |
| 259 | |
| 260 | </script> |
| 261 | {/literal} |
| 262 | |
| 263 | {* jQuery validate *} |
| 264 | {include file="CRM/Form/validate.tpl"} |
| 265 | |
| 266 | {* include common additional blocks tpl *} |
| 267 | {include file="CRM/common/additionalBlocks.tpl"} |
| 268 | |
| 269 | {/if} |