Merge pull request #9581 from colemanw/CRM-19802
[civicrm-core.git] / templates / CRM / Campaign / Form / Task / Interview.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2016 |
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 (CRM.$("#order_bys_2_column").val()){
102 CRM.$("#optionField_2").show();
103 }
104 if (CRM.$("#order_bys_3_column").val()){
105 CRM.$("#optionField_3").show();
106 }
107 if (CRM.$("#order_bys_4_column").val()){
108 CRM.$("#optionField_4").show();
109 }
110
111 function hideRow(i) {
112 showHideRow(i);
113 // clear values on hidden field, so they're not saved
114 CRM.$('select#order_by_column_'+ i).val('');
115 CRM.$('select#order_by_order_'+ i).val('ASC');
116 }
117 {/literal}
118 </script>
119 </div>
120
121 <table id="voterRecords-{$instanceId}" 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 ( ( $fieldName eq 'thankyou_date' ) or ( $fieldName eq 'cancel_date' ) or ( $fieldName eq 'receipt_date' ) or ( $fieldName eq 'activity_date_time') ) and $field.is_view neq 1 }
159 {include file="CRM/common/jcalendar.tpl" elementName=$fieldName elementIndex=$voterId batchUpdate=1}
160 {elseif $fieldName|substr:0:5 eq 'phone'}
161 {assign var="phone_ext_field" value=$fieldName|replace:'phone':'phone_ext'}
162 {$form.field.$voterId.$fieldName.html}
163 {if $form.field.$voterId.$phone_ext_field.html}
164 &nbsp;{$form.field.$voterId.$phone_ext_field.html}
165 {/if}
166 {else}
167 {$form.field.$voterId.$fieldName.html}
168 {/if}
169 </td>
170 {/foreach}
171 {/if}
172
173 <td class='note'>{$form.field.$voterId.note.html}</td>
174 <td class='result'>{$form.field.$voterId.result.html}</td>
175
176 <td>
177 <a id="interview_voter_button_{$voterId}" class='button' style="float:left;" href="#" title={ts}Vote{/ts} onclick="registerInterview( {$voterId} ); return false;">
178 {ts}record response{/ts}
179 </a>
180 {if $allowAjaxReleaseButton}
181 <a id="release_voter_button_{$voterId}" class='button' href="#" title={ts}Release{/ts} onclick="releaseOrReserveVoter( {$voterId} ); return false;">
182 {ts}release{/ts}
183 </a>
184 {/if}
185 <span id='restmsg_vote_{$voterId}' class="ok" style="display:none;float:right;">
186 {ts}Response Saved.{/ts}
187 </span>
188
189 <span id='restmsg_release_or_reserve_{$voterId}' class="ok" style="display:none;float:right;">
190 {ts}Released.{/ts}
191 </span>
192 </td>
193 </tr>
194 {/foreach}
195 </tbody>
196 </table>
197
198 {if !$votingTab}
199 <div class="spacer"></div>
200 <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>
201 {/if}
202
203 </fieldset>
204 </div>
205
206 {literal}
207 <script type="text/javascript">
208 var updateVote = "{/literal}{ts escape='js'}Update Response{/ts}{literal}";
209 var updateVoteforall = "{/literal}{ts escape='js'}Update Responses for All{/ts}{literal}";
210 CRM.$(function($) {
211 var count = 0; var columns='';
212
213 CRM.$('#voterRecords-{/literal}{$instanceId}{literal} th').each( function( ) {
214 if ( CRM.$(this).attr('class') == 'contact_details' ) {
215 columns += '{"sClass": "contact_details"},';
216 }
217 else {
218 columns += '{ "bSortable": false },';
219 }
220 count++;
221 });
222
223 columns = columns.substring(0, columns.length - 1 );
224 eval('columns =[' + columns + ']');
225
226 //load jQuery data table.
227 CRM.$('table#voterRecords-{/literal}{$instanceId}{literal}').dataTable( {
228 "sPaginationType": "full_numbers",
229 "bJQueryUI" : true,
230 "aoColumns" : columns
231 });
232
233 });
234
235 function registerInterview( voterId ) {
236 //reset all errors.
237 CRM.$( '#responseErrors' ).hide( ).html( '' );
238
239 //collect all submitted data.
240 var data = new Object;
241
242 //get the values for common elements.
243 var fieldName = 'field_' + voterId + '_custom_';
244 var specialFieldType = new Array( 'radio', 'checkbox', 'select' );
245 CRM.$( '[id^="'+ fieldName +'"]' ).each( function( ) {
246 fieldType = CRM.$( this ).attr( 'type' );
247 if ( specialFieldType.indexOf( fieldType ) == -1 ) {
248 data[CRM.$(this).attr( 'id' )] = CRM.$( this ).val( );
249 }
250 });
251
252 //get the values for select.
253 CRM.$('select[id^="'+ fieldName +'"]').each( function( ) {
254 value = CRM.$(this).val( );
255 if (CRM.$(this).attr( 'multiple')) {
256 values = value;
257 value = '';
258 if ( values ) {
259 submittedValues = values.toString().split(",");
260 value = new Object;
261 for (val in submittedValues) {
262 currentVal = submittedValues[val];
263 value[currentVal] = currentVal;
264 }
265 }
266 }
267 data[CRM.$(this).attr('id')] = value;
268 });
269
270 var checkBoxField = 'field['+ voterId +'][custom_';
271 CRM.$('input:checkbox[name^="'+ checkBoxField +'"]').each( function( ) {
272 value = '';
273 if (CRM.$(this).is(':checked') == true) value = 1;
274 data[CRM.$(this).attr( 'name' )] = value;
275 });
276
277 var allRadios = new Object;
278 var radioField = 'field['+ voterId +'][custom_';
279 CRM.$('input:radio[name^="'+ radioField +'"]').each( function( ) {
280 radioName = CRM.$(this).attr( 'name' );
281 if (CRM.$(this).is(':checked') == true) {
282 data[radioName] = CRM.$(this).val();
283 }
284 allRadios[radioName] = radioName;
285 });
286 for (radioName in allRadios) {
287 if (!data.hasOwnProperty(radioName)) data[radioName] = '';
288 }
289
290 //carry contact related profile field data.
291 var fieldName = 'field_' + voterId;
292 var checkBoxFieldName = 'field[' + voterId + ']';
293 CRM.$('[id^="'+ fieldName +'"], [id^="'+ checkBoxFieldName +'"]').each(function( ) {
294 fldId = CRM.$(this).attr('id');
295 if (fldId.indexOf('_custom_') == -1 &&
296 fldId.indexOf('_result') == -1 &&
297 fldId.indexOf('_note') == -1 ) {
298 data[fldId] = CRM.$(this).val( );
299 }
300 });
301
302 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
303 activityId = eval("surveyActivityIds.activity_id_" + voterId);
304 if (!activityId) return;
305
306 data['voter_id'] = voterId;
307 data['interviewer_id'] = {/literal}{$interviewerId}{literal};
308 data['activity_type_id'] = {/literal}{$surveyTypeId}{literal};
309 data['activity_id'] = activityId;
310 data['result'] = CRM.$( '#field_' + voterId + '_result' ).val( );
311 data['note'] = CRM.$( '#field_' + voterId + '_note' ).val( );
312 data['surveyTitle'] = {/literal}'{$surveyValues.title|escape:javascript}'{literal};
313 data['survey_id'] = {/literal}'{$surveyValues.id}'{literal};
314
315 var dataUrl = {/literal}"{crmURL p='civicrm/campaign/registerInterview' h=0}"{literal}
316
317 //post data to create interview.
318 CRM.$.post(dataUrl, data, function(interview) {
319 if ( interview.status == 'success' ) {
320 CRM.$("#row_"+voterId+' td.name').attr('class', 'name strikethrough' );
321 CRM.$('#restmsg_vote_' + voterId).fadeIn("slow").fadeOut("slow");
322 CRM.$('#interview_voter_button_' + voterId).html(updateVote);
323 CRM.$('#release_voter_button_' + voterId).hide( );
324 }
325 else if (interview.status == 'fail' && interview.errors) {
326 var errorList = '';
327 for (error in interview.errors) {
328 if (interview.errors[error]) errorList = errorList + '<li>' + interview.errors[error] + '</li>';
329 }
330 if ( errorList ) {
331 var allErrors = '<i class="crm-i fa-exclamation-triangle crm-i-red"></i> ' + ts('Please correct the following errors in the survey fields below:') + '<ul>' + errorList + '</ul>';
332 CRM.$('#responseErrors').show( ).html(allErrors);
333 }
334 }
335 }, 'json');
336 }
337
338 function releaseOrReserveVoter(voterId) {
339 if (!voterId) return;
340
341 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
342 activityId = eval("surveyActivityIds.activity_id_" + voterId);
343 if ( !activityId ) return;
344
345 var operation = 'release';
346 var isReleaseOrReserve = CRM.$('#field_' + voterId + '_is_release_or_reserve').val( );
347 if (isReleaseOrReserve == 1) {
348 operation = 'reserve';
349 isReleaseOrReserve = 0;
350 }
351 else {
352 isReleaseOrReserve = 1;
353 }
354
355 var data = new Object;
356 data['operation'] = operation;
357 data['isDelete'] = (operation == 'release') ? 1 : 0;
358 data['activity_id'] = activityId;
359
360 var actUrl = {/literal}
361 "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}"
362 {literal};
363
364 //post data to release / reserve voter.
365 CRM.$.post( actUrl,
366 data,
367 function( response ) {
368 if (response.status == 'success') {
369 if ( operation == 'release' ) {
370 CRM.$( '#interview_voter_button_' + voterId ).hide( );
371 CRM.$( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
372 CRM.$( '#row_' + voterId + ' td.name' ).addClass( 'disabled' );
373 CRM.$( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}reserve{/ts}{literal}" );
374 CRM.$( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Reserve{/ts}{literal}");
375 }
376 else {
377 CRM.$( '#interview_voter_button_' + voterId ).show( );
378 CRM.$( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
379 CRM.$( '#row_' + voterId + ' td.name' ).removeClass( 'disabled' );
380 CRM.$( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}release{/ts}{literal}" );
381 CRM.$( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Release{/ts}{literal}");
382 }
383 CRM.$( '#field_' + voterId + '_is_release_or_reserve' ).val( isReleaseOrReserve );
384 }
385 },
386 'json');
387 }
388
389 function registerInterviewforall( ) {
390 var Ids = {/literal}{$componentIdsJson}{literal};
391 for (var contactid in Ids) {
392 if (CRM.$('#field_'+ Ids[contactid] +'_result').val()) {
393 registerInterview(Ids[contactid]);
394 CRM.$('#interview_voter_button').html(updateVoteforall);
395 }
396 }
397 }
398
399 </script>
400 {/literal}
401 {*include batch copy js js file*}
402 {include file="CRM/common/batchCopy.tpl"}
403 {/if}