| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.7 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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} |
| 28 | <div class="messages status no-popup"> |
| 29 | <div class="icon inform-icon"></div> |
| 30 | |
| 31 | {ts}None 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 ui-icon-circle-plus"></div>{ts}Add Campaign{/ts}</span></a> |
| 36 | </div> |
| 37 | {elseif $buildSelector} |
| 38 | |
| 39 | {* load campaign selector *} |
| 40 | |
| 41 | {include file="CRM/common/enableDisableApi.tpl"} |
| 42 | |
| 43 | {literal} |
| 44 | <script type="text/javascript"> |
| 45 | CRM.$(function($) { |
| 46 | loadCampaignList(); |
| 47 | }); |
| 48 | </script> |
| 49 | {/literal} |
| 50 | <table class="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> |
| 55 | <th>{ts}Title{/ts}</th> |
| 56 | <th>{ts}Description{/ts}</th> |
| 57 | <th>{ts}Start Date{/ts}</th> |
| 58 | <th>{ts}End Date{/ts}</th> |
| 59 | <th class="hiddenElement">{ts}Type ID{/ts}</th> |
| 60 | <th>{ts}Type{/ts}</th> |
| 61 | <th class="hiddenElement">{ts}Status ID{/ts}</th> |
| 62 | <th>{ts}Status{/ts}</th> |
| 63 | <th class="hiddenElement">{ts}Is Active?{/ts}</th> |
| 64 | <th>{ts}Active?{/ts}</th> |
| 65 | <th></th> |
| 66 | </tr> |
| 67 | </thead> |
| 68 | <tbody></tbody> |
| 69 | </table> |
| 70 | {else} |
| 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 ui-icon-circle-plus"></div>{ts}Add Campaign{/ts}</span></a> |
| 74 | </div> |
| 75 | {* build search form here *} |
| 76 | |
| 77 | {* Search form and results for campaigns *} |
| 78 | <div class="crm-block crm-form-block crm-search-form-block"> |
| 79 | |
| 80 | {assign var='searchForm' value="search_form_$searchFor"} |
| 81 | |
| 82 | <div id="{$searchForm}" |
| 83 | class="crm-accordion-wrapper crm-campaign_search_form-accordion {if $force and !$buildSelector}collapsed{/if}"> |
| 84 | <div class="crm-accordion-header"> |
| 85 | {ts}Search Campaigns{/ts} |
| 86 | </div> |
| 87 | <!-- /.crm-accordion-header --> |
| 88 | |
| 89 | <div class="crm-accordion-body"> |
| 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 | <td>{$form.is_active.label}<br/> |
| 119 | {$form.is_active.html} |
| 120 | </td> |
| 121 | </tr> |
| 122 | |
| 123 | <tr> |
| 124 | <td colspan="2"> |
| 125 | {if $context eq 'search'} |
| 126 | {$form.buttons.html} |
| 127 | {else} |
| 128 | <a class="searchCampaign button" style="float:left;" href="#" title="{ts}Search{/ts}" |
| 129 | onClick="searchCampaigns( '{$qfKey}' );return false;">{ts}Search{/ts}</a> |
| 130 | {/if} |
| 131 | </td> |
| 132 | </tr> |
| 133 | </table> |
| 134 | {/strip} |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | {* search form ends here *} |
| 139 | <div id='campaignList'></div> |
| 140 | {/if} {* end of search form build *} |
| 141 | |
| 142 | |
| 143 | {literal} |
| 144 | <script type="text/javascript"> |
| 145 | (function($) { |
| 146 | |
| 147 | window.searchCampaigns = function searchCampaigns(qfKey) { |
| 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 | |
| 155 | $.get(dataUrl, null, function (campaignList) { |
| 156 | $('#campaignList').html(campaignList).trigger('crmLoad'); |
| 157 | |
| 158 | //collapse the search form. |
| 159 | var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal}; |
| 160 | $(searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle(); |
| 161 | }, 'html'); |
| 162 | }; |
| 163 | |
| 164 | window.loadCampaignList = function() { |
| 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; |
| 176 | var searchQill = []; |
| 177 | for (param in searchParams) { |
| 178 | if (val = $('#' + param).val()) { |
| 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">'); |
| 189 | $('table.campaigns', '#campaignList').dataTable({ |
| 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' }, |
| 198 | {sClass: 'crmf-title' }, |
| 199 | {sClass: 'crmf-description' }, |
| 200 | {sClass: 'crm-campaign-start_date' }, |
| 201 | {sClass: 'crm-campaign-end_date' }, |
| 202 | {sClass: 'crm-campaign-campaign-type_id hiddenElement' }, |
| 203 | {sClass: 'crmf-campaign_type_id' }, |
| 204 | {sClass: 'crm-campaign-campaign-status_id hiddenElement' }, |
| 205 | {sClass: 'crmf-status_id' }, |
| 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 () { |
| 219 | // FIXME: trigger crmLoad and crmEditable would happen automatically |
| 220 | $('.crm-editable').crmEditable(); |
| 221 | }, |
| 222 | "fnRowCallback": function (nRow, aData, iDisplayIndex) { |
| 223 | //insert the id for each row for enable/disable. |
| 224 | var rowId = 'campaign-' + aData[0]; |
| 225 | $(nRow).attr('id', rowId).addClass('crm-entity'); |
| 226 | //handled disabled rows. |
| 227 | var isActive = Boolean(Number(aData[10])); |
| 228 | if (!isActive) { |
| 229 | $(nRow).addClass('disabled'); |
| 230 | } |
| 231 | |
| 232 | // Crm-editable |
| 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'); |
| 237 | |
| 238 | return nRow; |
| 239 | }, |
| 240 | |
| 241 | "fnServerData": function (sSource, aoData, fnCallback) { |
| 242 | var dataLength = aoData.length; |
| 243 | |
| 244 | var count = 1; |
| 245 | var searchCriteria = []; |
| 246 | |
| 247 | //get the search criteria. |
| 248 | var searchParams = {/literal}{$searchParams}{literal}; |
| 249 | for (param in searchParams) { |
| 250 | fldName = param; |
| 251 | if (param == 'campaign_title') { |
| 252 | fldName = 'title'; |
| 253 | } |
| 254 | if (val = $('#' + param).val()) { |
| 255 | aoData[dataLength++] = {name: fldName, value: val}; |
| 256 | } |
| 257 | searchCriteria[count++] = fldName; |
| 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 | |
| 266 | $.ajax({ |
| 267 | "dataType": 'json', |
| 268 | "type": "POST", |
| 269 | "url": sSource, |
| 270 | "data": aoData, |
| 271 | "success": fnCallback |
| 272 | }); |
| 273 | } |
| 274 | }); |
| 275 | }; |
| 276 | |
| 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.$); |
| 289 | </script> |
| 290 | {/literal} |