Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-16-17-51-20
[civicrm-core.git] / templates / CRM / Campaign / Form / Search / Survey.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
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}None found.{/ts}
31 </div>
32
33 <div class="action-link">
34 {crmButton p='civicrm/survey/add' q='reset=1' h=0 icon="circle-plus"}{ts}Add Survey{/ts}{/crmButton}
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
45 {literal}
46 <script type="text/javascript">
47 CRM.$(function($) {
48 loadSurveyList( );
49 });
50 </script>
51 {/literal}
52
53 <table class="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 {crmButton p='civicrm/survey/add' q='reset=1' h=0 icon="circle-plus"}{ts}Add Survey{/ts}{/crmButton}
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 {/literal}
134 {* load selector when force *}
135 {if $force and !$buildSelector}
136 {literal}
137 CRM.$(function($) {
138 searchSurveys( {/literal}'{$qfKey}'{literal} );
139 });
140
141 {/literal}
142 {/if}
143 {literal}
144
145 function searchSurveys( qfKey )
146 {
147 var dataUrl = {/literal}"{crmURL h=0 q='search=1&snippet=4&type=survey'}"{literal};
148
149 //lets carry qfKey to retain form session.
150 if ( qfKey ) dataUrl = dataUrl + '&qfKey=' + qfKey;
151
152 CRM.$.get( dataUrl, null, function( surveyList ) {
153 CRM.$( '#surveyList' ).html( surveyList ).trigger('crmLoad');
154
155 //collapse the search form.
156 var searchFormName = '#search_form_' + {/literal}'{$searchFor}'{literal};
157 CRM.$( searchFormName + '.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
158 }, 'html' );
159 }
160
161 function loadSurveyList( )
162 {
163 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=surveyList' }"{literal};
164
165 //build the search qill.
166 //get the search criteria.
167 var searchParams = {/literal}{$searchParams}{literal};
168 var surveyTypes = {/literal}{$surveyTypes}{literal};
169 var surveyCampaigns = {/literal}{$surveyCampaigns}{literal};
170
171 var noRecordFoundMsg = "{/literal}{ts escape='js'}No matches found for:{/ts}{literal}";
172 noRecordFoundMsg += '<div class="qill">';
173
174 var count = 0;
175 var searchQill = [];
176 for ( param in searchParams ) {
177 if ( val = CRM.$( '#' + param ).val( ) ) {
178 if ( param == 'activity_type_id' ) val = surveyTypes[val];
179 if ( param == 'survey_campaign_id' ) val = surveyCampaigns[val];
180 searchQill[count++] = searchParams[param] + ' : ' + val;
181 }
182 }
183 noRecordFoundMsg += searchQill.join( '<span class="font-italic"> ...AND... </span></div><div class="qill">' );
184 CRM.$( 'table.surveys', '#surveyList').dataTable({
185 "bFilter" : false,
186 "bAutoWidth" : false,
187 "bProcessing": false,
188 "bLengthChange": false,
189 "aaSorting": [],
190 "aoColumns":[{sClass:'crm-survey-id hiddenElement' },
191 {sClass:'crmf-title crm-editable' },
192 {sClass:'crm-survey-campaign_id hiddenElement' },
193 {sClass:'crm-survey-campaign' },
194 {sClass:'crm-survey-activity_type_id hiddenElement' },
195 {sClass:'crm-survey-activity_type' },
196 {sClass:'crm-survey-release_frequency' },
197 {sClass:'crm-survey-default_number_of_contacts' },
198 {sClass:'crm-survey-max_number_of_contacts' },
199 {sClass:'crm-survey-is_default' },
200 {sClass:'crm-survey-is_active hiddenElement' },
201 {sClass:'crm-survey-isActive' },
202 {sClass:'crm-survey-result_id', bSortable:false},
203 {sClass:'crm-survey-action', bSortable:false},
204 {sClass:'crm-campaign-voterLinks', bSortable:false}
205 ],
206 "sPaginationType": "full_numbers",
207 "sDom" : 'rt<"crm-datatable-pager-bottom"ip>',
208 "bServerSide": true,
209 "bJQueryUI": true,
210 "sAjaxSource": sourceUrl,
211 "asStripClasses" : [ "odd-row", "even-row" ],
212 "oLanguage":{"sEmptyTable" : noRecordFoundMsg,
213 "sZeroRecords" : noRecordFoundMsg },
214 "fnDrawCallback": function() {
215 // FIXME: trigger crmLoad and crmEditable would happen automatically
216 CRM.$('.crm-editable').crmEditable();
217 },
218 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
219 //insert the id for each row for enable/disable.
220 var rowId = 'survey-' + aData[0];
221 CRM.$(nRow).attr( 'id', rowId).addClass('crm-entity');
222 //handled disabled rows.
223 var isActive = Boolean(Number(aData[10]));
224 if ( !isActive ) CRM.$(nRow).addClass( 'disabled' );
225
226 //add id for yes/no column.
227 CRM.$(nRow).children().eq(11).attr( 'id', rowId + '_status' );
228
229 return nRow;
230 },
231
232 "fnServerData": function ( sSource, aoData, fnCallback ) {
233 var dataLength = aoData.length;
234
235 var count = 1;
236 var searchCriteria = [];
237
238 //get the search criteria.
239 var searchParams = {/literal}{$searchParams}{literal};
240 for ( param in searchParams ) {
241 fldName = param;
242 if ( param == 'survey_title' ) fldName = 'title';
243 if ( param == 'survey_campaign_id' ) fldName = 'campaign_id';
244 if ( val = CRM.$( '#' + param ).val( ) ) {
245 aoData[dataLength++] = {name: fldName, value: val};
246 }
247 searchCriteria[count++] = fldName;
248 }
249
250 //do search for surveys.
251 aoData[dataLength++] = {name: 'search_for', value: 'survey'};
252
253 //lets transfer search criteria.
254 aoData[dataLength++] = {name: 'searchCriteria', value:searchCriteria.join(',')};
255
256 CRM.$.ajax( {
257 "dataType": 'json',
258 "type": "POST",
259 "url": sSource,
260 "data": aoData,
261 "success": fnCallback
262 } ); }
263 });
264 }
265
266 function displayResultSet( surveyId, surveyTitle, OptionGroupId ) {
267 var data = new Object;
268 data['option_group_id'] = OptionGroupId;
269 data['survey_id'] = surveyId;
270
271 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=loadOptionGroupDetails' }"{literal};
272 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'}Order{/ts}{literal}</th></tr>';
273 var setTitle = '{/literal}{ts escape='js'}Result Set for{/ts} {literal}' + surveyTitle;
274
275 CRM.$.post( dataUrl, data, function( opGroup ) {
276 if ( opGroup.status == 'success' ) {
277 var result = opGroup.result;
278 for( key in result ) {
279 var interval = '';
280 if ( result[key].interval && result[key].interval != 'undefined' ) {
281 interval = result[key].interval;
282 }
283 content += '<tr><td>'+ result[key].label +'</td><td>'+ result[key].value +'</td><td>'+ interval +'</td><td>'+ result[key].weight +'</td></tr>';
284 }
285
286 CRM.$("#survey-result-set-dialog").show( ).html('<table>'+content+'</table>').dialog({
287 title: setTitle,
288 modal: true,
289 width: 480,
290 overlay: {
291 opacity: 0.5,
292 background: "black"
293 },
294 beforeclose: function(event, ui) {
295 CRM.$(this).dialog("destroy");
296 }
297 });
298 }
299 }, "json" );
300
301 }
302
303 </script>
304 {/literal}