Commit | Line | Data |
---|---|---|
6a488035 TO |
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 | <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> | |
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*} | |
89 | {include file="CRM/common/enableDisable.tpl"} | |
90 | ||
91 | {literal} | |
92 | <script type="text/javascript"> | |
93 | cj( function() { | |
94 | buildGroupSelector( false ); | |
95 | cj('#_qf_Search_refresh').click( function() { | |
96 | buildGroupSelector( true ); | |
97 | }); | |
98 | }); | |
99 | ||
100 | function buildGroupSelector( filterSearch ) { | |
101 | if ( filterSearch ) { | |
102 | crmGroupSelector.fnDestroy(); | |
103 | var parentsOnly = 0; | |
104 | 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>'; | |
105 | } else { | |
106 | var parentsOnly = 1; | |
107 | var ZeroRecordText = {/literal}'{ts escape="js"}<div class="status messages">No Groups have been created for this site.{/ts}</div>'{literal}; | |
108 | } | |
109 | ||
110 | var columns = ''; | |
111 | var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}; | |
112 | var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; | |
113 | ||
114 | crmGroupSelector = cj('#crm-group-selector').dataTable({ | |
115 | "bFilter" : false, | |
116 | "bAutoWidth" : false, | |
117 | "aaSorting" : [], | |
118 | "aoColumns" : [ | |
119 | {sClass:'crm-group-name'}, | |
120 | {sClass:'crm-group-group_id'}, | |
121 | {sClass:'crm-group-created_by'}, | |
122 | {sClass:'crm-group-description', bSortable:false}, | |
123 | {sClass:'crm-group-group_type'}, | |
124 | {sClass:'crm-group-visibility'}, | |
125 | {sClass:'crm-group-group_links', bSortable:false}, | |
126 | {/literal}{if $showOrgInfo}{literal} | |
127 | {sClass:'crm-group-org_info', bSortable:false}, | |
128 | {/literal}{/if}{literal} | |
129 | {sClass:'hiddenElement', bSortable:false} | |
130 | ], | |
131 | "bProcessing": true, | |
132 | "asStripClasses" : [ "odd-row", "even-row" ], | |
133 | "sPaginationType": "full_numbers", | |
134 | "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', | |
135 | "bServerSide": true, | |
136 | "bJQueryUI": true, | |
137 | "sAjaxSource": sourceUrl, | |
138 | "iDisplayLength": 25, | |
139 | "oLanguage": { "sZeroRecords": ZeroRecordText, | |
140 | "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal}, | |
141 | "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal}, | |
142 | "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal}, | |
143 | "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal}, | |
144 | "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal}, | |
145 | "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal}, | |
146 | "oPaginate": { | |
147 | "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal}, | |
148 | "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal}, | |
149 | "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal}, | |
150 | "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal} | |
151 | } | |
152 | }, | |
153 | "fnDrawCallback": function() { setSelectorClass( parentsOnly, showOrgInfo ); }, | |
154 | "fnServerData": function ( sSource, aoData, fnCallback ) { | |
155 | aoData.push( {name:'showOrgInfo', value: showOrgInfo }, | |
156 | {name:'parentsOnly', value: parentsOnly } | |
157 | ); | |
158 | if ( filterSearch ) { | |
159 | var groupTypes = ''; | |
160 | if ( cj('.crm-group-search-form-block #group_type_1').prop('checked') ) { | |
161 | groupTypes = '1'; | |
162 | } | |
163 | ||
164 | if ( cj('.crm-group-search-form-block #group_type_2').prop('checked') ) { | |
165 | if ( groupTypes ) { | |
166 | groupTypes = groupTypes + ',2'; | |
167 | } else { | |
168 | groupTypes = groupTypes + '2'; | |
169 | } | |
170 | } | |
171 | ||
172 | var groupStatus = ''; | |
173 | if ( cj('.crm-group-search-form-block #group_status_1').prop('checked') ) { | |
174 | groupStatus = '1'; | |
175 | } | |
176 | ||
177 | if ( cj('.crm-group-search-form-block #group_status_2').prop('checked') ) { | |
178 | if ( groupStatus ) { | |
179 | groupStatus = '3'; | |
180 | } else { | |
181 | groupStatus = '2'; | |
182 | } | |
183 | } | |
184 | ||
185 | aoData.push( | |
186 | {name:'title', value: cj('.crm-group-search-form-block #title').val()}, | |
187 | {name:'created_by', value: cj('.crm-group-search-form-block #created_by').val()}, | |
188 | {name:'group_type', value: groupTypes }, | |
189 | {name:'visibility', value: cj('.crm-group-search-form-block #visibility').val()}, | |
190 | {name:'status', value: groupStatus } | |
191 | ); | |
192 | } | |
193 | cj.ajax( { | |
194 | "dataType": 'json', | |
195 | "type": "POST", | |
196 | "url": sSource, | |
197 | "data": aoData, | |
198 | "success": fnCallback | |
199 | } ); | |
200 | } | |
201 | }); | |
202 | } | |
203 | ||
204 | function setSelectorClass( parentsOnly, showOrgInfo ) { | |
205 | cj('#crm-group-selector tr').each( function( ) { | |
206 | var className = cj(this).find('td:last-child').text(); | |
207 | cj(this).addClass( className ); | |
208 | var rowID = cj(this).find('td:nth-child(2)').text(); | |
209 | cj(this).prop( 'id', 'row_' + rowID ); | |
210 | if (parentsOnly) { | |
211 | if ( cj(this).hasClass('crm-group-parent') ) { | |
212 | cj(this).find('td:first').prepend('{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}'); | |
213 | } | |
214 | } | |
215 | }); | |
216 | } | |
217 | ||
218 | // show hide children | |
219 | cj('#crm-group-selector').on( 'click', 'span.show-children', function(){ | |
220 | var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; | |
221 | var rowID = cj(this).parents('tr').prop('id'); | |
222 | var parentRow = rowID.split('_'); | |
223 | var parent_id = parentRow[1]; | |
224 | var group_id = ''; | |
225 | if ( parentRow[2]) { | |
226 | group_id = parentRow[2]; | |
227 | } | |
228 | var levelClass = 'level_2'; | |
229 | // check enclosing td if already at level 2 | |
230 | if ( cj(this).parent().hasClass('level_2') ) { | |
231 | levelClass = 'level_3'; | |
232 | } | |
233 | if ( cj(this).hasClass('collapsed') ) { | |
234 | cj(this).removeClass("collapsed").addClass("expanded").attr("title",{/literal}"{ts escape='js'}hide child groups{/ts}"{literal}); | |
235 | showChildren( parent_id, showOrgInfo, group_id, levelClass ); | |
236 | } | |
237 | else { | |
238 | cj(this).removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); | |
239 | cj('.parent_is_' + parent_id).find('.show-children').removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); | |
240 | cj('.parent_is_' + parent_id).hide(); | |
241 | cj('.parent_is_' + parent_id).each(function(i, obj) { | |
242 | // also hide children of children | |
243 | var gID = cj(this).find('td:nth-child(2)').text(); | |
244 | cj('.parent_is_' + gID).hide(); | |
245 | }); | |
246 | } | |
247 | }); | |
248 | ||
249 | function showChildren( parent_id, showOrgInfo, group_id, levelClass) { | |
250 | var rowID = '#row_' + parent_id; | |
251 | if ( group_id ) { | |
252 | rowID = '#row_' + parent_id + '_' + group_id; | |
253 | } | |
254 | if ( cj(rowID).next().hasClass('parent_is_' + parent_id ) ) { | |
255 | // child rows for this parent have already been retrieved so just show them | |
256 | cj('.parent_is_' + parent_id ).show(); | |
257 | } else { | |
258 | var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}; | |
259 | cj.ajax( { | |
260 | "dataType": 'json', | |
261 | "url": sourceUrl, | |
262 | "data": {'parent_id': parent_id, 'showOrgInfo': showOrgInfo}, | |
263 | "success": function(response){ | |
264 | var appendHTML = ''; | |
265 | cj.each( response, function( i, val ) { | |
266 | appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" class="parent_is_' + parent_id + ' crm-row-child ' + val.class + '">'; | |
267 | if ( val.is_parent ) { | |
268 | appendHTML += '<td class="crm-group-name ' + levelClass + '">' + '{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}' + val.group_name + '</td>'; | |
269 | } | |
270 | else { | |
271 | appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span>' + val.group_name + '</td>'; | |
272 | } | |
273 | appendHTML += "<td>" + val.group_id + "</td>"; | |
274 | appendHTML += "<td>" + val.created_by + "</td>"; | |
275 | if (val.group_description) { | |
276 | appendHTML += "<td>" + val.group_description + "</td>"; | |
277 | } else { | |
278 | appendHTML += "<td> </td>"; | |
279 | } | |
280 | appendHTML += "<td>" + val.group_type + "</td>"; | |
281 | appendHTML += "<td>" + val.visibility + "</td>"; | |
282 | appendHTML += "<td>" + val.links + "</td>"; | |
283 | appendHTML += "</tr>"; | |
284 | }); | |
285 | cj( rowID ).after( appendHTML ); | |
286 | } | |
287 | } ); | |
288 | } | |
289 | } | |
290 | ||
291 | </script> | |
292 | {/literal} |