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