Merge pull request #1465 from colemanw/CRM-12840
[civicrm-core.git] / templates / CRM / Contact / Form / CurrentEmployer.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 {* 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 }).result( function(event, data, formatted) {
38 var foundContact = ( parseInt( data[1] ) ) ? cj( "#current_employer_id" ).val( data[1] ) : cj( "#current_employer_id" ).val('');
39 if ( ! foundContact.val() ) {
40 cj('div#employer_address').html(newContactText).show();
41 }
42 else {
43 cj('div#employer_address').html('').hide();
44 }
45 }).bind('change blur', function() {
46 if ( !cj( "#current_employer_id" ).val( ) ) {
47 cj('div#employer_address').html(newContactText).show();
48 }
49 });
50
51 // remove current employer id when current employer removed.
52 cj("form").submit(function() {
53 if ( !cj('#current_employer').val() ) cj( "#current_employer_id" ).val('');
54 });
55
56 //current employer default setting
57 {/literal}
58 var cid = "{$contactId}";
59 var employerId = "{$currentEmployer}";
60 {literal}
61 if ( employerId ) {
62 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 ;
63
64 cj.ajax({
65 url : dataUrl,
66 async : false,
67 success : function(html){
68 //fixme for showing address in div
69 htmlText = html.split( '|' , 2);
70 cj('input#current_employer').val(htmlText[0]);
71 cj('input#current_employer_id').val(htmlText[1]);
72 }
73 });
74 }
75
76 cj("input#current_employer").click( function( ) {
77 cj("input#current_employer_id").val('');
78 });
79 </script>
80 {/literal}