CRM-14383 - Update cj closures
[civicrm-core.git] / templates / CRM / Campaign / Form / Search / Survey.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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 !$hasSurveys}
28 <div class="messages status no-popup">
29 <div class="icon inform-icon"></div> &nbsp;
30 {ts}No surveys found.{/ts}
31 </div>
32
33 <div class="action-link">
34 <a href="{crmURL p='civicrm/survey/add' q='reset=1' h=0 }" class="button"><span><div class="icon add-icon"></div>{ts}Add Survey{/ts}</span></a>
35 </div>
36
37 {elseif $buildSelector}
38
39 {* use to display result set of survey *}
40 <div id="survey-result-set-dialog" class="hiddenElement"></div>
41
42 {* load survey selector *}
43 {include file="CRM/common/enableDisableApi.tpl"}
44 {include file="CRM/common/crmeditable.tpl"}
45
46 {literal}
47 <script type="text/javascript">
48 CRM.$(function($) {
49 loadSurveyList( );
50 });
51 </script>
52 {/literal}
53
54 <table id="surveys">
55 <thead>
56 <tr class="columnheader">
57 <th class="hiddenElement">{ts}Survey 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}Survey Type ID{/ts}</th>
62 <th>{ts}Survey Type{/ts}</th>
63 <th>{ts}Release Frequency{/ts}</th>
64 <th>{ts}Reserve Each Time{/ts}</th>
65 <th>{ts}Total Reserve{/ts}</th>
66 <th>{ts}Default?{/ts}</th>
67 <th class="hiddenElement">{ts}Is Active?{/ts}</th>
68 <th>{ts}Active?{/ts}</th>
69 <th></th>
70 <th></th>
71 <th></th>
72 </tr>
73 </thead>
74 <tbody></tbody>
75 </table>
76
77 {else}
78
79 <div class="action-link">
80 <a href="{crmURL p='civicrm/survey/add' q='reset=1' h=0 }" class="button"><span><div class="icon add-icon"></div>{ts}Add Survey{/ts}</span></a>
81 </div>
82
83 {* build search form here *}
84
85 {* Search form and results for surveys *}
86 <div class="crm-block crm-form-block crm-search-form-block">
87 {assign var='searchForm' value="search_form_$searchFor"}
88
89 <div id="{$searchForm}" class="crm-accordion-wrapper crm-survey_search_form-accordion{if $force and !$buildSelector} collapsed{/if}">
90 <div class="crm-accordion-header">
91 {ts}Search Surveys{/ts}
92 </div><!-- /.crm-accordion-header -->
93
94 <div class="crm-accordion-body">
95 {strip}
96 <table class="form-layout-compressed">
97 <tr>
98 <td>{$form.survey_title.label}<br />
99 {$form.survey_title.html}
100 </td>
101 </tr>
102 <tr>
103 <td>{$form.activity_type_id.label}<br />
104 {$form.activity_type_id.html}
105 </td>
106 <td>{$form.survey_campaign_id.label}<br />
107 {$form.survey_campaign_id.html}
108 </td>
109 </tr>
110 <tr>
111 <td colspan="2">
112 {if $context eq 'search'}
113 {$form.buttons.html}
114 {else}
115 <a class="searchSurvey button" style="float:left;" href="#" title="{ts}Search{/ts}" onClick="searchSurveys( '{$qfKey}' );return false;">{ts}Search{/ts}</a>
116 {/if}
117 </td>
118 </tr>
119 </table>
120 {/strip}
121 </div>
122 </div>
123 </div>
124 {* search form ends here *}
125
126 <div id='surveyList'></div>
127
128 {/if} {* end of search form build *}
129
130
131 {literal}
132 <script type="text/javascript">
133
134 CRM.$(function($) {
135 cj().crmAccordions();
136 });
137
138 {/literal}
139 {* load selector when force *}
140 {if $force and !$buildSelector}
141 {literal}
142 CRM.$(function($) {
143 searchSurveys( {/literal}'{$qfKey}'{literal} );
144 });
145
146 {/literal}
147 {/if}
148 {literal}
149
150 function searchSurveys( qfKey )
151 {
152 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=survey'}"{literal};
153
154 //lets carry qfKey to retain form session.
155 if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey;
156
157 cj.get( dataUrl, null, function( surveyList ) {
158 cj( '#surveyList' ).html( surveyList ).trigger('crmLoad');
159
160 //collapse the search form.
161 var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal};
162 cj( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
163 }, 'html' );
164 }
165
166 function loadSurveyList( )
167 {
168 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=surveyList' }"{literal};
169
170 //build the search qill.
171 //get the search criteria.
172 var searchParams = {/literal}{$searchParams}{literal};
173 var surveyTypes = {/literal}{$surveyTypes}{literal};
174 var surveyCampaigns = {/literal}{$surveyCampaigns}{literal};
175
176 var noRecordFoundMsg = "{/literal}{ts escape='js'}No matches found for:{/ts}{literal}";
177 noRecordFoundMsg += '<div class="qill">';
178
179 var count = 0;
180 var searchQill = new Array( );
181 for ( param in searchParams ) {
182 if ( val = cj( '#' + param ).val( ) ) {
183 if ( param == 'activity_type_id' ) val = surveyTypes[val];
184 if ( param == 'survey_campaign_id' ) val = surveyCampaigns[val];
185 searchQill[count++] = searchParams[param] + ' : ' + val;
186 }
187 }
188 noRecordFoundMsg += searchQill.join( '<span class="font-italic"> ...AND... </span></div><div class="qill">' );
189
190 cj( '#surveys' ).dataTable({
191 "bFilter" : false,
192 "bAutoWidth" : false,
193 "bProcessing": false,
194 "bLengthChange": false,
195 "aaSorting": [],
196 "aoColumns":[{sClass:'crm-survey-id hiddenElement' },
197 {sClass:'crm-survey-title' },
198 {sClass:'crm-survey-campaign_id hiddenElement' },
199 {sClass:'crm-survey-campaign' },
200 {sClass:'crm-survey-activity_type_id hiddenElement' },
201 {sClass:'crm-survey-activity_type' },
202 {sClass:'crm-survey-release_frequency' },
203 {sClass:'crm-survey-default_number_of_contacts' },
204 {sClass:'crm-survey-max_number_of_contacts' },
205 {sClass:'crm-survey-is_default' },
206 {sClass:'crm-survey-is_active hiddenElement' },
207 {sClass:'crm-survey-isActive' },
208 {sClass:'crm-survey-result_id', bSortable:false},
209 {sClass:'crm-survey-action', bSortable:false},
210 {sClass:'crm-campaign-voterLinks', bSortable:false}
211 ],
212 "sPaginationType": "full_numbers",
213 "sDom" : 'rt<"crm-datatable-pager-bottom"ip>',
214 "bServerSide": true,
215 "bJQueryUI": true,
216 "sAjaxSource": sourceUrl,
217 "asStripClasses" : [ "odd-row", "even-row" ],
218 "oLanguage":{"sEmptyTable" : noRecordFoundMsg,
219 "sZeroRecords" : noRecordFoundMsg },
220 "fnDrawCallback": function() { cj().crmtooltip(); },
221 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
222 //insert the id for each row for enable/disable.
223 var rowId = 'survey_row_' + aData[0];
224 cj(nRow).attr( 'id', rowId );
225 //handled disabled rows.
226 var isActive = Boolean(Number(aData[10]));
227 if ( !isActive ) cj(nRow).addClass( 'disabled' );
228
229 //add id for yes/no column.
230 cj(nRow).children().eq(11).attr( 'id', rowId + '_status' );
231
232 return nRow;
233 },
234
235 "fnServerData": function ( sSource, aoData, fnCallback ) {
236 var dataLength = aoData.length;
237
238 var count = 1;
239 var searchCriteria = new Array( );
240
241 //get the search criteria.
242 var searchParams = {/literal}{$searchParams}{literal};
243 for ( param in searchParams ) {
244 fldName = param;
245 if ( param == 'survey_title' ) fldName = 'title';
246 if ( param == 'survey_campaign_id' ) fldName = 'campaign_id';
247 if ( val = cj( '#' + param ).val( ) ) {
248 aoData[dataLength++] = {name: fldName, value: val};
249 }
250 searchCriteria[count++] = fldName;
251 }
252
253 //do search for surveys.
254 aoData[dataLength++] = {name: 'search_for', value: 'survey'};
255
256 //lets transfer search criteria.
257 aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')};
258
259 cj.ajax( {
260 "dataType": 'json',
261 "type": "POST",
262 "url": sSource,
263 "data": aoData,
264 "success": fnCallback
265 } ); }
266 });
267 }
268
269 function displayResultSet( surveyId, surveyTitle, OptionGroupId ) {
270 var data = new Object;
271 data['option_group_id'] = OptionGroupId;
272 data['survey_id'] = surveyId;
273
274 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=loadOptionGroupDetails' }"{literal};
275 var content = '<tr><th>{/literal}{ts escape='js'}Label{/ts}{literal}</th><th>{/literal}{ts escape='js'}Value{/ts}{literal}</th><th>{/literal}{ts escape='js'}Recontact Interval{/ts}{literal}</th><th>{/literal}{ts escape='js'}Weight{/ts}{literal}</th></tr>';
276 var setTitle = '{/literal}{ts escape='js'}Result Set for{/ts} {literal}' + surveyTitle;
277
278 cj.post( dataUrl, data, function( opGroup ) {
279 if ( opGroup.status == 'success' ) {
280 var result = opGroup.result;
281 for( key in result ) {
282 var interval = '';
283 if ( result[key].interval && result[key].interval != 'undefined' ) {
284 interval = result[key].interval;
285 }
286 content += '<tr><td>'+ result[key].label +'</td><td>'+ result[key].value +'</td><td>'+ interval +'</td><td>'+ result[key].weight +'</td></tr>';
287 }
288
289 cj("#survey-result-set-dialog").show( ).html('<table>'+content+'</table>').dialog({
290 title: setTitle,
291 modal: true,
292 width: 480,
293 overlay: {
294 opacity: 0.5,
295 background: "black"
296 },
297 beforeclose: function(event, ui) {
298 cj(this).dialog("destroy");
299 }
300 });
301 }
302 }, "json" );
303
304 }
305
306 </script>
307 {/literal}