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