2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
26 {* this template is used for adding/editing/viewing relationships *}
28 {include file="CRM/Custom/Form/CustomData.tpl"}
30 {if $action eq 4 } {* action = view *}
31 <h3>{ts}View Relationship{/ts}</h3>
32 <div class="crm-block crm-content-block crm-relationship-view-block">
33 <table class="crm-info-panel">
34 {foreach from=$viewRelationship item="row"}
36 <td class="label">{$row.relation}</td>
37 <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.cid`"}">{$row.name}</a></td>
39 {if $isCurrentEmployer}
40 <tr><td class="label">{ts}Current Employee?{/ts}</td><td>{ts}Yes{/ts}</td></tr>
43 <tr><td class="label">{ts}Start Date{/ts}</td><td>{$row.start_date|crmDate}</td></tr>
46 <tr><td class="label">{ts}End Date{/ts}</td><td>{$row.end_date|crmDate}</td></tr>
49 <tr><td class="label">{ts}Description{/ts}</td><td>{$row.description}</td></tr>
51 {foreach from=$viewNote item="rec"}
53 <tr><td class="label">{ts}Note{/ts}</td><td>{$rec}</td></tr>
56 {if $row.is_permission_a_b}
57 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
58 <tr><td class="label"> </td><td><strong>'{$displayName}'</strong> can view and update information for <strong>'{$row.display_name}'</strong></td></tr>
60 <tr><td class="label"> </td><td><strong>'{$row.display_name}'</strong> can view and update information for <strong>'{$displayName}'</strong></td></tr>
63 {if $row.is_permission_b_a}
64 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
65 <tr><td class="label"> </td><td><strong>'{$row.display_name}'</strong> can view and update information for <strong>'{$displayName}'</strong></td></tr>
67 <tr><td class="label"> </td><td><strong>'{$displayName}'</strong> can view and update information for <strong>'{$row.display_name}'</strong></td></tr>
71 <tr><td class="label">{ts}Status{/ts}</td><td>{if $row.is_active}{ts}Enabled{/ts} {else} {ts}Disabled{/ts}{/if}</td></tr>
74 {include file="CRM/Custom/Page/CustomDataView.tpl"}
75 <div class="crm-submit-buttons"><input type="button" name='cancel' value="{ts}Done{/ts}" onclick="location.href='{crmURL p='civicrm/contact/view' q='action=browse&selectedChild=rel'}';"/></div>
79 {if $action eq 2 | $action eq 1} {* add and update actions *}
80 {* Retrieve the ID for the Employee / Employer relationship type *}
81 {crmAPI var="employmentRelationship" entity="RelationshipType" action="getvalue" version="3" name_a_b="Employee of" return="id"}
82 <h3>{if $action eq 1}{ts}New Relationship{/ts}{else}{ts}Edit Relationship{/ts}{/if}</h3>
83 <div class="crm-block crm-form-block crm-relationship-form-block">
85 <div class="description">
86 {ts}Select the relationship type. Then locate target contact(s) for this relationship by entering a partial name and selecting from the dropdown, or clicking 'Search'. If the target contact does not exist, you can create a new contact.{/ts}
89 <table class="form-layout-compressed">
90 <tr class="crm-relationship-form-block-relationship_type_id">
91 <td class="label">{$form.relationship_type_id.label}</td><td>{$form.relationship_type_id.html}</td>
92 {if $action EQ 2} {* action = update *}
94 <script type="text/javascript">
97 var relationshipType = cj('#relationship_type_id');
98 relationshipType.change( function( ) {
99 changeCustomData( 'Relationship' );
102 setPermissionStatus( relationshipType.val( ) );
106 <td><label>{$sort_name_b}</label></td></tr>
107 <tr class="crm-relationship-form-block-is_current_employer">
109 <span id="employee"><label>{ts}Current Employee?{/ts}</label></span>
110 <span id="employer"><label>{ts}Current Employer?{/ts}</label></span>
112 <td id="current_employer">{$form.is_current_employer.html}</td>
115 {else} {* action = add *}
117 {include file="CRM/Contact/Form/NewContact.tpl" newContactCallback="afterCreateNew()"}
118 <tr class="crm-relationship-form-block-rel_contact">
121 <script type="text/javascript">
124 enableDisableContactSelection( );
126 var relationshipType = cj('#relationship_type_id');
127 relationshipType.change( function() {
128 enableDisableContactSelection( );
129 cj('#relationship-refresh-save').hide();
130 cj('#saveButtons').hide();
132 changeCustomData( 'Relationship' );
133 setPermissionStatus( cj(this).val( ) );
135 setPermissionStatus( relationshipType.val( ) );
138 function enableDisableContactSelection( ) {
139 var relationshipTypeValue = cj('#relationship_type_id').val();
140 var contactAutocomplete = cj('#contact_1');
142 //always reset field so that correct data url is linked
143 contactAutocomplete.unautocomplete( );
145 if ( relationshipTypeValue ) {
146 cj('#profiles_1').attr('disabled', false);
147 contactAutocomplete.attr('disabled', false);
148 contactAutocomplete.addClass('ac_input');
149 buildCreateNewSelect( 'profiles_1', relationshipTypeValue );
151 cj('#profiles_1').attr('disabled', true);
152 contactAutocomplete.removeClass('ac_input');
153 contactAutocomplete.attr('disabled', true);
157 function afterCreateNew() {
158 var relType = cj('#relationship_type_id').val( );
159 var contactSelected = cj('#contact_1').val( );
160 if ( relType && contactSelected ) {
161 cj('#relationship-refresh-save').show( );
162 buildRelationFields( relType );
166 function createRelation( ) {
167 var relType = cj('#relationship_type_id').val( );
168 var relContact = cj('#contact_1');
170 var dataUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=relationship&rel="}'{literal} + relType;
171 relContact.autocomplete( dataUrl, { width : 200, selectFirst : false, matchContains: true, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal} });
172 relContact.result(function( event, data ) {
173 cj("input[name='contact_select_id[1]']").val(data[1]);
174 cj('#relationship-refresh-save').show( );
175 buildRelationFields( relType );
178 relContact.unautocomplete( );
182 function buildCreateNewSelect( selectID, relType ) {
183 selectID = '#' + selectID;
184 cj( selectID ).html('');
185 var postUrl = "{/literal}{crmURL p='civicrm/ajax/relationshipContactTypeList' h=0}{literal}";
186 cj.post( postUrl, { relType: relType },
187 function ( response ) {
188 cj( selectID ).get(0).add(new Option('{/literal}{ts escape="js"}- create new contact -{/ts}{literal}', ''));
189 response = eval( response );
190 for (i = 0; i < response.length; i++) {
191 cj( selectID ).get(0).add(new Option(response[i].name, response[i].value));
202 <div class="crm-submit-buttons">
203 <span id="relationship-refresh" class="crm-button crm-button-type-refresh crm-button_qf_Relationship_refresh">{$form._qf_Relationship_refresh.html}</span>
204 <span id="relationship-refresh-save" class="crm-button crm-button-type-save crm-button_qf_Relationship_refresh_save" style="display:none">{$form._qf_Relationship_refresh_save.html}</span>
205 <span class="crm-button crm-button-type-cancel crm-button_qf_Relationship_cancel">{$form._qf_Relationship_cancel.html}</span>
207 <div class="clear"></div>
209 {if $searchDone } {* Search button clicked *}
210 {if $searchCount || $callAjax}
211 {if $searchRows || $callAjax} {* we got rows to display *}
212 <fieldset id="searchResult"><legend>{ts}Mark Target Contact(s) for this Relationship{/ts}</legend>
213 <div class="description">
214 {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts}
218 <div id="count_selected"> </div><br />
219 {$form.store_contacts.html}
221 {if $isEmployeeOf || $isEmployerOf}
222 {$form.store_employer.html}
224 {include file="CRM/common/jsortable.tpl" sourceUrl=$sourceUrl useAjax=1 callBack=1 }
227 <table id="rel-contacts" class="pagerDisplay">
229 <tr class="columnheader">
230 <th id="nosort" class="contact_select"> </th>
231 <th>{ts}Name{/ts}</th>
232 {if $isEmployeeOf}<th id="nosort" class="current_employer">{ts}Current Employer?{/ts}</th>
233 {elseif $isEmployerOf}<th id="nosort" class="current_employer">{ts}Current Employee?{/ts}</th>{/if}
234 <th>{ts}City{/ts}</th>
235 <th>{ts}State{/ts}</th>
236 <th>{ts}Email{/ts}</th>
237 <th>{ts}Phone{/ts}</th>
242 {foreach from=$searchRows item=row}
243 <tr class="{cycle values="odd-row,even-row"}">
244 <td class="contact_select">{$form.contact_check[$row.id].html}</td>
245 <td>{$row.type} {$row.name}</td>
246 {if $isEmployeeOf}<td>{$form.employee_of[$row.id].html}</td>
247 {elseif $isEmployerOf}<td>{$form.employer_of[$row.id].html}</td>{/if}
249 <td>{$row.state}</td>
250 <td>{$row.email}</td>
251 <td>{$row.phone}</td>
255 <tr><td colspan="5" class="dataTables_empty">Loading data from server</td></tr>
261 <div class="spacer"></div>
262 {else} {* too many results - we display only 50 *}
263 {if $duplicateRelationship}
264 {capture assign=infoTitle}{ts}Duplicate relationship.{/ts}{/capture}
265 {capture assign=infoMessage}{ts}This relationship already exists.{/ts}{/capture}
267 {capture assign=infoTitle}{ts}Too many matching results.{/ts}{/capture}
268 {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture}
270 {include file="CRM/common/info.tpl"}
272 {else} {* no valid matches for name + contact_type *}
273 {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture}
274 {capture assign=infoMessage}<ul><li>{ts 1=$form.contact_1.value}Name like: %1{/ts}</li><li>{ts}Contact Type{/ts}: {$contact_type_display}</li></ul>{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture}
275 {include file="CRM/common/info.tpl"}
276 {/if} {* end if searchCount *}
278 {/if} {* end if searchDone *}
279 {/if} {* end action = add *}
281 <div id='saveElements'>
283 <div id='addCurrentEmployer'>
284 <table class="form-layout-compressed">
285 <tr class="crm-relationship-form-block-add_current_employer">
286 <td class="label">{$form.add_current_employer.label}</td>
287 <td>{$form.add_current_employer.html}</td>
291 <div id='addCurrentEmployee'>
292 <table class="form-layout-compressed">
293 <tr class="crm-relationship-form-block-add_current_employee">
294 <td class="label">{$form.add_current_employee.label}</td>
295 <td>{$form.add_current_employee.html}</td>
300 <table class="form-layout-compressed">
301 <tr class="crm-relationship-form-block-start_date">
302 <td class="label">{$form.start_date.label}</td>
303 <td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}</td></tr>
304 <tr class="crm-relationship-form-block-end_date">
305 <td class="label">{$form.end_date.label}</td>
306 <td>{include file="CRM/common/jcalendar.tpl" elementName=end_date}<br />
307 <span class="description">{ts}If this relationship has start and/or end dates, specify them here.{/ts}</span></td>
309 <tr class="crm-relationship-form-block-description">
310 <td class="label">{$form.description.label}</td>
311 <td>{$form.description.html}</td>
313 <tr class="crm-relationship-form-block-note">
314 <td class="label">{$form.note.label}</td>
315 <td>{$form.note.html}</td>
317 <tr class="crm-relationship-form-block-is_permission_a_b">
318 <td class="label"></td><td>{$form.is_permission_a_b.html}
319 <span id='permision_a_b-a_b' class="hiddenElement">
321 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for selected contact(s){/ts}
323 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_b}'</strong>
326 <span id='permision_a_b-b_a' class="hiddenElement">
328 <strong>{ts}Selected contact(s)</strong> can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
330 <strong>'{$sort_name_b}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
335 <tr class="crm-relationship-form-block-is_permission_b_a">
336 <td class="label"></td><td>{$form.is_permission_b_a.html}
337 <span id='permision_b_a-b_a' class="hiddenElement">
339 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for selected contact(s){/ts}
341 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_b}'</strong>
344 <span id='permision_b_a-a_b' class="hiddenElement">
346 <strong>{ts}Selected contact(s)</strong> can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
348 <strong>'{$sort_name_b}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
353 <tr class="crm-relationship-form-block-is_active">
354 <td class="label">{$form.is_active.label}</td>
355 <td>{$form.is_active.html}</td>
359 <script type="text/javascript">
360 function setPermissionStatus( relTypeDirection ) {
361 var direction = relTypeDirection.split( '_' );
362 cj('#permision_a_b-' + direction[1] + '_' + direction[2] ).show( );
363 cj('#permision_a_b-' + direction[2] + '_' + direction[1] ).hide( );
364 cj('#permision_b_a-' + direction[1] + '_' + direction[2] ).show( );
365 cj('#permision_b_a-' + direction[2] + '_' + direction[1] ).hide( );
369 </div>{* end of save element div *}
370 <div id="customData"></div>
371 <div class="spacer"></div>
372 <div class="crm-submit-buttons" id="saveButtons"> {include file="CRM/common/formButtons.tpl" location="bottom"}</div>
374 <div class="crm-submit-buttons" id="saveDetails">
375 <span class="crm-button crm-button-type-save crm-button_qf_Relationship_refresh_savedetails">{$form._qf_Relationship_refresh_savedetails.html}</span>
376 <span class="crm-button crm-button-type-cancel crm-button_qf_Relationship_cancel">{$form._qf_Relationship_cancel.html}</span>
379 </div> {* close main block div *}
383 <fieldset><legend>{ts}Delete Relationship{/ts}</legend>
385 {capture assign=relationshipsString}{$currentRelationships.$id.relation}{ $disableRelationships.$id.relation} {$currentRelationships.$id.name}{ $disableRelationships.$id.name }{/capture}
386 {ts 1=$relationshipsString}Are you sure you want to delete the Relationship '%1'?{/ts}
388 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
391 {/if} {* close of custom data else*}
395 <script type="text/javascript">
396 var contact_checked = new Array();
397 var employer_checked = new Array();
398 var employer_holdelement = new Array();
399 var countSelected = useEmployer = isRadio = 0;
401 {/literal} {if $isEmployeeOf || $isEmployerOf} {literal}
402 var storeElement = 'store_employers';
403 var employerClass = 'current_employer';
405 {/literal} {/if} {if $isEmployeeOf} {literal}
407 {/literal} {/if} {literal}
410 // clear old data if any
411 cj('#store_contacts').val('');
413 cj('#store_employers').val('');
416 cj('.pagerDisplay').on('click', '.contact_select input', function () {
417 var valueSelected = cj(this).val();
418 if ( cj(this).attr('checked') ) {
419 contact_checked[valueSelected] = valueSelected;
421 } else if( contact_checked[valueSelected] ) {
422 delete contact_checked[valueSelected];
424 if ( useEmployer && employer_holdelement[valueSelected] ) {
425 cj( employer_holdelement[valueSelected] ).attr('checked',false);
426 delete employer_checked[valueSelected];
427 delete employer_holdelement[valueSelected];
430 cj('#count_selected').html(countSelected +' Contacts selected.')
434 cj('.pagerDisplay').on('click', '.'+ employerClass +' input', function () {
435 var valueSelected = cj(this).val();
437 employer_checked = new Array();
439 if ( cj(this).attr('checked') ) {
440 // add validation to match with selected contacts
441 if( !contact_checked[valueSelected] ) {
442 cj(this).crmError({/literal}'{ts escape="js"}Current employer / Current employee should be among the selected contacts.{/ts}'{literal});
443 cj(this).attr('checked',false);
445 employer_checked[valueSelected] = valueSelected;
446 employer_holdelement[valueSelected] = this;
449 } else if ( employer_checked[valueSelected] ) {
450 delete employer_checked[valueSelected];
451 delete employer_holdelement[valueSelected];
458 function checkSelected( ) {
459 cj('.pagerDisplay tbody tr .contact_select input').each( function( ) {
460 if ( contact_checked[cj(this).val()] ) {
461 cj(this).attr('checked',true);
466 // register new elements
467 employer_holdelement = new Array();
468 cj('.pagerDisplay tbody tr .'+ employerClass +' input').each( function( ) {
469 if ( employer_checked[cj(this).val()] ) {
470 cj(this).attr('checked',true);
471 employer_holdelement[cj(this).val()] = this;
477 function submitAjaxData() {
478 var total_checked = new Array();
479 cj.each(contact_checked, function (index, value) {
480 if (typeof value !== "undefined") {
481 total_checked.push(value);
484 contact_checked = total_checked;
486 cj('#store_contacts').val( contact_checked.toString() );
488 cj('#store_employers').val( employer_checked.toString() );
497 {if ($action EQ 1) OR ($action EQ 2) }
498 {*include custom data js file*}
499 {include file="CRM/common/customData.tpl"}
501 <script type="text/javascript">
503 {/literal} {if $searchRows} {literal}
504 cj(".contact_select .form-checkbox").each( function( ) {
506 cj(this).attr('checked',true);
509 {/literal} {/if} {literal}
511 {/literal} {if $action EQ 1}{literal}
512 cj('#saveDetails').hide( );
513 cj('#addCurrentEmployer').hide( );
514 cj('#addCurrentEmployee').hide( );
517 if ( cj.browser.msie ) {
518 cj('#contact_1').keyup( function(e) {
519 if( e.keyCode == 9 || e.keyCode == 13 ) {
522 cj("input[name='contact_select_id[1]']").val('');
523 cj('#relationship-refresh').show( );
524 cj('#relationship-refresh-save').hide( );
527 cj('#contact_1').focus( function() {
528 cj("input[name='contact_select_id[1]']").val('');
529 cj('#relationship-refresh').show( );
530 cj('#relationship-refresh-save').hide( );
535 {/literal}{if $searchRows || $callAjax}{literal}
536 cj('#saveElements, #saveButtons').show();
537 {/literal}{else}{literal}
538 cj('#saveElements, #saveButtons').hide();
539 {/literal}{/if}{/if}{literal}
542 var relType = cj('#relationship_type_id').val( );
544 var relTypeId = relType.split("_");
546 CRM.buildCustomData( 'Relationship', relTypeId[0]);
549 CRM.buildCustomData('Relationship');
553 function buildRelationFields( relType ) {
554 {/literal} {if $action EQ 1} {literal}
556 var relTypeId = relType.split("_");
557 if ( relTypeId[0] == {/literal}{$employmentRelationship}{literal} ) {
558 if ( relTypeId[1] == 'a' ) {
559 cj('#addCurrentEmployee').show();
560 cj('#addCurrentEmployer').hide();
562 cj('#addCurrentEmployee').hide();
563 cj('#addCurrentEmployer').show();
566 cj('#addCurrentEmployee').hide();
567 cj('#addCurrentEmployer').hide();
569 cj('#relationship-refresh').hide();
570 cj('#relationship-refresh-save').show();
571 cj('#details-save').show();
572 cj('#saveElements').show();
573 cj('#saveDetails').show();
574 {/literal}{if $searchRows || $callAjax}{literal}
575 cj('#searchResult').hide();
576 {/literal}{/if}{literal}
577 cj('#saveButtons').hide();
579 {/literal}{/if}{literal}
582 function changeCustomData( cType ) {
583 {/literal}{if $action EQ 1} {literal}
584 cj('#customData').html('');
585 cj('#relationship-refresh').show();
586 cj('#saveElements').hide();
587 cj('#addCurrentEmployee').hide();
588 cj('#addCurrentEmployer').hide();
589 cj('#saveDetails').hide();
590 {/literal}{if $searchRows || $callAjax}{literal}
591 cj('#searchResult').hide();
592 {/literal}{/if}{literal}
593 {/literal}{/if} {literal}
595 var relType = cj('#relationship_type_id').val( );
597 var relTypeId = relType.split("_");
599 CRM.buildCustomData( cType, relTypeId[0]);
602 CRM.buildCustomData( cType );
611 <script type="text/javascript">
613 function currentEmployer( )
615 var relType = document.getElementById('relationship_type_id').value;
616 if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_a_b" ) {
617 cj('#current_employer').show();
618 cj('#employee').show();
619 cj('#employer').hide();
620 } else if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_b_a" ) {
621 cj('#current_employer').show();
622 cj('#employer').show();
623 cj('#employee').hide();
625 cj('#employer').hide();
626 cj('#employee').hide();
627 cj('#current_employer').hide();