Commit | Line | Data |
---|---|---|
6a488035 TO |
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} | |
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}); | |
aa2ced6f | 59 | var prePopulateData = {/literal}{$prePopulateData}{literal}; |
6a488035 TO |
60 | |
61 | var existingTokens = ''; | |
62 | cj( function( ) { | |
63 | // add multiple client option if configured | |
64 | if ( allowMultiClient ) { | |
65 | addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, {/literal}{$blockNo},"{$prefix}"{literal} ); | |
66 | } else { | |
67 | addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( {/literal}{$blockNo},"{$prefix}"{literal} ); | |
68 | } | |
69 | }); | |
70 | ||
71 | function newContact{/literal}{$prefix}{$blockNo}{literal}( gid, blockNo, prefix ) { | |
72 | var dataURL = {/literal}"{crmURL p='civicrm/profile/create' q="reset=1&snippet=5&context=dialog&blockNo=$blockNo&prefix=$prefix" h=0 }"{literal}; | |
73 | dataURL = dataURL + '&gid=' + gid; | |
74 | {/literal}{if $profileCreateCallback}{literal} | |
75 | dataURL = dataURL + '&createCallback=1'; | |
76 | {/literal}{/if}{literal} | |
77 | cj.ajax({ | |
78 | url: dataURL, | |
79 | success: function( content ) { | |
80 | cj( '#contact-dialog-'+ prefix + blockNo ).show( ).html( content ).dialog({ | |
81 | title: "{/literal}{ts escape='js'}Create New Contact{/ts}{literal}", | |
82 | modal: true, | |
83 | width: 680, | |
84 | overlay: { | |
85 | opacity: 0.5, | |
86 | background: "black" | |
87 | }, | |
88 | ||
89 | close: function(event, ui) { | |
90 | cj('#' + prefix + 'profiles_' + blockNo).val(''); | |
91 | {/literal} | |
92 | {if $newContactCallback} | |
93 | eval("{$newContactCallback}"); | |
94 | {/if} | |
95 | {literal} | |
96 | } | |
97 | }); | |
98 | } | |
99 | }); | |
100 | } | |
101 | ||
102 | function addMultiClientOption{/literal}{$prefix}{$blockNo}{literal}( prePopulateData, blockNo, prefix ) { | |
103 | var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name of an existing contact.{/ts}{literal}"; | |
104 | var contactUrl = {/literal}"{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }"{literal}; | |
105 | ||
106 | // setdefaults incase of formRule | |
107 | {/literal} | |
108 | {if $selectedContacts} | |
109 | {literal} var prePopulateData = cj.ajax({ url: contactUrl + "&cid={/literal}{$selectedContacts}{literal}", async: false }).responseText;{/literal} | |
110 | {/if} | |
111 | {literal} | |
112 | ||
6a488035 TO |
113 | cj('#' + prefix + 'contact_' + blockNo).tokenInput( contactUrl, { prePopulate:prePopulateData, theme: 'facebook', hintText: hintText }); |
114 | cj('ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px'); | |
115 | } | |
116 | ||
117 | function addSingleClientOption{/literal}{$prefix}{$blockNo}{literal}( blockNo, prefix ) { | |
118 | var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=newcontact' h=0 }"{literal}; | |
119 | {/literal}{if $action eq 2}{literal} | |
120 | contactUrl = contactUrl + '&cid=' + {/literal}{$contactId}{literal}; | |
121 | {/literal}{/if}{literal} | |
122 | ||
123 | var contactElement = '#' + prefix + 'contact_' + blockNo; | |
124 | var contactHiddenElement = 'input[name="{/literal}{$prefix}{literal}contact_select_id[' + blockNo +']"]'; | |
125 | cj( contactElement ).autocomplete( contactUrl, { | |
126 | selectFirst : false, matchContains: true, minChars: 1 | |
127 | }).result( function(event, data, formatted) { | |
128 | cj( contactHiddenElement ).val(data[1]); | |
129 | {/literal} | |
130 | {if $newContactCallback} | |
131 | eval("{$newContactCallback}"); | |
132 | {/if} | |
133 | {literal} | |
134 | }).focus( ); | |
135 | ||
136 | cj( contactElement ).click( function( ) { | |
137 | cj( contactHiddenElement ).val(''); | |
138 | }); | |
139 | ||
140 | cj( contactElement ).bind("keypress keyup", function(e) { | |
141 | if ( e.keyCode == 13 ) { | |
142 | return false; | |
143 | } | |
144 | }); | |
145 | } | |
146 | </script> | |
147 | {/literal} | |
148 | {/if}{* end of search if *} |