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 class="no-popup" 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"><a class="button form-submit cancel" href="{crmURL p='civicrm/contact/view' q='action=browse&selectedChild=rel'}">{ts}Done{/ts}</a></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>
84 <script type="text/javascript">
85 function setPermissionStatus( relTypeDirection ) {
86 var direction = relTypeDirection.split( '_' );
87 cj('#permision_a_b-' + direction[1] + '_' + direction[2] ).show( );
88 cj('#permision_a_b-' + direction[2] + '_' + direction[1] ).hide( );
89 cj('#permision_b_a-' + direction[1] + '_' + direction[2] ).show( );
90 cj('#permision_b_a-' + direction[2] + '_' + direction[1] ).hide( );
94 <div class="crm-block crm-form-block crm-relationship-form-block">
96 <div class="description">
97 {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}
100 <table class="form-layout-compressed">
101 <tr class="crm-relationship-form-block-relationship_type_id">
102 <td class="label">{$form.relationship_type_id.label}</td><td>{$form.relationship_type_id.html}</td>
103 {if $action EQ 2} {* action = update *}
105 <script type="text/javascript">
108 var relationshipType = cj('#relationship_type_id');
109 relationshipType.change( function( ) {
110 changeCustomData( 'Relationship' );
113 setPermissionStatus( relationshipType.val( ) );
117 <td><label>{$sort_name_b}</label></td></tr>
118 <tr class="crm-relationship-form-block-is_current_employer">
120 <span id="employee"><label>{ts}Current Employee?{/ts}</label></span>
121 <span id="employer"><label>{ts}Current Employer?{/ts}</label></span>
123 <td id="current_employer">{$form.is_current_employer.html}</td>
126 {else} {* action = add *}
128 {include file="CRM/Contact/Form/NewContact.tpl" newContactCallback="afterCreateNew()"}
129 <tr class="crm-relationship-form-block-rel_contact">
132 <script type="text/javascript">
135 enableDisableContactSelection( );
137 var relationshipType = cj('#relationship_type_id');
138 relationshipType.change( function() {
139 enableDisableContactSelection( );
140 cj('#relationship-refresh-save').hide();
141 cj('#saveButtons').hide();
143 changeCustomData( 'Relationship' );
144 setPermissionStatus( cj(this).val( ) );
146 setPermissionStatus( relationshipType.val( ) );
149 function enableDisableContactSelection( ) {
150 var relationshipTypeValue = cj('#relationship_type_id').val();
151 var contactAutocomplete = cj('#contact_1');
153 //always reset field so that correct data url is linked
154 contactAutocomplete.unautocomplete( );
156 if ( relationshipTypeValue ) {
157 cj('#profiles_1').prop('disabled', false);
158 contactAutocomplete.prop('disabled', false);
159 contactAutocomplete.addClass('ac_input');
160 buildCreateNewSelect( 'profiles_1', relationshipTypeValue );
162 cj('#profiles_1').prop('disabled', true);
163 contactAutocomplete.removeClass('ac_input');
164 contactAutocomplete.prop('disabled', true);
168 function afterCreateNew() {
169 var relType = cj('#relationship_type_id').val( );
170 var contactSelected = cj('#contact_1').val( );
171 if ( relType && contactSelected ) {
172 cj('#relationship-refresh-save').show( );
173 buildRelationFields( relType );
177 function createRelation( ) {
178 var relType = cj('#relationship_type_id').val( );
179 var relContact = cj('#contact_1');
181 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;
182 relContact.autocomplete( dataUrl, { width : 200, selectFirst : false, matchContains: true, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal} });
183 relContact.result(function( event, data ) {
184 cj("input[name='contact_select_id[1]']").val(data[1]);
185 cj('#relationship-refresh-save').show( );
186 buildRelationFields( relType );
189 relContact.unautocomplete( );
193 function buildCreateNewSelect( selectID, relType ) {
194 selectID = '#' + selectID;
195 cj( selectID ).html('');
196 var postUrl = "{/literal}{crmURL p='civicrm/ajax/relationshipContactTypeList' h=0}{literal}";
197 cj.post( postUrl, { relType: relType },
198 function ( response ) {
199 cj( selectID ).get(0).add(new Option('{/literal}{ts escape="js"}- create new contact -{/ts}{literal}', ''));
200 response = eval( response );
201 for (i = 0; i < response.length; i++) {
202 cj( selectID ).get(0).add(new Option(response[i].name, response[i].value));
213 <div class="crm-submit-buttons">
214 <span id="relationship-refresh" class="crm-button crm-button-type-refresh crm-button_qf_Relationship_refresh">{$form._qf_Relationship_refresh.html}</span>
215 <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>
216 <span class="crm-button crm-button-type-cancel crm-button_qf_Relationship_cancel">{$form._qf_Relationship_cancel.html}</span>
218 <div class="clear"></div>
220 {if $searchDone } {* Search button clicked *}
221 {if $searchCount || $callAjax}
222 {if $searchRows || $callAjax} {* we got rows to display *}
223 <fieldset id="searchResult"><legend>{ts}Mark Target Contact(s) for this Relationship{/ts}</legend>
224 <div class="description">
225 {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}
229 <div id="count_selected"> </div><br />
230 {$form.store_contacts.html}
232 {if $isEmployeeOf || $isEmployerOf}
233 {$form.store_employer.html}
235 {include file="CRM/common/jsortable.tpl" sourceUrl=$sourceUrl useAjax=1 callBack=1 }
238 <table id="rel-contacts" class="pagerDisplay">
240 <tr class="columnheader">
241 <th id="nosort" class="contact_select"> </th>
242 <th>{ts}Name{/ts}</th>
243 {if $isEmployeeOf}<th id="nosort" class="current_employer">{ts}Current Employer?{/ts}</th>
244 {elseif $isEmployerOf}<th id="nosort" class="current_employer">{ts}Current Employee?{/ts}</th>{/if}
245 <th>{ts}City{/ts}</th>
246 <th>{ts}State{/ts}</th>
247 <th>{ts}Email{/ts}</th>
248 <th>{ts}Phone{/ts}</th>
253 {foreach from=$searchRows item=row}
254 <tr class="{cycle values="odd-row,even-row"}">
255 <td class="contact_select">{$form.contact_check[$row.id].html}</td>
256 <td>{$row.type} {$row.name}</td>
257 {if $isEmployeeOf}<td>{$form.employee_of[$row.id].html}</td>
258 {elseif $isEmployerOf}<td>{$form.employer_of[$row.id].html}</td>{/if}
260 <td>{$row.state}</td>
261 <td>{$row.email}</td>
262 <td>{$row.phone}</td>
266 <tr><td colspan="5" class="dataTables_empty">Loading data from server</td></tr>
272 <div class="spacer"></div>
273 {else} {* too many results - we display only 50 *}
274 {if $duplicateRelationship}
275 {capture assign=infoTitle}{ts}Duplicate relationship.{/ts}{/capture}
276 {capture assign=infoMessage}{ts}This relationship already exists.{/ts}{/capture}
278 {capture assign=infoTitle}{ts}Too many matching results.{/ts}{/capture}
279 {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture}
281 {include file="CRM/common/info.tpl"}
283 {else} {* no valid matches for name + contact_type *}
284 {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture}
285 {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}
286 {include file="CRM/common/info.tpl"}
287 {/if} {* end if searchCount *}
289 {/if} {* end if searchDone *}
290 {/if} {* end action = add *}
292 <div id='saveElements'>
294 <div id='addCurrentEmployer'>
295 <table class="form-layout-compressed">
296 <tr class="crm-relationship-form-block-add_current_employer">
297 <td class="label">{$form.add_current_employer.label}</td>
298 <td>{$form.add_current_employer.html}</td>
302 <div id='addCurrentEmployee'>
303 <table class="form-layout-compressed">
304 <tr class="crm-relationship-form-block-add_current_employee">
305 <td class="label">{$form.add_current_employee.label}</td>
306 <td>{$form.add_current_employee.html}</td>
311 <table class="form-layout-compressed">
312 <tr class="crm-relationship-form-block-start_date">
313 <td class="label">{$form.start_date.label}</td>
314 <td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}</td></tr>
315 <tr class="crm-relationship-form-block-end_date">
316 <td class="label">{$form.end_date.label}</td>
317 <td>{include file="CRM/common/jcalendar.tpl" elementName=end_date}<br />
318 <span class="description">{ts}If this relationship has start and/or end dates, specify them here.{/ts}</span></td>
320 <tr class="crm-relationship-form-block-description">
321 <td class="label">{$form.description.label}</td>
322 <td>{$form.description.html}</td>
324 <tr class="crm-relationship-form-block-note">
325 <td class="label">{$form.note.label}</td>
326 <td>{$form.note.html}</td>
328 <tr class="crm-relationship-form-block-is_permission_a_b">
329 <td class="label"></td><td>{$form.is_permission_a_b.html}
330 <span id='permision_a_b-a_b' class="hiddenElement">
332 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for selected contact(s){/ts}
334 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_b}'</strong>
337 <span id='permision_a_b-b_a' class="hiddenElement">
339 <strong>{ts}Selected contact(s)</strong> can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
341 <strong>'{$sort_name_b}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
346 <tr class="crm-relationship-form-block-is_permission_b_a">
347 <td class="label"></td><td>{$form.is_permission_b_a.html}
348 <span id='permision_b_a-b_a' class="hiddenElement">
350 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for selected contact(s){/ts}
352 <strong>'{$sort_name_a}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_b}'</strong>
355 <span id='permision_b_a-a_b' class="hiddenElement">
357 <strong>{ts}Selected contact(s)</strong> can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
359 <strong>'{$sort_name_b}'</strong> {ts}can view and update information for {/ts} <strong>'{$sort_name_a}'</strong>
364 <tr class="crm-relationship-form-block-is_active">
365 <td class="label">{$form.is_active.label}</td>
366 <td>{$form.is_active.html}</td>
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).prop('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] ).prop('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).prop('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).prop('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).prop('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).prop('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").prop('checked',true);
505 {/literal} {/if} {literal}
507 {/literal} {if $action EQ 1}{literal}
508 cj('#saveDetails').hide( );
509 cj('#addCurrentEmployer').hide( );
510 cj('#addCurrentEmployee').hide( );
513 if ( cj.browser.msie ) {
514 cj('#contact_1').keyup( function(e) {
515 if( e.keyCode == 9 || e.keyCode == 13 ) {
518 cj("input[name='contact_select_id[1]']").val('');
519 cj('#relationship-refresh').show( );
520 cj('#relationship-refresh-save').hide( );
523 cj('#contact_1').focus( function() {
524 cj("input[name='contact_select_id[1]']").val('');
525 cj('#relationship-refresh').show( );
526 cj('#relationship-refresh-save').hide( );
531 {/literal}{if $searchRows || $callAjax}{literal}
532 cj('#saveElements, #saveButtons').show();
533 {/literal}{else}{literal}
534 cj('#saveElements, #saveButtons').hide();
535 {/literal}{/if}{/if}{literal}
538 var relType = cj('#relationship_type_id').val( );
540 var relTypeId = relType.split("_");
542 CRM.buildCustomData( 'Relationship', relTypeId[0]);
545 CRM.buildCustomData('Relationship');
549 function buildRelationFields( relType ) {
550 {/literal} {if $action EQ 1} {literal}
552 var relTypeId = relType.split("_");
553 if ( relTypeId[0] == {/literal}{$employmentRelationship}{literal} ) {
554 if ( relTypeId[1] == 'a' ) {
555 cj('#addCurrentEmployee').show();
556 cj('#addCurrentEmployer').hide();
558 cj('#addCurrentEmployee').hide();
559 cj('#addCurrentEmployer').show();
562 cj('#addCurrentEmployee').hide();
563 cj('#addCurrentEmployer').hide();
565 cj('#relationship-refresh').hide();
566 cj('#relationship-refresh-save').show();
567 cj('#details-save').show();
568 cj('#saveElements').show();
569 cj('#saveDetails').show();
570 {/literal}{if $searchRows || $callAjax}{literal}
571 cj('#searchResult').hide();
572 {/literal}{/if}{literal}
573 cj('#saveButtons').hide();
575 {/literal}{/if}{literal}
578 function changeCustomData( cType ) {
579 {/literal}{if $action EQ 1} {literal}
580 cj('#customData').html('');
581 cj('#relationship-refresh').show();
582 cj('#saveElements').hide();
583 cj('#addCurrentEmployee').hide();
584 cj('#addCurrentEmployer').hide();
585 cj('#saveDetails').hide();
586 {/literal}{if $searchRows || $callAjax}{literal}
587 cj('#searchResult').hide();
588 {/literal}{/if}{literal}
589 {/literal}{/if} {literal}
591 var relType = cj('#relationship_type_id').val( );
593 var relTypeId = relType.split("_");
595 CRM.buildCustomData( cType, relTypeId[0]);
598 CRM.buildCustomData( cType );
607 <script type="text/javascript">
609 function currentEmployer( )
611 var relType = document.getElementById('relationship_type_id').value;
612 if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_a_b" ) {
613 cj('#current_employer').show();
614 cj('#employee').show();
615 cj('#employer').hide();
616 } else if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_b_a" ) {
617 cj('#current_employer').show();
618 cj('#employer').show();
619 cj('#employee').hide();
621 cj('#employer').hide();
622 cj('#employee').hide();
623 cj('#current_employer').hide();