Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-05-28-14-04-12
[civicrm-core.git] / templates / CRM / Batch / Form / Entry.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 <div class="batch-entry form-item">
27 <div id="help">
28 {ts}Click Validate & Process below when you've entered all items for the batch. You can also Save & Continue Later at any time. Go to Administer > Customize Display & Screens > Profiles > Reserved Profiles > to add, remove or change the order of columns.{/ts}
29 </div>
30 {if $batchAmountMismatch}
31 <div class="status message status-warning">
32 <div class="icon alert-icon"></div> {ts}Total for amounts entered below does not match the expected batch total.{/ts}
33 </div>
34 <div class="crm-button crm-button_qf_Entry_upload_force-save">
35 {$form._qf_Entry_upload_force.html}
36 </div>
37 <div class="clear"></div>
38 {/if}
39 <table class="form-layout-compressed batch-totals">
40 <tr><td class="label">{ts}Total amount expected{/ts}</td><td class="right"><span class="batch-expected-total">{$batchTotal|crmMoney}</span></td></tr>
41 <tr><td class="label">{ts}Total amount entered{/ts}</td><td class="right">{$config->defaultCurrencySymbol} <span class="batch-actual-total"></span></td></tr>
42 </table>
43
44 <div class="crm-copy-fields crm-grid-table" id="crm-batch-entry-table">
45 <div class="crm-grid-header">
46 <div class="crm-grid-cell">&nbsp;</div>
47 <div class="crm-grid-cell">{ts}Contact{/ts}</div>
48 {if $batchType eq 2 }
49 <div class="crm-grid-cell">&nbsp;</div>
50 {/if}
51 {foreach from=$fields item=field key=fieldName}
52 <div class="crm-grid-cell"><img src="{$config->resourceBase}i/copy.png" alt="{ts 1=$field.title}Click to copy %1 from row one to all rows.{/ts}" fname="{$field.name}" class="action-icon" title="{ts}Click here to copy the value in row one to ALL rows.{/ts}" />{$field.title}</div>
53 {/foreach}
54 </div>
55 {section name='i' start=1 loop=$rowCount}
56 {assign var='rowNumber' value=$smarty.section.i.index}
57 <div class="{cycle values="odd-row,even-row"} selector-rows crm-grid-row" entity_id="{$rowNumber}">
58 <div class="compressed crm-grid-cell"><span class="batch-edit"></span></div>
59 {* contact select/create option*}
60 <div class="compressed crm-grid-cell">
61 {include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="primary_" newContactCallback="updateContactInfo($rowNumber, 'primary_')"}
62 </div>
63
64 {if $batchType eq 2 }
65 {$form.member_option.$rowNumber.html}
66 {/if}
67
68 {foreach from=$fields item=field key=fieldName}
69 {assign var=n value=$field.name}
70 {if ( $fields.$n.data_type eq 'Date') or ( in_array( $n, array( 'thankyou_date', 'cancel_date', 'receipt_date', 'receive_date', 'join_date', 'membership_start_date', 'membership_end_date' ) ) ) }
71 <div class="compressed crm-grid-cell"><span class="crm-batch-{$n}-{$rowNumber}">{include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$rowNumber batchUpdate=1}</span></div>
72 {elseif $n eq 'soft_credit'}
73 <div class="compressed crm-grid-cell">{include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="soft_credit_"}</div>
74 {elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
75 <div class="compressed crm-grid-cell">&nbsp;{$form.field.$rowNumber.$n.html}</div>
76 {else}
77 <div class="compressed crm-grid-cell">{$form.field.$rowNumber.$n.html}</div>
78 {/if}
79 {/foreach}
80 </div>
81 {/section}
82 </div>
83 <div class="crm-submit-buttons">{if $fields}{$form._qf_Batch_refresh.html}{/if} &nbsp; {$form.buttons.html}</div>
84 </div>
85 {literal}
86 <script type="text/javascript">
87 cj(function(){
88 cj('.selector-rows').change(function(){
89 var options = {
90 'url' : {/literal}"{crmURL p='civicrm/ajax/batch' h=0}"{literal}
91 };
92
93 cj("#Entry").ajaxSubmit(options);
94
95 // validate rows
96 checkColumns( cj(this) );
97 });
98
99 // validate rows
100 validateRow( );
101
102 //calculate the actual total for the batch
103 calculateActualTotal();
104
105 cj('input[id*="_total_amount"]').bind('keyup change', function(){
106 calculateActualTotal();
107 });
108
109 {/literal}{if $batchType eq 1 }{literal}
110 // hide all dates if send receipt is checked
111 hideSendReceipt();
112
113 // hide the receipt date if send receipt is checked
114 cj( 'input[id*="][send_receipt]"]').change( function() {
115 showHideReceipt( cj(this) );
116 });
117
118 {/literal}{else}{literal}
119 cj('select[id^="member_option_"]').each( function() {
120 if ( cj(this).val() == 1 ) {
121 cj(this).attr('disabled', true);
122 }
123 });
124
125 // set payment info accord to membership type
126 cj( 'select[id*="_membership_type_0"]').change( function() {
127 setPaymentBlock( cj(this), null );
128 });
129
130 cj( 'select[id*="_membership_type_1"]').change( function() {
131 setPaymentBlock( cj(this), cj(this).val() );
132 });
133
134 {/literal}{/if}{literal}
135
136 // line breaks between radio buttons and checkboxes
137 cj('input.form-radio').next().after('<br />');
138 cj('input.form-checkbox').next().after('<br />');
139
140 //set the focus on first element
141 cj('#primary_contact_1').focus();
142
143 });
144
145 function setPaymentBlock( form, memType ) {
146 var rowID = form.closest('div.crm-grid-row').attr('entity_id');
147 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/memType' h=0}"{literal};
148
149 if ( !memType ) {
150 memType = cj( 'select[id="field_'+ rowID+'_membership_type_1"]').val();
151 }
152
153 cj.post( dataUrl, {mtype: memType}, function( data ) {
154 cj('#field_' + rowID + '_financial_type').val( data.financial_type_id );
155 cj('#field_' + rowID + '_total_amount').val( data.total_amount ).change();
156 }, 'json');
157 }
158
159 function hideSendReceipt() {
160 cj( 'input[id*="][send_receipt]"]').each( function() {
161 showHideReceipt( cj(this) );
162 });
163 }
164
165 function showHideReceipt( elem ) {
166 var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
167 var element = 'field_' + rowID + '_receipt_date';
168 if ( elem.prop('checked') ) {
169 cj('.crm-batch-receipt_date-'+ rowID ).hide();
170 } else {
171 cj('.crm-batch-receipt_date-'+ rowID ).show();
172 }
173 }
174
175 function validateRow( ) {
176 cj('.selector-rows').each(function(){
177 checkColumns( cj(this) );
178 });
179 }
180
181 function checkColumns( parentRow ) {
182 // show valid row icon if all required data is field
183 var validRow = 0;
184 var inValidRow = 0;
185 var errorExists = false;
186 parentRow.find('div .required').each(function(){
187 if ( !cj(this).val( ) ) {
188 inValidRow++;
189 } else if ( cj(this).hasClass('error') && !cj(this).hasClass('valid') ) {
190 errorExists = true;
191 } else {
192 validRow++;
193 }
194 });
195
196 // this means use has entered some data
197 if ( errorExists ) {
198 parentRow.find("div:first span").prop('class', 'batch-invalid');
199 } else if ( inValidRow == 0 && validRow > 0 ) {
200 parentRow.find("div:first span").prop('class', 'batch-valid');
201 } else {
202 parentRow.find("div:first span").prop('class', 'batch-edit');
203 }
204 }
205
206 function calculateActualTotal() {
207 var total = 0;
208 cj('input[id*="_total_amount"]').each(function(){
209 if ( cj(this).val() ) {
210 total += parseFloat(cj(this).val());
211 }
212 });
213
214 cj('.batch-actual-total').html(formatMoney(total));
215 }
216
217 //money formatting/localization
218 function formatMoney ( amount ) {
219 var c = 2;
220 var t = '{/literal}{$config->monetaryThousandSeparator}{literal}';
221 var d = '{/literal}{$config->monetaryDecimalPoint}{literal}';
222
223 var n = amount,
224 c = isNaN(c = Math.abs(c)) ? 2 : c,
225 d = d == undefined ? "," : d,
226 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
227 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
228 j = (j = i.length) > 3 ? j % 3 : 0;
229
230 return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
231 }
232
233 function updateContactInfo( blockNo, prefix ) {
234 var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo +']"]';
235 var contactId = cj( contactHiddenElement ).val();;
236
237 var returnProperties = '';
238 var profileFields = new Array();
239 {/literal}
240 {if $contactFields}
241 {foreach from=$contactFields item=val key=fldName}
242 var fldName = "{$fldName}";
243 {literal}
244 if ( returnProperties ) {
245 returnProperties = returnProperties + ',';
246 }
247 var fld = fldName.split('-');
248 returnProperties = returnProperties + fld[0];
249 profileFields[fld[0]] = fldName;
250 {/literal}
251 {/foreach}
252 {/if}
253 {literal}
254
255 CRM.api('Contact','get',{
256 'sequential' :'1',
257 'contact_id': contactId,
258 'return': returnProperties },
259 { success: function (data) {
260 cj.each ( data.values[0], function( key, value ) {
261 // set the values
262 var actualFldName = profileFields[key];
263 if ( key == 'country' || key == 'state_province' ) {
264 idFldName = key + '_id';
265 value = data.values[0][idFldName];
266 }
267 setFieldValue( actualFldName, value, blockNo )
268 });
269
270 // for membership batch entry based on contact we need to enable / disable
271 // add membership select
272 {/literal}{if $batchType eq 2}{literal}
273 CRM.api('Membership','get',{
274 'sequential' :'1',
275 'contact_id': contactId,
276 },
277 { success: function (data) {
278 if ( data.count > 0 ) {
279 //get the information on membership type
280 var membershipTypeId = data.values[0].membership_type_id;
281 var membershipJoinDate = data.values[0].join_date;
282 CRM.api('MembershipType','get',{
283 'sequential' :'1',
284 'id' : membershipTypeId
285 },
286 { success: function (data){
287 var memTypeContactId = data.values[0].member_of_contact_id;
288 cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
289 cj('select[id="field_' + blockNo + '_membership_type_0"]').val( memTypeContactId ).change();
290 cj('select[id="field_' + blockNo + '_membership_type_1"]').val( membershipTypeId ).change();
291 setDateFieldValue( 'join_date', membershipJoinDate, blockNo )
292 }
293 });
294 }
295 }
296 });
297 {/literal}{/if}{literal}
298 }
299 });
300 }
301
302 /**
303 * This function is use to setdefault elements via ajax
304 *
305 * @param fname string field name
306 * @return void
307 */
308 function setFieldValue( fname, fieldValue, blockNo ) {
309 var elementId = cj('[name="field['+ blockNo +']['+ fname +']"]');
310
311 if ( elementId.length == 0 ) {
312 elementId = cj('input[type=checkbox][name^="field['+ blockNo +']['+ fname +']"][type!=hidden]');
313 }
314
315 // if element not found than return
316 if ( elementId.length == 0 ) {
317 return;
318 }
319
320 //check if it is date element
321 var isDateElement = elementId.attr('format');
322
323 // check if it is wysiwyg element
324 var editor = elementId.attr('editor');
325
326 //get the element type
327 var elementType = elementId.attr('type');
328
329 // set the value for all the elements, elements needs to be handled are
330 // select, checkbox, radio, date fields, text, textarea, multi-select
331 // wysiwyg editor, advanced multi-select ( to do )
332 if ( elementType == 'radio' ) {
333 if ( fieldValue ) {
334 elementId.filter("[value=" + fieldValue + "]").prop("checked",true);
335 } else {
336 elementId.removeProp('checked');
337 }
338 } else if ( elementType == 'checkbox' ) {
339 // handle checkbox
340 elementId.removeProp('checked');
341 if ( fieldValue ) {
342 cj.each( fieldValue, function( key, value ) {
343 cj('input[name="field['+ blockNo +']['+ fname +']['+ value +']"]').prop('checked', true);
344 });
345 }
346 } else if ( editor ) {
347 switch ( editor ) {
348 case 'ckeditor':
349 var elemtId = elementId.attr('id');
350 oEditor = CKEDITOR.instances[elemtId];
351 oEditor.setData( htmlContent );
352 break;
353 case 'tinymce':
354 var elemtId = element.attr('id');
355 tinyMCE.get( elemtId ).setContent( htmlContent );
356 break;
357 case 'joomlaeditor':
358 // TO DO
359 case 'drupalwysiwyg':
360 // TO DO
361 default:
362 elementId.val( fieldValue );
363 }
364 } else {
365 elementId.val( fieldValue );
366 }
367
368 // since we use different display field for date we also need to set it.
369 // also check for date time field and set the value correctly
370 if ( isDateElement && fieldValue ) {
371 setDateFieldValue( fname, fieldValue, blockNo )
372 }
373 }
374
375 function setDateFieldValue( fname, fieldValue, blockNo ) {
376 var dateValues = fieldValue.split(' ');
377
378 var actualDateElement = cj('#field_'+ blockNo +'_' + fname );
379 var date_format = actualDateElement.attr('format');
380 var altDateFormat = 'yy-mm-dd';
381
382 var actualDateValue = cj.datepicker.parseDate( altDateFormat, dateValues[0] );
383
384 // format date according to display field
385 var hiddenDateValue = cj.datepicker.formatDate( 'mm/dd/yy', actualDateValue );
386
387 actualDateElement.val( hiddenDateValue );
388
389 var displayDateValue = actualDateElement.val();
390 if ( date_format != 'mm/dd/yy' ) {
391 displayDateValue = cj.datepicker.formatDate( date_format, actualDateValue );
392 }
393
394 cj('#field_'+ blockNo +'_' + fname + '_display').val( displayDateValue );
395
396 // need to fix time formatting
397 if ( dateValues[1] ) {
398 cj('#field_'+ blockNo +'_' + fname + '_time').val(dateValues[1].substr(0,5));
399 }
400 }
401
402 </script>
403 {/literal}
404
405 {*include batch copy js js file*}
406 {include file="CRM/common/batchCopy.tpl"}