aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/lib/userpicker.js53
-rw-r--r--views/default/input/userpicker.php3
2 files changed, 16 insertions, 40 deletions
diff --git a/js/lib/userpicker.js b/js/lib/userpicker.js
index 826bf21a0..780fa47c6 100644
--- a/js/lib/userpicker.js
+++ b/js/lib/userpicker.js
@@ -1,14 +1,14 @@
elgg.provide('elgg.userpicker');
elgg.userpicker.init = function() {
+
// binding autocomplete.
// doing this as an each so we can pass this to functions.
$('.elgg-input-user-picker').each(function() {
-
- var _this = this;
-
+
$(this).autocomplete({
source: function(request, response) {
+
var params = elgg.userpicker.getSearchParams(this);
elgg.get('livesearch', {
@@ -20,53 +20,28 @@ elgg.userpicker.init = function() {
});
},
minLength: 2,
+ html: "html",
select: elgg.userpicker.addUser
})
-
- //@todo This seems convoluted
- .data("autocomplete")._renderItem = elgg.userpicker.formatItem;
});
};
-elgg.userpicker.formatItem = function(ul, item) {
- switch (item.type) {
- case 'user':
- case 'group':
- r = item.icon + item.name + ' - ' + item.desc;
- break;
-
- default:
- r = item.name + ' - ' + item.desc;
- break;
- }
-
- return $("<li/>")
- .data("item.autocomplete", item)
- .append(r)
- .appendTo(ul);
-};
-
+/**
+ * elgg.userpicker.userList is defined in the input/userpicker view
+ */
elgg.userpicker.addUser = function(event, ui) {
var info = ui.item;
-
+
// do not allow users to be added multiple times
if (!(info.guid in elgg.userpicker.userList)) {
elgg.userpicker.userList[info.guid] = true;
-
- var picker = $(this).closest('.elgg-user-picker');
- var users = picker.find('.elgg-user-picker-entries');
- var internalName = users.find('[type=hidden]').attr('name');
-
- // not sure why formatted isn't.
- var formatted = elgg.userpicker.formatItem(data);
-
- // add guid as hidden input and to list.
- var li = formatted + ' <div class="delete-button"><a onclick="elgg.userpicker.removeUser(this, ' + info.guid + ')"><strong>X</strong></a></div>'
- + '<input type="hidden" name="' + internalName + '" value="' + info.guid + '" />';
+ var users = $(this).siblings('.elgg-user-picker-entries');
+ var li = '<input type="hidden" name="members[]" value="' + info.guid + '" />';
$('<li>').html(li).appendTo(users);
-
- $(this).val('');
}
+
+ $(this).val('');
+ event.preventDefault();
};
elgg.userpicker.removeUser = function(link, guid) {
@@ -74,7 +49,7 @@ elgg.userpicker.removeUser = function(link, guid) {
};
elgg.userpicker.getSearchParams = function(e) {
- if ($(e).closest('.elgg-user-picker').find('[name=match_on]').attr('checked')) {
+ if (e.element.siblings('[name=match_on]').attr('checked')) {
return {'match_on[]': 'friends', 'term' : e.term};
} else {
return {'match_on[]': 'users', 'term' : e.term};
diff --git a/views/default/input/userpicker.php b/views/default/input/userpicker.php
index b852d24fc..94129d1e0 100644
--- a/views/default/input/userpicker.php
+++ b/views/default/input/userpicker.php
@@ -62,7 +62,8 @@ foreach ($vars['value'] as $user_id) {
?>
<div class="elgg-user-picker">
<input type="text" class="elgg-input-user-picker" size="30"/>
- <label><input type="checkbox" name="match_on" value="true" /><?php echo elgg_echo('userpicker:only_friends'); ?></label>
+ <input type="checkbox" name="match_on" value="true" />
+ <label><?php echo elgg_echo('userpicker:only_friends'); ?></label>
<ul class="elgg-user-picker-entries"><?php echo $user_list; ?></ul>
</div>
<script type="text/javascript">