mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Issue #1582 - Simplification and rewrite of userpicker() method.
This commit is contained in:
parent
0e9be6404b
commit
4125d04371
@ -1188,6 +1188,7 @@ class e_form
|
||||
* @param array|string $options [optional] 'readonly' (make field read only), 'name' (db field name, default user_name)
|
||||
* @return string HTML text for display
|
||||
*/
|
||||
/*
|
||||
function userpicker($name_fld, $id_fld='', $default_name, $default_id, $options = array())
|
||||
{
|
||||
if(!is_array($options))
|
||||
@ -1225,7 +1226,106 @@ class e_form
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* User Field - auto-complete search
|
||||
* @param string $name form element name
|
||||
* @param string|array $value comma separated list of user ids or array of userid=>username pairs.
|
||||
* @param array|string $options [optional]
|
||||
* @param int $options['limit'] Maximum number of users
|
||||
* @param string $options['id'] Custom id
|
||||
* @param string $options['inline'] Inline ID.
|
||||
*
|
||||
* @example $frm->userpicker('author', 1);
|
||||
* @example $frm->userpicker('authors', "1,2,3");
|
||||
* @example $frm->userpicker('author', array('user_id'=>1, 'user_name'=>'Admin');
|
||||
* @example $frm->userpicker('authors', array(0=>array('user_id'=>1, 'user_name'=>'Admin', 1=>array('user_id'=>2, 'user_name'=>'John'));
|
||||
*
|
||||
* @todo $options['type'] = 'select' - dropdown selections box with data returned as array instead of comma-separated.
|
||||
* @return string HTML text for display
|
||||
*/
|
||||
function userpicker($name, $value, $options = array())
|
||||
{
|
||||
if(!is_array($options))
|
||||
{
|
||||
parse_str($options, $options);
|
||||
}
|
||||
|
||||
$defaultItems = array();
|
||||
|
||||
if(is_array($value))
|
||||
{
|
||||
if(isset($value[0]))// multiple users.
|
||||
{
|
||||
foreach($value as $val)
|
||||
{
|
||||
$defaultItems[] = array('value'=>$val['user_id'], 'label'=>$val['user_name']);
|
||||
}
|
||||
|
||||
}
|
||||
else // single user
|
||||
{
|
||||
$defaultItems[] = array('value'=>$value['user_id'], 'label'=>$value['user_name']);
|
||||
}
|
||||
|
||||
}
|
||||
elseif(!empty($value)) /// comma separated with user-id lookup.
|
||||
{
|
||||
$tmp = explode(",", $value);
|
||||
foreach($tmp as $uid)
|
||||
{
|
||||
if($user = e107::user($uid))
|
||||
{
|
||||
$defaultItems[] = array('value'=>$user['user_id'], 'label'=>$user['user_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$parms = array(
|
||||
'selectize' => array(
|
||||
'loadPath' => e_BASE . 'user.php',
|
||||
'create' => false,
|
||||
'maxItems' => 1,
|
||||
'mode' => 'multi',
|
||||
'options' => $defaultItems
|
||||
)
|
||||
);
|
||||
|
||||
if(!empty($options['limit']))
|
||||
{
|
||||
$parms['selectize']['maxItems'] = intval($options['limit']);
|
||||
}
|
||||
|
||||
if(!empty($options['id']))
|
||||
{
|
||||
$parms['id'] = $options['id'];
|
||||
}
|
||||
|
||||
if(!empty($options['inline']))
|
||||
{
|
||||
$parms['selectize']['e_editable'] = $options['inline'];
|
||||
}
|
||||
|
||||
//TODO FIXME Filter by userclass. - see $frm->userlist().
|
||||
|
||||
$defValues = array();
|
||||
|
||||
foreach($defaultItems as $val)
|
||||
{
|
||||
$defValues[] = $val['value'];
|
||||
}
|
||||
|
||||
$ret = $this->text($name, implode(",",$defValues), 100, $parms);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A Rating element
|
||||
@ -4048,7 +4148,9 @@ class e_form
|
||||
$fieldID = $this->name2id($field . '_' . microtime(true));
|
||||
// Unique ID for each rows.
|
||||
$eEditableID = $this->name2id($fieldID . '_' . $row_id);
|
||||
$tpl = $this->userpicker($field, '', $ttl, $id, array('id' => $fieldID, 'selectize' => array('e_editable' => $eEditableID)));
|
||||
// $tpl = $this->userpicker($field, '', $ttl, $id, array('id' => $fieldID, 'selectize' => array('e_editable' => $eEditableID)));
|
||||
|
||||
$tpl = $this->userpicker($fieldID, array('user_id'=>$id, 'user_name'=>$ttl), array('id' => $fieldID, 'inline' => $eEditableID));
|
||||
$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
|
||||
$value = "<a id='" . $eEditableID . "' class='e-tip e-editable editable-click editable-userpicker' data-clear='false' data-tpl='" . str_replace("'", '"', $tpl) . "' data-name='" . $field . "' title=\"" . LAN_EDIT . " " . $attributes['title'] . "\" data-type='text' data-pk='" . $row_id . "' data-value='" . $id . "' data-url='" . e_SELF . "?mode={$mode}&action=inline&id={$row_id}&ajax_used=1' href='#'>" . $ttl . "</a>";
|
||||
}
|
||||
@ -4664,38 +4766,41 @@ class e_form
|
||||
case 'user':
|
||||
//user_id expected
|
||||
// Just temporary solution, could be changed soon
|
||||
|
||||
|
||||
if(!isset($parms['__options'])) $parms['__options'] = array();
|
||||
if(!is_array($parms['__options'])) parse_str($parms['__options'], $parms['__options']);
|
||||
|
||||
if((empty($value) && varset($parms['currentInit'],USERID)!=0 && varset($parms['default']) !=0) || vartrue($parms['current'])) // include current user by default.
|
||||
if((empty($value) && !empty($parms['currentInit']) && !isset($parms['default']) ) || !empty($parms['current']) || (vartrue($parms['default']) == 'USERID')) // include current user by default.
|
||||
{
|
||||
$value = USERID;
|
||||
if(vartrue($parms['current']))
|
||||
{
|
||||
$parms['__options']['readonly'] = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!is_array($value))
|
||||
{
|
||||
$value = $value ? e107::getSystemUser($value, true)->getUserData() : array();// e107::user($value);
|
||||
}
|
||||
// if(!is_array($value))
|
||||
// {
|
||||
// $value = $value ? e107::getSystemUser($value, true)->getUserData() : array();// e107::user($value);
|
||||
// }
|
||||
|
||||
$colname = vartrue($parms['nameType'], 'user_name');
|
||||
$parms['__options']['name'] = $colname;
|
||||
|
||||
if(!$value) $value = array();
|
||||
$uname = varset($value[$colname]);
|
||||
$value = varset($value['user_id'], 0);
|
||||
// if(!$value) $value = array();
|
||||
// $uname = varset($value[$colname]);
|
||||
// $value = varset($value['user_id'], 0);
|
||||
|
||||
if(!empty($parms['max']))
|
||||
if(!empty($parms['limit']))
|
||||
{
|
||||
$parms['__options']['selectize']['maxItems'] = intval($parms['max']);
|
||||
$parms['__options']['limit'] = intval($parms['limit']);
|
||||
}
|
||||
|
||||
$ret = $this->userpicker(vartrue($parms['nameField'], $key), $value, vartrue($parms['__options']));
|
||||
|
||||
|
||||
$ret = $this->userpicker(vartrue($parms['nameField'], $key), $key, $uname, $value, vartrue($parms['__options']));
|
||||
// $ret = $this->userpicker(vartrue($parms['nameField'], $key), $key, $uname, $value, vartrue($parms['__options']));
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
|
@ -170,8 +170,7 @@ if(!class_exists('plugin_pm_pm_shortcodes'))
|
||||
|
||||
if(check_class($this->pmPrefs['multi_class']))
|
||||
{
|
||||
$selectize = array('maxItems'=>10);
|
||||
$ret = e107::getForm()->userpicker('pm_to', null, null, null, array('selectize'=>$selectize));
|
||||
$ret = e107::getForm()->userpicker('pm_to', null, array('limit'=>10));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1011,6 +1011,10 @@ span.tag button.close {
|
||||
.selectize-control.multi .selectize-input > div { cursor: pointer; margin: 1px 5px 0 0; padding: 1px 3px; background: #3a87ad; color: #ffffff; border: 0 solid rgba(0, 0, 0, 0); text-shadow: 1px 1px 0 black; box-shadow: 1px 1px 0 black; font-size: 12px; font-weight: bold; }
|
||||
.selectize-control.single .selectize-input, .selectize-control.single .selectize-input.input-active, .selectize-control.single .selectize-input.input-active:hover, .selectize-control.single .selectize-input.focus, .selectize-control.multi .selectize-input, .selectize-control.multi .selectize-input.input-active, .selectize-control.multi .selectize-input.input-active:hover, .selectize-control.multi .selectize-input.focus { padding: 5px 5px 5px 5px !important; }
|
||||
|
||||
div.selectize-control .form-control { background-color: #212121; border: none; box-shadow: 2px 2px 2px rgba(0, 0, 0,0.5); }
|
||||
div.selectize-dropdown .option.active { color: #fff; background-color: #337ab7; }
|
||||
|
||||
|
||||
/* Theme Manager - Find online */
|
||||
.form-search > div > div > div > i.icon-search
|
||||
{
|
||||
@ -1258,9 +1262,6 @@ li.rssRow > div {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
body { background-color: rgb(68, 68, 68); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user