Merge pull request #5550 from civicrm/4.5
[civicrm-core.git] / templates / CRM / Group / Form / Search.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
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 <div class="crm-block crm-form-block crm-group-search-form-block">
27
28 <h3>{ts}Find Groups{/ts}</h3>
29 <table class="form-layout">
30 <tr>
31 <td>
32 {$form.title.label}<br />
33 {$form.title.html}<br />
34 <span class="description font-italic">
35 {ts}Complete OR partial group name.{/ts}
36 </span>
37 </td>
38 <td>
39 {$form.created_by.label}<br />
40 {$form.created_by.html}<br />
41 <span class="description font-italic">
42 {ts}Complete OR partial creator name.{/ts}
43 </span>
44 </td>
45 <td id="group_type-block">
46 {$form.group_type.label}<br />
47 {$form.group_type.html}<br />
48 <span class="description font-italic">
49 {ts}Filter search by group type(s).{/ts}
50 </span>
51 </td>
52 <td>
53 {$form.visibility.label}<br />
54 {$form.visibility.html}<br />
55 <span class="description font-italic">
56 {ts}Filter search by visibility.{/ts}
57 </span>
58 </td>
59 <td>
60 {$form.group_status.label}<br />
61 {$form.group_status.html}
62 </td>
63 </tr>
64 <tr>
65 <td>{$form.buttons.html}</td><td colspan="2">
66 </tr>
67 </table>
68 </div>
69 <div class="css_right">
70 <a class="crm-hover-button action-item" href="{crmURL q="reset=1&update_smart_groups=1"}">{ts}Update Smart Group Counts{/ts}</a> {help id="update_smart_groups"}
71 </div>
72 <table class="crm-group-selector">
73 <thead>
74 <tr>
75 <th class='crm-group-name'>{ts}Name{/ts}</th>
76 <th class='crm-group-count'>{ts}Count{/ts}</th>
77 <th class='crm-group-created_by'>{ts}Created By{/ts}</th>
78 <th class='crm-group-description'>{ts}Description{/ts}</th>
79 <th class='crm-group-group_type'>{ts}Group Type{/ts}</th>
80 <th class='crm-group-visibility'>{ts}Visibility{/ts}</th>
81 {if $showOrgInfo}
82 <th class='crm-group-org_info'>{ts}Organization{/ts}</th>
83 {/if}
84 <th class='crm-group-group_links nosort'>&nbsp;</th>
85 <th class='hiddenElement'>&nbsp;</th>
86 </tr>
87 </thead>
88 </table>
89
90 {* handle enable/disable actions*}
91 {include file="CRM/common/enableDisableApi.tpl"}
92
93 {literal}
94 <script type="text/javascript">
95 CRM.$(function($) {
96 // for CRM-11310 and CRM-10635 : processing just parent groups on initial display
97 // passing '1' for parentsOnlyArg to show parent child heirarchy structure display
98 // on initial load of manage group page and
99 // also to handle search filtering for initial load of same page.
100 buildGroupSelector(true, 1);
101 $('#_qf_Search_refresh').click( function() {
102 buildGroupSelector( true );
103 });
104 // Add livePage functionality
105 $('#crm-container')
106 .on('click', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', CRM.popup)
107 .on('crmPopupFormSuccess', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', function() {
108 // Refresh datatable when form completes
109 var $context = $('#crm-main-content-wrapper');
110 $('table.crm-group-selector', $context).dataTable().fnDraw();
111 });
112
113 function buildGroupSelector( filterSearch, parentsOnlyArg ) {
114 if ( filterSearch ) {
115 if (typeof crmGroupSelector !== 'undefined') {
116 crmGroupSelector.fnDestroy();
117 }
118 var parentsOnly = 0;
119 var ZeroRecordText = '<div class="status messages">{/literal}{ts escape="js"}No matching Groups found for your search criteria. Suggestions:{/ts}{literal}<div class="spacer"></div><ul><li>{/literal}{ts escape="js"}Check your spelling.{/ts}{literal}</li><li>{/literal}{ts escape="js"}Try a different spelling or use fewer letters.{/ts}{literal}</li><li>{/literal}{ts escape="js"}Make sure you have enough privileges in the access control system.{/ts}{literal}</li></ul></div>';
120 } else {
121 var parentsOnly = 1;
122 var ZeroRecordText = {/literal}'{ts escape="js"}<div class="status messages">No Groups have been created for this site.{/ts}</div>'{literal};
123 }
124
125 // this argument should only be used on initial display i.e onPageLoad
126 if (typeof parentsOnlyArg !== 'undefined') {
127 parentsOnly = parentsOnlyArg;
128 }
129
130 var columns = '';
131 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal};
132 var showOrgInfo = {/literal}"{$showOrgInfo}"{literal};
133 var $context = $('#crm-main-content-wrapper');
134
135 crmGroupSelector = $('table.crm-group-selector', $context).dataTable({
136 "bFilter" : false,
137 "bAutoWidth" : false,
138 "aaSorting" : [],
139 "aoColumns" : [
140 {sClass:'crm-group-name'},
141 {sClass:'crm-group-count'},
142 {sClass:'crm-group-created_by'},
143 {sClass:'crm-group-description', bSortable:false},
144 {sClass:'crm-group-group_type'},
145 {sClass:'crm-group-visibility'},
146 {sClass:'crm-group-group_links', bSortable:false},
147 {/literal}{if $showOrgInfo}{literal}
148 {sClass:'crm-group-org_info', bSortable:false},
149 {/literal}{/if}{literal}
150 {sClass:'hiddenElement', bSortable:false}
151 ],
152 "bProcessing": true,
153 "asStripClasses" : [ "odd-row", "even-row" ],
154 "sPaginationType": "full_numbers",
155 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
156 "bServerSide": true,
157 "bJQueryUI": true,
158 "sAjaxSource": sourceUrl,
159 "iDisplayLength": 25,
160 "oLanguage": { "sZeroRecords": ZeroRecordText,
161 "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
162 "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
163 "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
164 "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
165 "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
166 "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
167 "oPaginate": {
168 "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
169 "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
170 "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
171 "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
172 }
173 },
174 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
175 var id = $('td:last', nRow).text().split(',')[0];
176 var cl = $('td:last', nRow).text().split(',')[1];
177 $(nRow).addClass(cl).attr({id: 'row_' + id, 'data-id': id, 'data-entity': 'group'});
178 $('td:eq(0)', nRow).wrapInner('<span class="crm-editable crmf-title" />');
179 $('td:eq(1)', nRow).addClass('right');
180 $('td:eq(3)', nRow).wrapInner('<div class="crm-editable crmf-description" data-type="textarea" />');
181 $('td:eq(5)', nRow).wrapInner('<div class="crm-editable crmf-visibility" data-type="select" />');
182 if (parentsOnly) {
183 if ($(nRow).hasClass('crm-group-parent')) {
184 $(nRow).find('td:first').prepend('{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}');
185 }
186 }
187 return nRow;
188 },
189 "fnDrawCallback": function() {
190 // FIXME: trigger crmLoad and crmEditable would happen automatically
191 $('.crm-editable').crmEditable();
192 },
193 "fnServerData": function ( sSource, aoData, fnCallback ) {
194 aoData.push( {name:'showOrgInfo', value: showOrgInfo },
195 {name:'parentsOnly', value: parentsOnly }
196 );
197 if ( filterSearch ) {
198 var groupTypes = '';
199 $('#group_type-block input').each(function(index) {
200 if ($(this).prop('checked')) {
201 if (groupTypes) {
202 groupTypes = groupTypes + ',' + $(this).attr('id').substr(11);
203 }
204 else {
205 groupTypes = $(this).attr('id').substr(11);
206 }
207 }
208 });
209
210 var groupStatus = '';
211 if ( $('.crm-group-search-form-block #group_status_1').prop('checked') ) {
212 groupStatus = '1';
213 }
214
215 if ( $('.crm-group-search-form-block #group_status_2').prop('checked') ) {
216 if ( groupStatus ) {
217 groupStatus = '3';
218 } else {
219 groupStatus = '2';
220 }
221 }
222
223 aoData.push(
224 {name:'title', value: $('.crm-group-search-form-block #title').val()},
225 {name:'created_by', value: $('.crm-group-search-form-block #created_by').val()},
226 {name:'group_type', value: groupTypes },
227 {name:'visibility', value: $('.crm-group-search-form-block #visibility').val()},
228 {name:'status', value: groupStatus }
229 );
230 }
231 $.ajax( {
232 "dataType": 'json',
233 "type": "POST",
234 "url": sSource,
235 "data": aoData,
236 "success": fnCallback
237 } );
238 }
239 });
240 }
241
242 // show hide children
243 var $context = $('#crm-main-content-wrapper');
244 $('table.crm-group-selector', $context).on( 'click', 'span.show-children', function(){
245 var showOrgInfo = {/literal}"{$showOrgInfo}"{literal};
246 var rowID = $(this).parents('tr').prop('id');
247 var parentRow = rowID.split('_');
248 var parent_id = parentRow[1];
249 var group_id = '';
250 if ( parentRow[2]) {
251 group_id = parentRow[2];
252 }
253 var levelClass = 'level_2';
254 // check enclosing td if already at level 2
255 if ( $(this).parent().hasClass('level_2') ) {
256 levelClass = 'level_3';
257 }
258 if ( $(this).hasClass('collapsed') ) {
259 $(this).removeClass("collapsed").addClass("expanded").attr("title",{/literal}"{ts escape='js'}hide child groups{/ts}"{literal});
260 showChildren( parent_id, showOrgInfo, group_id, levelClass );
261 }
262 else {
263 $(this).removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal});
264 $('.parent_is_' + parent_id).find('.show-children').removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal});
265 $('.parent_is_' + parent_id).hide();
266 $('.parent_is_' + parent_id).each(function(i, obj) {
267 // also hide children of children
268 var gID = $(this).find('td:nth-child(2)').text();
269 $('.parent_is_' + gID).hide();
270 });
271 }
272 });
273 function showChildren( parent_id, showOrgInfo, group_id, levelClass) {
274 var rowID = '#row_' + parent_id;
275 if ( group_id ) {
276 rowID = '#row_' + parent_id + '_' + group_id;
277 }
278 if ( $(rowID).next().hasClass('parent_is_' + parent_id ) ) {
279 // child rows for this parent have already been retrieved so just show them
280 $('.parent_is_' + parent_id ).show();
281 } else {
282 var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal};
283 $.ajax( {
284 "dataType": 'json',
285 "url": sourceUrl,
286 "data": {'parent_id': parent_id, 'showOrgInfo': showOrgInfo},
287 "success": function(response){
288 var appendHTML = '';
289 $.each( response, function( i, val ) {
290 appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" data-entity="group" data-id="'+ val.group_id +'" class="parent_is_' + parent_id + ' crm-row-child ' + val.class.split(',')[1] + '">';
291 if ( val.is_parent ) {
292 appendHTML += '<td class="crm-group-name ' + levelClass + '">' + '{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}<span class="crm-editable crmf-title">' + val.group_name + '</span></td>';
293 }
294 else {
295 appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span><span class="crm-editable crmf-title">' + val.group_name + '</span></td>';
296 }
297 appendHTML += '<td class="right">' + val.count + "</td>";
298 appendHTML += "<td>" + val.created_by + "</td>";
299 appendHTML += '<td class="crm-editable crmf-description" data-type="textarea">' + (val.group_description || '') + "</td>";
300 appendHTML += "<td>" + val.group_type + "</td>";
301 appendHTML += '<td class="crm-editable crmf-visibility" data-type="select">' + val.visibility + "</td>";
302 if (showOrgInfo) {
303 appendHTML += "<td>" + val.org_info + "</td>";
304 }
305 appendHTML += "<td>" + val.links + "</td>";
306 appendHTML += "</tr>";
307 });
308 $( rowID ).after( appendHTML );
309 $( rowID ).next().trigger('crmLoad');
310 }
311 });
312 }
313 }
314 });
315
316 </script>
317 {/literal}