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