Merge pull request #2769 from colemanw/cj
[civicrm-core.git] / templates / CRM / Financial / Form / BatchTransaction.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 {* this template is used for batch transaction screen, assign/remove transactions to batch *}
27 {if $statusID eq 1}
28 <div class="crm-form-block crm-search-form-block">
29 <div class="crm-accordion-wrapper crm-batch_transaction_search-accordion collapsed">
30 <div class="crm-accordion-header crm-master-accordion-header">
31 {ts}Edit Search Criteria{/ts}
32 </div>
33 <div class="crm-accordion-body">
34 <div id="searchForm" class="crm-block crm-form-block crm-contact-custom-search-activity-search-form-block">
35 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
36 <table class="form-layout-compressed">
37 <tr>
38 <td class="font-size12pt" colspan="2">{$form.sort_name.label}&nbsp;&nbsp;{$form.sort_name.html|crmAddClass:'twenty'}</td>
39 </tr>
40 <tr>
41 {if $form.contact_tags}
42 <td><label>{ts}Contributor Tag(s){/ts}</label>
43 {$form.contact_tags.html}
44 </td>
45 {else}
46 <td>&nbsp;</td>
47 {/if}
48 {if $form.group}
49 <td><label>{ts}Contributor Group(s){/ts}</label>
50 {$form.group.html}
51 </td>
52 {else}
53 <td>&nbsp;</td>
54 {/if}
55 {include file="CRM/Contribute/Form/Search/Common.tpl"}
56 </table>
57 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div>
58 </div>
59 </div>
60 </div>
61 </div>
62 {if $statusID eq 1}
63 <div class="form-layout-compressed">{$form.trans_assign.html}&nbsp;{$form.submit.html}</div><br/>
64 {/if}
65 <div id="ltype">
66 <p></p>
67 <div class="form-item">
68 {strip}
69 <table id="crm-transaction-selector-assign" cellpadding="0" cellspacing="0" border="0">
70 <thead>
71 <tr>
72 <th class="crm-transaction-checkbox">{if $statusID eq 1}{$form.toggleSelect.html}{/if}</th>
73 <th class="crm-contact-type"></th>
74 <th class="crm-contact-name">{ts}Name{/ts}</th>
75 <th class="crm-amount">{ts}Amount{/ts}</th>
76 <th class="crm-trxnID">{ts}Trxn ID{/ts}</th>
77 <th class="crm-received">{ts}Received{/ts}</th>
78 <th class="crm-payment-method">{ts}Pay Method{/ts}</th>
79 <th class="crm-status">{ts}Status{/ts}</th>
80 <th class="crm-type">{ts}Financial Type{/ts}</th>
81 <th class="crm-transaction-links"></th>
82 </tr>
83 </thead>
84 </table>
85 {/strip}
86 </div>
87 </div>
88 {/if}
89
90 {literal}
91 <script type="text/javascript">
92 CRM.$(function($) {
93 cj().crmAccordions();
94 cj('#_qf_BatchTransaction_submit-top, #_qf_BatchTransaction_submit-botttom').click(function() {
95 cj('.crm-batch_transaction_search-accordion:not(.collapsed)').crmAccordionToggle();
96 });
97 var batchStatus = {/literal}{$statusID}{literal};
98 // build transaction listing only for open batches
99 if (batchStatus == 1) {
100 var paymentInstrumentID = {/literal}{if $paymentInstrumentID neq null}{$paymentInstrumentID}{else}'null'{/if}{literal};
101 if (paymentInstrumentID != 'null') {
102 buildTransactionSelectorAssign( true );
103 }
104 else {
105 buildTransactionSelectorAssign( false );
106 }
107 buildTransactionSelectorRemove();
108 cj('#_qf_BatchTransaction_submit-botttom, #_qf_BatchTransaction_submit-top').click( function() {
109 buildTransactionSelectorAssign( true );
110 return false;
111 });
112
113 cj("#trans_assign").prop('disabled',true);
114 cj("#trans_remove").prop('disabled',true);
115 cj('#crm-transaction-selector-assign #toggleSelect').click( function() {
116 enableActions('x');
117 });
118 cj('#crm-transaction-selector-remove #toggleSelects').click( function() {
119 enableActions('y');
120 });
121 cj('#Go').click( function() {
122 return selectAction("trans_assign","toggleSelect", "crm-transaction-selector-assign input[id^='mark_x_']");
123 });
124 cj('#GoRemove').click( function() {
125 return selectAction("trans_remove","toggleSelects", "crm-transaction-selector-remove input[id^='mark_y_']");
126 });
127 cj('#Go').click( function() {
128 if (cj("#trans_assign" ).val() != "" && cj("input[id^='mark_x_']").is(':checked')) {
129 bulkAssignRemove('Assign');
130 }
131 return false;
132 });
133 cj('#GoRemove').click( function() {
134 if (cj("#trans_remove" ).val() != "" && cj("input[id^='mark_y_']").is(':checked')) {
135 bulkAssignRemove('Remove');
136 }
137 return false;
138 });
139 cj("#crm-transaction-selector-assign input[id^='mark_x_']").click( function() {
140 enableActions('x');
141 });
142 cj("#crm-transaction-selector-remove input[id^='mark_y_']").click( function() {
143 enableActions('y');
144 });
145
146 cj("#crm-transaction-selector-assign #toggleSelect").click( function() {
147 if (cj("#crm-transaction-selector-assign #toggleSelect").is(':checked')) {
148 cj("#crm-transaction-selector-assign input[id^='mark_x_']").prop('checked',true);
149 }
150 else {
151 cj("#crm-transaction-selector-assign input[id^='mark_x_']").prop('checked',false);
152 }
153 });
154 cj("#crm-transaction-selector-remove #toggleSelects").click( function() {
155 if (cj("#crm-transaction-selector-remove #toggleSelects").is(':checked')) {
156 cj("#crm-transaction-selector-remove input[id^='mark_y_']").prop('checked',true);
157 }
158 else {
159 cj("#crm-transaction-selector-remove input[id^='mark_y_']").prop('checked',false);
160 }
161 });
162 }
163 else {
164 buildTransactionSelectorRemove();
165 }
166 });
167
168 function enableActions( type ) {
169 if (type == 'x') {
170 cj("#trans_assign").prop('disabled',false);
171 }
172 else {
173 cj("#trans_remove").prop('disabled',false);
174 }
175 }
176
177 function buildTransactionSelectorAssign(filterSearch) {
178 var columns = '';
179 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="className=CRM_Financial_Page_AJAX&fnName=getFinancialTransactionsList&snippet=4&context=financialBatch&entityID=$entityID&notPresent=1&statusID=$statusID"}'{literal};
180 if ( filterSearch ) {
181 sourceUrl = sourceUrl+"&search=1";
182 var ZeroRecordText = '<div class="status messages">{/literal}{ts escape="js"}No Contributions found for your search criteria.{/ts}{literal}</li></ul></div>';
183 }
184
185 crmBatchSelector1 = cj('#crm-transaction-selector-assign').dataTable({
186 "bDestroy" : true,
187 "bFilter" : false,
188 "bAutoWidth" : false,
189 "aaSorting" : [[5, 'desc']],
190 "aoColumns" : [
191 {sClass:'crm-transaction-checkbox', bSortable:false},
192 {sClass:'crm-contact-type', bSortable:false},
193 {sClass:'crm-contact-name'},
194 {sClass:'crm-amount'},
195 {sClass:'crm-trxnID'},
196 {sClass:'crm-received'},
197 {sClass:'crm-payment-method'},
198 {sClass:'crm-status'},
199 {sClass:'crm-type'},
200 {sClass:'crm-transaction-links', bSortable:false}
201 ],
202 "bProcessing": true,
203 "asStripClasses" : [ "odd-row", "even-row" ],
204 "sPaginationType": "full_numbers",
205 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
206 "bServerSide": true,
207 "bJQueryUI": true,
208 "sAjaxSource": sourceUrl,
209 "iDisplayLength": 25,
210 "oLanguage": {
211 "sZeroRecords": ZeroRecordText,
212 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
213 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
214 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
215 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
216 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
217 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
218 "oPaginate": {
219 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
220 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
221 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
222 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
223 }
224 },
225 "fnServerData": function ( sSource, aoData, fnCallback ) {
226 if ( filterSearch ) {
227 cj('#searchForm :input').each(function() {
228 if (cj(this).val()) {
229 aoData.push(
230 {name:cj(this).attr('id'), value: cj(this).val()}
231 );
232 cj(':radio, :checkbox').each(function() {
233 if (cj(this).is(':checked')) {
234 aoData.push( { name: cj(this).attr('name'), value: cj(this).val() } );
235 }
236 });
237 }
238 });
239 }
240 cj.ajax({
241 "dataType": 'json',
242 "type": "POST",
243 "url": sSource,
244 "data": aoData,
245 "success": fnCallback
246 });
247 }
248 });
249 }
250
251 function buildTransactionSelectorRemove( ) {
252 var columns = '';
253 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="className=CRM_Financial_Page_AJAX&fnName=getFinancialTransactionsList&snippet=4&context=financialBatch&entityID=$entityID&statusID=$statusID"}'{literal};
254
255 crmBatchSelector = cj('#crm-transaction-selector-remove').dataTable({
256 "bDestroy" : true,
257 "bFilter" : false,
258 "bAutoWidth" : false,
259 "aaSorting" : [[5, 'desc']],
260 "aoColumns" : [
261 {sClass:'crm-transaction-checkbox', bSortable:false},
262 {sClass:'crm-contact-type', bSortable:false},
263 {sClass:'crm-contact-name'},
264 {sClass:'crm-amount'},
265 {sClass:'crm-trxnID'},
266 {sClass:'crm-received'},
267 {sClass:'crm-payment-method'},
268 {sClass:'crm-status'},
269 {sClass:'crm-type'},
270 {sClass:'crm-transaction-links', bSortable:false}
271 ],
272 "bProcessing": true,
273 "asStripClasses" : [ "odd-row", "even-row" ],
274 "sPaginationType": "full_numbers",
275 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
276 "bServerSide": true,
277 "bJQueryUI": true,
278 "sAjaxSource": sourceUrl,
279 "iDisplayLength": 25,
280 "oLanguage": {
281 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
282 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
283 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
284 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
285 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
286 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
287 "oPaginate": {
288 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
289 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
290 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
291 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
292 }
293 },
294 "fnServerData": function (sSource, aoData, fnCallback) {
295 cj.ajax({
296 "dataType": 'json',
297 "type": "POST",
298 "url": sSource,
299 "data": aoData,
300 "success": fnCallback
301 });
302 }
303 });
304 }
305
306 function selectAction( id, toggleSelectId, checkId ) {
307 if (cj("#"+ id ).is(':disabled')) {
308 return false;
309 }
310 else if (!cj("#" + toggleSelectId).is(':checked') && !cj("#" + checkId).is(':checked') && cj("#" + id).val() != "") {
311 CRM.alert ({/literal}'{ts escape="js"}Please select one or more contributions for this action.{/ts}'{literal});
312 return false;
313 }
314 else if (cj("#" + id).val() == "") {
315 CRM.alert ({/literal}'{ts escape="js"}Please select an action from the drop-down menu.{/ts}'{literal});
316 return false;
317 }
318 }
319
320 function bulkAssignRemove( action ) {
321 var postUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q="className=CRM_Financial_Page_AJAX&fnName=bulkAssignRemove&entityID=$entityID" }"{literal};
322 var fids = [];
323 if (action == 'Assign') {
324 cj("input[id^='mark_x_']:checked").each( function () {
325 var a = cj(this).attr('id');
326 fids.push(a);
327 });
328 }
329 if (action == 'Remove') {
330 cj("input[id^='mark_y_']:checked").each( function () {
331 var a = cj(this).attr('id');
332 fids.push(a);
333 });
334 }
335 cj.post(postUrl, { ID: fids, action:action }, function(data) {
336 //this is custom status set when record update success.
337 if (data.status == 'record-updated-success') {
338 buildTransactionSelectorAssign( true );
339 buildTransactionSelectorRemove();
340 batchSummary({/literal}{$entityID}{literal});
341 }
342 else {
343 CRM.alert(data.status);
344 }
345 }, 'json');
346 }
347 </script>
348 {/literal}