CRM-10043 - merge in changes to Activity.tpl and splitting of ActivityJs.tpl with...
[civicrm-core.git] / templates / CRM / Activity / Form / ActivityJs.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 {* added onload javascript for source contact*}
27 {literal}
28 <script type="text/javascript">
29 var assignee_contact = followup_assignee_contact = '';
30
31 {/literal}
32 {if $assignee_contact}
33 var assignee_contact = {$assignee_contact};
34 {/if}
35 {if $followup_assignee_contact}
36 var followup_assignee_contact = {$followup_assignee_contact};
37 {/if}
38
39 {literal}
40 var assignee_contact_id = followup_assignee_contact_id = null;
41 //loop to set the value of cc and bcc if form rule.
42 var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}"; {/literal}
43 {foreach from=","|explode:"assignee,followup_assignee" key=key item=element}
44 {assign var=currentElement value=`$element`_contact_id}
45 {if $form.$currentElement.value}
46 {literal} var {/literal}{$currentElement}{literal} = cj.ajax({ url: toDataUrl + "&cid={/literal}{$form.$currentElement.value}{literal}", async: false }).responseText;{/literal}
47 {/if}
48 {/foreach}
49 {literal}
50
51 if ( assignee_contact_id ) {
52 eval( 'assignee_contact = ' + assignee_contact_id );
53 }
54 if ( followup_assignee_contact_id ) {
55 eval( 'followup_assignee_contact = ' + followup_assignee_contact_id );
56 }
57
58 cj(function( ) {
59 {/literal}
60 {if $source_contact and $admin and $action neq 4}
61 {literal} cj( '#source_contact_id' ).val( "{/literal}{$source_contact}{literal}");{/literal}
62 {/if}
63 {literal}
64
65 var sourceDataUrl = "{/literal}{$dataUrl}{literal}";
66 var tokenDataUrl_assignee = "{/literal}{$tokenUrl}&context={$tokenContext}_assignee{literal}";
67
68 var hintText = "{/literal}{ts escape='js'}Start typing a name or email address.{/ts}{literal}";
69 cj( "#assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: assignee_contact, theme: 'facebook', hintText: hintText });
70 cj( "#followup_assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: followup_assignee_contact, theme: 'facebook', hintText: hintText });
71 cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
72 cj('#source_contact_id').autocomplete( sourceDataUrl, { width : 180, selectFirst : false, hintText: hintText, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
73 }).result( function(event, data, formatted) { cj( "#source_contact_qid" ).val( data[1] );
74 }).bind( 'click', function( ) { if (!cj("#source_contact_id").val()) { cj( "#source_contact_qid" ).val(''); } });
75 });
76
77 /**
78 * Function to check activity status in relavent to activity date
79 *
80 * @param element message JSON object.
81 */
82 function activityStatus(message) {
83 var date = cj("#activity_date_time_display").datepicker('getDate');
84 if (date) {
85 var
86 now = new Date(),
87 time = cj("#activity_date_time_time").timeEntry('getTime') || date,
88 activityStatusId = cj('#status_id').val(),
89 d = date.toString().split(' '),
90 activityDate = new Date(d[0] + ' ' + d[1] + ' ' + d[2] + ' ' + d[3] + ' ' + time.toTimeString());
91 if (activityStatusId == 2 && now < activityDate) {
92 return confirm(message.completed);
93 }
94 else if (activityStatusId == 1 && now >= activityDate) {
95 return confirm(message.scheduled);
96 }
97 }
98 }
99
100 </script>
101 {/literal}