Merge pull request #1537 from buddha87/master

Fix: New Mail Modal Form fix
This commit is contained in:
buddha87 2016-03-08 21:57:21 +01:00
commit e619b9463e
7 changed files with 121 additions and 16 deletions

View File

@ -158,9 +158,10 @@ function setModalHandler() {
// unbind all previously-attached events
$("a[data-target='#globalModal']").unbind();
$("a[data-target='#globalModal']").click(function (ev) {
$(document).off('click.humhub');
$(document).on('click.humhub', "a[data-target='#globalModal']", function (ev) {
ev.preventDefault();
$("#globalModal").modal("show");
var target = $(this).attr("href");

View File

@ -207,6 +207,9 @@ use humhub\modules\space\models\Space;
$('#public').attr('checked', false);
$('#contentForm_message_contenteditable').html('<?php echo Html::encode(Yii::t("ContentModule.widgets_views_contentForm", "What's on your mind?")); ?>');
$('#contentForm_message_contenteditable').addClass('atwho-placeholder');
$('#contentFormBody').find('.atwho-input').trigger('clear');
// Notify FileUploadButtonWidget to clear (by providing uploaderId)
resetUploader('contentFormFiles');
} else {

View File

@ -18,7 +18,7 @@ $this->pageTitle = Yii::t('UserModule.views_auth_login', 'Login');
<div class="panel-body">
<?php $form = ActiveForm::begin(['id' => 'account-login-form']); ?>
<?php $form = ActiveForm::begin(['id' => 'account-login-form', 'enableClientValidation'=>false]); ?>
<p><?php echo Yii::t('UserModule.views_auth_login', "If you're already a member, please login with your username/email and password."); ?></p>

View File

@ -3,6 +3,7 @@
namespace humhub\modules\user\widgets;
use Yii;
use yii\helpers\Html;
use \yii\helpers\Url;
/**
@ -86,6 +87,18 @@ class UserPicker extends \yii\base\Widget
* @var string for input placeholder attribute.
*/
public $placeholderText = "";
/**
* Can be used to filter user roles like friends only
* @var type
*/
public $userRole = null;
/**
* Used to transfer additional data to the server
* @var type
*/
public $data = null;
/**
* Inits the User Picker
@ -118,17 +131,71 @@ class UserPicker extends \yii\base\Widget
$currentValue = $this->model->$attribute;
}
return $this->render('userPicker', array(
return $this->render('userPicker', [
'userSearchUrl' => $this->userSearchUrl,
'maxUsers' => $this->maxUsers,
'currentValue' => $currentValue,
'inputId' => $this->inputId,
'focus' => $this->focus,
'userGuid' => $this->userGuid,
'userRole' => $this->userRole,
'data' => json_encode($this->data),
'placeholderText' => $this->placeholderText,
));
]);
}
/**
* Creates an json result with user information arrays. A user will be marked
* as disabled, if the permission check fails on this user.
*
* @param type $users
* @param type $permission
* @return type
*/
public static function asJSON($users, $permission = null)
{
if (is_array($users)) {
$result = [];
foreach ($users as $user) {
if ($user != null) {
$result[] = self::createJSONUserInfo($user, $permission);
}
}
return $result;
} else {
return self::createJsonUserInfo($users, $permission);
}
}
/**
* Creates an single user-information array for a given user. A user will be marked
* as disabled, if the permission check fails on this user.
*
* @param type $user
* @param type $permission
* @return type
*/
private static function createJSONUserInfo($user, $permission = null, $priority = null)
{
$disabled = false;
if($permission != null && $permission instanceof \humhub\libs\BasePermission) {
$disabled = !$user->getPermissionManager()->can($permission);
} else if($permission != null) {
$disabled = $permission;
}
$priority = ($priority == null) ? 0 : $priority;
$userInfo = [];
$userInfo['guid'] = $user->guid;
$userInfo['disabled'] = $disabled;
$userInfo['displayName'] = Html::encode($user->displayName);
$userInfo['image'] = $user->getProfileImage()->getUrl();
$userInfo['priority'] = $priority;
$userInfo['link'] = $user->getUrl();
return $userInfo;
}
}
?>

View File

@ -41,6 +41,7 @@ foreach (explode(",", $currentValue) as $guid) {
currentValue: '<?php echo $newValue; ?>',
focus: '<?php echo $focus; ?>',
userGuid: '<?php echo $userGuid; ?>',
data: <?php echo $data ?>,
placeholderText: '<?php echo $placeholderText; ?>'
});
});

View File

@ -92,7 +92,7 @@ use yii\helpers\Url;
//it seems atwho detatches the original element so we have to do a requery
$editableContent = $('#<?php echo $id; ?>_contenteditable');
// remove placeholder text
$editableContent.on('focus', function () {
if ($(this).hasClass('atwho-placeholder')) {
@ -109,7 +109,6 @@ use yii\helpers\Url;
}
}).on('paste', function (event) {
// disable standard behavior
event.preventDefault();
@ -141,6 +140,9 @@ use yii\helpers\Url;
}).on("inserted.atwho", function (event, $li) {
// set attribute for showing search hint
$(this).attr('data-query', '0');
}).on('clear', function(evt) {
$(this).html(placeholder);
$(this).addClass('atwho-placeholder');
});
});

View File

@ -23,6 +23,7 @@ $.fn.userpicker = function (options) {
renderType: "normal", // possible values are "normal", "partial"
focus: false,
userGuid: "",
data: {},
placeholderText: 'Add an user'
}, options);
@ -113,7 +114,7 @@ $.fn.userpicker = function (options) {
// set focus
$('#' + uniqueID + '_tag_input_field').focus();
})
});
$('#' + uniqueID + '_tag_input_field').keydown(function (event) {
@ -144,7 +145,7 @@ $.fn.userpicker = function (options) {
}
}
})
});
$('#' + uniqueID + '_tag_input_field').keyup(function (event) {
@ -208,17 +209,17 @@ $.fn.userpicker = function (options) {
}
})
});
$('#' + uniqueID + '_tag_input_field').focusout(function () {
// set the plain text including user guids to the original input or textarea element
$(options.inputId).val($.fn.userpicker.parseUserInput(uniqueID));
})
});
function loadUser(string) {
function loadUser(keyword) {
// remove existings entries
$('#' + uniqueID + '_userpicker li').remove();
@ -226,11 +227,41 @@ $.fn.userpicker = function (options) {
// show loader while loading
$('#' + uniqueID + '_userpicker').html('<li><div class="loader"><div class="sk-spinner sk-spinner-three-bounce"><div class="sk-bounce1"></div><div class="sk-bounce2"></div><div class="sk-bounce3"></div></div></div></li>');
jQuery.getJSON(options.searchUrl.replace('-keywordPlaceholder-', string), function (json) {
// build data object
var data = options['data'] || {};
//This is the preferred way of adding the keyword
if(options['searchUrl'].indexOf('-keywordPlaceholder-') < 0) {
data['keyword'] = keyword;
}
//Set the user role filter
if(options['userRole']) {
data['userRole'] = options['userRole'];
}
console.log(data);
jQuery.getJSON(options.searchUrl.replace('-keywordPlaceholder-', keyword), data, function (json) {
// remove existings entries
$('#' + uniqueID + '_userpicker li').remove();
// quick sort by disabled/enabled and contains keyword
json.sort(function(a,b) {
if(a.disabled !== b.disabled) {
return (a.disabled < b.disabled) ? -1 : 1;
} else if(a.priority !== b.priority) {
return (a.priority > b.priority) ? -1 : 1;
} else if(a.displayName.indexOf(keyword) >= 0 && b.displayName.indexOf(keyword) < 0) {
return -1;
} else if(a.displayName.indexOf(keyword) < 0 && b.displayName.indexOf(keyword) >= 0) {
return 1;
}
return 0;
});
if (json.length > 0) {
@ -239,9 +270,9 @@ $.fn.userpicker = function (options) {
var _takenStyle = "";
var _takenData = false;
// set options to link, that this entry is already taken or not available
if ($('#' + uniqueID + '_' + json[i].guid).length != 0 || json[i].isMember == true || json[i].guid == options.userGuid) {
if (json[i].disabled == true || $('#' + uniqueID + '_' + json[i].guid).length != 0 || json[i].isMember == true || json[i].guid == options.userGuid) {
_takenStyle = "opacity: 0.4;"
_takenData = true;
}
@ -275,7 +306,7 @@ $.fn.userpicker = function (options) {
$('#' + uniqueID + '_userpicker li').removeHighlight();
// add new highlight matching strings
$('#' + uniqueID + '_userpicker li').highlight(string);
$('#' + uniqueID + '_userpicker li').highlight(keyword);
// add selection to the first space entry
$('#' + uniqueID + '_userpicker li:eq(0)').addClass('selected');