elgg.provide('elgg.userpicker');
+/**
+ * Userpicker initialization
+ *
+ * The userpicker is an autocomplete library for selecting multiple users or
+ * friends. It works in concert with the view input/userpicker.
+ *
+ * @return void
+ */
elgg.userpicker.init = function() {
// binding autocomplete.
}
/**
+ * Adds a user to the select user list
+ *
* elgg.userpicker.userList is defined in the input/userpicker view
+ *
+ * @param {Object} event
+ * @param {Object} ui The object returned by the autocomplete endpoint
+ * @return void
*/
elgg.userpicker.addUser = function(event, ui) {
var info = ui.item;
elgg.userpicker.userList[info.guid] = true;
var users = $(this).siblings('.elgg-user-picker-list');
var li = '<input type="hidden" name="members[]" value="' + info.guid + '" />';
- li += elgg.userpicker.renderUser(info);
+ li += elgg.userpicker.viewUser(info);
$('<li>').html(li).appendTo(users);
}
event.preventDefault();
}
+/**
+ * Remove a user from the selected user list
+ *
+ * @param {Object} event
+ * @return void
+ */
elgg.userpicker.removeUser = function(event) {
var item = $(this).closest('.elgg-user-picker-list > li');
}
/**
- * The html in this method has to remain sync'ed with input/userpicker
+ * Render the list item for insertion into the selected user list
+ *
+ * The html in this method has to remain synced with the input/userpicker view
+ *
+ * @param {Object} info The object returned by the autocomplete endpoint
+ * @return string
*/
-elgg.userpicker.renderUser = function(info) {
+elgg.userpicker.viewUser = function(info) {
var deleteLink = "<a href='#' class='elgg-userpicker-remove'>X</a>";
return html;
}
+/**
+ * Get the parameters to use for autocomplete
+ *
+ * This grabs the value of the friends checkbox.
+ *
+ * @param {Object} obj Object for the autocomplete callback
+ * @return Object
+ */
elgg.userpicker.getSearchParams = function(obj) {
if (obj.element.siblings('[name=match_on]').attr('checked')) {
return {'match_on[]': 'friends', 'term' : obj.term};
*
* The name of the hidden fields is members[]
*
- * Defaults to lazy load user lists in paginated alphabetical order. User needs
+ * @warning Only a single input/userpicker is supported per web page.
+ *
+ * Defaults to lazy load user lists in alphabetical order. User needs
* to type two characters before seeing the user popup list.
*
- * As users are checked they move down to a "users" box.
+ * As users are selected they move down to a "users" box.
* When this happens, a hidden input is created with the
* name of members[] and a value of the GUID.
- *
- * @warning: this is not stable
*/
elgg_load_js('elgg.userpicker');
$icon = elgg_view_entity_icon($user, 'tiny', array('hover' => false));
+ // this html must be synced with the userpicker.js library
$code = '<li><div class="elgg-image-block">';
$code .= "<div class='elgg-image'>$icon</div>";
$code .= "<div class='elgg-image-alt'><a href='#' class='elgg-userpicker-remove'>X</a></div>";
<ul class="elgg-user-picker-list"><?php echo $user_list; ?></ul>
</div>
<script type="text/javascript">
+ // @todo grab the values in the init function rather than using inline JS
elgg.userpicker.userList = <?php echo $json_values ?>;
</script>
\ No newline at end of file