Merge pull request #911 from agh1/membership-dash-counts-new
[civicrm-core.git] / templates / CRM / Contact / Form / NewContact.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
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')) }
28 {assign var='fldName' value=$prefix|cat:'contact'}
29 {assign var='profSelect' value=$prefix|cat:'profiles'}
30
31 {if $noLabel}
32 <div>
33 {if !$skipBreak}
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>
37 {/if}
38 {else}
39 {$form.$fldName.$blockNo.html}
40 {if $form.$profSelect and $showNewSelect}
41 &nbsp;&nbsp;{ts}OR{/ts}&nbsp;&nbsp;{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
42 {/if}
43 {/if}
44 </div>
45 {else}
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 &nbsp;&nbsp;{ts}OR{/ts}&nbsp;&nbsp;{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
51 {/if}
52 </td>
53 </tr>
54 {/if}
55
56 {literal}
57 <script type="text/javascript">
58 var allowMultiClient = Boolean({/literal}{if !empty($multiClient)}1{else}0{/if}{literal});
59
60 {/literal}
61 var prePopulateData = '';
62 {if $prePopulateData}
63 prePopulateData = {$prePopulateData};
64 {/if}
65 {literal}
66
67 var existingTokens = '';
68 cj( function( ) {
69 // add multiple client option if configured
70 if ( allowMultiClient ) {
71 addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, {/literal}{$blockNo},"{$prefix}"{literal} );
72 } else {
73 addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( {/literal}{$blockNo},"{$prefix}"{literal} );
74 }
75 });
76
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}
83 cj.ajax({
84 url: dataURL,
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}",
88 modal: true,
89 width: 680,
90 overlay: {
91 opacity: 0.5,
92 background: "black"
93 },
94
95 close: function(event, ui) {
96 cj('#' + prefix + 'profiles_' + blockNo).val('');
97 {/literal}
98 {if $newContactCallback}
99 eval("{$newContactCallback}");
100 {/if}
101 {literal}
102 }
103 });
104 }
105 });
106 }
107
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};
111
112 // setdefaults incase of formRule
113 {/literal}
114 {if $selectedContacts}
115 {literal} var prePopulateData = cj.ajax({ url: contactUrl + "&cid={/literal}{$selectedContacts}{literal}", async: false }).responseText;{/literal}
116 {/if}
117 {literal}
118
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');
121 }
122
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}
128
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, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
133 }).result( function(event, data, formatted) {
134 cj( contactHiddenElement ).val(data[1]);
135 {/literal}
136 {if $newContactCallback}
137 eval("{$newContactCallback}");
138 {/if}
139 {literal}
140 }).focus( );
141
142 cj( contactElement ).click( function( ) {
143 cj( contactHiddenElement ).val('');
144 });
145
146 cj( contactElement ).bind("keypress keyup", function(e) {
147 if ( e.keyCode == 13 ) {
148 return false;
149 }
150 });
151 }
152 </script>
153 {/literal}
154 {/if}{* end of search if *}