Merge pull request #3302 from eileenmcnaughton/code-cleanup
[civicrm-core.git] / templates / CRM / Activity / Selector / Selector.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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
27 <div class="crm-activity-selector-{$context}">
28 <div class="crm-accordion-wrapper crm-search_filters-accordion">
29 <div class="crm-accordion-header">
30 {ts}Filter by Activity Type{/ts}</a>
31 </div><!-- /.crm-accordion-header -->
32 <div class="crm-accordion-body">
33 <div class="no-border form-layout-compressed" id="searchOptions">
34 <div class="crm-contact-form-block-activity_type_filter_id crm-inline-edit-field">
35 {$form.activity_type_filter_id.label} {$form.activity_type_filter_id.html|crmAddClass:big}
36 </div>
37 <div class="crm-contact-form-block-activity_type_exclude_filter_id crm-inline-edit-field">
38 {$form.activity_type_exclude_filter_id.label} {$form.activity_type_exclude_filter_id.html|crmAddClass:big}
39 </div>
40 </div>
41 </div><!-- /.crm-accordion-body -->
42 </div><!-- /.crm-accordion-wrapper -->
43 <table id="contact-activity-selector-{$context}">
44 <thead>
45 <tr>
46 <th class='crm-contact-activity-activity_type'>{ts}Type{/ts}</th>
47 <th class='crm-contact-activity_subject'>{ts}Subject{/ts}</th>
48 <th class='crm-contact-activity-source_contact'>{ts}Added By{/ts}</th>
49 <th class='crm-contact-activity-target_contact nosort'>{ts}With{/ts}</th>
50 <th class='crm-contact-activity-assignee_contact nosort'>{ts}Assigned{/ts}</th>
51 <th class='crm-contact-activity-activity_date'>{ts}Date{/ts}</th>
52 <th class='crm-contact-activity-activity_status'>{ts}Status{/ts}</th>
53 <th class='crm-contact-activity-links nosort'>&nbsp;</th>
54 <th class='hiddenElement'>&nbsp;</th>
55 </tr>
56 </thead>
57 </table>
58 </div>
59 {include file="CRM/Case/Form/ActivityToCase.tpl" contactID=$contactId}
60 {literal}
61 <script type="text/javascript">
62 var {/literal}{$context}{literal}oTable;
63
64 CRM.$(function($) {
65 var context = {/literal}"{$context}"{literal};
66 var filterSearchOnLoad = false;
67 if (context == 'activity') {
68 filterSearchOnLoad = true;
69 }
70 buildContactActivities{/literal}{$context}{literal}( filterSearchOnLoad );
71
72 cj('.crm-activity-selector-'+ context +' #activity_type_filter_id').change( function( ) {
73 buildContactActivities{/literal}{$context}{literal}( true );
74 });
75
76 cj('.crm-activity-selector-'+ context +' #activity_type_exclude_filter_id').change( function( ) {
77 buildContactActivities{/literal}{$context}{literal}( true );
78 });
79 });
80
81 function buildContactActivities{/literal}{$context}{literal}( filterSearch ) {
82 if ( filterSearch && {/literal}{$context}{literal}oTable ) {
83 {/literal}{$context}{literal}oTable.fnDestroy();
84 }
85
86 var context = {/literal}"{$context}"{literal};
87 var columns = '';
88 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/contactactivity" h=0 q="snippet=4&context=$context&cid=$contactId"}'{literal};
89
90 var ZeroRecordText = {/literal}'{ts escape="js"}No matches found{/ts}'{literal};
91 if ( cj('.crm-activity-selector-'+ context +' select#activity_type_filter_id').val( ) ) {
92 ZeroRecordText += {/literal}'{ts escape="js"} for Activity Type = "{/ts}'{literal} + cj('.crm-activity-selector-'+ context +' select#activity_type_filter_id :selected').text( ) + '"';
93 }
94 else {
95 ZeroRecordText += '.';
96 }
97
98 {/literal}{$context}{literal}oTable = cj('#contact-activity-selector-' + context ).dataTable({
99 "bFilter" : false,
100 "bAutoWidth" : false,
101 "aaSorting" : [],
102 "aoColumns" : [
103 {sClass:'crm-contact-activity-activity_type'},
104 {sClass:'crm-contact-activity_subject'},
105 {sClass:'crm-contact-activity-source_contact'},
106 {sClass:'crm-contact-activity-target_contact', bSortable:false},
107 {sClass:'crm-contact-activity-assignee_contact', bSortable:false},
108 {sClass:'crm-contact-activity-activity_date'},
109 {sClass:'crm-contact-activity-activity_status'},
110 {sClass:'crm-contact-activity-links', bSortable:false},
111 {sClass:'hiddenElement', bSortable:false}
112 ],
113 "bProcessing": true,
114 "sPaginationType": "full_numbers",
115 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
116 "bServerSide": true,
117 "bJQueryUI": true,
118 "sAjaxSource": sourceUrl,
119 "iDisplayLength": 25,
120 "oLanguage": {
121 "sZeroRecords": ZeroRecordText,
122 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
123 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
124 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
125 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
126 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
127 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
128 "oPaginate": {
129 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
130 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
131 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
132 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
133 }
134 },
135 "fnDrawCallback": function() { setSelectorClass{/literal}{$context}{literal}( context ); },
136 "fnServerData": function ( sSource, aoData, fnCallback ) {
137 aoData.push( {name:'contact_id', value: {/literal}{$contactId}{literal}},
138 {name:'admin', value: {/literal}'{$admin}'{literal}}
139 );
140
141 if ( filterSearch ) {
142 aoData.push(
143 {name:'activity_type_id', value: cj('.crm-activity-selector-'+ context +' select#activity_type_filter_id').val()},
144 {name:'activity_type_exclude_id', value: cj('.crm-activity-selector-'+ context +' select#activity_type_exclude_filter_id').val()}
145 );
146 }
147 cj.ajax( {
148 "dataType": 'json',
149 "type": "POST",
150 "url": sSource,
151 "data": aoData,
152 "success": fnCallback,
153 // CRM-10244
154 "dataFilter": function(data, type) { return data.replace(/[\n\v\t]/g, " "); }
155 });
156 }
157 });
158 }
159
160 function setSelectorClass{/literal}{$context}{literal}( context ) {
161 cj('#contact-activity-selector-' + context + ' td:last-child').each( function( ) {
162 cj(this).parent().addClass(cj(this).text() );
163 });
164 }
165 </script>
166 {/literal}