commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / templates / CRM / Campaign / Form / Task / Interview.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 ( ($field.data_type eq 'Date') or
159 ( $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 }
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 {literal}
208 <script type="text/javascript">
209 var updateVote = "{/literal}{ts escape='js'}Update Response{/ts}{literal}";
210 var updateVoteforall = "{/literal}{ts escape='js'}Update Responses for All{/ts}{literal}";
211 CRM.$(function($) {
212 var count = 0; var columns='';
213
214 CRM.$('#voterRecords-{/literal}{$instanceId}{literal} th').each( function( ) {
215 if ( CRM.$(this).attr('class') == 'contact_details' ) {
216 columns += '{"sClass": "contact_details"},';
217 }
218 else {
219 columns += '{ "bSortable": false },';
220 }
221 count++;
222 });
223
224 columns = columns.substring(0, columns.length - 1 );
225 eval('columns =[' + columns + ']');
226
227 //load jQuery data table.
228 CRM.$('table#voterRecords-{/literal}{$instanceId}{literal}').dataTable( {
229 "sPaginationType": "full_numbers",
230 "bJQueryUI" : true,
231 "aoColumns" : columns
232 });
233
234 });
235
236 function registerInterview( voterId ) {
237 //reset all errors.
238 CRM.$( '#responseErrors' ).hide( ).html( '' );
239
240 //collect all submitted data.
241 var data = new Object;
242
243 //get the values for common elements.
244 var fieldName = 'field_' + voterId + '_custom_';
245 var specialFieldType = new Array( 'radio', 'checkbox', 'select' );
246 CRM.$( '[id^="'+ fieldName +'"]' ).each( function( ) {
247 fieldType = CRM.$( this ).attr( 'type' );
248 if ( specialFieldType.indexOf( fieldType ) == -1 ) {
249 data[CRM.$(this).attr( 'id' )] = CRM.$( this ).val( );
250 }
251 });
252
253 //get the values for select.
254 CRM.$('select[id^="'+ fieldName +'"]').each( function( ) {
255 value = CRM.$(this).val( );
256 if (CRM.$(this).attr( 'multiple')) {
257 values = value;
258 value = '';
259 if ( values ) {
260 submittedValues = values.toString().split(",");
261 value = new Object;
262 for (val in submittedValues) {
263 currentVal = submittedValues[val];
264 value[currentVal] = currentVal;
265 }
266 }
267 }
268 data[CRM.$(this).attr('id')] = value;
269 });
270
271 var checkBoxField = 'field['+ voterId +'][custom_';
272 CRM.$('input:checkbox[name^="'+ checkBoxField +'"]').each( function( ) {
273 value = '';
274 if (CRM.$(this).is(':checked') == true) value = 1;
275 data[CRM.$(this).attr( 'name' )] = value;
276 });
277
278 var allRadios = new Object;
279 var radioField = 'field['+ voterId +'][custom_';
280 CRM.$('input:radio[name^="'+ radioField +'"]').each( function( ) {
281 radioName = CRM.$(this).attr( 'name' );
282 if (CRM.$(this).is(':checked') == true) {
283 data[radioName] = CRM.$(this).val();
284 }
285 allRadios[radioName] = radioName;
286 });
287 for (radioName in allRadios) {
288 if (!data.hasOwnProperty(radioName)) data[radioName] = '';
289 }
290
291 //carry contact related profile field data.
292 var fieldName = 'field_' + voterId;
293 var checkBoxFieldName = 'field[' + voterId + ']';
294 CRM.$('[id^="'+ fieldName +'"], [id^="'+ checkBoxFieldName +'"]').each(function( ) {
295 fldId = CRM.$(this).attr('id');
296 if (fldId.indexOf('_custom_') == -1 &&
297 fldId.indexOf('_result') == -1 &&
298 fldId.indexOf('_note') == -1 ) {
299 data[fldId] = CRM.$(this).val( );
300 }
301 });
302
303 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
304 activityId = eval("surveyActivityIds.activity_id_" + voterId);
305 if (!activityId) return;
306
307 data['voter_id'] = voterId;
308 data['interviewer_id'] = {/literal}{$interviewerId}{literal};
309 data['activity_type_id'] = {/literal}{$surveyTypeId}{literal};
310 data['activity_id'] = activityId;
311 data['result'] = CRM.$( '#field_' + voterId + '_result' ).val( );
312 data['note'] = CRM.$( '#field_' + voterId + '_note' ).val( );
313 data['surveyTitle'] = {/literal}'{$surveyValues.title|escape:javascript}'{literal};
314 data['survey_id'] = {/literal}'{$surveyValues.id}'{literal};
315
316 var dataUrl = {/literal}"{crmURL p='civicrm/campaign/registerInterview' h=0}"{literal}
317
318 //post data to create interview.
319 CRM.$.post(dataUrl, data, function(interview) {
320 if ( interview.status == 'success' ) {
321 CRM.$("#row_"+voterId+' td.name').attr('class', 'name strikethrough' );
322 CRM.$('#restmsg_vote_' + voterId).fadeIn("slow").fadeOut("slow");
323 CRM.$('#interview_voter_button_' + voterId).html(updateVote);
324 CRM.$('#release_voter_button_' + voterId).hide( );
325 }
326 else if (interview.status == 'fail' && interview.errors) {
327 var errorList = '';
328 for (error in interview.errors) {
329 if (interview.errors[error]) errorList = errorList + '<li>' + interview.errors[error] + '</li>';
330 }
331 if ( errorList ) {
332 var allErrors = '<div class = "icon red-icon ui-icon-alert"></div>Please correct the following errors in the survey fields below:' + '<ul>' + errorList + '</ul>';
333 CRM.$('#responseErrors').show( ).html(allErrors);
334 }
335 }
336 }, 'json');
337 }
338
339 function releaseOrReserveVoter(voterId) {
340 if (!voterId) return;
341
342 var surveyActivityIds = {/literal}{$surveyActivityIds}{literal};
343 activityId = eval("surveyActivityIds.activity_id_" + voterId);
344 if ( !activityId ) return;
345
346 var operation = 'release';
347 var isReleaseOrReserve = CRM.$('#field_' + voterId + '_is_release_or_reserve').val( );
348 if (isReleaseOrReserve == 1) {
349 operation = 'reserve';
350 isReleaseOrReserve = 0;
351 }
352 else {
353 isReleaseOrReserve = 1;
354 }
355
356 var data = new Object;
357 data['operation'] = operation;
358 data['isDelete'] = (operation == 'release') ? 1 : 0;
359 data['activity_id'] = activityId;
360
361 var actUrl = {/literal}
362 "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}"
363 {literal};
364
365 //post data to release / reserve voter.
366 CRM.$.post( actUrl,
367 data,
368 function( response ) {
369 if (response.status == 'success') {
370 if ( operation == 'release' ) {
371 CRM.$( '#interview_voter_button_' + voterId ).hide( );
372 CRM.$( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
373 CRM.$( '#row_' + voterId + ' td.name' ).addClass( 'disabled' );
374 CRM.$( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}reserve{/ts}{literal}" );
375 CRM.$( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Reserve{/ts}{literal}");
376 }
377 else {
378 CRM.$( '#interview_voter_button_' + voterId ).show( );
379 CRM.$( '#restmsg_release_or_reserve' + voterId ).fadeIn( 'slow' ).fadeOut( 'slow' );
380 CRM.$( '#row_' + voterId + ' td.name' ).removeClass( 'disabled' );
381 CRM.$( '#release_voter_button_'+ voterId ).html( "{/literal}{ts escape='js'}release{/ts}{literal}" );
382 CRM.$( '#release_voter_button_' + voterId ).attr('title',"{/literal}{ts escape='js'}Release{/ts}{literal}");
383 }
384 CRM.$( '#field_' + voterId + '_is_release_or_reserve' ).val( isReleaseOrReserve );
385 }
386 },
387 'json');
388 }
389
390 function registerInterviewforall( ) {
391 var Ids = {/literal}{$componentIdsJson}{literal};
392 for (var contactid in Ids) {
393 if (CRM.$('#field_'+ Ids[contactid] +'_result').val()) {
394 registerInterview(Ids[contactid]);
395 CRM.$('#interview_voter_button').html(updateVoteforall);
396 }
397 }
398 }
399
400 </script>
401 {/literal}
402 {*include batch copy js js file*}
403 {include file="CRM/common/batchCopy.tpl"}
404 {/if}
405