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