New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[imp] use layout for user field #1185

Closed
wants to merge 1 commit into
base: master
from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+90 −62
Diff settings

Always

Just for now

@@ -0,0 +1,71 @@
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
$data = $displayData;
$html = array();
$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $data->id
. (isset($data->groups) ? ('&amp;groups=' . base64_encode(json_encode($data->groups))) : '')
. (isset($data->excluded) ? ('&amp;excluded=' . base64_encode(json_encode($data->excluded))) : '');
// Initialize some field attributes.
$attr = $data->element['class'] ? ' class="' . (string) $data->element['class'] . '"' : '';
$attr .= $data->element['size'] ? ' size="' . (int) $data->element['size'] . '"' : '';
// Initialize JavaScript field attributes.
$onchange = (string) $data->element['onchange'];
// Load the modal behavior script.
JHtml::_('behavior.modal', 'a.modal_' . $data->id);
// Build the script.
$script = "
function jSelectUser_" . $data->id . "(id, title) {
var old_id = document.getElementById('" . $data->id . "_id').value;
if (old_id != id) {
document.getElementById('" . $data->id . "_id').value = id;
document.getElementById('" . $data->id . "_name').value = title;
" . $onchange . "
}
SqueezeBox.close();
}
";
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration($script);
// Load the current username if available.
$table = JTable::getInstance('user');
if ($data->value)
{
$table->load($data->value);
}
else
{
$table->username = JText::_('JLIB_FORM_SELECT_USER');
}
?>
<?php // Create a dummy text field with the user name. ?>
<div class="input-append">
<input class="input-medium" type="text" id="<?php echo $data->id; ?>_name" value="<?php echo htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8'); ?>" disabled="disabled" <?php echo $attr; ?> />
<?php
// Create the user select button.
if ($data->element['readonly'] != 'true') : ?>
<a class="btn btn-primary modal_<?php echo $data->id; ?>" title="<?php echo JText::_('JLIB_FORM_CHANGE_USER'); ?>" href="<?php echo $link; ?>" rel="{handler: 'iframe', size: {x: 800, y: 500}}">
<i class="icon-user"></i>
</a>
<?php endif; ?>
</div>

<?php // Create the real field, hidden, that stored the user id. ?>
<input type="hidden" id="<?php echo $data->id; ?>_id" name="<?php echo $data->name; ?>" value="<?php echo (int) $data->value; ?>" />
@@ -26,6 +26,20 @@ class JFormFieldUser extends JFormField
*/
public $type = 'User';
/**
* Filtering groups
*
* @var array
*/
protected $groups = null;
/**
* Users to exclude from the list of users
*
* @var array
*/
protected $excluded = null;
/**
* Method to get the user field input markup.
*
@@ -35,67 +49,10 @@ class JFormFieldUser extends JFormField
*/
protected function getInput()
{
$html = array();
$groups = $this->getGroups();
$excluded = $this->getExcluded();
$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id
. (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');
// Initialize some field attributes.
$attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
// Initialize JavaScript field attributes.
$onchange = (string) $this->element['onchange'];
// Load the modal behavior script.
JHtml::_('behavior.modal', 'a.modal_' . $this->id);
// Build the script.
$script = array();
$script[] = ' function jSelectUser_' . $this->id . '(id, title) {';
$script[] = ' var old_id = document.getElementById("' . $this->id . '_id").value;';
$script[] = ' if (old_id != id) {';
$script[] = ' document.getElementById("' . $this->id . '_id").value = id;';
$script[] = ' document.getElementById("' . $this->id . '_name").value = title;';
$script[] = ' ' . $onchange;
$script[] = ' }';
$script[] = ' SqueezeBox.close();';
$script[] = ' }';
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Load the current username if available.
$table = JTable::getInstance('user');
if ($this->value)
{
$table->load($this->value);
}
else
{
$table->username = JText::_('JLIB_FORM_SELECT_USER');
}
// Create a dummy text field with the user name.
$html[] = '<div class="input-append">';
$html[] = ' <input class="input-medium" type="text" id="' . $this->id . '_name" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"'
. ' disabled="disabled"' . $attr . ' />';
// Create the user select button.
if ($this->element['readonly'] != 'true')
{
$html[] = ' <a class="btn btn-primary modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"'
. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
$html[] = '<i class="icon-user"></i></a>';
}
$html[] = '</div>';
// Create the real field, hidden, that stored the user id.
$html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . (int) $this->value . '" />';
$this->groups = $this->getGroups();
$this->excluded = $this->getExcluded();
return implode("\n", $html);
return JLayoutHelper::render("libraries.cms.forms.fields.user", $this);
}
/**
@@ -107,7 +64,7 @@ protected function getInput()
*/
protected function getGroups()
{
return null;
return $this->excluded;
}
/**
@@ -119,6 +76,6 @@ protected function getGroups()
*/
protected function getExcluded()
{
return null;
return $this->groups;
}
}
ProTip! Use n and p to navigate between commits in a pull request.