2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 <div class="messages status crm-error no-popup">
29 <div class="icon inform-icon"></div>
31 {foreach from=$errorMessages item=errorMsg}
32 <li>{ts}{$errorMsg}{/ts}</li>
38 {elseif $buildSelector}
40 {* load voter selector for reserve/release *}
43 <script type="text/javascript">
50 <table class="gotvVoterRecords">
52 <tr class="columnheader">
54 <th>{ts}Name{/ts}</th>
55 <th>{ts}Street Address{/ts}</th>
56 <th>{ts}Street Name{/ts}</th>
57 <th>{ts}Street Number{/ts}</th>
58 <th>{ts}Street Unit{/ts}</th>
59 {if $searchVoterFor eq 'release'}
60 <th>{ts}Is Interview Conducted?{/ts}</th>
61 {elseif $searchVoterFor eq 'gotv'}
62 <th>{ts}Voted?{/ts}</th>
64 <th>{ts}Is Reserved?{/ts}</th>
73 {* build search form *}
74 {include file='CRM/Campaign/Form/Search/Common.tpl' context='gotv'}
75 <div class="crm-block crm-form-block crm-search-form-block">
76 <div id='voterList'></div>
79 {/if} {* end of search form build *}
83 <script type="text/javascript">
86 {* load selector when force *}
87 {if $force and !$buildSelector}
90 searchVoters( {/literal}'{$qfKey}'{literal} );
97 function searchVoters( qfKey )
99 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4'}"{literal};
101 //carry survey and interviewer id,
102 //might be helpful if user jump from current tab to interview tab.
103 var surveyId = CRM.$( '#campaign_survey_id' ).val();
104 var interviewerId = CRM.$( '#survey_interviewer_id' ).val();
105 if ( surveyId ) dataUrl = dataUrl + '&sid=' + surveyId;
106 if ( interviewerId ) dataUrl = dataUrl + '&cid=' + interviewerId;
108 //lets carry qfKey to retain form session.
109 if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey;
111 CRM.$.get( dataUrl, null, function( voterList ) {
112 CRM.$( '#voterList' ).html( voterList ).trigger('crmLoad');
114 //collapse the search form.
115 var searchFormName = '#search_form_' + {/literal}'{$searchVoterFor}'{literal};
116 CRM.$( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
120 function loadVoterList( )
122 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=voterList' }"{literal};
124 var searchVoterFor = {/literal}'{$searchVoterFor}'{literal};
125 CRM.$( 'table.gotvVoterRecords', 'form.{/literal}{$form.formClass}{literal}').dataTable({
127 "bAutoWidth" : false,
130 "aaSorting": [[0,''],[1,'asc'], [2,'asc'], [3,'asc'], [4,'asc'], [5,'asc'] ],
131 "aoColumns":[{bSortable:false},{sClass:""},{sClass:""},{sClass:""},{sClass:""},{sClass:""},{bSortable:false}],
132 "sPaginationType": "full_numbers",
133 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
135 "sAjaxSource": sourceUrl,
137 "fnServerData": function ( sSource, aoData, fnCallback ) {
138 var dataLength = aoData.length;
141 var searchCriteria = ['campaign_search_voter_for'];
143 //get the search criteria.
144 var searchParams = {/literal}{$searchParams}{literal};
145 for ( param in searchParams ) {
146 if ( val = CRM.$( '#' + param ).val( ) ) {
147 aoData[dataLength++] = {name: param , value: val };
149 searchCriteria[count++] = param;
152 //do search to reserve voters.
153 aoData[dataLength++] = {name: 'campaign_search_voter_for', value: searchVoterFor};
155 //lets transfer search criteria.
156 aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')};
163 "success": fnCallback
168 function processVoterData( element, operation )
171 var data = new Object;
172 if ( !operation ) return;
174 var data = new Object;
175 if ( operation == 'release' ) {
176 data['operation'] = operation;
177 data['activity_id'] = CRM.$( element ).val( );
178 data['isDelete'] = CRM.$( element ).prop('checked') ? 1:0;
179 } else if ( operation == 'reserve' ) {
180 var interviewerId = CRM.$( '#survey_interviewer_id' ).val( );
181 data['operation'] = operation;
182 data['source_record_id'] = CRM.$( '#campaign_survey_id' ).val( );
183 data['target_contact_id'] = CRM.$( element ).val( );
184 data['source_contact_id'] = interviewerId;
185 data['assignee_contact_id'] = interviewerId;
186 data['isReserved'] = CRM.$( element ).prop('checked') ? 1:0;
187 } else if ( operation == 'gotv' ) {
188 data['operation'] = operation;
189 data['activity_id'] = CRM.$( element ).val( );
190 data['hasVoted'] = CRM.$( element ).prop('checked') ? 1: 0;
192 data['surveyTitle'] = {/literal}'{$surveyTitle|escape:javascript}'{literal};
194 var actUrl = {/literal}
195 "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}"
198 //post data to save voter as voted/non voted.
201 function( response ) {
202 if ( response.status == 'success' ) {
203 var msgId = '#success_msg_' + CRM.$( element ).val( );
204 CRM.$( msgId ).fadeIn('slow').fadeOut('slow');
205 if ( operation == 'release' ) {
206 msg = '{/literal}{ts escape='js'}Save as voted.{/ts}{literal}';
207 var isDeleted = CRM.$( element ).prop('checked') ? 1:0;
208 if ( !isDeleted ) msg = '{/literal}{ts escape='js'}Save as non voted.{/ts}{literal}';
209 } else if ( operation == 'gotv' ) {
210 msg = '{/literal}{ts escape='js'}Vote Recorded.{/ts}{literal}';
211 var hasVoted = CRM.$( element ).prop('checked') ? 1:0;
212 var trObject = CRM.$( '[id^="survey_activity['+ CRM.$( element ).val() +']"]' ).parents('tr' );
213 var methodName = 'addClass';
215 msg = '{/literal}{ts escape='js'}Vote Cancelled.{/ts}{literal}';
216 methodName = 'removeClass';
218 eval( 'trObject.' + methodName + "( 'name disabled' )" );
219 } else if ( operation == 'reserve' ) {
220 if ( CRM.$( element ).prop('checked') ) {
221 msg = '{/literal}{ts escape='js'}Reserved.{/ts}{literal}';
223 msg = '{/literal}{ts escape='js'}Released.{/ts}{literal}';
226 CRM.$( msgId ).html( msg );