Ian province abbreviation patch - issue 724
[civicrm-core.git] / templates / CRM / Campaign / Form / Search / Campaign.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 &nbsp;
1eba7e53 31 {ts}None found.{/ts}
55a66cac
KJ
32 </div>
33 <div class="action-link">
34 <a href="{crmURL p='civicrm/campaign/add' q='reset=1' h=0 }" class="button"><span><div
52604b19 35 class="icon ui-icon-circle-plus"></div>{ts}Add Campaign{/ts}</span></a>
55a66cac 36 </div>
6a488035
TO
37{elseif $buildSelector}
38
55a66cac
KJ
39{* load campaign selector *}
40
4d17a233 41 {include file="CRM/common/enableDisableApi.tpl"}
55a66cac
KJ
42
43 {literal}
44 <script type="text/javascript">
3cc60a06 45 CRM.$(function($) {
55a66cac
KJ
46 loadCampaignList();
47 });
48 </script>
49 {/literal}
24e7a504 50 <table class="campaigns">
55a66cac
KJ
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
52604b19 73 class="icon ui-icon-circle-plus"></div>{ts}Add Campaign{/ts}</span></a>
55a66cac
KJ
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} &nbsp;
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>
da6cc247
TM
118 <td>{$form.is_active.label}<br/>
119 {$form.is_active.html}
120 </td>
55a66cac
KJ
121 </tr>
122
123 <tr>
124 <td colspan="2">
125 {if $context eq 'search'}
126 {$form.buttons.html}
127 {else}
e141e20e 128 <a class="searchCampaign button" style="float:left;" href="#" title="{ts}Search{/ts}"
55a66cac
KJ
129 onClick="searchCampaigns( '{$qfKey}' );return false;">{ts}Search{/ts}</a>
130 {/if}
131 </td>
132 </tr>
133 </table>
134 {/strip}
6a488035
TO
135 </div>
136 </div>
137 </div>
55a66cac
KJ
138{* search form ends here *}
139 <div id='campaignList'></div>
6a488035
TO
140{/if} {* end of search form build *}
141
142
143{literal}
144<script type="text/javascript">
b633f8bd 145(function($) {
6a488035 146
b633f8bd 147 window.searchCampaigns = function searchCampaigns(qfKey) {
55a66cac
KJ
148 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=campaign'}"{literal};
149
150 //lets carry qfKey to retain form session.
151 if (qfKey) {
152 dataUrl = dataUrl + '&qfKey=' + qfKey;
153 }
154
b633f8bd
CW
155 $.get(dataUrl, null, function (campaignList) {
156 $('#campaignList').html(campaignList).trigger('crmLoad');
55a66cac
KJ
157
158 //collapse the search form.
159 var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal};
b633f8bd 160 $(searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
55a66cac 161 }, 'html');
b633f8bd 162 };
55a66cac 163
b633f8bd 164 window.loadCampaignList = function() {
55a66cac
KJ
165 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=campaignList' }"{literal};
166
167 //build the search qill.
168 //get the search criteria.
169 var searchParams = {/literal}{$searchParams}{literal};
170 var campaignTypes = {/literal}{$campaignTypes}{literal};
171 var campaignStatus = {/literal}{$campaignStatus}{literal};
172 var noRecordFoundMsg = '{/literal}{ts escape='js'}No matches found for:{/ts}{literal}';
173 noRecordFoundMsg += '<div class="qill">';
174
175 var count = 0;
ae8f569f 176 var searchQill = [];
55a66cac 177 for (param in searchParams) {
b633f8bd 178 if (val = $('#' + param).val()) {
55a66cac
KJ
179 if (param == 'status_id') {
180 val = campaignStatus[val];
181 }
182 if (param == 'campaign_type_id') {
183 val = campaignTypes[val];
184 }
185 searchQill[count++] = searchParams[param] + ' : ' + val;
186 }
187 }
188 noRecordFoundMsg += searchQill.join('<span class="font-italic"> ...AND... </span></div><div class="qill">');
b633f8bd 189 $('table.campaigns', '#campaignList').dataTable({
55a66cac
KJ
190 "bFilter": false,
191 "bAutoWidth": false,
192 "bProcessing": false,
193 "bLengthChange": false,
194 "aaSorting": [],
195 "aoColumns": [
196 {sClass: 'crm-campaign-id hiddenElement' },
197 {sClass: 'crm-campaign-name hiddenElement' },
85e10782
CW
198 {sClass: 'crmf-title' },
199 {sClass: 'crmf-description' },
55a66cac
KJ
200 {sClass: 'crm-campaign-start_date' },
201 {sClass: 'crm-campaign-end_date' },
202 {sClass: 'crm-campaign-campaign-type_id hiddenElement' },
85e10782 203 {sClass: 'crmf-campaign_type_id' },
55a66cac 204 {sClass: 'crm-campaign-campaign-status_id hiddenElement' },
85e10782 205 {sClass: 'crmf-status_id' },
55a66cac
KJ
206 {sClass: 'crm-campaign-campaign-is_active hiddenElement' },
207 {sClass: 'crm-campaign-campaign-isAactive' },
208 {sClass: 'crm-campaign-action', bSortable: false}
209 ],
210 "sPaginationType": "full_numbers",
211 "sDom": 'rt<"crm-datatable-pager-bottom"ip>',
212 "bServerSide": true,
213 "bJQueryUI": true,
214 "sAjaxSource": sourceUrl,
215 "asStripClasses": ["odd-row", "even-row"],
216 "oLanguage": {"sEmptyTable": noRecordFoundMsg,
217 "sZeroRecords": noRecordFoundMsg },
218 "fnDrawCallback": function () {
18afc30c 219 // FIXME: trigger crmLoad and crmEditable would happen automatically
b633f8bd 220 $('.crm-editable').crmEditable();
55a66cac
KJ
221 },
222 "fnRowCallback": function (nRow, aData, iDisplayIndex) {
223 //insert the id for each row for enable/disable.
a2e0853f 224 var rowId = 'campaign-' + aData[0];
b633f8bd 225 $(nRow).attr('id', rowId).addClass('crm-entity');
55a66cac
KJ
226 //handled disabled rows.
227 var isActive = Boolean(Number(aData[10]));
228 if (!isActive) {
b633f8bd 229 $(nRow).addClass('disabled');
55a66cac
KJ
230 }
231
b633f8bd 232 // Crm-editable
85e10782
CW
233 $(nRow).children().eq(2).addClass('crm-editable');
234 $(nRow).children().eq(3).data('type', 'textarea').addClass('crm-editable');
235 $(nRow).children().eq(7).data('type', 'select').addClass('crm-editable');
236 $(nRow).children().eq(9).data({type: 'select', emptyOption: ''}).addClass('crm-editable');
55a66cac
KJ
237
238 return nRow;
239 },
240
241 "fnServerData": function (sSource, aoData, fnCallback) {
242 var dataLength = aoData.length;
243
244 var count = 1;
ae8f569f 245 var searchCriteria = [];
55a66cac
KJ
246
247 //get the search criteria.
248 var searchParams = {/literal}{$searchParams}{literal};
249 for (param in searchParams) {
6a488035 250 fldName = param;
55a66cac
KJ
251 if (param == 'campaign_title') {
252 fldName = 'title';
253 }
b633f8bd 254 if (val = $('#' + param).val()) {
6a488035
TO
255 aoData[dataLength++] = {name: fldName, value: val};
256 }
257 searchCriteria[count++] = fldName;
55a66cac
KJ
258 }
259
260 //do search for campaigns.
261 aoData[dataLength++] = {name: 'search_for', value: 'campaign'};
262
263 //lets transfer search criteria.
264 aoData[dataLength++] = {name: 'searchCriteria', value: searchCriteria.join(',')};
265
b633f8bd 266 $.ajax({
55a66cac
KJ
267 "dataType": 'json',
268 "type": "POST",
269 "url": sSource,
270 "data": aoData,
271 "success": fnCallback
272 });
273 }
274 });
b633f8bd 275 };
6a488035 276
b633f8bd
CW
277 {/literal}
278 {* load selector when force *}
279 {if $force and !$buildSelector}
280 {literal}
281 $(function($) {
282 searchCampaigns({/literal}'{$qfKey}'{literal});
283 });
284
285 {/literal}
286 {/if}
287 {literal}
288})(CRM.$);
6a488035
TO
289</script>
290{/literal}