grouppicker.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Group Picker. Sends an array of group guids.
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. *
  8. * @uses $vars['values'] Array of gruop guids for already selected groups or null
  9. * @uses $vars['limit'] Limit number of groups (default 0 = no limit)
  10. * @uses $vars['name'] Name of the returned data array (default "groups")
  11. * @uses $vars['handler'] Name of page handler used to power search (default "livesearch")
  12. *
  13. * Defaults to lazy load group lists in alphabetical order. User needs
  14. * to type two characters before seeing the group popup list.
  15. *
  16. * As groups are selected they move down to a "groups" box.
  17. * When this happens, a hidden input is created to return the GUID in the array with the form
  18. */
  19. elgg_load_js('jquery.ui.autocomplete.html');
  20. if (empty($vars['name'])) {
  21. $vars['name'] = 'groups';
  22. }
  23. $name = $vars['name'];
  24. $name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
  25. $guids = (array)elgg_extract('values', $vars, array());
  26. $handler = elgg_extract('handler', $vars, 'livesearch');
  27. $handler = htmlspecialchars($handler, ENT_QUOTES, 'UTF-8');
  28. $limit = (int)elgg_extract('limit', $vars, 0);
  29. ?>
  30. <div class="elgg-group-picker ui-front" data-limit="<?php echo $limit ?>" data-name="<?php echo $name ?>" data-handler="<?php echo $handler ?>">
  31. <input type="text" class="elgg-input-group-picker" size="30"/>
  32. <ul class="elgg-group-picker-list">
  33. <?php
  34. foreach ($guids as $guid) {
  35. $entity = get_entity($guid);
  36. if ($entity) {
  37. echo elgg_view('input/grouppicker/item', array(
  38. 'entity' => $entity,
  39. 'input_name' => $vars['name'],
  40. ));
  41. }
  42. }
  43. ?>
  44. </ul>
  45. </div>
  46. <script type="text/javascript">
  47. // make sure the jQueryUI Autocomplete lib is available in ajax loaded views
  48. if (typeof(filter) !== "function") {
  49. $.getScript(elgg.get_site_url() + "vendors/jquery/jquery.ui.autocomplete.html.js");
  50. }
  51. require(['elgg/GroupPicker'], function (GroupPicker) {
  52. GroupPicker.setup('.elgg-group-picker[data-name="<?php echo $name ?>"]');
  53. });
  54. </script>