mirror of
https://github.com/humhub/humhub.git
synced 2025-04-21 15:41:54 +02:00
Updated the UserPicker (Disabled users who are already members)
This commit is contained in:
parent
15ec80ef57
commit
0c5d037b61
@ -46,7 +46,9 @@
|
||||
'beforeSend' => 'function(){ $("#invite-loader").removeClass("hidden"); }',
|
||||
'success' => 'function(html){ $("#globalModal").html(html); }',
|
||||
), array('class' => 'btn btn-primary', 'id' => 'inviteBtn'));
|
||||
?><button type="button" class="btn btn-primary" data-dismiss="modal"><?php echo Yii::t('base', 'Close'); ?></button>
|
||||
?>
|
||||
<button type="button" class="btn btn-primary"
|
||||
data-dismiss="modal"><?php echo Yii::t('base', 'Close'); ?></button>
|
||||
|
||||
<div class="col-md-1 modal-loader">
|
||||
<div id="invite-loader" class="loader loader-small hidden"></div>
|
||||
|
@ -30,6 +30,7 @@ class SearchController extends Controller {
|
||||
$keyword = Yii::app()->request->getParam('keyword', ""); // guid of user/workspace
|
||||
$page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination)
|
||||
$limit = (int) Yii::app()->request->getParam('limit', HSetting::Get('paginationSize')); // current page (pagination)
|
||||
$spaceId = (int) Yii::app()->request->getParam('space_id', 0);
|
||||
$hitCount = 0;
|
||||
|
||||
$keyword = Yii::app()->input->stripClean($keyword);
|
||||
@ -49,6 +50,9 @@ class SearchController extends Controller {
|
||||
$query = "email:" . $keyword . " AND (model:User)";
|
||||
}
|
||||
|
||||
// get members of the current space
|
||||
$spaceMembers = SpaceMembership::model()->findAll('space_id=:space_id', array(':space_id'=>$spaceId));
|
||||
|
||||
//$hits = HSearch::getInstance()->Find($query);
|
||||
//, $limit, $page
|
||||
$hits = new ArrayObject(
|
||||
@ -80,6 +84,7 @@ class SearchController extends Controller {
|
||||
$userInfo['displayName'] = $user->displayName;
|
||||
$userInfo['image'] = $user->getProfileImage()->getUrl();
|
||||
$userInfo['link'] = $user->getUrl();
|
||||
$userInfo['isMember'] = $this->checkMembership($spaceMembers, $userId);
|
||||
$results[] = $userInfo;
|
||||
} else {
|
||||
Yii::log("Could not load use with id " . $userId . " from search index!", CLogger::LEVEL_ERROR);
|
||||
@ -93,6 +98,23 @@ class SearchController extends Controller {
|
||||
Yii::app()->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* check Membership of users
|
||||
*
|
||||
*/
|
||||
private function checkMembership($members, $userId) {
|
||||
|
||||
// check if current user is member of this space
|
||||
foreach ($members as $member) {
|
||||
if ($userId == $member->user_id) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -230,14 +230,22 @@ $.fn.userpicker = function (options) {
|
||||
|
||||
for (var i = 0; i < json.length; i++) {
|
||||
|
||||
// build <li> entry
|
||||
var str = '<li id="user_' + json[i].guid + '"><a tabindex="-1" href="javascript:$.fn.userpicker.addUserTag(\'' + json[i].guid + '\', \'' + json[i].image + '\', \'' + json[i].displayName + '\', \'' + uniqueID + '\');"><img class="img-rounded" src="' + json[i].image + '" height="20" width="20" alt=""/> ' + json[i].displayName + '</a></li>';
|
||||
var _takenStyle = "";
|
||||
var _takenData = false;
|
||||
|
||||
// append the entry to the <ul> list if user is not already added
|
||||
if ($('#' + uniqueID + '_' + json[i].guid).length == 0) {
|
||||
$('#' + uniqueID + '_userpicker').append(str);
|
||||
// set options to link, that this entry is already taken or not available
|
||||
if ($('#' + uniqueID + '_' + json[i].guid).length != 0 || json[i].isMember == true) {
|
||||
_takenStyle = "opacity: 0.4;"
|
||||
_takenData = true;
|
||||
}
|
||||
|
||||
// build <li> entry
|
||||
var str = '<li id="user_' + json[i].guid + '"><a style="' + _takenStyle + '" data-taken="' + _takenData + '" tabindex="-1" href="javascript:$.fn.userpicker.addUserTag(\'' + json[i].guid + '\', \'' + json[i].image + '\', \'' + json[i].displayName + '\', \'' + uniqueID + '\');"><img class="img-rounded" src="' + json[i].image + '" height="20" width="20" alt=""/> ' + json[i].displayName + '</a></li>';
|
||||
|
||||
// append the entry to the <ul> list
|
||||
$('#' + uniqueID + '_userpicker').append(str);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// check if the list is empty
|
||||
@ -290,35 +298,36 @@ $.fn.userpicker = function (options) {
|
||||
// Add a usertag for invitation
|
||||
$.fn.userpicker.addUserTag = function (guid, image_url, name, id) {
|
||||
|
||||
// Building a new <li> entry
|
||||
var _tagcode = '<li class="userInput" id="' + id + '_' + guid + '"><img class="img-rounded" alt="24x24" data-src="holder.js/24x24" style="width: 24px; height: 24px;" src="' + image_url + '" alt="' + name + '" width="24" height="24" />' + name + '<i class="icon-remove-sign"></i></li>';
|
||||
if ($('#user_' + guid + ' a').attr('data-taken') != "true") {
|
||||
|
||||
// Building a new <li> entry
|
||||
var _tagcode = '<li class="userInput" id="' + id + '_' + guid + '"><img class="img-rounded" alt="24x24" data-src="holder.js/24x24" style="width: 24px; height: 24px;" src="' + image_url + '" alt="' + name + '" width="24" height="24" />' + name + '<i class="icon-remove-sign"></i></li>';
|
||||
|
||||
|
||||
// insert the new created <li> entry into the <ul> construct
|
||||
$('#' + id + '_tag_input').before(_tagcode);
|
||||
// insert the new created <li> entry into the <ul> construct
|
||||
$('#' + id + '_tag_input').before(_tagcode);
|
||||
|
||||
// remove tag, by clicking the close icon
|
||||
$('#'+ id +'_' + guid + " i").click(function () {
|
||||
// remove tag, by clicking the close icon
|
||||
$('#' + id + '_' + guid + " i").click(function () {
|
||||
|
||||
// remove user tag
|
||||
$('#'+ id +'_' + guid).remove();
|
||||
// remove user tag
|
||||
$('#' + id + '_' + guid).remove();
|
||||
|
||||
// reduce the count of added user
|
||||
userCount--;
|
||||
// reduce the count of added user
|
||||
userCount--;
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
// hide user results
|
||||
$('#' + id + '_userpicker').hide();
|
||||
// hide user results
|
||||
$('#' + id + '_userpicker').hide();
|
||||
|
||||
// set focus to the input element
|
||||
$('#' + id + '_tag_input_field').focus();
|
||||
// set focus to the input element
|
||||
$('#' + id + '_tag_input_field').focus();
|
||||
|
||||
// Clear the textinput
|
||||
$('#' + id + '_tag_input_field').val('');
|
||||
// Clear the textinput
|
||||
$('#' + id + '_tag_input_field').val('');
|
||||
|
||||
// raise the count of added user
|
||||
//id++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -336,7 +345,7 @@ $.fn.userpicker.parseUserInput = function (id) {
|
||||
|
||||
|
||||
// get user guid without unique userpicker id
|
||||
var pureID = this.id.replace(id+'_','');
|
||||
var pureID = this.id.replace(id + '_', '');
|
||||
|
||||
// add the user guid as plain text
|
||||
$(this).after(pureID + ",");
|
||||
|
@ -83,7 +83,7 @@ class UserPickerWidget extends HWidget {
|
||||
|
||||
// Default user search for all users
|
||||
if ($this->userSearchUrl == "")
|
||||
$this->userSearchUrl = Yii::app()->getController()->createUrl('//user/search/json', array('keyword' => '-keywordPlaceholder-'));
|
||||
$this->userSearchUrl = Yii::app()->getController()->createUrl('//user/search/json', array('keyword' => '-keywordPlaceholder-', 'space_id' => Yii::app()->getController()->getSpace()->id));
|
||||
|
||||
$assetPrefix = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../resources', true, 0, defined('YII_DEBUG'));
|
||||
Yii::app()->clientScript->registerScriptFile($assetPrefix . '/jquery.highlight.min.js', CClientScript::POS_END);
|
||||
|
Loading…
x
Reference in New Issue
Block a user