Merge pull request #3302 from eileenmcnaughton/code-cleanup
[civicrm-core.git] / templates / CRM / Campaign / Form / Search / Petition.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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 !$hasPetitions}
28 <div class="messages status no-popup">
29 <div class="icon inform-icon"></div> &nbsp;
30 {ts}No petitions found.{/ts}
31 </div>
32
33 <div class="action-link">
34 <a href="{crmURL p='civicrm/petition/add' q='reset=1' h=0 }" class="button"><span><div class="icon add-icon"></div>{ts}Add Petition{/ts}</span></a>
35 </div>
36
37 {elseif $buildSelector}
38
39 {* use to display result set of petition *}
40 <div id="petition-result-set-dialog" class="hiddenElement"></div>
41
42 {* load petition selector *}
43
44 {include file="CRM/common/enableDisableApi.tpl"}
45 {include file="CRM/common/crmeditable.tpl"}
46
47 {literal}
48 <script type="text/javascript">
49 CRM.$(function($) {
50 loadPetitionList( );
51 });
52 </script>
53 {/literal}
54
55 <table id="petitions">
56 <thead>
57 <tr class="columnheader">
58 <th class="hiddenElement">{ts}Petition ID{/ts}</th>
59 <th>{ts}Title{/ts}</th>
60 <th class="hiddenElement">{ts}Campaign ID{/ts}</th>
61 <th>{ts}Campaign{/ts}</th>
62 <th class="hiddenElement">{ts}Petition Type ID{/ts}</th>
63 <th class="hiddenElement">{ts}Petition Type{/ts}</th>
64 <th>{ts}Default?{/ts}</th>
65 <th class="hiddenElement">{ts}Is Active?{/ts}</th>
66 <th>{ts}Active?{/ts}</th>
67 <th></th>
68 </tr>
69 </thead>
70 <tbody></tbody>
71 </table>
72
73 {else}
74
75 <div class="action-link">
76 <a href="{crmURL p='civicrm/petition/add' q='reset=1' h=0 }" class="button"><span><div class="icon add-icon"></div>{ts}Add Petition{/ts}</span></a>
77 </div>
78
79 {* build search form here *}
80
81 {* Search form and results for petitions *}
82 <div class="crm-block crm-form-block crm-search-form-block">
83
84 {assign var='searchForm' value="search_form_$searchFor"}
85
86 <div id="{$searchForm}" class="crm-accordion-wrapper crm-petition_search_form-accordion {if $force and !$buildSelector}collapsed{/if}">
87 <div class="crm-accordion-header">
88 {ts}Search Petitions{/ts}
89 </div><!-- /.crm-accordion-header -->
90
91 <div class="crm-accordion-body">
92 {strip}
93 <table class="form-layout-compressed">
94 <tr>
95 <td>{$form.petition_title.label}<br />
96 {$form.petition_title.html}
97 </td>
98 <td>{$form.petition_campaign_id.label}<br />
99 {$form.petition_campaign_id.html}
100 </td>
101 </tr>
102 <tr>
103 <td colspan="2">
104 {if $context eq 'search'}
105 {$form.buttons.html}
106 {else}
107 <a class="searchPetition button" style="float:left;" href="#" title={ts}Search{/ts} onClick="searchPetitions( '{$qfKey}' );return false;">{ts}Search{/ts}</a>
108 {/if}
109 </td>
110 </tr>
111 </table>
112 {/strip}
113 </div>
114 </div>
115 </div>
116 {* search form ends here *}
117
118 <div id='petitionList'></div>
119
120 {/if} {* end of search form build *}
121
122
123 {literal}
124 <script type="text/javascript">
125
126 {/literal}
127 {* load selector when force *}
128 {if $force and !$buildSelector}
129 {literal}
130 CRM.$(function($) {
131 searchPetitions( {/literal}'{$qfKey}'{literal} );
132 });
133
134 {/literal}
135 {/if}
136 {literal}
137
138 function searchPetitions( qfKey )
139 {
140 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=petition'}"{literal};
141
142 //lets carry qfKey to retain form session.
143 if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey;
144
145 cj.get( dataUrl, null, function( petitionList ) {
146 cj( '#petitionList' ).html( petitionList ).trigger('crmLoad');
147
148 //collapse the search form.
149 var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal};
150 cj( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
151 }, 'html' );
152 }
153
154 function loadPetitionList( )
155 {
156 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=petitionList' }"{literal};
157
158 //build the search qill.
159 //get the search criteria.
160 var searchParams = {/literal}{$searchParams}{literal};
161 var campaigns = {/literal}{$petitionCampaigns}{literal};
162
163 var noRecordFoundMsg = '{/literal}{ts escape='js'}No matches found for:{/ts}{literal}';
164 noRecordFoundMsg += '<div class="qill">';
165
166 var count = 0;
167 var searchQill = new Array( );
168 for ( param in searchParams ) {
169 if ( val = cj( '#' + param ).val( ) ) {
170 if ( param == 'petition_campaign_id' ) val = campaigns[val];
171 searchQill[count++] = searchParams[param] + ' : ' + val;
172 }
173 }
174 noRecordFoundMsg += searchQill.join( '<span class="font-italic"> ...AND... </span></div><div class="qill">' );
175
176 cj( '#petitions' ).dataTable({
177 "bFilter" : false,
178 "bAutoWidth" : false,
179 "bProcessing": false,
180 "bLengthChange": false,
181 "aaSorting": [],
182 "aoColumns":[{sClass:'crm-petition-id hiddenElement' },
183 {sClass:'crm-petition-title' },
184 {sClass:'crm-petition-campaign_id hiddenElement' },
185 {sClass:'crm-petition-campaign' },
186 {sClass:'crm-petition-activity_type_id hiddenElement' },
187 {sClass:'crm-petition-activity_type hiddenElement' },
188 {sClass:'crm-petition-is_default' },
189 {sClass:'crm-petition-is_active hiddenElement' },
190 {sClass:'crm-petition-isActive' },
191 {sClass:'crm-petition-action', bSortable:false}
192 ],
193 "sPaginationType": "full_numbers",
194 "sDom" : 'rt<"crm-datatable-pager-bottom"ip>',
195 "bServerSide": true,
196 "bJQueryUI": true,
197 "sAjaxSource": sourceUrl,
198 "asStripClasses" : [ "odd-row", "even-row" ],
199 "oLanguage":{"sEmptyTable" : noRecordFoundMsg,
200 "sZeroRecords" : noRecordFoundMsg },
201 "fnDrawCallback": function() { cj().crmtooltip(); },
202 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
203 //insert the id for each row for enable/disable.
204 var rowId = 'petition_row_' + aData[0];
205 cj(nRow).attr( 'id', rowId );
206 //handled disabled rows.
207 var isActive = Boolean(Number(aData[7]));
208 if ( !isActive ) cj(nRow).addClass( 'disabled' );
209
210 //add id for yes/no column.
211 cj(nRow).children().eq(8).attr( 'id', rowId + '_status' );
212
213 return nRow;
214 },
215
216 "fnServerData": function ( sSource, aoData, fnCallback ) {
217 var dataLength = aoData.length;
218
219 var count = 1;
220 var searchCriteria = new Array( );
221
222 //get the search criteria.
223 var searchParams = {/literal}{$searchParams}{literal};
224 for ( param in searchParams ) {
225 fldName = param;
226 if ( param == 'petition_title' ) fldName = 'title';
227 if ( param == 'petition_campaign_id' ) fldName = 'campaign_id';
228 if ( val = cj( '#' + param ).val( ) ) {
229 aoData[dataLength++] = {name: fldName, value: val};
230 }
231 searchCriteria[count++] = fldName;
232 }
233
234 //do search for petitions.
235 aoData[dataLength++] = {name: 'search_for', value: 'petition'};
236
237 //lets transfer search criteria.
238 aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')};
239
240 cj.ajax( {
241 "dataType": 'json',
242 "type": "POST",
243 "url": sSource,
244 "data": aoData,
245 "success": fnCallback
246 } ); }
247 });
248 }
249
250 </script>
251 {/literal}