Merge pull request #2370 from kurund/CRM-14087
[civicrm-core.git] / templates / CRM / Contact / Form / CurrentEmployer.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 {* tpl for current employer js *}
27 {literal}
28 <script type="text/javascript">
29 var dataUrl = "{/literal}{$employerDataURL}{literal}";
30 var newContactText = "{/literal}({ts}new contact record{/ts}){literal}";
31 cj('#current_employer').attr("title","Current employer auto complete");
32 cj('#current_employer').autocomplete( dataUrl, {
33 width : 250,
34 selectFirst : false,
35 matchCase : true,
36 matchContains: true,
37 max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
38 }).result( function(event, data, formatted) {
39 var foundContact = ( parseInt( data[1] ) ) ? cj( "#current_employer_id" ).val( data[1] ) : cj( "#current_employer_id" ).val('');
40 if ( ! foundContact.val() ) {
41 cj('div#employer_address').html(newContactText).show();
42 }
43 else {
44 cj('div#employer_address').html('').hide();
45 }
46 }).bind('change blur', function() {
47 if ( !cj( "#current_employer_id" ).val( ) ) {
48 cj('div#employer_address').html(newContactText).show();
49 }
50 });
51
52 // remove current employer id when current employer removed.
53 cj("form").submit(function() {
54 if ( !cj('#current_employer').val() ) cj( "#current_employer_id" ).val('');
55 });
56
57 //current employer default setting
58 {/literal}
59 var cid = "{$contactId}";
60 var employerId = "{$currentEmployer}";
61 {literal}
62 if ( employerId ) {
63 var dataUrl = "{/literal}{crmURL p='civicrm/ajax/rest' h=0 q="className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&id=" }{literal}" + employerId + "&employee_id=" + cid ;
64
65 cj.ajax({
66 url : dataUrl,
67 async : false,
68 success : function(html){
69 //fixme for showing address in div
70 htmlText = html.split( '|' , 2);
71 cj('input#current_employer').val(htmlText[0]);
72 cj('input#current_employer_id').val(htmlText[1]);
73 }
74 });
75 }
76
77 cj("input#current_employer").click( function( ) {
78 cj("input#current_employer_id").val('');
79 });
80 </script>
81 {/literal}