Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
232624b1 | 3 | | CiviCRM version 4.4 | |
6a488035 TO |
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*} | |
2e318c36 | 27 | {if !in_array($context, array('search','advanced', 'builder')) || $parent eq 'activity'} |
6a488035 TO |
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} | |
35729234 | 40 | {if $form.$profSelect and $showNewSelect} |
6a488035 TO |
41 | {ts}OR{/ts} {$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 | {ts}OR{/ts} {$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}); | |
3d9aa8f4 KJ |
59 | |
60 | {/literal} | |
61 | var prePopulateData = ''; | |
62 | {if $prePopulateData} | |
63 | prePopulateData = {$prePopulateData}; | |
64 | {/if} | |
65 | {literal} | |
6a488035 TO |
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} | |
bf1fdddd PJ |
115 | {literal} |
116 | var prePopulateData = cj.ajax({ url: contactUrl + "&cid={/literal}{$selectedContacts}{literal}", async: false }).responseText; | |
117 | prePopulateData = cj.parseJSON(prePopulateData); | |
118 | {/literal} | |
6a488035 TO |
119 | {/if} |
120 | {literal} | |
121 | ||
6a488035 TO |
122 | cj('#' + prefix + 'contact_' + blockNo).tokenInput( contactUrl, { prePopulate:prePopulateData, theme: 'facebook', hintText: hintText }); |
123 | cj('ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px'); | |
124 | } | |
125 | ||
126 | function addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( blockNo, prefix ) { | |
127 | var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=newcontact' h=0 }"{literal}; | |
128 | {/literal}{if $action eq 2}{literal} | |
129 | contactUrl = contactUrl + '&cid=' + {/literal}{$contactId}{literal}; | |
130 | {/literal}{/if}{literal} | |
131 | ||
132 | var contactElement = '#' + prefix + 'contact_' + blockNo; | |
133 | var contactHiddenElement = 'input[name="{/literal}{$prefix}{literal}contact_select_id[' + blockNo +']"]'; | |
134 | cj( contactElement ).autocomplete( contactUrl, { | |
401906c1 | 135 | selectFirst : false, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal} |
6a488035 TO |
136 | }).result( function(event, data, formatted) { |
137 | cj( contactHiddenElement ).val(data[1]); | |
138 | {/literal} | |
139 | {if $newContactCallback} | |
140 | eval("{$newContactCallback}"); | |
141 | {/if} | |
142 | {literal} | |
143 | }).focus( ); | |
144 | ||
145 | cj( contactElement ).click( function( ) { | |
146 | cj( contactHiddenElement ).val(''); | |
147 | }); | |
148 | ||
149 | cj( contactElement ).bind("keypress keyup", function(e) { | |
150 | if ( e.keyCode == 13 ) { | |
151 | return false; | |
152 | } | |
153 | }); | |
154 | } | |
155 | </script> | |
156 | {/literal} | |
157 | {/if}{* end of search if *} |