Merge pull request #2540 from eileenmcnaughton/CRM-14235
[civicrm-core.git] / templates / CRM / Contact / Form / NewContact.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 {* template for adding form elements for selecting existing or creating new contact*}
27 {if !in_array($context, array('search','advanced', 'builder')) || $parent eq 'activity'}
28 {assign var='fldName' value=$prefix|cat:'contact'}
29 {assign var='profSelect' value=$prefix|cat:'profiles'}
30 {* Focus on select contact element unless focus=false is passed in. *}
31 {assign var='focus' value=$focus|default:true}
32
33 {if $noLabel}
34 <div>
35 {if !$skipBreak}
36 {$form.$fldName.$blockNo.html} <br/>
37 {if $form.$profSelect}
38 {ts}OR{/ts}<br/>{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
39 {/if}
40 {else}
41 {$form.$fldName.$blockNo.html}
42 {if $form.$profSelect and $showNewSelect}
43 &nbsp;&nbsp;{ts}OR{/ts}&nbsp;&nbsp;{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
44 {/if}
45 {/if}
46 </div>
47 {else}
48 <tr class="crm-new-contact-form-block-contact crm-new-contact-form-block-contact-{$blockNo}">
49 <td class="label">{$form.$fldName.$blockNo.label}</td>
50 <td>{$form.$fldName.$blockNo.html}
51 {if $form.$profSelect}
52 &nbsp;&nbsp;{ts}OR{/ts}&nbsp;&nbsp;{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
53 {/if}
54 </td>
55 </tr>
56 {/if}
57
58 {literal}
59 <script type="text/javascript">
60 var allowMultiClient = Boolean({/literal}{if !empty($multiClient)}1{else}0{/if}{literal});
61
62 {/literal}
63 var prePopulateData = '';
64 {if $prePopulateData}
65 prePopulateData = {$prePopulateData};
66 {/if}
67 {literal}
68
69 var existingTokens = '';
70 cj( function( ) {
71 // add multiple client option if configured
72 if ( allowMultiClient ) {
73 addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, {/literal}{$blockNo},"{$prefix}"{literal} );
74 } else {
75 addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( {/literal}{$blockNo},"{$prefix}"{literal} );
76 }
77 });
78
79 function newContact{/literal}{$prefix}{$blockNo}{literal}( gid, blockNo, prefix ) {
80 var dataURL = {/literal}"{crmURL p='civicrm/profile/create' q="reset=1&snippet=5&context=dialog&blockNo=$blockNo&prefix=$prefix" h=0 }"{literal};
81 dataURL = dataURL + '&gid=' + gid;
82 {/literal}{if $profileCreateCallback}{literal}
83 dataURL = dataURL + '&createCallback=1';
84 {/literal}{/if}{literal}
85 cj.ajax({
86 url: dataURL,
87 success: function( content ) {
88 cj( '#contact-dialog-'+ prefix + blockNo ).show( ).html( content ).dialog({
89 title: "{/literal}{ts escape='js'}Create New Contact{/ts}{literal}",
90 modal: true,
91 width: 680,
92 overlay: {
93 opacity: 0.5,
94 background: "black"
95 },
96
97 close: function(event, ui) {
98 cj('#' + prefix + 'profiles_' + blockNo).val('');
99 {/literal}
100 {if $newContactCallback}
101 eval("{$newContactCallback}");
102 {/if}
103 {literal}
104 }
105 });
106 }
107 });
108 }
109
110 function addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, blockNo, prefix ) {
111 var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name of an existing contact.{/ts}{literal}";
112 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }"{literal};
113
114 // setdefaults incase of formRule
115 {/literal}
116 {if $selectedContacts}
117 {literal}
118 var prePopulateData = cj.ajax({ url: contactUrl + "&cid={/literal}{$selectedContacts}{literal}", async: false }).responseText;
119 prePopulateData = cj.parseJSON(prePopulateData);
120 {/literal}
121 {/if}
122 {literal}
123
124 cj('#' + prefix + 'contact_' + blockNo).tokenInput( contactUrl, { prePopulate:prePopulateData, theme: 'facebook', hintText: hintText });
125 cj('ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px');
126 }
127
128 function addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( blockNo, prefix ) {
129 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=newcontact' h=0 }"{literal};
130 {/literal}{if $action eq 2}{literal}
131 contactUrl = contactUrl + '&cid=' + {/literal}{$contactId}{literal};
132 {/literal}{/if}{literal}
133
134 var contactElement = '#' + prefix + 'contact_' + blockNo;
135 var contactHiddenElement = 'input[name="{/literal}{$prefix}{literal}contact_select_id[' + blockNo +']"]';
136 cj( contactElement ).autocomplete( contactUrl, {
137 selectFirst : false, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
138 }).result( function(event, data, formatted) {
139 cj( contactHiddenElement ).val(data[1]);
140 {/literal}
141 {if $newContactCallback}
142 eval("{$newContactCallback}");
143 {/if}
144 {literal}
145 }){/literal}{if $focus}.focus( ){/if}{literal};
146
147 cj( contactElement ).click( function( ) {
148 cj( contactHiddenElement ).val('');
149 });
150
151 cj( contactElement ).bind("keypress keyup", function(e) {
152 if ( e.keyCode == 13 ) {
153 return false;
154 }
155 });
156 }
157 </script>
158 {/literal}
159 {/if}{* end of search if *}