diff options
author | cash <cash.costello@gmail.com> | 2011-10-13 21:31:27 -0400 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-10-13 21:31:27 -0400 |
commit | c6a14d6c6a04eeee2c126ea20ec0e9ee23489ef3 (patch) | |
tree | 6808e6674d64e7b0997271c347bd605a81e4b843 | |
parent | 7e23a3bd6382190084f136ed5aeb6b910ae00eee (diff) | |
download | elgg-c6a14d6c6a04eeee2c126ea20ec0e9ee23489ef3.tar.gz elgg-c6a14d6c6a04eeee2c126ea20ec0e9ee23489ef3.tar.bz2 |
displaying users that have been selected and added remove capability
-rw-r--r-- | engine/lib/input.php | 39 | ||||
-rw-r--r-- | js/lib/userpicker.js | 40 | ||||
-rw-r--r-- | views/default/css/elements/forms.php | 15 | ||||
-rw-r--r-- | views/default/input/userpicker.php | 19 |
4 files changed, 81 insertions, 32 deletions
diff --git a/engine/lib/input.php b/engine/lib/input.php index ceda2be3b..f2cefc3e5 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -288,17 +288,26 @@ function input_livesearch_page_handler($page) { if ($entities = get_data($query)) { foreach ($entities as $entity) { + $entity = get_entity($entity->guid); + if (!$entity) { + continue; + } + if (in_array('groups', $match_on)) { $value = $entity->guid; } else { $value = $entity->username; } - $output = elgg_view_list_item(get_entity($entity->guid), array( + $output = elgg_view_list_item($entity, array( 'hover' => false, 'class' => 'elgg-autocomplete-item', )); + $icon = elgg_view_entity_icon($entity, 'tiny', array( + 'hover' => false, + )); + $result = array( 'type' => 'user', 'name' => $entity->name, @@ -306,6 +315,8 @@ function input_livesearch_page_handler($page) { 'guid' => $entity->guid, 'label' => $output, 'value' => $value, + 'icon' => $icon, + 'url' => $entity->getURL(), ); $results[$entity->name . rand(1, 100)] = $result; } @@ -326,11 +337,20 @@ function input_livesearch_page_handler($page) { "; if ($entities = get_data($query)) { foreach ($entities as $entity) { - $output = elgg_view_list_item(get_entity($entity->guid), array( + $entity = get_entity($entity->guid); + if (!$entity) { + continue; + } + + $output = elgg_view_list_item($entity, array( 'hover' => false, 'class' => 'elgg-autocomplete-item', )); + $icon = elgg_view_entity_icon($entity, 'tiny', array( + 'hover' => false, + )); + $result = array( 'type' => 'group', 'name' => $entity->name, @@ -338,6 +358,8 @@ function input_livesearch_page_handler($page) { 'guid' => $entity->guid, 'label' => $output, 'value' => $entity->guid, + 'icon' => $icon, + 'url' => $entity->getURL(), ); $results[$entity->name . rand(1, 100)] = $result; @@ -362,11 +384,20 @@ function input_livesearch_page_handler($page) { if ($entities = get_data($query)) { foreach ($entities as $entity) { - $output = elgg_view_list_item(get_entity($entity->guid), array( + $entity = get_entity($entity->guid); + if (!$entity) { + continue; + } + + $output = elgg_view_list_item($entity, array( 'hover' => false, 'class' => 'elgg-autocomplete-item', )); + $icon = elgg_view_entity_icon($entity, 'tiny', array( + 'hover' => false, + )); + $result = array( 'type' => 'user', 'name' => $entity->name, @@ -374,6 +405,8 @@ function input_livesearch_page_handler($page) { 'guid' => $entity->guid, 'label' => $output, 'value' => $entity->username, + 'icon' => $icon, + 'url' => $entity->getURL(), ); $results[$entity->name . rand(1, 100)] = $result; } diff --git a/js/lib/userpicker.js b/js/lib/userpicker.js index 780fa47c6..ece5a6951 100644 --- a/js/lib/userpicker.js +++ b/js/lib/userpicker.js @@ -24,7 +24,9 @@ elgg.userpicker.init = function() { select: elgg.userpicker.addUser }) }); -}; + + $('.elgg-userpicker-remove').live('click', elgg.userpicker.removeUser); +} /** * elgg.userpicker.userList is defined in the input/userpicker view @@ -35,24 +37,42 @@ elgg.userpicker.addUser = function(event, ui) { // do not allow users to be added multiple times if (!(info.guid in elgg.userpicker.userList)) { elgg.userpicker.userList[info.guid] = true; - var users = $(this).siblings('.elgg-user-picker-entries'); + var users = $(this).siblings('.elgg-user-picker-list'); var li = '<input type="hidden" name="members[]" value="' + info.guid + '" />'; + li += elgg.userpicker.renderUser(info); $('<li>').html(li).appendTo(users); } $(this).val(''); event.preventDefault(); -}; +} + +elgg.userpicker.removeUser = function(event) { + $(this).closest('.elgg-user-picker-list > li').remove(); + event.preventDefault(); +} -elgg.userpicker.removeUser = function(link, guid) { - $(link).closest('.elgg-user-picker-entries > li').remove(); -}; +/** + * The html in this method has to remain sync'ed with input/userpicker + */ +elgg.userpicker.renderUser = function(info) { + + var deleteLink = "<a href='#' class='elgg-userpicker-remove'>X</a>"; + + var html = "<div class='elgg-image-block'>"; + html += "<div class='elgg-image'>" + info.icon + "</div>"; + html += "<div class='elgg-image-alt'>" + deleteLink + "</div>"; + html += "<div class='elgg-body'>" + info.name + "</div>"; + html += "</div"; + + return html; +} -elgg.userpicker.getSearchParams = function(e) { - if (e.element.siblings('[name=match_on]').attr('checked')) { - return {'match_on[]': 'friends', 'term' : e.term}; +elgg.userpicker.getSearchParams = function(obj) { + if (obj.element.siblings('[name=match_on]').attr('checked')) { + return {'match_on[]': 'friends', 'term' : obj.term}; } else { - return {'match_on[]': 'users', 'term' : e.term}; + return {'match_on[]': 'users', 'term' : obj.term}; } } diff --git a/views/default/css/elements/forms.php b/views/default/css/elements/forms.php index fa90f2bfd..255d95622 100644 --- a/views/default/css/elements/forms.php +++ b/views/default/css/elements/forms.php @@ -272,15 +272,12 @@ input[type="radio"] { /* *************************************** USER PICKER *************************************** */ -.user-picker .user-picker-entry { - clear:both; - height:25px; - padding:5px; - margin-top:5px; - border-bottom:1px solid #cccccc; -} -.user-picker-entry .elgg-button-delete { - margin-right:10px; +.elgg-user-picker-list li:first-child { + border-top: 1px dotted #ccc; + margin-top: 5px; +} +.elgg-user-picker-list > li { + border-bottom: 1px dotted #ccc; } /* *************************************** diff --git a/views/default/input/userpicker.php b/views/default/input/userpicker.php index 94129d1e0..87cc6e24a 100644 --- a/views/default/input/userpicker.php +++ b/views/default/input/userpicker.php @@ -24,18 +24,17 @@ elgg_load_js('elgg.userpicker'); function user_picker_add_user($user_id) { $user = get_entity($user_id); if (!$user || !($user instanceof ElggUser)) { - return FALSE; + return false; } - $icon = $user->getIconURL('tiny'); - - $code = '<li class="elgg-image-block">'; - $code .= "<div class='elgg-image'><img class=\"livesearch_icon\" src=\"$icon\" /></div>"; - $code .= "<div class='elgg-image-alt'><a onclick='elgg.userpicker.removeUser(this, $user_id)'><strong>X</strong></a></div>"; - $code .= "<div class='elgg-body'>"; - $code .= "$user->name - $user->username"; - $code .= "<input type=\"hidden\" name=\"members[]\" value=\"$user_id\">"; + $icon = elgg_view_entity_icon($user, 'tiny', array('hover' => false)); + + $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>"; + $code .= "<div class='elgg-body'>" . $user->name . "</div>"; $code .= "</div>"; + $code .= "<input type=\"hidden\" name=\"members[]\" value=\"$user_id\">"; $code .= '</li>'; return $code; @@ -64,7 +63,7 @@ foreach ($vars['value'] as $user_id) { <input type="text" class="elgg-input-user-picker" size="30"/> <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> + <ul class="elgg-user-picker-list"><?php echo $user_list; ?></ul> </div> <script type="text/javascript"> elgg.userpicker.userList = <?php echo $json_values ?>; |