CRM-14383 - Update cj closures
[civicrm-core.git] / templates / CRM / Campaign / Form / Task / Interview.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 {if $votingTab and $errorMessages}
27 <div class='messages status'>
28 <div class="icon inform-icon"></div>
29 <ul>
30 {foreach from=$errorMessages item=errorMsg}
31 <li>{ts}{$errorMsg}{/ts}</li>
32 {/foreach}
33 </ul>
34 </div>
35 </div>
36 {elseif $voterDetails}
37 <div class="form-item">
38 <fieldset>
39 {if $surveyValues.instructions}
40 <div id='survey_instructions' class='help'>{ts 1=$surveyValues.instructions}%1{/ts}</div>
41 {/if}
42
43 <div id='responseErrors' class = "hiddenElement messages crm-error"></div>
44
45 <div id='help'>
46 {if $votingTab}
47 {ts}Click <strong>record response</strong> button to update values for each respondent as needed.{/ts}
48 {else}
49 {ts}Click <strong>record response</strong> button to update values for each respondent as needed. <br />Click <strong>Release Respondents >></strong> button below to release any respondents for whom you haven't recorded a response. <br />Click <strong>Reserve More Respondents >></strong> button if you need to get more respondents to interview.{/ts}
50 {/if}
51 </div>
52 {if $instanceId}
53 {capture assign=instanceURL}{crmURL p="civicrm/report/instance/$instanceId" q="reset=1"}{/capture}
54 <div class="float-right"><a href='{$instanceURL}' class="button">{ts}Survey Report{/ts}</a></div>
55 {/if}
56 <div id="order-by-elements" class="civireport-criteria">
57 <table id="optionField" class="form-layout-compressed">
58 <tr>
59 <th></th>
60 <th>{ts}Column{/ts}</th>
61 <th>{ts}Order{/ts}</th>
62 </tr>
63
64 {section name=rowLoop start=1 loop=5}
65 {assign var=index value=$smarty.section.rowLoop.index}
66 <tr id="optionField_{$index}" class="form-item {cycle values="odd-row,even-row"}">
67 <td>
68 {if $index GT 1}
69 <a onclick="hideRow({$index}); return false;" name="orderBy_{$index}" href="#" class="form-link"><img src="{$config->resourceBase}i/TreeMinus.gif" class="action-icon" alt="{ts}hide field or section{/ts}"/></a>
70 {/if}
71 </td>
72 <td> {$form.order_bys.$index.column.html}</td>
73 <td> {$form.order_bys.$index.order.html}</td>
74 <td>
75 {if $index eq 1}
76 {$form.buttons._qf_Interview_submit_orderBy.html}
77 {/if}
78 </td>
79 </tr>
80 {/section}
81 </table>
82 <div id="optionFieldLink" class="add-remove-link">
83 <a onclick="showHideRow(); return false;" name="optionFieldLink" href="#" class="form-link"><img src="{$config->resourceBase}i/TreePlus.gif" class="action-icon" alt="{ts}show field or section{/ts}"/>{ts}another column{/ts}</a>
84 </div>
85
86 <script type="text/javascript">
87 var showRows = new Array('optionField_1');
88 var hideBlocks = new Array('optionField_2','optionField_3','optionField_4');
89 var rowcounter = 0;
90 {literal}
91 if (navigator.appName == "Microsoft Internet Explorer") {
92 for ( var count = 0; count < hideBlocks.length; count++ ) {
93 var r = document.getElementById(hideBlocks[count]);
94 r.style.display = 'none';
95 }
96 }
97
98 // hide and display the appropriate blocks as directed by the php code
99 on_load_init_blocks( showRows, hideBlocks, '' );
100
101 if (cj("#order_bys_2_column").val()){
102 cj("#optionField_2").show();
103 }
104 if (cj("#order_bys_3_column").val()){
105 cj("#optionField_3").show();
106 }
107 if (cj("#order_bys_4_column").val()){
108 cj("#optionField_4").show();
109 }
110
111 function hideRow(i) {
112 showHideRow(i);
113 // clear values on hidden field, so they're not saved
114 cj('select#order_by_column_'+ i).val('');
115 cj('select#order_by_order_'+ i).val('ASC');
116 }
117 {/literal}
118 </script>
119 </div>
120
121 <table id="voterRecords" class="display crm-copy-fields">
122 <thead>
123 <tr class="columnheader">
124 {foreach from=$readOnlyFields item=fTitle key=fName}
125 <th {if $fName neq 'contact_type'} class="contact_details"{/if}>{$fTitle}</th>
126 {/foreach}
127
128 {* display headers for profile survey fields *}
129 {if $surveyFields}
130 {foreach from=$surveyFields item=field key=fieldName}
131 {if $field.skipDisplay}
132 {continue}
133 {/if}
134 <th><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}</th>
135 {/foreach}
136 {/if}
137
138 <th><img src="{$config->resourceBase}i/copy.png" alt="{ts 1=note}Click to copy %1 from row one to all rows.{/ts}" fname="note" class="action-icon" title="{ts}Click here to copy the value in row one to ALL rows.{/ts}" />{ts}Note{/ts}</th>
139 <th><img src="{$config->resourceBase}i/copy.png" alt="{ts 1=result}Click to copy %1 from row one to all rows.{/ts}" fname="result" class="action-icon" title="{ts}Click here to copy the value in row one to ALL rows.{/ts}" />{ts}Result{/ts}</th>
140 <th><a id="interview_voter_button" class='button' style="float:left;" href="#" title={ts}Vote{/ts} onclick="registerInterviewforall( ); return false;">{ts}Record Responses for All{/ts}</a></th>
141 </tr>
142 </thead>
143
144 <tbody>
145 {foreach from=$componentIds item=voterId}
146 <tr id="row_{$voterId}" class="{cycle values="odd-row,even-row"}" entity_id="{$voterId}">
147 {foreach from=$readOnlyFields item=fTitle key=fName}
148 <td {if $fName neq 'contact_type'} class="name"{/if}>{$voterDetails.$voterId.$fName}</td>
149 {/foreach}
150
151 {* here build the survey profile fields *}
152 {if $surveyFields}
153 {foreach from=$surveyFields item=field key=fieldName}
154 {if $field.skipDisplay}
155 {continue}
156 {/if}
157 <td class="compressed {$field.data_type} {$fieldName}">
158 {if ( $field.data_type eq 'Date' and $field.is_view eq 0) or
159 ( $fieldName eq 'thankyou_date' ) or ( $fieldName eq 'cancel_date' ) or ( $fieldName eq 'receipt_date' ) or ( $fieldName eq 'activity_date_time') }
160 {include file="CRM/common/jcalendar.tpl" elementName=$fieldName elementIndex=$voterId batchUpdate=1}
161 {elseif $fieldName|substr:0:5 eq 'phone'}
162 {assign var="phone_ext_field" value=$fieldName|replace:'phone':'phone_ext'}
163 {$form.field.$voterId.$fieldName.html}
164 {if $form.field.$voterId.$phone_ext_field.html}
165 &nbsp;{$form.field.$voterId.$phone_ext_field.html}
166 {/if}
167 {else}
168 {$form.field.$voterId.$fieldName.html}
169 {/if}
170 </td>
171 {/foreach}
172 {/if}
173
174 <td class='note'>{$form.field.$voterId.note.html}</td>
175 <td class='result'>{$form.field.$voterId.result.html}</td>
176
177 <td>
178 <a id="interview_voter_button_{$voterId}" class='button' style="float:left;" href="#" title={ts}Vote{/ts} onclick="registerInterview( {$voterId} ); return false;">
179 {ts}record response{/ts}
180 </a>
181 {if $allowAjaxReleaseButton}
182 <a id="release_voter_button_{$voterId}" class='button' href="#" title={ts}Release{/ts} onclick="releaseOrReserveVoter( {$voterId} ); return false;">
183 {ts}release{/ts}
184 </a>
185 {/if}
186 <span id='restmsg_vote_{$voterId}' class="ok" style="display:none;float:right;">
187 {ts}Response Saved.{/ts}
188 </span>
189
190 <span id='restmsg_release_or_reserve_{$voterId}' class="ok" style="display:none;float:right;">
191 {ts}Released.{/ts}
192 </span>
193 </td>
194 </tr>
195 {/foreach}
196 </tbody>
197 </table>
198
199 {if !$votingTab}
200 <div class="spacer"></div>
201 <div class="crm-submit-buttons">{$form.buttons._qf_Interview_cancel_interview.html}&nbsp;{$form.buttons._qf_Interview_next_interviewToRelease.html}&nbsp;{$form.buttons._qf_Interview_done_interviewToReserve.html}</div>
202 {/if}
203
204 </fieldset>
205 </div>
206
207
208 {literal}
209 <script type="text/javascript">
210 var updateVote = "{/literal}{ts escape='js'}Update Response{/ts}{literal}";
211 var updateVoteforall = "{/literal}{ts escape='js'}Update Responses for All{/ts}{literal}";
212 CRM.$(function($) {
213 var count = 0; var columns='';
214
215 cj('#voterRecords th').each( function( ) {
216 if ( cj(this).attr('class') == 'contact_details' ) {
217 columns += '{"sClass": "contact_details"},';
218 }
219 else {
220 columns += '{ "bSortable": false },';
221 }
222 count++;
223 });
224
225 columns = columns.substring(0, columns.length - 1 );
226 eval('columns =[' + columns + ']');
227
228 //load jQuery data table.
229 cj('#voterRecords').dataTable( {
230 "sPaginationType": "full_numbers",
231 "bJQueryUI" : true,
232 "aoColumns" : columns
233 });
234
235 });
236
237 function registerInterview( voterId ) {
238 //reset all errors.
239 cj( '#responseErrors' ).hide( ).html( '' );
240
241 //collect all submitted data.
242 var data = new Object;
243
244 //get the values for common elements.
245 var fieldName = 'field_' + voterId + '_custom_';
246 var specialFieldType = new Array( 'radio', 'checkbox', 'select' );
247 cj( '[id^="'+ fieldName +'"]' ).each( function( ) {
248 fieldType = cj( this ).attr( 'type' );
249 if ( specialFieldType.indexOf( fieldType ) == -1 ) {
250 data[cj(this).attr( 'id' )] = cj( this ).val( );
251 }
252 });
253
254 //get the values for select.
255 cj('select[id^="'+ fieldName +'"]').each( function( ) {
256 value = cj(this).val( );
257 if (cj(this).attr( 'multiple')) {
258 values = value;
259 value = '';
260 if ( values ) {
261 submittedValues = values.toString().split(",");
262 value = new Object;
263 for (val in submittedValues) {
264 currentVal = submittedValues[val];
265 value[currentVal] = currentVal;
266 }
267 }
268 }
269 data[cj(this).attr('id')] = value;
270 });
271
272 var checkBoxField = 'field['+ voterId +'][custom_';
273 cj('input:checkbox[name^="'+ checkBoxField +'"]').each( function( ) {
274 value = '';
275 if (cj(this).is(':checked') == true) value = 1;
276 data[cj(this).attr( 'name' )] = value;
277 });
278
279 var allRadios = new Object;
280 var radioField = 'field['+ voterId +'][custom_';
281 cj('input:radio[name^="'+ radioField +'"]').each( function( ) {
282 radioName = cj(this).attr( 'name' );
283 if (cj(this).is(':checked') == true) {
284 data[radioName] = cj(this).val();
285 }
286 allRadios[radioName] = radioName;
287 });
288 for (radioName in allRadios) {
289 if (!data.hasOwnProperty(radioName)) data[radioName] = '';
290 }
291
292 //carry contact related profile field data.
293 var fieldName = 'field_' + voterId;
294 var checkBoxFieldName = 'field[' + voterId + ']';
295 cj('[id^="'+ fieldName +'"], [id^="'+ checkBoxFieldName +'"]').each(function( ) {
296 fldId = cj(this).attr('id');
297 if (fldId.indexOf('_custom_') == -1 &&
298 fldId.indexOf('_result') == -1 &&
299 fldId.indexOf('_note') == -1 ) {
300 data[fldId] = cj(this).val( );
301 }
302 });
303
304 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
305 activityId = eval("surveyActivityIds.activity_id_" + voterId);
306 if (!activityId) return;
307
308 data['voter_id'] = voterId;
309 data['interviewer_id'] = {/literal}{$interviewerId}{literal};
310 data['activity_type_id'] = {/literal}{$surveyTypeId}{literal};
311 data['activity_id'] = activityId;
312 data['result'] = cj( '#field_' + voterId + '_result' ).val( );
313 data['note'] = cj( '#field_' + voterId + '_note' ).val( );
314 data['surveyTitle'] = {/literal}'{$surveyValues.title|escape:javascript}'{literal};
315 data['survey_id'] = {/literal}'{$surveyValues.id}'{literal};
316
317 var dataUrl = {/literal}"{crmURL p='civicrm/campaign/registerInterview' h=0}"{literal}
318
319 //post data to create interview.
320 cj.post(dataUrl, data, function(interview) {
321 if ( interview.status == 'success' ) {
322 cj("#row_"+voterId+' td.name').attr('class', 'name survey-completed' );
323 cj('#restmsg_vote_' + voterId).fadeIn("slow").fadeOut("slow");
324 cj('#interview_voter_button_' + voterId).html(updateVote);
325 cj('#release_voter_button_' + voterId).hide( );
326 }
327 else if (interview.status == 'fail' && interview.errors) {
328 var errorList = '';
329 for (error in interview.errors) {
330 if (interview.errors[error]) errorList = errorList + '<li>' + interview.errors[error] + '</li>';
331 }
332 if ( errorList ) {
333 var allErrors = '<div class = "icon red-icon alert-icon"></div>Please correct the following errors in the survey fields below:' + '<ul>' + errorList + '</ul>';
334 cj('#responseErrors').show( ).html(allErrors);
335 }
336 }
337 }, 'json');
338 }
339
340 function releaseOrReserveVoter(voterId) {
341 if (!voterId) return;
342
343 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
344 activityId = eval("surveyActivityIds.activity_id_" + voterId);
345 if ( !activityId ) return;
346
347 var operation = 'release';
348 var isReleaseOrReserve = cj('#field_' + voterId + '_is_release_or_reserve').val( );
349 if (isReleaseOrReserve == 1) {
350 operation = 'reserve';
351 isReleaseOrReserve = 0;
352 }
353 else {
354 isReleaseOrReserve = 1;
355 }
356
357 var data = new Object;
358 data['operation'] = operation;
359 data['isDelete'] = (operation == 'release') ? 1 : 0;
360 data['activity_id'] = activityId;
361
362 var actUrl = {/literal}
363 "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}"
364 {literal};
365
366 //post data to release / reserve voter.
367 cj.post( actUrl,
368 data,
369 function( response ) {
370 if (response.status == 'success') {
371 if ( operation == 'release' ) {
372 cj( '#interview_voter_button_' + voterId ).hide( );
373 cj( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
374 cj( '#row_' + voterId + ' td.name' ).addClass( 'disabled' );
375 cj( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}reserve{/ts}{literal}" );
376 cj( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Reserve{/ts}{literal}");
377 }
378 else {
379 cj( '#interview_voter_button_' + voterId ).show( );
380 cj( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
381 cj( '#row_' + voterId + ' td.name' ).removeClass( 'disabled' );
382 cj( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}release{/ts}{literal}" );
383 cj( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Release{/ts}{literal}");
384 }
385 cj( '#field_' + voterId + '_is_release_or_reserve' ).val( isReleaseOrReserve );
386 }
387 },
388 'json');
389 }
390
391 function registerInterviewforall( ) {
392 var Ids = {/literal}{$componentIdsJson}{literal};
393 for (var contactid in Ids) {
394 if (cj('#field_'+ Ids[contactid] +'_result').val()) {
395 registerInterview(Ids[contactid]);
396 cj('#interview_voter_button').html(updateVoteforall);
397 }
398 }
399 }
400
401 </script>
402 {/literal}
403 {*include batch copy js js file*}
404 {include file="CRM/common/batchCopy.tpl"}
405 {/if}
406