2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
10 {if $votingTab and $errorMessages}
11 <div class='messages status'>
12 <div class="icon inform-icon"></div>
14 {foreach from=$errorMessages item=errorMsg}
15 <li>{ts}{$errorMsg}{/ts}</li>
20 {elseif $voterDetails}
21 <div class="form-item">
23 {if $surveyValues.instructions}
24 <div id='survey_instructions' class='help'>{ts 1=$surveyValues.instructions}%1{/ts}</div>
27 <div id='responseErrors' class = "hiddenElement messages crm-error"></div>
31 {ts}Click <strong>record response</strong> button to update values for each respondent as needed.{/ts}
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}
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>
40 <div id="order-by-elements" class="civireport-criteria">
41 <table id="optionField" class="form-layout-compressed">
44 <th>{ts}Column{/ts}</th>
45 <th>{ts}Order{/ts}</th>
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"}">
54 <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>
57 <td> {$form.order_bys.$index.column.html}</td>
58 <td> {$form.order_bys.$index.order.html}</td>
61 {$form.buttons._qf_Interview_submit_orderBy.html}
67 <div id="optionFieldLink" class="add-remove-link">
68 <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>
71 <script type="text/javascript">
72 var showRows = new Array('optionField_1');
73 var hideBlocks = new Array('optionField_2','optionField_3','optionField_4');
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';
83 // hide and display the appropriate blocks as directed by the php code
84 on_load_init_blocks( showRows, hideBlocks, '' );
86 if (CRM.$("#order_bys_2_column").val()){
87 CRM.$("#optionField_2").show();
89 if (CRM.$("#order_bys_3_column").val()){
90 CRM.$("#optionField_3").show();
92 if (CRM.$("#order_bys_4_column").val()){
93 CRM.$("#optionField_4").show();
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');
106 <table id="voterRecords-{$instanceId}" class="display crm-copy-fields">
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>
113 {* display headers for profile survey fields *}
115 {foreach from=$surveyFields item=field key=fieldName}
116 {if $field.skipDisplay}
119 <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>
123 <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>
124 <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>
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>
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>
136 {* here build the survey profile fields *}
138 {foreach from=$surveyFields item=field key=fieldName}
139 {if $field.skipDisplay}
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 {$form.field.$voterId.$phone_ext_field.html}
150 {$form.field.$voterId.$fieldName.html}
156 <td class='note'>{$form.field.$voterId.note.html}</td>
157 <td class='result'>{$form.field.$voterId.result.html}</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}
163 {if $allowAjaxReleaseButton}
164 <a id="release_voter_button_{$voterId}" class='button' href="#" title={ts}Release{/ts} onclick="releaseOrReserveVoter( {$voterId} ); return false;">
168 <span id='restmsg_vote_{$voterId}' class="ok" style="display:none;float:right;">
169 {ts}Response Saved.{/ts}
172 <span id='restmsg_release_or_reserve_{$voterId}' class="ok" style="display:none;float:right;">
182 <div class="spacer"></div>
183 <div class="crm-submit-buttons">{$form.buttons._qf_Interview_cancel_interview.html} {$form.buttons._qf_Interview_next_interviewToRelease.html} {$form.buttons._qf_Interview_done_interviewToReserve.html}</div>
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}";
194 var count = 0; var columns='';
196 CRM.$('#voterRecords-{/literal}{$instanceId}{literal} th').each( function( ) {
197 if ( CRM.$(this).attr('class') == 'contact_details' ) {
198 columns += '{"sClass": "contact_details"},';
201 columns += '{ "bSortable": false },';
206 columns = columns.substring(0, columns.length - 1 );
207 eval('columns =[' + columns + ']');
209 //load jQuery data table.
210 CRM.$('table#voterRecords-{/literal}{$instanceId}{literal}').dataTable( {
211 "sPaginationType": "full_numbers",
213 "aoColumns" : columns
218 function registerInterview( voterId ) {
220 CRM.$( '#responseErrors' ).hide( ).html( '' );
222 //collect all submitted data.
223 var data = new Object;
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( );
235 //get the values for select.
236 CRM.$('select[id^="'+ fieldName +'"]').each( function( ) {
237 value = CRM.$(this).val( );
238 if (CRM.$(this).attr( 'multiple')) {
242 submittedValues = values.toString().split(",");
244 for (val in submittedValues) {
245 currentVal = submittedValues[val];
246 value[currentVal] = currentVal;
250 data[CRM.$(this).attr('id')] = value;
253 var checkBoxField = 'field['+ voterId +'][custom_';
254 CRM.$('input:checkbox[name^="'+ checkBoxField +'"]').each( function( ) {
256 if (CRM.$(this).is(':checked') == true) value = 1;
257 data[CRM.$(this).attr( 'name' )] = value;
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();
267 allRadios[radioName] = radioName;
269 for (radioName in allRadios) {
270 if (!data.hasOwnProperty(radioName)) data[radioName] = '';
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( );
285 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
286 activityId = eval("surveyActivityIds.activity_id_" + voterId);
287 if (!activityId) return;
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};
298 var dataUrl = {/literal}"{crmURL p='civicrm/campaign/registerInterview' h=0}"{literal}
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( );
308 else if (interview.status == 'fail' && interview.errors) {
310 for (error in interview.errors) {
311 if (interview.errors[error]) errorList = errorList + '<li>' + interview.errors[error] + '</li>';
314 var allErrors = '<i class="crm-i fa-exclamation-triangle crm-i-red"></i> {/literal}{ts}Please correct the following errors in the survey fields below:{/ts}{literal}<ul>' + errorList + '</ul>';
315 CRM.$('#responseErrors').show( ).html(allErrors);
321 function releaseOrReserveVoter(voterId) {
322 if (!voterId) return;
324 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
325 activityId = eval("surveyActivityIds.activity_id_" + voterId);
326 if ( !activityId ) return;
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;
335 isReleaseOrReserve = 1;
338 var data = new Object;
339 data['operation'] = operation;
340 data['isDelete'] = (operation == 'release') ? 1 : 0;
341 data['activity_id'] = activityId;
343 var actUrl = {/literal}
344 "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}"
347 //post data to release / reserve voter.
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}");
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}");
366 CRM.$( '#field_' + voterId + '_is_release_or_reserve' ).val( isReleaseOrReserve );
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);
384 {*include batch copy js js file*}
385 {include file="CRM/common/batchCopy.tpl"}