2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
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 {* template for adding form elements for selecting existing or creating new contact*}
27 {if !in_array($context, array('search','advanced', 'builder')) }
28 {assign var='fldName' value=$prefix|cat:'contact'}
29 {assign var='profSelect' value=$prefix|cat:'profiles'}
34 {$form.$fldName.$blockNo.html} <br/>
35 {if $form.$profSelect}
36 {ts}OR{/ts}<br/>{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
39 {$form.$fldName.$blockNo.html}
40 {if $form.$profSelect}
41 {ts}OR{/ts} {$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
46 <tr class="crm-new-contact-form-block-contact crm-new-contact-form-block-contact-{$blockNo}">
47 <td class="label">{$form.$fldName.$blockNo.label}</td>
48 <td>{$form.$fldName.$blockNo.html}
49 {if $form.$profSelect}
50 {ts}OR{/ts} {$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
57 <script type="text/javascript">
58 var allowMultiClient = Boolean({/literal}{if !empty($multiClient)}1{else}0{/if}{literal});
61 var prePopulateData = '';
63 prePopulateData = {$prePopulateData};
67 var existingTokens = '';
69 // add multiple client option if configured
70 if ( allowMultiClient ) {
71 addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, {/literal}{$blockNo},"{$prefix}"{literal} );
73 addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( {/literal}{$blockNo},"{$prefix}"{literal} );
77 function newContact{/literal}{$prefix}{$blockNo}{literal}( gid, blockNo, prefix ) {
78 var dataURL = {/literal}"{crmURL p='civicrm/profile/create' q="reset=1&snippet=5&context=dialog&blockNo=$blockNo&prefix=$prefix" h=0 }"{literal};
79 dataURL = dataURL + '&gid=' + gid;
80 {/literal}{if $profileCreateCallback}{literal}
81 dataURL = dataURL + '&createCallback=1';
82 {/literal}{/if}{literal}
85 success: function( content ) {
86 cj( '#contact-dialog-'+ prefix + blockNo ).show( ).html( content ).dialog({
87 title: "{/literal}{ts escape='js'}Create New Contact{/ts}{literal}",
95 close: function(event, ui) {
96 cj('#' + prefix + 'profiles_' + blockNo).val('');
98 {if $newContactCallback}
99 eval("{$newContactCallback}");
108 function addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, blockNo, prefix ) {
109 var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name of an existing contact.{/ts}{literal}";
110 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }"{literal};
112 // setdefaults incase of formRule
114 {if $selectedContacts}
115 {literal} var prePopulateData = cj.ajax({ url: contactUrl + "&cid={/literal}{$selectedContacts}{literal}", async: false }).responseText;{/literal}
119 cj('#' + prefix + 'contact_' + blockNo).tokenInput( contactUrl, { prePopulate:prePopulateData, theme: 'facebook', hintText: hintText });
120 cj('ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px');
123 function addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( blockNo, prefix ) {
124 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=newcontact' h=0 }"{literal};
125 {/literal}{if $action eq 2}{literal}
126 contactUrl = contactUrl + '&cid=' + {/literal}{$contactId}{literal};
127 {/literal}{/if}{literal}
129 var contactElement = '#' + prefix + 'contact_' + blockNo;
130 var contactHiddenElement = 'input[name="{/literal}{$prefix}{literal}contact_select_id[' + blockNo +']"]';
131 cj( contactElement ).autocomplete( contactUrl, {
132 selectFirst : false, matchContains: true, minChars: 1
133 }).result( function(event, data, formatted) {
134 cj( contactHiddenElement ).val(data[1]);
136 {if $newContactCallback}
137 eval("{$newContactCallback}");
142 cj( contactElement ).click( function( ) {
143 cj( contactHiddenElement ).val('');
146 cj( contactElement ).bind("keypress keyup", function(e) {
147 if ( e.keyCode == 13 ) {
154 {/if}{* end of search if *}