Merge pull request #2495 from civicrm/4.4
[civicrm-core.git] / templates / CRM / Campaign / Form / Search / Petition.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 cj( 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 cj(function() {
127 cj().crmAccordions();
128 });
129
130 {/literal}
131 {* load selector when force *}
132 {if $force and !$buildSelector}
133 {literal}
134 cj( function( ) {
135 searchPetitions( {/literal}'{$qfKey}'{literal} );
136 });
137
138 {/literal}
139 {/if}
140 {literal}
141
142 function searchPetitions( qfKey )
143 {
144 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=petition'}"{literal};
145
146 //lets carry qfKey to retain form session.
147 if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey;
148
149 cj.get( dataUrl, null, function( petitionList ) {
150 cj( '#petitionList' ).html( petitionList );
151
152 //collapse the search form.
153 var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal};
154 cj( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
155 }, 'html' );
156 }
157
158 function loadPetitionList( )
159 {
160 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=petitionList' }"{literal};
161
162 //build the search qill.
163 //get the search criteria.
164 var searchParams = {/literal}{$searchParams}{literal};
165 var campaigns = {/literal}{$petitionCampaigns}{literal};
166
167 var noRecordFoundMsg = '{/literal}{ts escape='js'}No matches found for:{/ts}{literal}';
168 noRecordFoundMsg += '<div class="qill">';
169
170 var count = 0;
171 var searchQill = new Array( );
172 for ( param in searchParams ) {
173 if ( val = cj( '#' + param ).val( ) ) {
174 if ( param == 'petition_campaign_id' ) val = campaigns[val];
175 searchQill[count++] = searchParams[param] + ' : ' + val;
176 }
177 }
178 noRecordFoundMsg += searchQill.join( '<span class="font-italic"> ...AND... </span></div><div class="qill">' );
179
180 cj( '#petitions' ).dataTable({
181 "bFilter" : false,
182 "bAutoWidth" : false,
183 "bProcessing": false,
184 "bLengthChange": false,
185 "aaSorting": [],
186 "aoColumns":[{sClass:'crm-petition-id hiddenElement' },
187 {sClass:'crm-petition-title' },
188 {sClass:'crm-petition-campaign_id hiddenElement' },
189 {sClass:'crm-petition-campaign' },
190 {sClass:'crm-petition-activity_type_id hiddenElement' },
191 {sClass:'crm-petition-activity_type hiddenElement' },
192 {sClass:'crm-petition-is_default' },
193 {sClass:'crm-petition-is_active hiddenElement' },
194 {sClass:'crm-petition-isActive' },
195 {sClass:'crm-petition-action', bSortable:false}
196 ],
197 "sPaginationType": "full_numbers",
198 "sDom" : 'rt<"crm-datatable-pager-bottom"ip>',
199 "bServerSide": true,
200 "bJQueryUI": true,
201 "sAjaxSource": sourceUrl,
202 "asStripClasses" : [ "odd-row", "even-row" ],
203 "oLanguage":{"sEmptyTable" : noRecordFoundMsg,
204 "sZeroRecords" : noRecordFoundMsg },
205 "fnDrawCallback": function() { cj().crmtooltip(); },
206 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
207 //insert the id for each row for enable/disable.
208 var rowId = 'petition_row_' + aData[0];
209 cj(nRow).attr( 'id', rowId );
210 //handled disabled rows.
211 var isActive = Boolean(Number(aData[7]));
212 if ( !isActive ) cj(nRow).addClass( 'disabled' );
213
214 //add id for yes/no column.
215 cj(nRow).children().eq(8).attr( 'id', rowId + '_status' );
216
217 return nRow;
218 },
219
220 "fnServerData": function ( sSource, aoData, fnCallback ) {
221 var dataLength = aoData.length;
222
223 var count = 1;
224 var searchCriteria = new Array( );
225
226 //get the search criteria.
227 var searchParams = {/literal}{$searchParams}{literal};
228 for ( param in searchParams ) {
229 fldName = param;
230 if ( param == 'petition_title' ) fldName = 'title';
231 if ( param == 'petition_campaign_id' ) fldName = 'campaign_id';
232 if ( val = cj( '#' + param ).val( ) ) {
233 aoData[dataLength++] = {name: fldName, value: val};
234 }
235 searchCriteria[count++] = fldName;
236 }
237
238 //do search for petitions.
239 aoData[dataLength++] = {name: 'search_for', value: 'petition'};
240
241 //lets transfer search criteria.
242 aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')};
243
244 cj.ajax( {
245 "dataType": 'json',
246 "type": "POST",
247 "url": sSource,
248 "data": aoData,
249 "success": fnCallback
250 } ); }
251 });
252 }
253
254 </script>
255 {/literal}