Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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> | |
e26be6fb | 45 | <td id="group_type-block"> |
6a488035 TO |
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 | <br/> | |
70 | <table id="crm-group-selector"> | |
71 | <thead> | |
72 | <tr> | |
73 | <th class='crm-group-name'>{ts}Name{/ts}</th> | |
74 | <th class='crm-group-group_id'>{ts}ID{/ts}</th> | |
75 | <th class='crm-group-created_by'>{ts}Created By{/ts}</th> | |
76 | <th class='crm-group-description'>{ts}Description{/ts}</th> | |
77 | <th class='crm-group-group_type'>{ts}Group Type{/ts}</th> | |
78 | <th class='crm-group-visibility'>{ts}Visibility{/ts}</th> | |
79 | {if $showOrgInfo} | |
80 | <th class='crm-group-org_info'>{ts}Organization{/ts}</th> | |
81 | {/if} | |
82 | <th class='crm-group-group_links nosort'> </th> | |
83 | <th class='hiddenElement'> </th> | |
84 | </tr> | |
85 | </thead> | |
86 | </table> | |
87 | ||
88 | {* handle enable/disable actions*} | |
4d17a233 CW |
89 | {include file="CRM/common/enableDisableApi.tpl"} |
90 | {include file="CRM/common/crmeditable.tpl"} | |
6a488035 TO |
91 | |
92 | {literal} | |
93 | <script type="text/javascript"> | |
3cc60a06 | 94 | CRM.$(function($) { |
151c3d15 PJ |
95 | // for CRM-11310 and CRM-10635 : processing just parent groups on initial display |
96 | // passing '1' for parentsOnlyArg to show parent child heirarchy structure display | |
97 | // on initial load of manage group page and | |
98 | // also to handle search filtering for initial load of same page. | |
99 | buildGroupSelector(true, 1); | |
7d644ac8 | 100 | $('#_qf_Search_refresh').click( function() { |
6a488035 TO |
101 | buildGroupSelector( true ); |
102 | }); | |
7d644ac8 | 103 | // Add livePage functionality |
1a62cf90 CW |
104 | $('#crm-container') |
105 | .on('click', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', CRM.popup) | |
106 | .on('crmPopupFormSuccess', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', function() { | |
7d644ac8 CW |
107 | // Refresh datatable when form completes |
108 | $('#crm-group-selector').dataTable().fnDraw(); | |
8c012232 | 109 | }); |
6a488035 TO |
110 | }); |
111 | ||
151c3d15 | 112 | function buildGroupSelector( filterSearch, parentsOnlyArg ) { |
6a488035 | 113 | if ( filterSearch ) { |
6ac0bdde PJ |
114 | if (typeof crmGroupSelector !== 'undefined') { |
115 | crmGroupSelector.fnDestroy(); | |
116 | } | |
6a488035 TO |
117 | var parentsOnly = 0; |
118 | 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>'; | |
119 | } else { | |
120 | var parentsOnly = 1; | |
121 | var ZeroRecordText = {/literal}'{ts escape="js"}<div class="status messages">No Groups have been created for this site.{/ts}</div>'{literal}; | |
122 | } | |
123 | ||
151c3d15 PJ |
124 | // this argument should only be used on initial display i.e onPageLoad |
125 | if (typeof parentsOnlyArg !== 'undefined') { | |
126 | parentsOnly = parentsOnlyArg; | |
127 | } | |
128 | ||
6a488035 TO |
129 | var columns = ''; |
130 | var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}; | |
131 | var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; | |
132 | ||
133 | crmGroupSelector = cj('#crm-group-selector').dataTable({ | |
134 | "bFilter" : false, | |
135 | "bAutoWidth" : false, | |
136 | "aaSorting" : [], | |
137 | "aoColumns" : [ | |
138 | {sClass:'crm-group-name'}, | |
139 | {sClass:'crm-group-group_id'}, | |
140 | {sClass:'crm-group-created_by'}, | |
141 | {sClass:'crm-group-description', bSortable:false}, | |
142 | {sClass:'crm-group-group_type'}, | |
143 | {sClass:'crm-group-visibility'}, | |
144 | {sClass:'crm-group-group_links', bSortable:false}, | |
145 | {/literal}{if $showOrgInfo}{literal} | |
146 | {sClass:'crm-group-org_info', bSortable:false}, | |
147 | {/literal}{/if}{literal} | |
148 | {sClass:'hiddenElement', bSortable:false} | |
149 | ], | |
150 | "bProcessing": true, | |
151 | "asStripClasses" : [ "odd-row", "even-row" ], | |
152 | "sPaginationType": "full_numbers", | |
153 | "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', | |
154 | "bServerSide": true, | |
155 | "bJQueryUI": true, | |
156 | "sAjaxSource": sourceUrl, | |
157 | "iDisplayLength": 25, | |
158 | "oLanguage": { "sZeroRecords": ZeroRecordText, | |
159 | "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal}, | |
160 | "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal}, | |
161 | "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal}, | |
162 | "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal}, | |
163 | "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal}, | |
164 | "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal}, | |
165 | "oPaginate": { | |
166 | "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal}, | |
167 | "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal}, | |
168 | "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal}, | |
169 | "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal} | |
170 | } | |
171 | }, | |
7d644ac8 CW |
172 | "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { |
173 | var id = cj('td:eq(1)', nRow).text(); | |
174 | cj(nRow).addClass('crm-entity').attr('data-entity', 'group').attr('data-id', id); | |
175 | cj('td:eq(0)', nRow).wrapInner('<span class="crm-editable crmf-name" />'); | |
176 | cj('td:eq(3)', nRow).wrapInner('<span class="crm-editable crmf-description" data-type="textarea" />'); | |
177 | return nRow; | |
178 | }, | |
179 | "fnDrawCallback": function() { | |
180 | setSelectorClass( parentsOnly, showOrgInfo ); | |
181 | cj('.crm-editable').crmEditable(); | |
182 | }, | |
6a488035 TO |
183 | "fnServerData": function ( sSource, aoData, fnCallback ) { |
184 | aoData.push( {name:'showOrgInfo', value: showOrgInfo }, | |
185 | {name:'parentsOnly', value: parentsOnly } | |
186 | ); | |
187 | if ( filterSearch ) { | |
188 | var groupTypes = ''; | |
e26be6fb PJ |
189 | cj('#group_type-block input').each(function(index) { |
190 | if (cj(this).prop('checked')) { | |
191 | if (groupTypes) { | |
192 | groupTypes = groupTypes + ',' + cj(this).attr('id').substr(11); | |
193 | } | |
194 | else { | |
195 | groupTypes = cj(this).attr('id').substr(11); | |
196 | } | |
6a488035 | 197 | } |
e26be6fb | 198 | }); |
6a488035 TO |
199 | |
200 | var groupStatus = ''; | |
201 | if ( cj('.crm-group-search-form-block #group_status_1').prop('checked') ) { | |
202 | groupStatus = '1'; | |
203 | } | |
204 | ||
205 | if ( cj('.crm-group-search-form-block #group_status_2').prop('checked') ) { | |
206 | if ( groupStatus ) { | |
207 | groupStatus = '3'; | |
208 | } else { | |
209 | groupStatus = '2'; | |
210 | } | |
211 | } | |
212 | ||
213 | aoData.push( | |
214 | {name:'title', value: cj('.crm-group-search-form-block #title').val()}, | |
215 | {name:'created_by', value: cj('.crm-group-search-form-block #created_by').val()}, | |
216 | {name:'group_type', value: groupTypes }, | |
217 | {name:'visibility', value: cj('.crm-group-search-form-block #visibility').val()}, | |
218 | {name:'status', value: groupStatus } | |
219 | ); | |
220 | } | |
221 | cj.ajax( { | |
222 | "dataType": 'json', | |
223 | "type": "POST", | |
224 | "url": sSource, | |
225 | "data": aoData, | |
226 | "success": fnCallback | |
227 | } ); | |
228 | } | |
229 | }); | |
230 | } | |
231 | ||
232 | function setSelectorClass( parentsOnly, showOrgInfo ) { | |
233 | cj('#crm-group-selector tr').each( function( ) { | |
234 | var className = cj(this).find('td:last-child').text(); | |
235 | cj(this).addClass( className ); | |
236 | var rowID = cj(this).find('td:nth-child(2)').text(); | |
237 | cj(this).prop( 'id', 'row_' + rowID ); | |
238 | if (parentsOnly) { | |
239 | if ( cj(this).hasClass('crm-group-parent') ) { | |
240 | cj(this).find('td:first').prepend('{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}'); | |
241 | } | |
242 | } | |
243 | }); | |
244 | } | |
245 | ||
246 | // show hide children | |
247 | cj('#crm-group-selector').on( 'click', 'span.show-children', function(){ | |
248 | var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; | |
249 | var rowID = cj(this).parents('tr').prop('id'); | |
250 | var parentRow = rowID.split('_'); | |
251 | var parent_id = parentRow[1]; | |
252 | var group_id = ''; | |
253 | if ( parentRow[2]) { | |
254 | group_id = parentRow[2]; | |
255 | } | |
256 | var levelClass = 'level_2'; | |
257 | // check enclosing td if already at level 2 | |
258 | if ( cj(this).parent().hasClass('level_2') ) { | |
259 | levelClass = 'level_3'; | |
260 | } | |
261 | if ( cj(this).hasClass('collapsed') ) { | |
262 | cj(this).removeClass("collapsed").addClass("expanded").attr("title",{/literal}"{ts escape='js'}hide child groups{/ts}"{literal}); | |
263 | showChildren( parent_id, showOrgInfo, group_id, levelClass ); | |
264 | } | |
265 | else { | |
266 | cj(this).removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); | |
267 | cj('.parent_is_' + parent_id).find('.show-children').removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); | |
268 | cj('.parent_is_' + parent_id).hide(); | |
269 | cj('.parent_is_' + parent_id).each(function(i, obj) { | |
270 | // also hide children of children | |
271 | var gID = cj(this).find('td:nth-child(2)').text(); | |
272 | cj('.parent_is_' + gID).hide(); | |
273 | }); | |
274 | } | |
275 | }); | |
276 | ||
277 | function showChildren( parent_id, showOrgInfo, group_id, levelClass) { | |
278 | var rowID = '#row_' + parent_id; | |
279 | if ( group_id ) { | |
280 | rowID = '#row_' + parent_id + '_' + group_id; | |
281 | } | |
282 | if ( cj(rowID).next().hasClass('parent_is_' + parent_id ) ) { | |
283 | // child rows for this parent have already been retrieved so just show them | |
284 | cj('.parent_is_' + parent_id ).show(); | |
285 | } else { | |
286 | var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}; | |
287 | cj.ajax( { | |
288 | "dataType": 'json', | |
289 | "url": sourceUrl, | |
290 | "data": {'parent_id': parent_id, 'showOrgInfo': showOrgInfo}, | |
291 | "success": function(response){ | |
292 | var appendHTML = ''; | |
293 | cj.each( response, function( i, val ) { | |
7d644ac8 | 294 | appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" data-entity="group" data-id="'+ val.group_id +'" class="crm-entity parent_is_' + parent_id + ' crm-row-child ' + val.class + '">'; |
6a488035 | 295 | if ( val.is_parent ) { |
7d644ac8 | 296 | 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-name">' + val.group_name + '</span></td>'; |
6a488035 TO |
297 | } |
298 | else { | |
7d644ac8 | 299 | appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span><span class="crm-editable crmf-name">' + val.group_name + '</span></td>'; |
6a488035 TO |
300 | } |
301 | appendHTML += "<td>" + val.group_id + "</td>"; | |
302 | appendHTML += "<td>" + val.created_by + "</td>"; | |
7d644ac8 | 303 | appendHTML += '<td><span class="crm-editable crmf-description" data-type="textarea">' + (val.group_description || '') + "</span></td>"; |
6a488035 TO |
304 | appendHTML += "<td>" + val.group_type + "</td>"; |
305 | appendHTML += "<td>" + val.visibility + "</td>"; | |
995d35d9 DG |
306 | if (showOrgInfo) { |
307 | appendHTML += "<td>" + val.org_info + "</td>"; | |
308 | } | |
6a488035 TO |
309 | appendHTML += "<td>" + val.links + "</td>"; |
310 | appendHTML += "</tr>"; | |
311 | }); | |
312 | cj( rowID ).after( appendHTML ); | |
b22f0cad | 313 | cj( rowID ).next().trigger('crmLoad'); |
7d644ac8 | 314 | cj('.crm-editable').crmEditable(); |
6a488035 TO |
315 | } |
316 | } ); | |
317 | } | |
318 | } | |
319 | ||
320 | </script> | |
321 | {/literal} |