Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
27 | {if $errorMessages} | |
28 | <div class="messages status crm-error no-popup"> | |
29 | <div class="icon inform-icon"></div> | |
30 | <ul> | |
31 | {foreach from=$errorMessages item=errorMsg} | |
32 | <li>{ts}{$errorMsg}{/ts}</li> | |
33 | {/foreach} | |
34 | </ul> | |
35 | </div> | |
36 | </div> | |
37 | ||
38 | {elseif $buildSelector} | |
39 | ||
40 | {* load voter selector for reserve/release *} | |
41 | ||
42 | {literal} | |
43 | <script type="text/javascript"> | |
3cc60a06 | 44 | CRM.$(function($) { |
6a488035 TO |
45 | loadVoterList( ); |
46 | }); | |
47 | </script> | |
48 | {/literal} | |
49 | ||
24e7a504 | 50 | <table class="gotvVoterRecords"> |
6a488035 TO |
51 | <thead> |
52 | <tr class="columnheader"> | |
53 | <th></th> | |
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> | |
63 | {else} | |
64 | <th>{ts}Is Reserved?{/ts}</th> | |
65 | {/if} | |
66 | </tr> | |
67 | </thead> | |
68 | <tbody></tbody> | |
69 | </table> | |
70 | ||
71 | {else} | |
72 | ||
73 | {* build search form *} | |
74 | {include file='CRM/Campaign/Form/Search/Common.tpl' context='gotv'} | |
75 | <div id='voterList'></div> | |
76 | ||
77 | {/if} {* end of search form build *} | |
78 | ||
79 | ||
80 | {literal} | |
81 | <script type="text/javascript"> | |
82 | ||
83 | {/literal} | |
84 | {* load selector when force *} | |
85 | {if $force and !$buildSelector} | |
86 | {literal} | |
3cc60a06 | 87 | CRM.$(function($) { |
6a488035 TO |
88 | searchVoters( {/literal}'{$qfKey}'{literal} ); |
89 | }); | |
90 | ||
91 | {/literal} | |
92 | {/if} | |
93 | {literal} | |
94 | ||
95 | function searchVoters( qfKey ) | |
96 | { | |
97 | var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4'}"{literal}; | |
98 | ||
99 | //carry survey and interviewer id, | |
100 | //might be helpful if user jump from current tab to interview tab. | |
2c68626a DJ |
101 | var surveyId = CRM.$( '#campaign_survey_id' ).val(); |
102 | var interviewerId = CRM.$( '#survey_interviewer_id' ).val(); | |
6a488035 TO |
103 | if ( surveyId ) dataUrl = dataUrl + '&sid=' + surveyId; |
104 | if ( interviewerId ) dataUrl = dataUrl + '&cid=' + interviewerId; | |
105 | ||
106 | //lets carry qfKey to retain form session. | |
107 | if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey; | |
108 | ||
2c68626a DJ |
109 | CRM.$.get( dataUrl, null, function( voterList ) { |
110 | CRM.$( '#voterList' ).html( voterList ).trigger('crmLoad'); | |
6a488035 TO |
111 | |
112 | //collapse the search form. | |
113 | var searchFormName = '#search_form_' + {/literal}'{$searchVoterFor}'{literal}; | |
2c68626a | 114 | CRM.$( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle(); |
6a488035 TO |
115 | }, 'html' ); |
116 | } | |
117 | ||
118 | function loadVoterList( ) | |
119 | { | |
120 | var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=voterList' }"{literal}; | |
121 | ||
122 | var searchVoterFor = {/literal}'{$searchVoterFor}'{literal}; | |
483a3659 | 123 | CRM.$( 'table.gotvVoterRecords', 'form#{/literal}{$form.formName}{literal}').dataTable({ |
6a488035 TO |
124 | "bFilter" : false, |
125 | "bAutoWidth" : false, | |
126 | "bProcessing": true, | |
127 | "bJQueryUI" : true, | |
128 | "aaSorting": [[0,''],[1,'asc'], [2,'asc'], [3,'asc'], [4,'asc'], [5,'asc'] ], | |
129 | "aoColumns":[{bSortable:false},{sClass:""},{sClass:""},{sClass:""},{sClass:""},{sClass:""},{bSortable:false}], | |
130 | "sPaginationType": "full_numbers", | |
131 | "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', | |
132 | "bServerSide": true, | |
133 | "sAjaxSource": sourceUrl, | |
2c68626a | 134 | "fnDrawCallback": function() { CRM.$().crmtooltip(); }, |
6a488035 TO |
135 | |
136 | "fnServerData": function ( sSource, aoData, fnCallback ) { | |
137 | var dataLength = aoData.length; | |
138 | ||
139 | var count = 1; | |
ae8f569f | 140 | var searchCriteria = ['campaign_search_voter_for']; |
6a488035 TO |
141 | |
142 | //get the search criteria. | |
143 | var searchParams = {/literal}{$searchParams}{literal}; | |
144 | for ( param in searchParams ) { | |
2c68626a | 145 | if ( val = CRM.$( '#' + param ).val( ) ) { |
6a488035 TO |
146 | aoData[dataLength++] = {name: param , value: val }; |
147 | } | |
148 | searchCriteria[count++] = param; | |
149 | } | |
150 | ||
151 | //do search to reserve voters. | |
152 | aoData[dataLength++] = {name: 'campaign_search_voter_for', value: searchVoterFor}; | |
153 | ||
154 | //lets transfer search criteria. | |
155 | aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')}; | |
156 | ||
2c68626a | 157 | CRM.$.ajax( { |
6a488035 TO |
158 | "dataType": 'json', |
159 | "type": "POST", | |
160 | "url": sSource, | |
161 | "data": aoData, | |
162 | "success": fnCallback | |
163 | } ); } | |
164 | }); | |
165 | } | |
166 | ||
167 | function processVoterData( element, operation ) | |
168 | { | |
169 | ||
170 | var data = new Object; | |
171 | if ( !operation ) return; | |
172 | ||
173 | var data = new Object; | |
174 | if ( operation == 'release' ) { | |
175 | data['operation'] = operation; | |
2c68626a DJ |
176 | data['activity_id'] = CRM.$( element ).val( ); |
177 | data['isDelete'] = CRM.$( element ).prop('checked') ? 1:0; | |
6a488035 | 178 | } else if ( operation == 'reserve' ) { |
2c68626a | 179 | var interviewerId = CRM.$( '#survey_interviewer_id' ).val( ); |
6a488035 | 180 | data['operation'] = operation; |
2c68626a DJ |
181 | data['source_record_id'] = CRM.$( '#campaign_survey_id' ).val( ); |
182 | data['target_contact_id'] = CRM.$( element ).val( ); | |
6a488035 TO |
183 | data['source_contact_id'] = interviewerId; |
184 | data['assignee_contact_id'] = interviewerId; | |
2c68626a | 185 | data['isReserved'] = CRM.$( element ).prop('checked') ? 1:0; |
6a488035 TO |
186 | } else if ( operation == 'gotv' ) { |
187 | data['operation'] = operation; | |
2c68626a DJ |
188 | data['activity_id'] = CRM.$( element ).val( ); |
189 | data['hasVoted'] = CRM.$( element ).prop('checked') ? 1: 0; | |
6a488035 TO |
190 | } |
191 | data['surveyTitle'] = {/literal}'{$surveyTitle|escape:javascript}'{literal}; | |
192 | ||
193 | var actUrl = {/literal} | |
194 | "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=processVoterData'}" | |
195 | {literal}; | |
196 | ||
197 | //post data to save voter as voted/non voted. | |
2c68626a | 198 | CRM.$.post( actUrl, |
6a488035 TO |
199 | data, |
200 | function( response ) { | |
201 | if ( response.status == 'success' ) { | |
2c68626a DJ |
202 | var msgId = '#success_msg_' + CRM.$( element ).val( ); |
203 | CRM.$( msgId ).fadeIn('slow').fadeOut('slow'); | |
6a488035 TO |
204 | if ( operation == 'release' ) { |
205 | msg = '{/literal}{ts escape='js'}Save as voted.{/ts}{literal}'; | |
2c68626a | 206 | var isDeleted = CRM.$( element ).prop('checked') ? 1:0; |
6a488035 TO |
207 | if ( !isDeleted ) msg = '{/literal}{ts escape='js'}Save as non voted.{/ts}{literal}'; |
208 | } else if ( operation == 'gotv' ) { | |
209 | msg = '{/literal}{ts escape='js'}Vote Recorded.{/ts}{literal}'; | |
2c68626a DJ |
210 | var hasVoted = CRM.$( element ).prop('checked') ? 1:0; |
211 | var trObject = CRM.$( '[id^="survey_activity['+ CRM.$( element ).val() +']"]' ).parents('tr' ); | |
6a488035 TO |
212 | var methodName = 'addClass'; |
213 | if ( !hasVoted ) { | |
214 | msg = '{/literal}{ts escape='js'}Vote Cancelled.{/ts}{literal}'; | |
215 | methodName = 'removeClass'; | |
216 | } | |
217 | eval( 'trObject.' + methodName + "( 'name disabled' )" ); | |
218 | } else if ( operation == 'reserve' ) { | |
2c68626a | 219 | if ( CRM.$( element ).prop('checked') ) { |
6a488035 TO |
220 | msg = '{/literal}{ts escape='js'}Reserved.{/ts}{literal}'; |
221 | } else { | |
222 | msg = '{/literal}{ts escape='js'}Released.{/ts}{literal}'; | |
223 | } | |
224 | } | |
2c68626a | 225 | CRM.$( msgId ).html( msg ); |
6a488035 TO |
226 | } |
227 | }, 'json' ); | |
228 | ||
229 | } | |
230 | ||
231 | </script> | |
232 | {/literal} |