Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
3 | | CiviCRM version 4.3 | | |
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 !$hasCampaigns} | |
55a66cac KJ |
28 | <div class="messages status no-popup"> |
29 | <div class="icon inform-icon"></div> | |
30 | | |
31 | {ts}No campaigns found.{/ts} | |
32 | </div> | |
33 | <div class="action-link"> | |
34 | <a href="{crmURL p='civicrm/campaign/add' q='reset=1' h=0 }" class="button"><span><div | |
35 | class="icon add-icon"></div>{ts}Add Campaign{/ts}</span></a> | |
36 | </div> | |
6a488035 TO |
37 | {elseif $buildSelector} |
38 | ||
55a66cac KJ |
39 | {* load campaign selector *} |
40 | ||
41 | {include file="CRM/common/enableDisable.tpl"} | |
42 | ||
43 | {literal} | |
44 | <script type="text/javascript"> | |
45 | cj(function () { | |
46 | loadCampaignList(); | |
47 | }); | |
48 | </script> | |
49 | {/literal} | |
50 | <table id="campaigns"> | |
51 | <thead> | |
52 | <tr class="columnheader"> | |
53 | <th class="hiddenElement">{ts}Campaign ID{/ts}</th> | |
54 | <th class="hiddenElement">{ts}Campaign Name{/ts}</th> | |
6a488035 | 55 | <th>{ts}Title{/ts}</th> |
55a66cac KJ |
56 | <th>{ts}Description{/ts}</th> |
57 | <th>{ts}Start Date{/ts}</th> | |
58 | <th>{ts}End Date{/ts}</th> | |
6a488035 TO |
59 | <th class="hiddenElement">{ts}Type ID{/ts}</th> |
60 | <th>{ts}Type{/ts}</th> | |
61 | <th class="hiddenElement">{ts}Status ID{/ts}</th> | |
55a66cac | 62 | <th>{ts}Status{/ts}</th> |
6a488035 | 63 | <th class="hiddenElement">{ts}Is Active?{/ts}</th> |
55a66cac | 64 | <th>{ts}Active?{/ts}</th> |
6a488035 | 65 | <th></th> |
55a66cac KJ |
66 | </tr> |
67 | </thead> | |
68 | <tbody></tbody> | |
69 | </table> | |
6a488035 | 70 | {else} |
55a66cac KJ |
71 | <div class="action-link"> |
72 | <a href="{crmURL p='civicrm/campaign/add' q='reset=1' h=0 }" class="button"><span><div | |
73 | class="icon add-icon"></div>{ts}Add Campaign{/ts}</span></a> | |
74 | </div> | |
75 | {* build search form here *} | |
6a488035 | 76 | |
55a66cac KJ |
77 | {* Search form and results for campaigns *} |
78 | <div class="crm-block crm-form-block crm-search-form-block"> | |
6a488035 TO |
79 | |
80 | {assign var='searchForm' value="search_form_$searchFor"} | |
81 | ||
55a66cac KJ |
82 | <div id="{$searchForm}" |
83 | class="crm-accordion-wrapper crm-campaign_search_form-accordion {if $force and !$buildSelector}collapsed{/if}"> | |
6a488035 | 84 | <div class="crm-accordion-header"> |
55a66cac KJ |
85 | {ts}Search Campaigns{/ts} |
86 | </div> | |
87 | <!-- /.crm-accordion-header --> | |
6a488035 TO |
88 | |
89 | <div class="crm-accordion-body"> | |
55a66cac KJ |
90 | {strip} |
91 | <table class="form-layout-compressed"> | |
92 | <tr> | |
93 | <td>{$form.campaign_title.label}<br/> | |
94 | {$form.campaign_title.html} | |
95 | </td> | |
96 | <td> | |
97 | {$form.description.label}<br/> | |
98 | {$form.description.html|crmAddClass:huge} | |
99 | </td> | |
100 | </tr> | |
101 | ||
102 | <tr> | |
103 | <td>{$form.start_date.label}<br/> | |
104 | {include file="CRM/common/jcalendar.tpl" elementName=start_date} | |
105 | </td> | |
106 | <td>{$form.end_date.label}<br/> | |
107 | {include file="CRM/common/jcalendar.tpl" elementName=end_date} | |
108 | </td> | |
109 | </tr> | |
110 | ||
111 | <tr> | |
112 | <td>{$form.campaign_type_id.label}<br/> | |
113 | {$form.campaign_type_id.html} | |
114 | </td> | |
115 | <td>{$form.status_id.label}<br/> | |
116 | {$form.status_id.html} | |
117 | </td> | |
118 | </tr> | |
119 | ||
120 | <tr> | |
121 | <td colspan="2"> | |
122 | {if $context eq 'search'} | |
123 | {$form.buttons.html} | |
124 | {else} | |
125 | <a class="searchCampaign button" style="float:left;" href="#" title={ts}Search{/ts} | |
126 | onClick="searchCampaigns( '{$qfKey}' );return false;">{ts}Search{/ts}</a> | |
127 | {/if} | |
128 | </td> | |
129 | </tr> | |
130 | </table> | |
131 | {/strip} | |
6a488035 TO |
132 | </div> |
133 | </div> | |
134 | </div> | |
55a66cac KJ |
135 | {* search form ends here *} |
136 | <div id='campaignList'></div> | |
6a488035 TO |
137 | {/if} {* end of search form build *} |
138 | ||
139 | ||
140 | {literal} | |
141 | <script type="text/javascript"> | |
142 | ||
55a66cac | 143 | cj(function () { |
6a488035 | 144 | cj().crmAccordions(); |
55a66cac KJ |
145 | }); |
146 | ||
147 | {/literal} | |
148 | {* load selector when force *} | |
149 | {if $force and !$buildSelector} | |
150 | {literal} | |
151 | cj(function () { | |
152 | searchCampaigns({/literal}'{$qfKey}'{literal}); | |
153 | }); | |
154 | ||
155 | {/literal} | |
156 | {/if} | |
157 | {literal} | |
158 | ||
159 | function searchCampaigns(qfKey) { | |
160 | var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=campaign'}"{literal}; | |
161 | ||
162 | //lets carry qfKey to retain form session. | |
163 | if (qfKey) { | |
164 | dataUrl = dataUrl + '&qfKey=' + qfKey; | |
165 | } | |
166 | ||
167 | cj.get(dataUrl, null, function (campaignList) { | |
168 | cj('#campaignList').html(campaignList); | |
169 | ||
170 | //collapse the search form. | |
171 | var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal}; | |
172 | cj(searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle(); | |
173 | }, 'html'); | |
6a488035 | 174 | } |
55a66cac KJ |
175 | |
176 | function loadCampaignList() { | |
177 | var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=campaignList' }"{literal}; | |
178 | ||
179 | //build the search qill. | |
180 | //get the search criteria. | |
181 | var searchParams = {/literal}{$searchParams}{literal}; | |
182 | var campaignTypes = {/literal}{$campaignTypes}{literal}; | |
183 | var campaignStatus = {/literal}{$campaignStatus}{literal}; | |
184 | var noRecordFoundMsg = '{/literal}{ts escape='js'}No matches found for:{/ts}{literal}'; | |
185 | noRecordFoundMsg += '<div class="qill">'; | |
186 | ||
187 | var count = 0; | |
188 | var searchQill = new Array(); | |
189 | for (param in searchParams) { | |
190 | if (val = cj('#' + param).val()) { | |
191 | if (param == 'status_id') { | |
192 | val = campaignStatus[val]; | |
193 | } | |
194 | if (param == 'campaign_type_id') { | |
195 | val = campaignTypes[val]; | |
196 | } | |
197 | searchQill[count++] = searchParams[param] + ' : ' + val; | |
198 | } | |
199 | } | |
200 | noRecordFoundMsg += searchQill.join('<span class="font-italic"> ...AND... </span></div><div class="qill">'); | |
201 | ||
202 | cj('#campaigns').dataTable({ | |
203 | "bFilter": false, | |
204 | "bAutoWidth": false, | |
205 | "bProcessing": false, | |
206 | "bLengthChange": false, | |
207 | "aaSorting": [], | |
208 | "aoColumns": [ | |
209 | {sClass: 'crm-campaign-id hiddenElement' }, | |
210 | {sClass: 'crm-campaign-name hiddenElement' }, | |
211 | {sClass: 'crm-campaign-title' }, | |
212 | {sClass: 'crm-campaign-description' }, | |
213 | {sClass: 'crm-campaign-start_date' }, | |
214 | {sClass: 'crm-campaign-end_date' }, | |
215 | {sClass: 'crm-campaign-campaign-type_id hiddenElement' }, | |
216 | {sClass: 'crm-campaign-campaign-type' }, | |
217 | {sClass: 'crm-campaign-campaign-status_id hiddenElement' }, | |
218 | {sClass: 'crm-campaign-campaign-status' }, | |
219 | {sClass: 'crm-campaign-campaign-is_active hiddenElement' }, | |
220 | {sClass: 'crm-campaign-campaign-isAactive' }, | |
221 | {sClass: 'crm-campaign-action', bSortable: false} | |
222 | ], | |
223 | "sPaginationType": "full_numbers", | |
224 | "sDom": 'rt<"crm-datatable-pager-bottom"ip>', | |
225 | "bServerSide": true, | |
226 | "bJQueryUI": true, | |
227 | "sAjaxSource": sourceUrl, | |
228 | "asStripClasses": ["odd-row", "even-row"], | |
229 | "oLanguage": {"sEmptyTable": noRecordFoundMsg, | |
230 | "sZeroRecords": noRecordFoundMsg }, | |
231 | "fnDrawCallback": function () { | |
232 | cj().crmtooltip(); | |
233 | }, | |
234 | "fnRowCallback": function (nRow, aData, iDisplayIndex) { | |
235 | //insert the id for each row for enable/disable. | |
236 | var rowId = 'campaign_row_' + aData[0]; | |
237 | cj(nRow).attr('id', rowId); | |
238 | //handled disabled rows. | |
239 | var isActive = Boolean(Number(aData[10])); | |
240 | if (!isActive) { | |
241 | cj(nRow).addClass('disabled'); | |
242 | } | |
243 | ||
244 | //add id for yes/no column. | |
245 | cj(nRow).children().eq(11).attr('id', rowId + '_status'); | |
246 | ||
247 | return nRow; | |
248 | }, | |
249 | ||
250 | "fnServerData": function (sSource, aoData, fnCallback) { | |
251 | var dataLength = aoData.length; | |
252 | ||
253 | var count = 1; | |
254 | var searchCriteria = new Array(); | |
255 | ||
256 | //get the search criteria. | |
257 | var searchParams = {/literal}{$searchParams}{literal}; | |
258 | for (param in searchParams) { | |
6a488035 | 259 | fldName = param; |
55a66cac KJ |
260 | if (param == 'campaign_title') { |
261 | fldName = 'title'; | |
262 | } | |
263 | if (val = cj('#' + param).val()) { | |
6a488035 TO |
264 | aoData[dataLength++] = {name: fldName, value: val}; |
265 | } | |
266 | searchCriteria[count++] = fldName; | |
55a66cac KJ |
267 | } |
268 | ||
269 | //do search for campaigns. | |
270 | aoData[dataLength++] = {name: 'search_for', value: 'campaign'}; | |
271 | ||
272 | //lets transfer search criteria. | |
273 | aoData[dataLength++] = {name: 'searchCriteria', value: searchCriteria.join(',')}; | |
274 | ||
275 | cj.ajax({ | |
276 | "dataType": 'json', | |
277 | "type": "POST", | |
278 | "url": sSource, | |
279 | "data": aoData, | |
280 | "success": fnCallback | |
281 | }); | |
282 | } | |
283 | }); | |
284 | } | |
6a488035 TO |
285 | |
286 | </script> | |
287 | {/literal} |